Repository navigation
TD-5450: Scrubber: real tokens after a secret name in any case go - #311
Merged
Merged
Conversation
A value that only looked like a code name was let through: npm_…, shpat_…, SG.….…, MySuperSecretKey2024, Abc123Def456, Summer2024!. Each part of a name now reads as lower, camel, Pascal or UPPER case with digits only at a word's end, and outside a type annotation holds at most 3 digits unless it is a lower-case word and its digits (x25519). The credential word alone, quoted and escaped-JSON keys, "=>", ":=" and X-API-Key count as a name; a quoted value runs to its closing quote; a key's "==" padding is not a comparison; an upper-case name after an escaped line break is found again. So that code stays, "::" is not a separator, and a type annotation (with generics and paths), a name on a lower-case module path, a colour, a version range or npm alias, a regex literal, a conditional and an assignment inside minified code read as code. Checked on 513 MB of real code: every new mask is a secret-shaped value, and every lost one was main masking code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR
Review (FIX FIRST): synthetic passwords main masked showed ("$" in a
word, UPPER+digits after ":", "=" in quoted values, a trailing "." or
"$", JSON-escaped "/"). Main's any-case rule now runs unchanged beside
the new one. Main's rules run in main's order and their masks are taken
back to the text; the new rule and URL user info are found on that same
text; all are masked once, so one mask never hides the name or the
"scheme://" another rule needs (re-review). secret_spans uses the same
spans.
The new rule reads those shapes as values too, and finds
os.environ["X"] = "…", --password X, quoted "ya29.…" tokens,
b''/r''/''' strings and YAML Summer2024!. Prose (Password/secret),
relative file paths, versions, ~/ paths, digests and names inside an
ARN stay; a quoted value stops before a following ";key=".
Speed: names in a long path or expression are checked once each; the
ARN check is one pass.
Tests assert the whole output (where each mask ends) and add each
review case; provider-shaped values are built at run time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR
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.
Secret names in any case (TD-5447) still let real tokens through, because the code check took them for names:
npm_token=npm_…,shopify_access_token=shpat_…,sendgrid_api_key=SG.….…,jwt_secret=MySuperSecretKey2024,smtp_password=Abc123Def456,db_password=Summer2024!. A quoted JSON or dict key ({"client_secret": "…"}) never matched, and neither did the credential word alone (password=AbC123/xyz+9Q=). Now they all go, and code that names a secret stays as it is. Nothing main masks shows: main's rule still runs beside the new one (second commit, after the Manager's review).What changes
Second commit (
238729cb), after the Manager's review found passwords main masked showing:scheme://the next rule needed (the re-review's…\nDB_PASSWORD=…\napi_token = …showed the second value).secret_spansuses the same spans. The upper-case rule's new form, right after an escaped line break ("a\nDB_PASSWORD=hunter22"), is a separate regex found on the text beside main's rules, so it can't change what main's rules see (the second re-review).$only starts a name (Pa$$w0rd); a lone upper-case word after:is a type only with up to 3 digits (UINT32, notORACLE2024); a quoted value holds no code's assignments, conditionals or module paths ("Pa55=word","ya29.…"); only a 1-2 character name counts as minified code before=; a name doesn't end in.; a backslash ends a value only as an escape that ends it (\n,\",\\), so a JSON-escaped\/stays inside.os.environ["DB_PASSWORD"] = "…"), a flag and its value after a space (--password X,--token X),b'…',r'…'and'''…'''strings, and YAML'sdb_password: Summer2024!.@param password: Password/secret …,token: docs/auth/v2.md, a secret's name inside an ARN, a version with a pre-release (v1.2.3-rc.1+build.5), a~/path, asha256:digest; a quoted value stops before a following;key=.First commit (
ced1e839),core/tstd/logging.py, the any-case rule, plus one fix to the upper-case rule:_,.and::) reads as lower, camel, Pascal or UPPER case, with digits only at the end of a word. Outside a type annotation, a part may also hold at most 3 digits, unless it is a lower-case word and its digits (x25519,sha256). Before, any identifier, dotted name or PascalCase word with digits counted.npm_aBc…789,shpat_0123…,SG.….…,Summer2024,Abc123Def456,Passw0rd.token_v2,cfg.token,process.env.API_TOKEN,Http2Client,Uint8Array,vocab_size-1.Summer2024!is no longer read as a name followed by an operator.password=,PASSWORD=,Token:); before, a name character had to come before it;{"client_secret": "…"},{\"client_secret\":\"…\"}), and a backtick-quoted value;=>, Go's:=, Make's?=, and anX-API-Keyheader (api-keyjoins the credential words).==padding is not a comparison.db_secret=dGhp…==was skipped on main for every lower-case name.'django-insecure-h7#q!x2v@k9$z&3m'showed&3mon main. It doesn't run past a space or bracket, where the quote may close a string instead."a\nDB_PASSWORD=hunter22"showed the password on main.:(_is_type) has capitalised words, at most one acronym, at most two digit groups, and at most one one-letter word ("Ed"), not right after the acronym. The second review found that a looser shape let about 1 random key in 20 through afterclient_secret:in YAML or a header.::is never a separator, so a Rust path stays (use winnow::token::take_till1;);:with no quote, with acronyms, digits, generics and paths:private_key: Ed25519PrivateKey,secret: Zeroizing<PayloadU8>,pub Token: super::super::Win32::Foundation::HANDLE,D3DKMT_PRESENTHISTORYTOKEN_0;rust_openssl.hpke.MLKEM768X25519PrivateKey);Token: "#ddd0c0"), a version range or npm alias ("^1.0.0-beta.2","npm:jsonwebtoken@9.0.0");k8s_secret,i18n_token,e2e_token), an address (127.0.0.1:8080), a lower-case path (/run/secrets/db.pem), and a number with an exponent in arithmetic (1e3*r);/--ease-out:\s*…/), a conditional ({token:e?1:0}), and an assignment inside minified code (case"Token":i=e.value).frag_token: crate::__u32,api_token = Config::TOKEN_V2,InheritPrivateKey: X509RequestInheritOptions), it still does, since main's rule still runs (see the question below).Before / after
e2e/td5450_cases.py, 13 shapes (the ticket's 11, plus==padding twice): main64d25272shows 13; this branch masks 13.Nothing main masks shows (
e2e/td5450_regression_fuzz.py, synthetic passwords and keys in 10 assignment forms, plus pairs of assignments joined by escapes,;,&and spaces, with URL values). A value counts if any character main masks shows:ced1e839The 1 is in
secret_spansonly: in"…aws_secret_access_key = 1fCKuL/9\"}"main's span took in the\of the escaped closing quote, and this branch's stops before it, since masking it would break the JSON escape. Main'sredact_secretsshows that value; this branch's masks it.The review's cases (
e2e/td5450_review_cases.py): all 10 of 1a-1e masked (the first commit showed all 10); the 4 prose and ARN cases left alone; 8 of the 9 shapes main misses now masked, all but a key and its value on separate lines.Real code and docs (
e2e/td5450_corpus_diff.py):secret_spanswith main'slogging.py(4ff45906) and this branch's, over this repository, the core's installed Python packages, the UI's node packages and the Rust crates in the Cargo registry: 43,442 files, about 513 million characters.TOKEN = "td5203-literal-…",password: "s3cret-smtp-pw"); URL-parser test vectors ("password": "%3A%40c"); example passwords in library docs (Playwright'spassword: 's3cr3t', Tauri's); rustls test secrets inb"…"strings; and codecov badge tokens in README URLs.Random keys (
e2e/td5450_rate.py, 2,000 keys per row): the share that still shows.client_secret:(main)token:,password:orX-Auth-Token:(main)Over 10,000 keys of 20 and 32 characters after
client_secret:andtoken:, 0 show on this branch and not on main; 9,780 show on main and not here. What still shows is mostly main's own rule that a word with up to 3 digits after it is code (secret1,gpt2).Time (
e2e/td5450_timing.py, one core, 4 MiB; every shape grows linearly from 1 MiB):x_token=a+a+…(the review's)secret:x_token=+ 40 different names joined by+"token":keys in a rowIndependent review
A fresh reviewer agent with read-only access, and no access to my conclusions, reviewed three rounds. It wrote its own scripts and ran them on one core.
First round, FIX FIRST, on the first commit:
:of::as a separator (use winnow::token::take_till1;becametoken:[REDACTED]). The digit limit also rejected real names (x25519_generate_private_key,Zeroizing<PayloadU8>,Curve25519SeedBin). My own scan had covered only the Python and node packages.=>, Go:=,X-API-Key, and a quoted value cut at&.{token:e?1:0}.All fixed in the second round. The Cargo registry joined my scan.
Second round, FIX FIRST:
name:, about 1 random key in 20 read as a type name (client_secret: RVdD53X83RZJ…). Main shows 0.3% of 32-character keys; the second commit showed 4.7%.k8s_secret,i18n_token,e2e_token).All fixed in the third round, as above, with a test for each.
Third round, MERGE. Its measurements:
Its low items:
_ALGORITHMexception (private_key = x25519_private_key) and the backtick-quoted value, and one random key for each of the two type rules. The reviewer's 2,000-key rate didn't move without those two rules. On my 10,000 keys, though, 7 more keys show without the digit-group limit and 3 more without the acronym rule, so they stay.Fourth round (the Manager), FIX FIRST, on the first commit, against the bar "nothing main masked may show":
$inside a word,name: UPPER+digits,=in a quoted value, a trailing.or$, a JSON-escaped\/.@param password: Password/secret …,token: docs/auth/v2.md, a secret name inside an ARN.os.environ["…"] = "…",--password X,"ya29.…",b'…'/r'…'/'''…''', YAMLSummer2024!.x_token=a+a+…took 7.4 s at 4 MiB against 2.2 s on main.All addressed in the second commit, as described above.
Fifth round (a fresh reviewer), FIX FIRST, on the first draft of the second commit:
…\nDB_PASSWORD=…\napi_token = Zry9…); the first commit had the same bug.scheme://off a URL, so part of its password showed.;key=; versions,~/paths andsha256:digests were masked.Sixth round, FIX FIRST: findings 1 and 2 fixed and the span mapping exact (50,000 cases against its own reference), but main's chain still used the changed upper-case regex, so after
\nDB_TOKEN=…\na few characters main masked showed (AKIA…andghp_…tails). Fixed by running main's chain with main's own regex and finding the escaped-line-break form separately. It also judged the escaped-quote backslash in the fuzz table not a regression: main's own output shows that value.Seventh round, MERGE, on this commit:
[REDACTED]text in the inputs): 0 where main'sredact_secretsmasks a character this branch shows (the drafts had 25, then 2). Insecret_spans, 2 differences, both characters main's own output printed while its spans claimed them.redact_secrets, 46,550 lines, 0 lost.x_token=a+a+…it measured 1.12 s against main's 1.21 s."FOO\nDB_PASSWORD=hunter22\nLOG_LEVEL=debug"masks throughLOG_LEVEL=debug, as main does for the same line without the escape.x9K2mQ7vB4nL8pR3tY6wZ1aS5dF0gHand the Django key are literal. They match no provider's format, and push protection passed them on the first commit.Tests
GitHub's push protection blocked the first push: it took the test's fake Shopify token for a real one. The test now builds the npm, Shopify and SendGrid values from pieces at run time, so the repository holds no token-shaped text. The npm and Shopify values are the same as before; the SendGrid value's second part is a different made-up run. The code under test is unchanged.
New tests (
tests/test_pem_redaction.py). Each secret case checks the whole output andsecret_spans, so a value masked only in part fails (the Manager's review: before, only where the mask started was checked):==padding, the credential word alone, quoted, escaped and backtick-quoted values, PHP, Go, Make, the header, the Django key, random keys after an unquoted name, an upper-case name after an escaped line break; and, from the second commit, the review's 1a-1e (Pa$$w0rd,ORACLE2024,"Pa55=word",summer2024.,monkey2010$,wJalr…\/K7MDENG\/…, …) and the shapes main misses (os.environ[…],--password X,"ya29.…",b'…',r'…','''…''', YAMLSummer2024!);;user=, and the second re-review's three upper-case names after an escaped line break followed by an AWS key, a GitHub token or a JSON-escaped quote;secret_spansmust agree with the output;@param password: Password/secret …,token: docs/auth/v2.md, ARNs, a version with a pre-release, a~/path and asha256:digest;crate::__u32,Config::TOKEN_V2,X509RequestInheritOptions);The whole file: 562 pass on this branch. With this branch's tests, the first commit fails 40 and main (
4ff45906) fails 42. Two unpushed drafts of the second commit failed 8 (before the single pass: the 5 cases above and the version,~/path and digest shapes) and 3 (before main's own upper-case regex: the second re-review's 3 cases).Run, one core, on this branch: the 48 test files that mention redaction or hold the fixtures above: 2,146 passed. The full suite runs in CI; the machine is on a CPU hold for other work.
Left as they are
Welcome1!,hunter2,Summer_2024. Each is shaped like a code name or arithmetic (secret1,value!,cache_2024); main shows them too.smtp_password: Abc123Def456reads exactly like a type annotation (private_key: Ed25519PrivateKey). Quoted, or with=, it goes.Authorization: Token …and<password>…</password>: each needs a different rule; all show on main too.private_key: "Ed25519PrivateKey"), a quoted algorithm name ("secret": "ED25519"),api_key: IPv4Address,Token: 1h30m,secret: oauth2/v3/certs, and the user name in a URL whose password holds a backslash (secret: https://admin:Abc\\def123@db.localbecomessecret: [REDACTED]@db.local). None of the first five turned up in the 43,442 files scanned.\of an escaped closing quote after a value is outsidesecret_spanshere and inside on main (see the fuzz table); the value itself is masked.Question
Keeping main's rule keeps main's masks on code too:
frag_token: crate::__u32,api_token = Config::TOKEN_V2andInheritPrivateKey: X509RequestInheritOptionsare masked again (the first commit had stopped masking 20 such spans). Leaving out of main's rule the values the new rule reads as Rust paths or annotation types would bring those back, but nothing main masks showing would then hold only as far as that carve-out is right. I recommend keeping it as it is. Your call.Checks
release_scan --git: 0 hits.🤖 Generated with Claude Code
https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR