Repository navigation
feat(redact): redact secrets/PII before traces and CI artifacts hit disk - #4
Merged
Merged
Conversation
Redactor with built-in secret rules (on by default: provider API keys, GitHub/Slack/AWS/Google tokens, JWTs, bearer headers, PEM keys, values under sensitive keys) and opt-in PII rules (email, Luhn-checked cards, phone, IPv4). Applied in Tracer._emit (fail closed: unredactable records are dropped and counted), the suite_artifact fixture and html_report. RedactingSink wraps any sink. Zero deps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This redacts secrets and PII before traces and CI artifacts are written. New module:
spanlite.redact.Redactordeep-walks dicts, lists, tuples and strings and replaces matches with[REDACTED:<rule>]. It also has:counts, the number of hits per rulecustom=for your own string hookextend(("ticket", r"TCK-\d+"))to add rulesrules_by_name([...])to pick built-in rulesBearer …headers and PEM private keyspassword,api_key,authorization,token,cookie, …)Redactor.with_pii()adds email, card numbers (Luhn-checked), phone and IPv4. These can match ordinary data (ids, numbers, versions), so they are off by default.Tracer._emit, before every sink (JSONL and memory). In-memorytracer.spanskeep raw values for test assertions.suite_artifactpytest fixture.html_report(case ids, suite and score names).redactor=..., andredactor=Noneturns it off.tracer.dropped_records,RedactingSink.dropped). It is never written raw.RedactingSink(inner, redactor)wraps any sink you call directly.There are no new deps. I did not touch
__init__.pyorpyproject.toml; import fromspanlite.redact.About open PR #3 (
feat/promote-regression): #3 is still unmerged. I branched frommainand avoided the files it changes, exceptREADME.md. The new README section sits next to "Usefulness", away from #3's hunk. A local trial merge of this branch with #3 auto-merges cleanly, and all 33 tests pass on the merged tree. If #3 lands, its regression packs (promote()) could run their output through the sameRedactorin a follow-up. This PR does not do that.Why
spanlite's pitch is "JSONL on disk + CI artifacts", and those files are exactly where leaked prompts, keys and PII persist.
How to try
Tests
tests/test_redact.pyadds 19 tests. The synthetic secrets are built at runtime, so no token-shaped literal is committed. They cover:RedactingSinksuite_artifactdefault and opt-outhtml_reportLocally: 27 passed (8 existing + 19 new) on Python 3.13. CI runs 3.10 and 3.12.
OSS / learning project; no production claims.