Repository navigation
fix(capture): keep secrets and reasoning out of capture and the store - #67
Conversation
Auto-capture sent the whole transcript, including pasted API keys and the model's reasoning parts, to the capture model, and stored whatever came back. A key in the transcript ended up in the store and in later system prompts. - flattenTranscript skips reasoning/thinking parts. - New src/secrets.ts redacts well-known token families, bearer tokens, PEM private keys and high-entropy values assigned to *_KEY/*_TOKEN/ *_SECRET/*_PASSWORD names. It's applied to the capture prompt and in runWriteGate, so manual, imported, updated and captured writes share it. - Env-var references and identifiers are left alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
abogartz
left a comment
There was a problem hiding this comment.
Request changes. The leak is real, the redactor is better than I expected, and the maintainer has decided to keep the scrub — what's missing is documentation and honest scoping of what "one rule set" actually covers.
Verified on 0.8.1 (main @ 4643ec4) and on your branch
flattenTranscripton main ships reasoning and thinking parts to the capture model, including the fallback case:assistant: internal chain of thought mentioning sk-…→ on your branch the transcript is exactlyuser: please remember the flimflam widget build command.buildCapturePrompton main embeds a pasted key verbatim; on your branch it is[redacted].runWriteGateredacts before hashing/analysis/persistence: amemory_remembercarryingsk-…stores no key on your branch (main stores it verbatim).- Independent false-positive battery (my cases, not yours): redacted 5/5 secret shapes (
sk-,ghp_,Bearer <token with digits>, PEM block,API_KEY="aB3dE5fG7hI9jK1lM3nO"); left untouched 10/10 realistic keepers —API_KEY=process.env.OPENAI_API_KEY,const API_TOKEN = resolveTokenName,Bearer authentication-scheme,Authorization: Bearer <your-account-slug-2024>,bun test ./test/, a 40-char action SHA pin, an issue/logfmtfilename reference, ordinary prose about API keys. So "leaves ordinary code alone" holds. Known deliberate misses: hex-only secrets (SESSION_SECRET=deadbeef…, two character classes) and low-class passwords. - 291 pass / 4 skip / 0 fail; 3 of your tests fail against main's source;
tscclean.
Change 1 (required): README section
There is no documentation change in this PR, and it introduces a behaviour that silently rewrites what the model asked to store. Maintainer ruling: the tool reply stays as it is (no redacted= notice); disclosure belongs in the README. Please add a section covering:
- what runs where:
src/secrets.tsat the write gate overscope,content,issue,tags, and on the capture prompt; - the token families covered (the list above) and that matches become
[redacted]; - that it is best-effort, not a guarantee — with the concrete misses (hex-only secrets, low-character-class passwords, credentials in prose without an assignment);
- that the tool still reports
Rememberedwhen it redacts, so the stored text may differ from what was sent; - that existing stores are not scrubbed and
memory_exportwrites whatever is already stored, verbatim; - that auto-capture is off by default, so the capture-egress half protects opt-in installs while the gate half applies to every install (please state the severity that way in the body too).
Change 2 (required): the claim "no write path can retain a credential" is not true today
The viewer's edit and restore endpoints call appendMemory directly — that is main's own comment at src/memory.ts:165 ("the viewer's restore/edit paths do not [go through the gate]"). I confirmed it: writing through appendMemory stored sk-abcdef1234567890ABCDEFGH verbatim on your branch.
Two acceptable resolutions:
- Preferred: scrub in
appendMemory(the single write choke point) and keep the gate scrub so hashing/dedup/canonical analysis see the redacted text. This is the pattern #64 uses for control characters, and it makes the sentence true instead of qualified. - Acceptable: keep it gate-only, but narrow the code comment and the PR body to "every gate-fed write path", and keep the viewer gap visible in the follow-up I filed.
Change 3 (small): don't silently rewrite metadata
scope and tags are scrubbed too. If a scope ever matches a pattern it becomes [redacted], i.e. the memory is silently re-scoped — worse for a retrieval system than a rejection, because it changes where the row shows up with no signal. #64 rejects bad metadata with a reason; I'd align: rewrite content (the maintainer's call), reject scope/tags/issue that contain a credential-shaped value.
Not a request
Skipping reasoning/thinking is right regardless of provider, and also removes the largest chunk of transcript tokens from the capture call. The hadPrivatePart guard (don't fall back to top-level text for a message that only had private parts) is the correct detail and I verified it works.
…ument it Review follow-up for abogartz#67: - appendMemory redacts content too, so the viewer's edit and restore-entry paths are covered, not just gate-fed writes. - Credential-shaped scope/tags/issue are rejected (gate block credential_in_metadata; appendMemory throws) instead of being rewritten. Only content is rewritten. - The auto-capture outcome evidence no longer records a raw scope. - README section: what runs where, families covered, known misses, forward-only (see abogartz#74), and capture being opt-in. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/capture.ts # src/gates.ts # src/index.ts # src/memory.ts # test/write-caps.test.ts
|
Thanks. Pushed and merged with main (0.8.4), taking your preferred route:
I also found and fixed one leak while doing this: the auto-capture outcome evidence logged the raw candidate scope, which could hold a credential. It's redacted now, with a test. |
abogartz
left a comment
There was a problem hiding this comment.
Approving. All three items from my request-changes review are done and verified on the combined branch (all five batch PRs merge cleanly onto 0.8.4, as you said — I checked), and your open question at the bottom turned up something real.
Verified live on my own probes against the merged source:
- The choke point closes the viewer path: calling
appendMemorydirectly withsk-…content — exactly the/api/editand/api/restore-entrybypass — stores[redacted], raw key absent from the day file. - Reject, not rewrite: a credential-shaped
scopethrows fromappendMemoryand nothing is written; the gate blocks withcredential_in_metadataon a credential-shaped tag; the evidence log contains neither thexoxb-…nor thesk-…value. Matches #64's stance. - README "Secret redaction" says what runs where, names the known misses (hex-only, low-entropy prose, no-assignment credentials), keeps the
Rememberedreply honest ("stored text can differ from what was sent"), and states redaction is forward-only withmemory_exportwriting legacy rows verbatim (#74 stays open deliberately).
Your session.idle question — you are right, and it is worse than a test-only gap. On a real 2.x host the envelope carries the payload under event.data: our own identity handler already does ev.data ?? ev.properties precisely because session.created has no properties there. The capture handler you cite (now index.ts:869) reads only event.sessionID ?? event.properties?.sessionID, so on 2.x every session.idle hits the typeof sid !== "string" guard and capture silently never runs — in this repo's history on main, not something this PR introduces. Consistent with that: no auto_capture_* evidence row exists in the live store's entire history, though auto-capture was also off in my config, so that alone was never proof — the envelope analysis is. I am filing a follow-up issue with the one-line fix (?? event.data?.sessionID) and a fake-2.x-host test; deliberately not asking for it in this PR, which is already at the right size.
Combined-batch gates: 324 pass / 4 skip / 0 fail, tsc --noEmit clean, biome exit 0.
|
🎉 This PR is included in version 0.8.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
When auto-capture runs, it sends the flattened transcript to the capture model and stores what comes back. Separately, any write can store a credential verbatim. I found both while reviewing 0.8.0, and both are unchanged in 0.8.1. Updated after your review: redaction now also runs in
appendMemory, metadata is rejected instead of rewritten, and there's a README section.The problem and its reach. Auto-capture is off by default, so the capture half affects opt-in installs. The write half affects every install.
reasoning/thinkingparts are also sent to the capture model.memory_rememberand the other write paths store a credential verbatim, and from then on it's injected into the system prompt.#38 covers instruction-shaped content, not credentials.
Change:
flattenTranscriptskipsreasoning/thinkingparts, including the fallback to top-level text for a message that only had private parts.src/secrets.ts, a small, best-effort redactor:sk-…,ghp_/gho_/github_pat_,xoxb-/xoxp-,AKIA…,AIza…;Bearer <token>, when the token contains a digit;*_KEY/*_TOKEN/*_SECRET/*_PASSWORD/password.[redacted]):runWriteGate, before hashing, canonical analysis, dedup, evidence and persistence. That coversmemory_remember,memory_update,memory_import, auto-capture candidates andmemory_init;appendMemory, the single write choke point. That also covers the viewer's/api/editand/api/restore-entry, which bypass the gate.scope,tagsorissueis refused, so a memory is never silently re-scoped:credential_in_metadatablock with a hint naming the field;appendMemory, as a thrown error.This matches fix(inject): keep every rendered memory field on its framed line #64's reject-don't-rewrite approach for control characters. The evidence records only the field names, and the auto-capture outcome record no longer logs a raw scope.
/api/restore, rows already in a store, and lookups (memory_recall/memory_forget/memory_exportby scope still match a legacy row, so it can still be removed).memory_rememberstill repliesRememberedwhen it redacts, so the stored text can differ from what was sent (per your ruling, no notice in the reply). Finally, it says redaction is forward-only: existing stores aren't scrubbed andmemory_exportwrites them verbatim (Secrets already in the store are never scrubbed, and memory_export writes them verbatim #74).Not changed, but worth a look: capture reads
event.sessionID ?? event.properties.sessionID(index.ts:869). On opencode 2.x,session.idlecarries it inevent.data.sessionID, which your identity handler a few lines up already reads. In a fake 2.x host, capture made 0 model calls. Does it fire for you on a real 2.x host?Tests:
test/capture.test.ts:test/write-caps.test.ts:appendMemorycalled directly redacts content (yoursk-abcdef…repro).credential_in_metadataand no secret in evidence.memory_rememberreplies with the unchangedRemembered: ….test/viewer.test.ts: a viewer edit stores the replacement redacted.With the source change reverted, the new tests fail.
Checks (Linux, Bun 1.4.4, on 0.8.4):
bun test ./test/310 pass, 4 skip, 0 fail.bun run test:e2eagainst opencode 2.0.26: 9 pass.tsc --noEmitis clean, andbiome lintexits 0 with warnings unchanged frommain. Nothing here is platform-specific.Merge order: main (0.8.4) is merged in. Where #64 and this PR both validate metadata (the gate and
appendMemory), the control-character check runs first, then the credential check, then content redaction. It applies cleanly alongside #62, #66 and #76 and #77; I merged all of them together on 0.8.4 to check.🤖 Generated with Claude Code