Repository navigation
fix(security): redact github_pat_ tokens and empty-user url passwords - #1306
Conversation
The live redaction table matched only gh[pousr]_ GitHub tokens, so fine-grained github_pat_ tokens were published as is. The url-userinfo pattern needed a non-empty user, so redis://:password@host kept its password. The cut-tail patterns had the same two gaps. Co-authored-by: Claude (claude-opus-5-5) <noreply@anthropic.com>
Windows compatibility review —
|
Windows compatibility review —
|
LivXue
left a comment
There was a problem hiding this comment.
Approving at de426fb.
Both leaks are real and both are closed. With the merge-base redact.py I reproduced github_pat_... surviving in an ACP tool.start title, a tool.complete preview and an error message, and redis://:hunter2secret@cache:6379/0 surviving in the same places; at this head all of them read [redacted] while the surrounding shape stays legible. full_failure_text and _bounded_body go through the same table, and the replay path reuses it.
The test that guards the PAT rule now pins the whole value rather than a prefix. That mattered more than it looked: with only the old 29-character fixture, narrowing the value class to [A-Za-z0-9]{22,} and dropping the underscore left the suite green while a real token exposed sixty characters after the marker. The fixture is now a full 93-character token with an underscore at position 22, there is an explicit residue assertion, and the 21/22 pair pins the floor. Four mutants red: drop the underscore from the class, lower the quantifier to 10, raise it to 30, and match the bare prefix only.
The trajectory table gained the same url-password rule, and keeping group(1) leaves the URL readable around the placeholder. Removing the rule reds its test.
One thing worth knowing rather than blocking: the empty-user form also redacts text that merely looks like ://: followed by @, so a regex fragment in a transcript can be masked when it is not a credential. That is fail-closed and I would not narrow the class to avoid it.
No production defect found.
Summary
redact()left two credential shapes in ACP frames, failure text and provider call records:github_pat_...). Thegithubpattern only knewgh[pousr]_.raven/trajectory/redact.pyalready matchesgithub_pat_[A-Za-z0-9_]{22,}, and this uses the same shape.redis://:password@host,https://:token@host).url-userinfoneeded one or more user characters.The change adds
github_pat_[A-Za-z0-9_]{22,}to thegithubpattern andgithub_pat_to the cut-tail prefixes. It changes+to*for the user part inurl-userinfoand in its cut-tail pattern. Only the password is replaced, as before (redis://:[redacted]@cache:6379/0).The trajectory bundle pattern layer had the
github_pat_rule but no URL rule, so a shared bundle could still carryredis://:password@host. It now has the sameurl-passwordshape, for an empty user and for a named one (postgres://admin:[REDACTED:pattern.url-password]@db:5432/app), and keeps the URL readable.The
github_pat_test now uses a real 93-character token (22 characters, an underscore, 59 characters). It asserts that the token, its 82-character value and the 60 characters after the underscore are all gone, and a second pair pins the 22-character floor from both sides.Validated with Claude Opus 5.5.
Type
Verification
Local, Linux, Python 3.12.13, at this head:
uv run pytest tests/test_acp_redact.py -n 0: 57 passed. With the same tests and the oldredact.py: 7 failed, 50 passed.uv run pytest tests/test_trajectory_redact.py -n 0: 28 passed. The five files that exercise the change: 378 passed.Earlier, on Windows Python 3.13 and before the added tests: the 24 other test files that import
redact,failure_text,call_recordoracp.updatesgave 2273 passed, 6 skipped, 52 failed. On main the same files gave the same result, and the 52 failing tests have the same names (intest_subagent_acp.py,test_acp_updates.py,test_subagent_manager.pyandtest_agents_code_flow_todo.py). They fail on this Windows machine without the change, so they are not from it.ruff checkandruff format --check(0.15.12) on the changed files: clean.uv run ty check raven/security/redact.py: all checks passed.Mutation checks at this head: dropping the underscore (
[A-Za-z0-9]{22,}) fails the whole-token test while the rest stays green;{22,}to{10,}and{22,}to{30,}each fail the floor test; matching onlygithub_pat_fails both; deleting the trajectoryurl-passwordpattern fails the new trajectory test.Differential fuzz against the old table: 4000 URLs generated as
scheme://user:password@hostwith a 0 to 8 character user and a 3 to 20 character password, checked againsturllib.parse.urlsplit(url).password(0 passwords left, the old table leaves 456). 4000github_pat_strings,github_pat_plus 22 to 80 alphabet characters (0 left, the old table has no rule for the shape and leaves all 4000).Timing on 250k-character inputs (
github_pat_runs,://followed by colons,://:arepeated): 0.06 s or less per call, plain andtruncated=True.Relevant tests pass locally
Relevant lint / type checks pass locally
User-facing docs or screenshots are updated when needed
Risk
Three more shapes become
[redacted]in published text. Agithub_pat_run of 22+ characters is now hidden even when glued to a word (xgithub_pat_...), the same asghp_already is. URLs with no password, an empty password, or a password under 3 characters are unchanged. A redacted trajectory bundle now removes URL passwords in its pattern layer as well, and a URL with no password is unchanged there. Roll back by reverting the commits.Related Issues
Fixes #1305