Skip to content

Secrets already in the store are never scrubbed, and memory_export writes them verbatim #74

Closed

Description

@abogartz

Part of #83.

Problem

PR #67 stops credentials from being written from now on, but nothing deals with credentials that are already in the store, and memory_export will hand them to anyone holding the file.

Verified on main and on the #67 branch:

What to decide and build

  1. Detection: reuse src/secrets.ts as a scanner and report where matches live (day file, snapshot, evidence) without echoing the secret — offsets/line numbers and the matched family only.
  2. Scrub tool: an explicit, snapshot-first, audited operation (mirroring prune: reason + snapshot + deletions-style audit) that replaces matches with [redacted] across day files. Snapshots should be handled too, or the scrub is cosmetic while memory_undo still restores the secret.
  3. Policy statement in the README: redaction is forward-only; scrubbing an existing store is an explicit operation; export may contain secrets that predate it.
  4. ts stability interaction: rewriting a row's content in place must keep its ts (row identity) — check that this still invalidates an epoch under PR fix(inject): refresh the frozen memory block when its rows change #65's content-hashed storeVersion (it does) and that the blocklist/blocklist-free rows behave as expected.

Context

Split out of the #67 review, where the maintainer ruled to keep the best-effort scrub and document it rather than expanding it into a migration in that PR.


Slice 1 acceptance criteria: redact at export

Added 2026-11-02 at the maintainer's direction so this is executable. This slice closes the export face of the problem only. Items 2, 3 and 4 above (scrub tool, snapshots, README policy) stay open as follow-ups.

Verified on main today, so the claims below are current:

  1. A new test file under test/ fails at the merge-base and passes on the branch. Report both pass/fail counts.
  2. A row whose content holds a sk--prefixed token exports JSONL that contains [redacted] and does not contain the token.
  3. Same guarantee for the issue field, which is free text.
  4. A row with no credential-shaped text serialises byte-identically to today's output. No reformatting, no key reordering, no whitespace change.
  5. The header line and the returned count are unchanged.
  6. Export stays a read path: after exporting, re-read the store and assert the original row content is untouched. Redaction happens on the value being written, never on the row.
  7. bun run typecheck, bun run lint and bun run test all pass.
  8. git diff --name-only against the base lists src/portable/export.ts, the one new test file, and test/write-caps.test.ts — nothing else. The change to test/write-caps.test.ts is confined to the two lines that assert a stored credential survives export (currently 165-166). They must still assert the row is present via scope, and must now assert the credential is replaced by [redacted]. No other assertion in that file may change.

Out of scope: rewriting day files or snapshots, memory_undo, memory_import, writeExport's flags or mode, EXPORT_HEADER, EXPORT_VERSION, and any pattern change in src/store/secrets.ts.

If a criterion cannot be met without touching an out-of-scope file, stop and label this fix:blocked rather than widening the diff.

Activity

  1. added
    enhancement
    on Oct 24, 2026
  2. added
    store-security
    on Oct 24, 2026
  3. added
    severity:high
    on Oct 30, 2026
  4. abogartz commented on Oct 30, 2026

    @abogartz
    OwnerAuthor

    Severity triage 2026-10-30 — severity:high

    Reviewed against main @ 525ed89. Still unbuilt: no scrub operation exists anywhere — grep -rn '"scrub\|scrub:' src/index.ts → zero hits. What ships today is forward-only redaction (src/secrets.ts, used on capture egress) plus a scrub at the evidence write boundary (src/evidence.ts:50 scrubFields).

    Marked high, not critical, because it requires a secret to already be in the store — it is a latent-condition ticket, not a live leak. But it stays above the mediums because when it does bite, the exposure is compounding and every existing mitigation stops at the write:

    Your own framing in the body is the right bar: "must not be cosmetic while memory_undo --force can restore a redacted secret from a snapshot." That is the acceptance test that matters — a scrub of day files alone leaves the secret one undo away, so snapshots must be in scope or the ticket isn't done.

    Sequence note: this was written as "sharpest after #24" — #24 (path containment) is now CLOSED, so nothing blocks it. The ts-stability interaction you flagged (rewriting content in place must preserve row identity while still invalidating a content-hashed epoch) is still a real constraint to pin in the same PR.

  5. WhollyMindless commented on Nov 1, 2026

    @WhollyMindless
    Contributor

    Before proposing an implementation, could we settle the recovery policy for this? Your requirement that snapshots must not let force-undo restore a scrubbed secret is clear. The remaining tension is with the issue's "snapshot-first" direction: an ordinary pre-scrub snapshot would preserve exactly the values being removed.

    My proposed default is an explicit dry-run/apply operation that sanitizes existing snapshots as well as live rows, preserves row timestamps, and creates only sanitized recovery copies. It would retain no unsanitized backup in the normal restore namespace. That makes false-positive redaction deliberately irreversible through ordinary undo, which deserves an explicit operator warning and your agreement.

    1. Is that the intended policy, or do you want a separately specified, operator-managed recovery mechanism for false positives? I would avoid silently creating a secret-bearing backup elsewhere.
    2. For interrupted or partially failed scrubs, is a clearly reported, resumable partial result acceptable, with no success claim until all in-scope live/history files are clean? Multi-file replacement cannot honestly promise an atomic store-wide scrub using the current write primitives.

    The regression bar would include force-undo of every retained snapshot after a successful scrub, plus interrupted-operation recovery, with scan/audit output never echoing matched secrets. Happy to narrow or defer this; this comment asks for design direction and does not claim implementation.

  6. added
    agent:ready
    on Nov 2, 2026
  7. abogartz commented on Nov 2, 2026

    @abogartz
    OwnerAuthor

    Scope ruling, 2026-11-02: slice 1 is export-only, per the acceptance criteria added above. Snapshots, the scrub tool and the README policy statement stay open in this ticket.

    @WhollyMindless your recovery-policy question is the right question and slice 1 does not answer it. It gates the scrub-tool slice, which rewrites durable data, so it needs its own decision about whether an unsanitized pre-scrub snapshot may exist at all. I have filed that as a separate ticket so it has somewhere to be argued that is not blocking this one.

    Slice 1 restores nothing and rewrites nothing: redaction happens on the value being serialised into the export file, never on the stored row.

    Two claims in the original body are now stale and I corrected them inline: export destination is confined to <memory-root>/exports/ via resolveContained since #143, so #24 is not part of this; and the evidence log is already scrubbed at its write boundary (src/evidence/record.ts:52 scrubFields, called at :116), so that "worth confirming" item is settled. What remains genuinely unbuilt is the scrub operation itself — git grep for a scrub entry point on main returns nothing.

  8. added
    fix:working
    fix:blocked
    and removed
    fix:working
    on Nov 2, 2026
  9. ocsi-fixer commented on Nov 2, 2026

    @ocsi-fixer

    Blocked: criterion 2 contradicts an existing in-scope-forbidden test. Reproduced the defect on main @ bf7f6d2 (src/portable/export.ts serialises content/issue with no redaction), implemented the slice (redact on the serialised value via redactSecrets, store untouched), and added test/export-redaction.test.ts: 3 pass / 2 fail at the merge-base, 5 pass / 0 fail on the branch. But test/write-caps.test.ts:166 asserts readFileSync(exportFile, "utf8")).toContain(legacySecret) — it pins that memory_export writes a stored ghp_ secret verbatim (the behavior this ticket calls the defect). Criterion 2 forbids a stored token in the export, criterion 7 requires bun run test green, and criterion 8 limits the diff to src/portable/export.ts plus the one new test file, so the pin cannot be updated inside scope; measured: bun run typecheck and bun run lint pass, bun run test is 864 pass / 14 skip / 1 fail (write-caps.test.ts:166), and write-caps alone is 10 pass / 0 fail at the merge-base and fails only under the fix. Needs a maintainer ruling: either amend the file scope to allow updating test/write-caps.test.ts:165-166 to the redacted expectation, or restate criterion 2 — no implementation satisfies both as written.

  10. abogartz commented on Nov 2, 2026

    @abogartz
    OwnerAuthor

    Ruling: criterion 8 amended, fix:blocked cleared. Proceed.

    test/write-caps.test.ts is now in scope, limited to the two lines that assert a credential survives export.

    That test exists to prove an export is a confined copy of the store (#24). It used a credential-shaped string as convenient payload. Its purpose is not "a secret survives export" — that is the defect this ticket reports. Keep the purpose, change the expectation: assert the row is still present via scope, assert the credential is replaced by [redacted].

    No other assertion in that file may change. Everything else you measured stands, including the 3 fail → 5 pass differential and leaving the stored row untouched.

  11. removed
    fix:blocked
    on Nov 2, 2026
  12. added
    fix:working
    fix:pr-open
    and removed
    fix:working
    on Nov 2, 2026
  13. added a commit that references this issue on Nov 2, 2026
  14. abogartz-opencode-self-improvement commented on Nov 2, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.15.9 🎉

    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

    agent:readyenhancementfix:pr-openreleasedseverity:highstore-security

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions