Skip to content

feat: opt-in secret/credential redaction for snapshot data#2207

Closed
vivekchand wants to merge 1 commit into
mainfrom
auto/issue-2198-secret-redaction
Closed

feat: opt-in secret/credential redaction for snapshot data#2207
vivekchand wants to merge 1 commit into
mainfrom
auto/issue-2198-secret-redaction

Conversation

@vivekchand
Copy link
Copy Markdown
Owner

Closes #2198

Summary

  • clawmetry/redact.py (new, ~96 LOC): compile_patterns() caches compiled regexes for 10 default secret shapes (Bearer tokens, sk-*, ghp_*, gho_*, glpat-*, xox[baprs]-*, AWS keys, and generic api_key/password/token/secret assignments); redact_value() recurses dict/list/str; build_redactor(config) returns a bound callable or None when disabled.
  • clawmetry/sync.py (~12 LOC changed): _project_snapshot_messages() gains an optional redactor param — secrets are scrubbed after the raw-key strip and before size-capping, so truncated text is also clean. _build_transcripts() loads config, builds the redactor, and passes it down.
  • tests/test_redact.py (new, ~170 LOC): 22 unit tests covering each default pattern, nested dict/list/str recursion, no-match passthrough, default-off behaviour, custom replacement text, custom patterns, bad-pattern graceful fallback, and empty-input edge cases.

Test plan

  • python -m pytest tests/test_redact.py -v → 22 passed
  • Syntax check: python -m py_compile clawmetry/redact.py passes
  • Default-off: no behaviour change for existing users (build_redactor({}) returns None)
  • Enable with {"redact": {"enabled": true}} in config; verify curl -H 'Authorization: Bearer sk-abc…' appears as [REDACTED] in snapshot messages

Generated by Claude Code

Adds opt-in redaction layer (off by default) that scrubs secrets from
session transcript snapshots before they leave the machine. Covers
Bearer tokens, OpenAI sk- keys, GitHub/GitLab PATs, Slack tokens,
and generic api_key/password/token assignments.

Enable with config.redact.enabled = true; configure replacement text,
scope (snapshot vs ingest), and custom patterns as needed.

Closes #2198

Co-Authored-By: Claude <noreply@anthropic.com>
@vivekchand
Copy link
Copy Markdown
Owner Author

Superseded by the already-merged #2204 (feat(security): redact secrets at the ingest chokepoint).

#2204 redacts inside LocalStore.ingest() — a single chokepoint upstream of every downstream consumer, including the snapshot builder this PR was going to scrub. By the time _project_snapshot_messages() reads the row, the secret is already [REDACTED:<sha8>], so this PR has no incremental coverage; in fact it would be strictly weaker than #2204 alone, which also protects local DuckDB-on-disk.

Differences I checked, just to be thorough:

Closing as duplicate. The work was solid — just landed second.

🤖 Filed by Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: secret/credential redaction before storage + cloud sync

2 participants