Repository navigation
Description
Reproduced on current main 91f7a56 (v0.14.13), Windows/Bun 1.3.10, through the registered memory_undo tool.
The model-facing rollback path ignores its execution context and has no repository authorization. It restores a shared whole-day file, so force:true supplied by a session in A can remove private B memories that the same session cannot recall, forget, or merge.
Deterministic sequence:
- Seed an A row and snapshot its day file.
- Append a private B row to that same day file.
- A's
memory_recallcannot see B's marker (control). - A's
memory_undo({list:true})supplies the snapshot name. - A calls
memory_undo({snapshot,force:true}): success is reported and B's row disappears from the live store.
Observed: Restored ... from force snapshot; foreignSurvives=false. The safety snapshot exists, so this is unauthorized live-store rollback, not irrecoverable erasure. The default non-force mode correctly refuses this particular divergent snapshot; choosing force bypasses the concurrency check but should not grant authority over another repository.
Cause: tool entry has execute(args), calls restoreSnapshot without a Reader, and that helper replaces the entire shared file. Path containment protects the filesystem location, not ownership of its rows.
Suggested fix / acceptance: thread the caller's immutable Reader into model-facing rollback; preserve foreign live rows and do not revive/replace foreign snapshot rows in any mode. A simpler fail-closed alternative is to refuse mixed-repository restores from plugin sessions and direct the user to the explicit admin viewer. Keep the viewer/admin full-store rollback contract. Include a mixed A/B day-file test for force, merge, and default modes, plus same-repository controls.
Related: #131's rule that a known row id is not authority. A known snapshot name and model-selected force flag likewise are not admin authorization.
Runnable regression test (expected red on v0.14.13)
Save as review-undo-ownership.test.ts at the repository root, then run bun test ./review-undo-ownership.test.ts. Uses the repository's existing inert host harness and temporary stores; no live memory or model calls.
import { afterEach, beforeEach, expect, spyOn, test } from "bun:test";
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { basename, dirname, join, resolve } from "node:path";
import { loadPlugin, type LoadedPlugin } from "./test/harness.ts";
import { appendMemory, loadAll, snapshotFiles } from "./src/memory.ts";
import { rememberSessionDir, resetSessionScopes, resolveRepo, setRepoScope } from "./src/repokey.ts";
import { resetState } from "./src/state.ts";
import * as evidence from "./src/evidence.ts";
let root: string, a: string, b: string;
let plugins: LoadedPlugin[];
beforeEach(() => {
root = mkdtempSync(join(tmpdir(), "osi-review-v01413-"));
a = join(root, "repo-a"); b = join(root, "repo-b");
mkdirSync(a); mkdirSync(b);
process.env.OPENCODE_MEMORY_DIR = join(root, "memory");
process.env.OPENCODE_COMMANDS_DIR = join(root, "commands");
resetState(); resetSessionScopes(); setRepoScope(null); plugins = [];
});
afterEach(async () => {
for (const p of plugins) await p.cleanup();
resetState(); resetSessionScopes(); setRepoScope(null);
delete process.env.OPENCODE_MEMORY_DIR; delete process.env.OPENCODE_COMMANDS_DIR;
if (dirname(resolve(root)) !== resolve(tmpdir()) || !basename(root).startsWith("osi-review-v01413-")) {
throw new Error("Unexpected fixture cleanup path");
}
rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
});
async function plugin(dir: string | null) {
const p = await loadPlugin(dir); plugins.push(p); return p;
}
async function seed(dir: string, content: string) {
const scope = resolveRepo(dir);
return appendMemory({ type: "context", scope: "planning", content, status: "open", repo: scope.key, repoPath: scope.path });
}
const ctx = (sessionID: string) => ({ sessionID, id: "review-proof" });
const candidate = { type: "context", scope: "planning", status: "open", content: "UNRESOLVED_A_PRIVATE_RELEASE_PLAN" };
test("force undo from A must preserve a private B row that A cannot read", async () => {
const pa = await plugin(a);
const own = await seed(a, "A_SNAPSHOT_BASELINE");
const file = (await loadAll()).find(m => m.ts === own)!.file;
const [snapshot] = await snapshotFiles([file]);
const foreign = await seed(b, "B_PRIVATE_ROW_ADDED_AFTER_A_SNAPSHOT");
const hidden = await pa.tools.memory_recall.execute({ query: "B_PRIVATE_ROW_ADDED_AFTER_A_SNAPSHOT" }, ctx("ses-a"));
expect(hidden.content).not.toContain("B_PRIVATE_ROW_ADDED_AFTER_A_SNAPSHOT");
const listed = await pa.tools.memory_undo.execute({ list: true }, ctx("ses-a"));
expect(listed.content).toContain(basename(snapshot!));
const result = await pa.tools.memory_undo.execute({ snapshot: basename(snapshot!), force: true }, ctx("ses-a"));
const foreignSurvives = (await loadAll()).some(m => m.ts === foreign);
console.log("foreign-undo", JSON.stringify({result: result.content, foreignSurvives}));
expect(foreignSurvives).toBe(true);
});
test("control: default undo refuses a rollback that would erase a later row", async () => {
const pa = await plugin(a);
const own = await seed(a, "A_SNAPSHOT_BASELINE");
const [snapshot] = await snapshotFiles([(await loadAll()).find(m => m.ts === own)!.file]);
const foreign = await seed(b, "B_LATER_PRIVATE_ROW");
const result = await pa.tools.memory_undo.execute({ snapshot: basename(snapshot!) }, ctx("ses-a"));
expect(result.content).toContain("Undo refused");
expect((await loadAll()).some(m => m.ts === foreign)).toBe(true);
});
Activity
WhollyMindless commentedon Oct 28, 2026
Taking this one — same branch as #143 (
fix/security-143-153, off91f7a56/ 0.14.13): both issues are the identical missing-threading pattern,execute(args)entries that never resolvereaderFromSid, so the fix rides together as one "finish entry-point breadth" review.Plan per the acceptance criteria:
test/as the regression.Merge main (v0.14.14, abogartz#157) into fix/security-143-153
test(security): probes for export breadth and undo ownership (#143 #153)
fix(security): export and undo carry the caller's reader (#143 #153)
Merge pull request #156 from WhollyMindless/fix/security-143-153
chore(release): 0.14.15 [skip ci]
WhollyMindless commentedon Oct 28, 2026
Closing as fixed by #156, merged in 1bd2123 and included in v0.14.15. Independent verification of final head 834ccba confirmed foreign live rows are preserved and foreign snapshot rows are not resurrected by session rollback; check, merge, force, unresolved-session, and admin controls passed. Verification: #156 (comment) .