Skip to content

Scrub credentials out of exported metadata, not just exported text - #370

Merged
abogartz merged 2 commits into
mainfrom
300-export-scrub
Nov 9, 2026
Merged

abogartz merged 2 commits into
mainfrom
300-export-scrub

Conversation

@abogartz

@abogartz abogartz commented Nov 9, 2026

Copy link
Copy Markdown
Owner

What this does

memory_export writes your memories to a JSONL file you can hand to another machine. Since #74 it scrubs credentials out of the memory text on the way out, because a row stored before credential-checking existed can still hold a token. It did not scrub the metadata on the same row: scope, tags, and kw (the search keywords) were written exactly as stored.

New writes cannot put a credential in those fields — the tool schema refuses control characters and the write boundary refuses credential-shaped metadata. The gap is for rows that predate those checks, and for a store someone edited by hand: exporting one shipped the token verbatim in a file whose whole purpose is leaving the machine.

This closes it with the rule #74 already stated in that file — redact the value being serialised, never the row. The store is not rewritten; only the export copy is scrubbed.

What is deliberately left alone: repo and repoPath. Those are derived origin stamps, not prose, and the import side validates them — rewriting them would break the check that stops a portable file from claiming a repository it did not come from.

Consequences worth knowing

  • An export of a legacy row now shows [redacted] where a credential was stored, in scope, tags, kw, content and issue.
  • Importing such a file creates the row with the scrubbed metadata. That is the point: a credential does not hop machines inside a memory row.
  • Nothing in the store changes, so memory_undo and the viewer still see the original bytes.

Tests

  • RED first: a legacy row whose scope and a tag hold an sk- token exported the token.
  • GREEN: the exported line carries [redacted] in all three metadata fields, and the store file is byte-identical before and after the export.
  • One existing pin asserted the old verbatim behaviour (write-caps: "legacy secrets remain verbatim…"). It now asserts the new contract, and additionally pins that the store still holds the original credential-shaped scope and secret — redaction stays forward-only. Recall and forget by that scope still work, which is what that test was really about.
  • README: the limits bullet no longer claims the export writes everything verbatim.

bun run gate green: 1129 unit tests + 30 terminal/BDD tests against a real host, 0 fail. bunx tsc --noEmit clean; lint and format identical to main's baseline.

Closes #300.

#74 slice 1 redacted content and issue at serialisation and left the metadata
fields as stored. New writes cannot carry a credential in scope/tags/kw (the
schema rejects control characters, the write boundary rejects credential-shaped
metadata), but a row stored before those checks — or hand-edited into the store —
exported its token verbatim into a file meant to leave the machine.

Same rule as slice 1: redact the value being serialised, never the row. repo and
repoPath stay as stored: they are derived stamps, and rewriting them would break
the import-side validation that keeps a portable file honest.

RED first: a legacy row whose scope and a tag hold an sk- token exported the
token. GREEN: the exported line carries [redacted] and the store file is
byte-unchanged. write-caps' legacy-row pin, which asserted the old verbatim
export, now asserts the new contract and additionally pins that the STORE still
holds the original scope and secret (redaction stays forward-only).

README: the limits bullet no longer claims memory_export writes everything
verbatim.
@abogartz

abogartz commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Adversarial self-review (author-side, not independent)

Attacked the "leave repo/repoPath alone" decision and the import round-trip. Both survive.

Verified clean:

  • The strongest candidate for a metadata credential — an origin URL with an embedded token (https://user:ghp_…@host/repo) — cannot ride out through repo: resolveRepo() stores a 12-hex sha1 of the normalised remote, never the raw URL. repoPath is a local filesystem path; scrubbing it would break the import-side provenance check, exactly as the body argues. Leaving both is the right trade.
  • Partial replacement keeps the row usable: deploy-[redacted] still passes the import scope validation (no control characters, not credential-shaped), so a scrubbed legacy row imports instead of being dropped.
  • m.tags?.map(redactSecrets) — the loader hands back string[], and Array.map passing index/array as extra arguments is harmless to a one-parameter function.
  • Forward-only is pinned on both sides: the new test asserts the store file is byte-identical after export, and the rewritten write-caps pin asserts the store still holds the original credential-shaped scope while the export does not.
  • README limits bullet now matches the code. CI green on all four jobs; git merge-tree against current main is clean.

Findings:

  1. 🔵 Known-limitation, worth one README clause. redactSecrets is prefix-family based (known token prefixes, PEM markers, high-entropy credential-named assignments). A credential in scope/tags/kw that matches no family still exports verbatim. This is not a regression — same scrubber as Secrets already in the store are never scrubbed, and memory_export writes them verbatim #74 on content — but the bullet reads like a guarantee where it is a best-effort sweep.
  2. 🔵 Round-trip consequence nobody wrote down: a scrubbed legacy row imported back into the SAME store will not dedup against the original row (different scope/content hash), so the operator gets a second row. Correct security trade — a duplicate beats a token — but a user who exports, hand-inspects, re-imports will see it and file a bug. One sentence in the consequences section of memory_export writes scope/tags/kw unscrubbed; README export claim is stale #300 would preempt that.

Verdict: approve. Branch is 23 commits behind main; merge-tree clean, landing is mechanical.

@abogartz
abogartz merged commit 05dd81a into main Nov 9, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.22.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz

abogartz commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Merged into main at 05dd81a with admin override (solo author). Landed in the order the self-review set: this PR before #368. The review's follow-ups are tracked separately (#375 for the re-tag scan; the optional nits were left as written).

@abogartz
abogartz deleted the 300-export-scrub branch November 19, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory_export writes scope/tags/kw unscrubbed; README export claim is stale

1 participant