Skip to content

security: auto-capture truncates before redaction and sends private-key fragments (medium) #132

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 prerequisites

With opt-in auto-capture enabled, a credential that crosses the last-8,000-character transcript boundary can be partially disclosed to the configured capture model. The proof demonstrates key-body fragments, not recovery of a complete usable private key.

captureSession calls buildCapturePrompt(transcript.slice(-8000), captureMax). Redaction occurs later inside buildCapturePrompt. The PEM regex needs both BEGIN and END markers. A crop starting inside a key removes BEGIN, so the remaining body and END marker survive. Prefix-based secret detection has the same general truncation-boundary hazard.

Expected behavior / acceptance

  • Redact the complete transcript before applying the character budget.
  • Add an actual capture-pipeline regression with a PEM block crossing the crop boundary; no body fragments should reach generate.text.
  • Test crop boundaries inside supported token families as well as PEM blocks, while retaining the existing reasoning/private-part exclusion tests.
  • Use a fake capture model and synthetic credentials; no paid call or live key is needed.
  • Document the limitations of inherently incomplete credential fragments rather than treating regexes as comprehensive secret protection.

The reproduction below first proves the intact synthetic PEM is redacted, then invokes the registered compaction hook and inspects the fake model's prompt, which contains key bytes and END PRIVATE KEY on the reviewed revision.

Related: #74 and #83; this concerns new capture egress, not historical-store cleanup.

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: cropping the transcript before redaction leaks a private-key fragment to capture', async () => {
  plugin = await loadPlugin(a, { autoCapture: true, captureModel: 'fake/model' });
  const keyBody = ('AbCdEfGhIjKlMnOpQrStUvWxYz0123456789+/'.repeat(50)).match(/.{1,64}/g)!.join('\n');
  const pem = '-----BEGIN PRIVATE KEY-----\n' + keyBody + '\n-----END PRIVATE KEY-----';
  const transcript = pem + '\n' + 'Ordinary discussion about the task. '.repeat(200);
  expect(redactSecrets(pem)).toBe('[redacted]');
  const cropped = transcript.slice(-8000);
  expect(cropped).not.toContain('BEGIN PRIVATE KEY');
  expect(cropped).toContain('END PRIVATE KEY');
  let finish!: () => void;
  const reachedModel = new Promise<void>(resolve => { finish = resolve; });
  Object.defineProperty(plugin.capture.generate, 'response', { get() { finish(); return '[]'; } });
  await plugin.sessionHooks.compaction({ sessionID: 'ses-capture', system: [], messages: [{ role: 'user', content: transcript }] });
  await reachedModel;
  const prompt = plugin.capture.generate.calls[0].prompt;
  expect(prompt).toContain(keyBody.split('\n')[5]);
  expect(prompt).toContain('END PRIVATE KEY');
});

Activity

  1. WhollyMindless commented on Oct 26, 2026

    @WhollyMindless
    ContributorAuthor

    Follow-up review: the reproduced capture-crop leak appears addressed by #135 at c9791ed.

    The capture pipeline now redacts the complete flattened transcript before applying the 8,000-character window. Both real compaction-hook regressions pass: a PEM block straddling the crop boundary and a supported token whose prefix would otherwise fall outside the window. The full existing suite also passes on the combined head.

    PR review and validation context. These tests use a fake capture model and synthetic credentials on Windows / Bun 1.3.10. The result establishes the crop-order fix; regex redaction still cannot guarantee protection for inherently incomplete or unrecognized credential fragments, so please preserve that limitation explicitly in the documentation. This is a review of the proposed code, not a claim that it has shipped.

  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.13 🎉

    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