Skip to content

fix(security): redact github_pat_ tokens and empty-user url passwords - #1306

Merged
LivXue merged 4 commits into
EverMind-AI:mainfrom
goranai:fix/redact_github_pat_and_empty_url_user
Nov 20, 2026
Merged

LivXue merged 4 commits into
EverMind-AI:mainfrom
goranai:fix/redact_github_pat_and_empty_url_user

Conversation

@goranai

@goranai goranai commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

redact() left two credential shapes in ACP frames, failure text and provider call records:

  • fine-grained GitHub tokens (github_pat_...). The github pattern only knew gh[pousr]_. raven/trajectory/redact.py already matches github_pat_[A-Za-z0-9_]{22,}, and this uses the same shape.
  • URL passwords with an empty user (redis://:password@host, https://:token@host). url-userinfo needed one or more user characters.

The change adds github_pat_[A-Za-z0-9_]{22,} to the github pattern and github_pat_ to the cut-tail prefixes. It changes + to * for the user part in url-userinfo and 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 carry redis://:password@host. It now has the same url-password shape, 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

  • Fix
  • Feature
  • Docs
  • CI / tooling
  • Refactor
  • Other

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 old redact.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_record or acp.updates gave 2273 passed, 6 skipped, 52 failed. On main the same files gave the same result, and the 52 failing tests have the same names (in test_subagent_acp.py, test_acp_updates.py, test_subagent_manager.py and test_agents_code_flow_todo.py). They fail on this Windows machine without the change, so they are not from it.

  • ruff check and ruff 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 only github_pat_ fails both; deleting the trajectory url-password pattern fails the new trajectory test.

  • Differential fuzz against the old table: 4000 URLs generated as scheme://user:password@host with a 0 to 8 character user and a 3 to 20 character password, checked against urllib.parse.urlsplit(url).password (0 passwords left, the old table leaves 456). 4000 github_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, ://:a repeated): 0.06 s or less per call, plain and truncated=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. A github_pat_ run of 22+ characters is now hidden even when glued to a word (xgithub_pat_...), the same as ghp_ 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.

  • Security impact considered
  • Backward compatibility considered
  • Rollback path is clear for risky changes

Related Issues

Fixes #1305

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>
@LivXue

LivXue commented Nov 16, 2026

Copy link
Copy Markdown
Member

Windows compatibility review — 94ca3f8318

Reviewed at head 94ca3f8318b165319fd6c590b8575011a8c86359 (base 51b40ee536). Scope: the full base-to-head diff (raven/security/redact.py, tests/test_acp_redact.py), the surrounding pattern table, and the truncation-scan companions.

No Windows compatibility issue found.

Three regex edits and their tests: the url-userinfo user section accepts an empty user, github also matches github_pat_…, and both are mirrored in _TRUNCATED_SECRETS. No filesystem, subprocess, path, encoding or platform surface is touched; the patterns are byte-agnostic str patterns with ASCII character classes, so they behave identically on Windows and POSIX. The one thing worth checking is whether the widened patterns can over-match on this host's text — e.g. a Windows path or an unrelated github_pat_-looking string — and the added TestWhatItLeavesAlone cases (redis://cache:6379/0 ping, a plain clone URL) pass alongside the existing negative cases.

Verification (native Windows host, Python 3.12.13, shared venv, worktree pinned to the head):

  • python -S runner.py tests/test_acp_redact.py -q → 55 passed in 21.88s, including the two new positives, the new negative, and the truncation/fuzz tails (github_pat_, redis://:) added under TestTheLimits.

Coverage gaps: the property-style loops are seeded and finite (random.Random(978), 3000 iterations), so this is the same confidence the file already carried rather than exhaustive validation; no real ACP payload was replayed.

@LivXue

LivXue commented Nov 20, 2026

Copy link
Copy Markdown
Member

Windows compatibility review — f8d8456c6b

Reviewed at head f8d8456c6b8f60dbccd05dd04208b9f68b234c49 (rebased onto newer main). Scope: the PR's own diff (2 files) — a github_pat_… alternative in the github pattern, an empty-user URL userinfo (redis://:secret@host), and the matching truncated-tail entries, plus the cases.

No Windows compatibility issue found.

Pure text processing: no path, subprocess, encoding, or platform branch, and the redaction output is platform-independent.

On the patterns:

  • github_pat_[A-Za-z0-9_]{22,} sits beside the existing gh[pousr]_ forms under the same github name, and both the full and truncated variants carry it, so a cut tail is handled like the other vendor keys.
  • (://[^\s/:@]*:)([^\s/@]{3,})(?=@) only loosens the user segment; the password still needs three characters before an @, so an ordinary host:port URL keeps its value (redis://cache:6379/0 is in the negative cases) and only scheme://user:secret@ / scheme://:secret@ matches.
  • The two new tests (the github_pat_ clone URL and the redis-cli -u redis://:… command) reproduce the shapes my earlier review on 94ca3f83 described, and the fuzz/property cases now include both new tails.

Verification, native Windows host (GitHub tarball of f8d8456c6b, extracted under D:\tmp\rv1306):

  • python -S runner.py tests/test_acp_redact.py -q → 55 passed

Gaps: unit-suite only (no live tool-output capture); the tree is the commit's export rather than a git worktree.

@LivXue LivXue left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@LivXue
LivXue merged commit 4161c0e into EverMind-AI:main Nov 20, 2026
23 of 26 checks passed
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.

redact() misses fine-grained GitHub tokens (github_pat_) and URL passwords with an empty user (redis://:pw@host)

2 participants