Repository navigation
Conversation
…itten or cut A private key cut short (no END line) lost only the part before its first escaped newline, so a key in a JSON or .env value, a repr, or JSON inside JSON showed its body in chat, tool output and on the wire. Its body now runs across any line break, real or escaped, with the decoration, line prefixes and string joins that tools and source code put around lines, and escaped key characters. Base64url bodies, lower-case BEGIN lines, PGP private key blocks and SSH2 private keys are covered. The first line must read as key text, not as code or words, and a key cut short inside a string stops at the string's end, so prose and code after a BEGIN line keep their words. The END search stops at the next BEGIN line (2,000 BEGIN lines in 1 MiB: ~2 minutes before, ~0.2 s now); header lines and long runs are read once. Secret names match in any case (aws_secret_access_key = ...), with code left alone: the name must end in a credential word, == is a comparison, and the value must not read as code (numbers, versions, dates, type names, snake_case and dotted names, arithmetic such as pos+1 or offset+limit). 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.
The scrubber missed a private key that was cut short (no END line) once its line breaks were written as escapes. That covers a key in a JSON or .env value, a Python repr, JSON inside JSON, and many tools' output. Its body then showed in chat text, tool output and on the wire. This PR closes that gap and matches secret names in any case (
aws_secret_access_key = …).What changes
A private key's body never shows, however it is written or cut (
core/tstd/logging.py).\n,\\n,\u000a,\012,\N{LINE FEED}),%0A, /&#10;/
,<br>, a<p>/<div>per line, SQL's|| chr(10) ||, and strings joined across lines in source code or a JSON array.+, a shell's\,cat -A's$, ANSI colours and zero-width characters around the break.INFO);cat -n,less -N,N |, bat's│, grep's2:/k.pem:2:/k.pem-2-).\/,\u002b,%2F,/,/.Proc-Type/DEK-Infolines, lower-case and URL-encoded BEGIN lines, PGP private key blocks, SSH2 private keys.Prose and code after a BEGIN line keep their words.
+or/. It must not read as an assignment, a dict key, a call, an attribute or words.Read once.
Secret names in any case.
aws_secret_access_key = …,db_password=…,apiToken: '…'. Code that names a secret the same way is left alone. In lower or mixed case:auth_token_ttl,max_tokens,x_tokenizerstay);==,!=,>=and<=are comparisons;/,+or=, and must not read as code:/;pos+1oroffset+limit;Each value is read once. The capitals pattern main already had is unchanged.
Docs: the TD-5447 backlog entry.
Before / after
For each of 80 key shapes: every cut point × 5 endings × 3 places (text, the wire, JSON-escaped on the wire). The 11 shapes from TD-5445's report are first; the rest were found by me and by four review rounds.
aws_secret_access_key = wJalr…tests/test_pem_redaction.pyis new. Against main'ststd: 290 failed, 133 passed (td5447-new-tests-on-main-by-test). The 133 that pass on main are:Main fails 5 of the 7 prose texts and 7 of the 12 code-after-BEGIN texts: it masks the words after a BEGIN line.
Cost
Ordinary large text,
redact_secrets, median of 5 interleaved runs against main on a heavily loaded shared machine (load average 68):The text is this repo's own source and docs, plus generated base64, JSON and log lines (
e2escripttd5447_perf_ordinary.py). The reply funnel runs this scrub on the event loop today; TD-5446 moves large replies off it.Independent review
Four rounds. Each was a fresh reviewer agent with read-only access and no access to my conclusions, and each wrote its own scripts. I reproduced every finding before fixing it.
Round 1 (first version):
max_tokens=4096,my_secret = secret1);//comments showed the key; main hid those;Round 2: my fixes had made three new problems:
It also found settings masked (
auth_token_ttl=3600s,apiToken: Uint8Array) and 15 more key shapes.Round 3: my fixes had again made problems:
"\nother = 1,"""\n\ndef, the next dict key);prevToken===nextToken,offset+limit).It also found grep -A and bat gutters and
\u002bshowing the key.Round 4:
\nwas read as a new string, which ate the next line (return KEY,"hello"in a list);" + base64Body + "eaten;>=/<=masked.Checking round 4's fixes: I reran all four reviewers' scripts on them. No key shows, except one synthetic shape described below. All 26 of round 4's adversarial inputs grow about 4× from 1M to 4M repetitions (
td5447-review4-perf-rerun). There was no fifth fresh review.Known and left as they are:
"MIIE…then"NYv…with no closing quotes) still show. Crossing such a quote is what made the mask eat code after a string's closing quote. I don't know a tool that writes this.commit_token=1c57…,model_token = gpt-4o-mini,ssh_private_key: /home/u/.ssh/id_rsa). See question (c).password=…without a prefix, and word-plus-3-digits values (hunter22). See question (a).secret_spansandredact_secretsdiffer on glued fragments about as often as on main: 959 against 1,062 of 30,000 random texts.Questions
password=…,token=…) be covered too? Code uses them most."X_" + "TOKEN_" * N + "="(6.9 s at 48 KB on main). Fix it here or separately?Full suite
On
1b2dc5b0, at load average 20-21: 2 failed, 10,989 passed, 13 skipped, 4 deselected.test_session_preset.py: a test daemon hadn't bound its port in time (assert 0 > 0onws_server.port).An earlier full run on the same commit, at load average about 68 while the machine's disk was running low, had 48 failed and 4 errors. Nearly all were test daemons that didn't bind or answer in time.
CI on a clean runner is the reference.
Checks
release_scan --git: 0 hits.🤖 Generated with Claude Code
https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR