Skip to content

security: editing a repo-private memory in the viewer makes it global (high) #129

Closed

Description

@WhollyMindless

Verified against upstream main at cf9b73c4f352bdc1fbd3c1332fca4183a63e3fb8 (0.14.9) during the 2026-10-26 security review, using Windows and Bun 1.3.10. Severity is a review priority, not a calculated CVSS score. The reproduction invokes actual plugin hooks/tools through the repository's fake-host harness; it is not a real-host end-to-end exploit.

Impact and cause

An ordinary typo correction in the viewer makes a repository-private memory eligible for recall and automatic injection in every other project.

editMemory appends the replacement without copying target.repo or target.repoPath. The standalone viewer has no repo scope, so appendMemory leaves it unstamped. isVisibleHere treats unstamped rows as global. No hostile website, forged Host, XSS, or cross-site request is needed: the normal same-origin edit is sufficient.

The usual UI also omits the old tags and issue, so editing drops import/auto-capture provenance. The direct privacy reproduction below proves the origin-stamp loss.

Expected behavior / acceptance

  • Editing a row preserves its repository key/path and does not broaden visibility; a row from A stays invisible in B after editing.
  • Preserve source/provenance metadata when omitted from an edit request.
  • Making a row global requires an explicit action; it must not follow from the viewer lacking a session scope.
  • Preserve origin metadata in deletion audit records and restore flows, so restoration can retain the original visibility. Handle legacy unstamped audit rows deliberately.
  • Add a regression through the actual viewer edit route and repository-filtered reads, not only an isolated append test.

Related work

The README documents global viewer restores; the reproduced failure also affects ordinary edits. Related scoping/provenance work: #8, #37, #83.

Reproduction

Save the following as security-review-repro.test.ts at the repository root of the reviewed revision and run bun test ./security-review-repro.test.ts --timeout 20000. All files are temporary fixtures and any model API is fake. These assertions deliberately confirm the current vulnerable behavior; passing means the bug reproduced, not that it is fixed. The fixtures are retained in the OS temp directory for inspection.

Self-contained Bun reproduction
// Review-only proofs against upstream cf9b73c (0.14.9). No real stores, keys, or model calls.
import { beforeEach, afterEach, expect, test } from 'bun:test';
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { loadPlugin, type LoadedPlugin } from './test/harness.ts';
import { appendMemory, loadAll, isActive, isVisibleHere } from './src/memory.ts';
import { rememberSessionDir, resetSessionScopes, resolveRepo, setRepoScope } from './src/repokey.ts';
import { resetState, setCurrent } from './src/state.ts';
import { dateStr, evidenceDir } from './src/config.ts';
import { redactSecrets } from './src/secrets.ts';
import { resetCaptureCooldowns } from './src/index.ts';
import { startViewer, type ViewerServer } from './src/viewer/server.ts';

let root: string;
let a: string;
let b: string;
let plugin: LoadedPlugin | undefined;
let viewer: ViewerServer | undefined;
beforeEach(() => {
  root = mkdtempSync(join(tmpdir(), 'osi-security-proof-'));
  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');
  process.env.OPENCODE_CBM_BIN = join(root, 'no-graph-binary');
  resetState(); resetSessionScopes(); resetCaptureCooldowns(); setRepoScope(null);
});
afterEach(async () => {
  viewer?.server.stop(true); viewer = undefined;
  await plugin?.cleanup(); plugin = undefined;
  resetState(); resetSessionScopes(); setRepoScope(null);
  delete process.env.OPENCODE_MEMORY_DIR;
  delete process.env.OPENCODE_COMMANDS_DIR;
  delete process.env.OPENCODE_CBM_BIN;
  // Keep only synthetic temp fixtures for inspection; never touch user state.
});

test('confirmed: viewer edit turns a repo-private memory into a global memory', async () => {
  const scopeA = resolveRepo(a);
  const ts = await appendMemory({ type: 'context', scope: 'customer', content: 'Private customer migration schedule.',
    repo: scopeA.key, repoPath: scopeA.path });
  setRepoScope(resolveRepo(b));
  expect((await loadAll()).filter(isVisibleHere)).toHaveLength(0);
  setRepoScope(null); // separate viewer process has no repository scope
  viewer = await startViewer(0);
  const response = await viewer.server.fetch(new Request(new URL('/api/edit', viewer.url), {
    method: 'POST', headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ ts, type: 'context', scope: 'customer', content: 'Private customer migration schedule, corrected.', reason: 'Correct typo' }),
  }));
  expect(response.status).toBe(200);
  setRepoScope(resolveRepo(b));
  const visibleInB = (await loadAll()).filter(isActive).filter(isVisibleHere);
  expect(visibleInB).toHaveLength(1);
  expect(visibleInB[0].repo).toBeUndefined();
  expect(visibleInB[0].content).toContain('Private customer');
});

Activity

  1. WhollyMindless commented on Oct 26, 2026

    @WhollyMindless
    ContributorAuthor

    Follow-up review: the reproduced viewer visibility bug appears addressed by #133 (a8c5b7a, exercised in the combined #135 head c9791ed).

    The real viewer-route regressions pass: editing a private A row keeps it invisible in B; omitted issue/tags/keywords survive the edit; deletion audit and restore preserve the origin stamp; a legacy unstamped row remains global.

    PR review and validation context. This is an assessment of the proposed code, not a claim that it has merged or shipped. The remaining blockers reported on the stack concern #127/#128/#131 and merge error reporting.

  2. added a commit that references this issue on Oct 28, 2026
  3. abogartz-opencode-self-improvement commented on Oct 28, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.14.12 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions