Repository navigation
fix(security): keep plural-route commit permalinks out of the bare-secret pass - #23146
Conversation
Sensitive Change ReviewSensitive files changed:
|
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the fix is two lines inside the existing commit ceiling, it adds no host allowlist, and the wider residual it accepts is measured, disclosed and pinned at its new boundary. Notes
[DESIGN-REVIEWED] c1a7d67 Description read[DESCRIPTION-READ] 554d47180e72b368d8827acbc48a7a89f47814abc84b3e52663f8e6d7b1d9b3c That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix has linked issues (#23131, #20017, #15565) and tests that fail on base. It is a two-line change to the existing commit ceiling, which is already the mechanism for this, and it adds no new surface. What this change shipsInventory (4 items) — 4 justifiedIntent: commit permalinks on hosts with
[FIRST-PRINCIPLES-REVIEWED] c1a7d67 Description read[DESCRIPTION-READ] bccea19b30b4cc26b25e6b476d4d720b6a02ad6697957ac689390ca109c75e4d That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
101e327 to
2c513de
Compare
|
Sensitive change review
|
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: This change only adds ways to decline a match. The bare-secret classifier gains two more route words that count as a routed commit, and it now declines a window that takes fewer commit digits. Together these can only turn a fragment window from flagged to declined, never the reverse. So the exfil tier, which calls TIGHTENING: Nothing gets stricter here; the commit ceiling in ADJUDICATED: 14 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: The diff makes no assumptions about paths, separators, interpreters or executables. Its only input is URL text with
There is no platform the diff relies on that these candidates leave unprobed. UNADJUDICATED: The same [SCOPE-REVIEWED] c1a7d67 |
2c513de to
8bcb1f5
Compare
Sensitive change review
|
8bcb1f5 to
f14a87a
Compare
|
Sensitive change review
|
|
The red |
|
|
3cf1706 to
d4b4a22
Compare
Sensitive change review
|
|
@bolichen97 thanks, addressed in
Trade-off, stated plainly: package names longer than 19 characters can still leave a firing window with fewer than eight digits, so some of those links stay redacted (558 of 20,000 over a synthetic 400-name corpus, against 1,386 at 12). That fails safe. Secret recall at 8: 0 lost in 20,000 random keys x 10 glued placements. Local gates (141 security/redaction test files, 🤖 AI-assisted comment 🤖 |
|
CI note for head 🤖 AI-assisted comment 🤖 |
bolichen97
left a comment
There was a problem hiding this comment.
Thanks for reworking the floor. Reviewed at d4b4a22.
My earlier review at 3cf1706 asked for three things, and this head covers all of them:
- The floor is now 8 with a measured reason: the widest firing window in a
packages/<19 char name>/blobs/link leaves exactly eight digits. - The boundary is pinned: one, two and seven digits stay redacted, and eight is the accepted residual.
- The residual is written into both the code comment and the spec section.
What I checked: the production change is the blobs?/trees? alternation and the floor constant; the ceiling still applies only to fragments and only after _looks_like_secret_key, so a standalone key is never exempted. test/test_commit_permalink_redaction.py passes locally (114 passed). Linked issue is tier T1, no other open PR touches these files, and main still has the floor at 12.
One optional wording note is inline. This touches secret redaction, and CI is still finishing (one Frontend Tests job is rerunning), so I am leaving the approval to a maintainer once checks are green.
| - **JWT / JWE / OAuth Bearer tokens** (JSON-aware Bearer): JWTs (`eyJ<header>.<payload>.<sig>` — `eyJ` is the base64url of the `{"` header prefix) and HTTP `Authorization: Bearer <token>` headers. The `eyJ` segment quantifier is `(?:\.[A-Za-z0-9_-]*){2,4}` so it redacts both a 3-segment signed JWT (JWS) and a 5-segment encrypted JWT (JWE, RFC 7516 — `header.encrypted_key.iv.ciphertext.tag`) as one whole token — including `dir`/`ECDH-ES` JWEs whose Encrypted Key segment is EMPTY (`header..iv.ciphertext.tag`); a fixed 3-segment pattern would truncate a JWE and leak its ciphertext + tag. The JWT alternative is case-sensitive (`eyJ` is a fixed base64url prefix); the Bearer header name + scheme are matched case-insensitively via scoped `(?i:…)` groups because HTTP header names are case-insensitive (RFC 7230 §3.2), HTTP/2 mandates lowercase names, and the `Bearer` scheme is case-insensitive (RFC 6750 §2.1) — so lowercase `authorization: bearer …` from `requests`/`net/http`/HTTP2 frame logs is redacted too. The header/scheme separator is JSON-aware: an optional quote may precede the `:`/`=` and the token (`(?i:Authorization)["']?\s*[:=]\s*["']?(?i:Bearer)…`), so a serialized `{"Authorization": "Bearer <tok>"}` in a structured-log/JSON request dump is redacted, not just the raw HTTP header. Both are scoped tightly — the JWT segment class `[A-Za-z0-9_-]` cannot cross the literal `.` separators, and the Bearer token class (`[A-Za-z0-9._~+/-]+=*`, RFC 6750 `b64token`) stops at whitespace/quotes — so neither over-captures. A `Bearer` header carrying a JWT redacts as a single match (the Bearer alternative's class subsumes the JWT), while a bare JWT is caught independently (defense in depth). Bare `eyJ…` with no `.`-segments and the word `Bearer` without the `Authorization:` prefix are NOT redacted (no false positives). The JWS/JWE branch is shape-only, so a hit on it counts only when its first segment base64url-decodes to a JSON object (a JOSE header, or the payload of an itsdangerous / Flask-session token): `honeyJar.example.com` is left alone. Every pass-1 consumer and the stream's partial-JWT holdback anchor apply the check. A rejected span is rescanned, so a credential inside it still redacts. A header holding a second `eyJ` stays a credential, which keeps the rescan linear. The scan itself (`_credential_search`) finds the JWT branch's leftmost start with its own finder, which skips a failed segment run whole because every `eyJ` in one run shares the run's end, then calls `_CREDENTIAL_PATTERNS.match` at the earlier of that start and the other branches' leftmost start; each step returns the same match `search` would, and a long `eyJ` run costs linear time instead of quadratic. The other branches' leftmost start comes from `_CREDENTIAL_STARTS_SANS_JWT`, whose Telegram branch only starts where no digit precedes it (a later digit in one run has fewer digits before the same `:`), so a long digit run is walked once too; `_sans_jwt_start` covers a scan that resumes inside a run. The JWT start keeps the end of the run it matched in, so when an overlapping match of another branch (a Slack token ending inside that run) moves the scan past the start, the next `eyJ` in the same run is taken without walking the run again. The `sanitize.ts` mirror still matches on shape alone. **Two-segment dashboard link token**: `dashboard.token_auth.generate_token` emits `base64url(payload).base64url(hmac_sig)`, which is TWO segments, so the `{2,4}` quantifier never matched it and the token fell through to the pass-3 bare-secret heuristic, whose run class `[A-Za-z0-9+/]` is standard base64 and excludes base64url's `-`/`_`. Redaction therefore depended on the alphabet of a random HMAC signature. That rate is derivable, so it is stated as a closed form rather than as a sample: HMAC-SHA256 is 256 bits and base64url-unpadded gives 43 chars, of which the first 42 each carry a full 6 bits (uniform over the 64-char alphabet, exactly 2 of which are `-`/`_`) while the 43rd carries only the leftover 4 bits (256 - 42*6) in the HIGH bits of its 6-bit group, low 2 bits zero, so it spans exactly the 16 alphabet indices divisible by 4 (`048AEIMQUYcgkosw`), never `-`/`_` at 62/63 (verified by encoding all 256 possible final digest bytes). Hence P(no `-`/`_`) = `(62/64)^42` = 26.4%, so roughly a quarter of tokens had only the signature replaced and the payload claims stayed verbatim in a URL that still looked complete but no longer authenticated; the other ~74% were emitted with no redaction at all. (An earlier 400-signature estimate published 29% here. Two 5000-mint runs land at 26.0% and 27.1%, straddling the closed form, so the published figure was a small-sample artefact.) The link token now has its OWN alternative, `(?<![A-Za-z0-9_.-])eyJ[A-Za-z0-9_-]{96,}\.[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])`, ordered AFTER the `{2,4}` one so a real JWS still redacts whole instead of matching `header.payload` and leaving `.signature` exposed. The `{2,4}` floor was deliberately NOT relaxed to `{1,4}`: the alternative has no left boundary and its post-header segments allow an EMPTY match, so `{1,4}` matches ordinary code and prose (`keyJson.get(raw)` becomes `k[REDACTED: credential](raw)`, and a JWT quoted at the end of a sentence loses its trailing period). The segment lengths come from the generator rather than from guesswork, because a length FLOOR alone is beatable by a verbose enough identifier: at `{40,}` the 40-char `eyJsonSerializerConfigurationFactoryBuilder.deserializeFromStringValue` matched. `token_auth._sign` is HMAC-SHA256 base64url-unpadded, so the signature is EXACTLY 43 chars for every token ever minted, a property of the digest and not of the payload, so it is pinned as `{43}`; `test_link_token_signature_is_43_chars` fails loudly if that digest changes rather than letting redaction silently stop matching. `generate_token` always emits `sub`/`exp`/`session_exp`/`iat`/`nonce`/`gen` with a 16-hex-char nonce and float timestamps (`app`, `prompt` and `extra` only add), so payload length is not fixed: it scales with `len(sub)` and with the repr width of each float timestamp, which base64 quantises into 4-char steps. The floor is therefore derived rather than sampled: a 1-char `sub` (the narrowest a caller passes), `gen=0`, and all three timestamps at their shortest 12-char repr (an exactly-integral `time.time()` in the current 10-digit epoch era) measures 145 chars past `eyJ`, leaving the `{96,}` floor 49 chars of headroom. ONLY that derived floor is pinned; live payload sizes are not, because the spread moves with float reprs and caller mix (measured 168-185 for the mandatory-only callers, and 192-223 for the two that also pass `app=`, which adds an `"app"` claim). `test_link_token_payload_clears_the_96_char_floor` pins the derived floor so a shorter claim set fails loudly instead of silently disabling redaction. The left boundary includes `.` so an attribute access (`obj.eyJsonReader.readValueFromInputStream`) is excluded. A false positive here is not purely cosmetic: `chat_turn/file_changes.py` (`_flush_file_changes`) redacts file-diff chip bodies IN PLACE before persistence ("so both the live and persisted views are clean"), so a bad match is written to the persisted view with no recovery path. Artifact content and compressed history are redacted on the serialization/output path instead (`handlers/artifacts_parts/record_serialization.py::_serialize`), so those surfaces are not rewritten on disk. The product's own link delivery is unaffected by construction: `slack/allowlist.py::send_dashboard_link` builds the presigned URL and posts it via `slack.post_message` without calling `redact_credentials()` (and `slack/client.py` does not redact internally), so `!dashboard` and `kirocrew token` are outside this path. What the fix closes is an agent-authored URL carrying a live token into chat, which is the XPIA data-exfiltration row of the threat table above | ||
| - Base64 detection: finds 40+ char base64 chunks, decodes them, checks if decoded content matches any credential pattern | ||
| - **Bare label-less secret-key detection**: a 40-char AWS *secret access key* (the value paired with an `AKIA`/`ASIA` ID) is a bare base64 run with NO prefix and NO `key=` label, so the fixed-format patterns above miss it when it appears standalone (echoed alone, in a log line, in a JSON array element). A third redaction pass adds an entropy + structural heuristic: `_BARE_SECRET_RUN_RE` isolates each `[A-Za-z0-9+/]{40,}` run (word-boundary look-arounds so surrounding prose is preserved), then `_looks_like_secret_key()` applies every gate below — a token must clear ALL of them (design bias is toward NOT redacting: a false negative reverts to prior behavior, a false positive corrupts benign output). Gates, ordered by measured cost per rejection (cheapest first): (1) length is EXACTLY 40 (AWS secret-key length); (2) contains lower + upper + digit (rejects all-lower prose, ALL-UPPER constants, base32, digit runs); (3) not an all-hex run (`_HEX_ONLY_RE` rejects 40-char git SHAs and 32/64-char md5/sha256 digests — verified even for mixed-case hex that would otherwise clear the entropy gate); (4) the longest run of consecutive lowercase letters ≤ `_SECRET_MAX_LOWER_RUN` (5), decided by `_lowercase_run_exceeds(token, cap)`, which stops as soon as a run reaches `cap + 1` instead of measuring the longest run in the whole token; (5) vowel ratio ≤ `_SECRET_MAX_VOWEL_RATIO` (0.30); (6) Shannon entropy ≥ `_SECRET_ENTROPY_MIN` (4.3 bits/char — real random keys average ~4.78 and rarely drop below ~4.4, while camelCase identifiers and file paths cluster at 4.0-4.3; the canonical AWS example scores 4.66); (7) does not base64-decode to ≥85% printable ASCII (`_decodes_to_printable_text` leaves encoded-text blobs to the decode-and-scan pass). **The order of gates 4-7 is a performance property, not a correctness one:** all four are pure predicates that return `False` on failure, so every permutation produces the same verdict on every input — which is exactly why a behavior test cannot pin it. The two structural gates reject more per microsecond than entropy does, so they run first and entropy is paid only on the windows that clear them. `TestSecretGateOrderIsCostOrdered` counts gate evaluations and fails if the order regresses to entropy-first; do not reorder these four back without re-measuring. Both structural gates apply to EVERY token: unlike a naive design, the presence of `/` or `+` is **not** a free pass to redact, so a 40-char mixed-case file path (e.g. `src/main/java/com/Example/FooBarBazClas1`) — which contains `/` yet is built from dictionary-word segments with long lowercase runs — stays intact. The pass scans the ORIGINAL text (stable offsets) and skips any run already redacted by pass 1/2. Tests (`test_security.py::TestBareSecretKeyRedaction`) prove true positives on real secret shapes and NO over-redaction of git SHAs, UUIDs, sha256/md5 hex, base32, prose, code identifiers, or slash-delimited file paths. **Glued-secret sliding window**: `_looks_like_secret_key()` only accepts an EXACTLY-40-char token (gate 1) — its documented boundary assumption — but `_BARE_SECRET_RUN_RE` captures the *longest* base64 run, so a real 40-char secret glued to an adjacent base64 char with no delimiter (`X`+secret, secret+`A`, `SECRET=`+secret+`ABC`, secret+`X`+secret) forms a 41+ char run that fails the exact-40 gate and would leak verbatim. Pass 3 therefore gates each captured run through `_contains_bare_secret()`, which slides a 40-char window across the run and redacts the whole run when ANY window clears every gate; this stays linear (the regex yields disjoint spans). A >40-char camelCase *identifier* run survives the slide (no window within it clears the structural gates), but a deep absolute *path* does not on its own: `/` is in the run alphabet, so a path such as `/Volumes/workplace/TRAM/QuickProp2/src/ATVTramQuickPropCDK/lib/config/consumerVpcs` is ONE run, and a window straddling several CamelCase components clears every gate (CamelCase caps its lowercase run, acronyms crush its vowel ratio, a version digit supplies the third class, the separators lift its entropy) — which redacted the whole path and left a file-viewer chip dereferencing `[REDACTED: credential].ts`. **Fragment separator ceiling** (`_SECRET_MAX_SLASHES`, 3): inside `_contains_bare_secret()`, a classifier-positive window is declined when it holds more than three `/` AND the run is longer than one key — separator density is what tells a path window (one `/` per component) from a key (`/` is 1 base64 character in 64, so a real key averages 0.6). Two conditions keep it a gate rather than a hole: it applies only to a FRAGMENT, so a standalone 40-char key is judged by the seven gates alone however many `/` it carries; and it is read AFTER `_looks_like_secret_key()` answers, so every offset is still classified and a key glued into a run is still found at its own offset. Measured on 200k uniformly random 40-char keys it declines 0.36% on its own, against 9.29% for the lowercase-run gate and 6.60% for the vowel-ratio gate. The accepted residual — a key carrying 4+ `/` AND glued into a longer run — is byte-identical to a benign path window at this layer and is pinned as a decision by `test_the_accepted_residual_is_a_separator_heavy_key_glued_into_a_run` (`TestPathWindowsAreNotBareSecrets`). **Fragment commit ceiling** (`_ROUTED_COMMIT_RE`, `_ROUTED_COMMIT_PIECE_MIN`): a commit permalink is one run too (`com/Owner/RepoName/blob/<commit>/src/file`), and its window straddling `RepoName/blob/` and the start of the commit clears every gate on two separators, with capitals from the repository name and lowercase and digits from the hex. A classifier-positive FRAGMENT window is declined when it crosses the opening `/` of a routed commit and takes twelve of its digits. A routed commit is a path segment of exactly 40 or 64 lowercase hex digits, as git prints one, right after a `blob`, `tree`, `blame`, `raw`, `commit`, `commits` or `src` segment and ending at a `/` or the run's edge. The same two conditions as the separator ceiling apply. The route is what keeps a key out: a key's own window crosses that `/` only when the key itself holds it and twelve hex digits after it. A window starting inside a commit is judged as before, and so is hex a key carries anywhere else. Commits are a whole window long, so each window reads only the first commit starting after it, and a run full of them stays linear (`test_a_window_reads_only_the_commit_it_can_cross`). Measured on ten commits of each of the 1,000 most-starred GitHub repositories, 3.58% of their blob permalinks fired without the ceiling and 0.02% with it, and none of 20,000 key-shaped random keys is lost glued before, after or inside a commit, after a letter, after a route, or in a URL path. The residuals are a repository name whose own capitals fill most of a window, a window that starts inside the commit and runs into a path with capitals (1.08% of links to a capitalised file name such as File.py, against 4.64% without the ceiling), and a key that carries a route word and a `/` followed by twelve or more hex digits running to its end, pinned by `test_the_accepted_residual_is_a_key_that_ends_in_a_routed_commit` (`test/test_commit_permalink_redaction.py`). Not covered: raw.githubusercontent.com links, which put the commit straight after the repository name with no route word, and commits typed in upper or mixed case, which git never prints. **Document links** (`_DOCUMENT_LINK_RE`): a Google document id is ~44 random base64url characters, so a 40-char window inside it is byte-indistinguishable from a key and pass 3 would replace the whole `com/document/d/<id>/edit` run. Pass 3 therefore skips a run only when it lies wholly inside a link that matches a fixed route on a fixed host: HTTPS, a lowercase literal host right after the scheme (no userinfo, no port) of `docs.google.com`, `drive.google.com` or `<tenant>.atlassian.net`, and every path segment fixed or from a closed class (Google id `[A-Za-z0-9_-]{25,72}`, Confluence space key alphanumeric, page id digits); a piece of exactly 40 characters that `_looks_like_secret_key` accepts voids the match, with pieces cut once at `/` and the non-run characters `-_%.~` and once more at `+` (the space of a Confluence title slug), and a further base64-alphabet character after the route fails it. Query, fragment, userinfo, look-alike hosts and every pass 1, 2 and 4 hit are judged unchanged. The accepted residual is a key without `/` glued to more letters or digits inside the id or page title, or carrying its own `+` inside a title, which is indistinguishable from the id it sits in; about 2% of real Google ids carry a key-shaped 40-char piece between their random `-`/`_` and stay redacted (`test/test_document_link_redaction.py`). **PlantUML diagram links** (same regex): a PlantUML server link `https://<host>/[plantuml/]<png|svg|txt|uml>/<diagram>`, on a host whose first label is `plantuml` after an optional `www.`, carries its diagram as raw deflate in PlantUML's `0-9A-Za-z-_` alphabet, so nearly every one fires pass 3. Such a match is kept by decoding rather than by the 40-char piece check: `_plantuml_source` must see whole 4-character groups and inflate them to one complete stream of printable text, with nothing after it but the last group's padding (at most two zero bytes), so a stream cut through a key glued to a diagram never decodes, and `redact_credentials` must leave that text unchanged (a key, a base64-encoded assignment or a `?token=` value inside the diagram source voids it). Inflation is bounded at `_PLANTUML_RATIO_CAP` (16) times the encoded length per diagram and `_PLANTUML_SOURCE_CAP` (16 KiB) per call; past either bound the link is judged as before. While a decoded diagram is scanned, `_IN_DIAGRAM_SCAN` turns the route off, so a diagram link inside it is never decoded again. Query, fragment, userinfo, look-alike hosts and other path verbs are judged unchanged (`test/test_plantuml_link_redaction.py`). **SRI integrity digests** (`_SRI_INTEGRITY_RE`): a Subresource Integrity value (a `<script integrity=...>` attribute, npm's `package-lock.json`, Bazel's `integrity =`) is the algorithm name, `-`, and the standard-base64 digest — `sha256-<43 chars>=`, `sha384-<64 chars>` or `sha512-<86 chars>==`. The digest is a hash, so it is random base64 and a window inside it clears every gate; `-` and `=` are outside the run alphabet, so the digest is one whole run and pass 3 replaced it (84% of sha256 digests, more for the longer two). Pass 3 therefore skips a run only when it IS the digest of such a value: the lowercase algorithm name right after a non-run character, exactly that algorithm's digest length, exactly the padding that length takes, and no run or padding character after it. A 40-char key under the name (wrong length for every algorithm), the right length with the wrong padding or a glued character after it, the right length under another algorithm's name, a name glued to a run before it or written in upper case, a non-SRI name (`sha1-`, `md5-`), and a key beside the value in the same line or a later field are all judged as before; so is every pass-1, pass-2 and pass-4 hit, and the exfil URL scan (`_text_contains_bare_secret`), which does not consult the shape. The accepted residual is a 43-, 64- or 86-character secret a writer deliberately labels as a digest, byte-identical to one (`test/test_sri_integrity_redaction.py`). **macOS per-user directory id** (`_host_darwin_user_dir_id`, macOS only): `confstr` gives every process its temp and cache roots as `/var/folders/<2>/<30>/T` and `.../C`, whose two variable components are an OS-generated lowercase encoding of the user's UUID and uid. Scanned as one run, a window straddling that id and the `T` clears every gate, which turns every path under the temp dir into the tag, including a computer-use screenshot the model echoes as `` to show the user. Pass 3 scans the original run and exempts only windows that share at least `_HOST_ID_EXEMPT_OVERLAP` (24) bytes IN PLACE with the host id. The fast paths, fragment separator ceiling and printable-base64 exclusion all use the whole run's context, never a sliced piece's length or alignment. Any other positive window overlapping the id is still a hit, and pass 3 redacts every uncovered piece such a window INTERSECTS (not only one that wholly contains it), with earlier passes' spans subtracted as usual; the id and the prefix stay plaintext because they are withheld from the scan, not redacted. Every window the base scan classifies as a key is classified identically except one sharing ≥ 24 bytes with this host's id, because the run-level context remains the whole run's; the exemption gives up only windows that overlap the id that heavily. 24 exempts the screenshot spooler path (32), the bare root (33) and an `mkdtemp` `tmpXXXXXXXX` dir with a one-character leaf (24); a temp path whose run continues 15 or more run-alphabet bytes past the directory letter can still yield a positive window below 24 and stays redacted, exactly as without the exemption (over-redaction, never under-redaction), and a real key glued across the id with less overlap — the `<last-id-byte>/T/…` shape — is still judged and redacted. Only THIS HOST's id is withheld, read once from `confstr(_CS_DARWIN_USER_TEMP_DIR)`: in free text an id's bytes are otherwise the writer's to choose, and 33 chosen bytes plus seven after `/T` form a classifier-positive window the split would give up, whereas the host's own id is chosen by nobody who writes text. `confstr` refuses the name off Darwin, and a refusal or an off-grammar answer withholds nothing. The match also carries the path grammar: the prefix starts a path (no run-alphabet byte, `/` included, before it), and the byte after the directory letter does not continue the run -- `/` starts the next component, and any byte outside `[A-Za-z0-9+/]` ends the run there, so the bare root printed, quoted in JSON, inside a `PosixPath` repr, or followed by a newline is exempt the same as one that ends the text, while `/Tevil` is a chosen name and is not. Ending the run at the letter gives up nothing past it: the pieces left in that run are the prefix and the two-byte `/T`, each shorter than one key, and a key after `/T_evil/` or `/T_` is its own run and is found there. `dashboard.handlers.files._redact_project_path` keeps its own, wider split for resolved project paths, gated on `platform_compat.IS_MACOS`, where the bytes are a real directory the OS created. Pinned in `TestPathWindowsAreNotBareSecrets` on real-shaped ids and the path the spooler actually writes; widening the id to any string of its shape, loosening either anchor, dropping the withholding or classifying sliced pieces instead of original-run windows reds a test there | ||
| - **Bare label-less secret-key detection**: a 40-char AWS *secret access key* (the value paired with an `AKIA`/`ASIA` ID) is a bare base64 run with NO prefix and NO `key=` label, so the fixed-format patterns above miss it when it appears standalone (echoed alone, in a log line, in a JSON array element). A third redaction pass adds an entropy + structural heuristic: `_BARE_SECRET_RUN_RE` isolates each `[A-Za-z0-9+/]{40,}` run (word-boundary look-arounds so surrounding prose is preserved), then `_looks_like_secret_key()` applies every gate below — a token must clear ALL of them (design bias is toward NOT redacting: a false negative reverts to prior behavior, a false positive corrupts benign output). Gates, ordered by measured cost per rejection (cheapest first): (1) length is EXACTLY 40 (AWS secret-key length); (2) contains lower + upper + digit (rejects all-lower prose, ALL-UPPER constants, base32, digit runs); (3) not an all-hex run (`_HEX_ONLY_RE` rejects 40-char git SHAs and 32/64-char md5/sha256 digests — verified even for mixed-case hex that would otherwise clear the entropy gate); (4) the longest run of consecutive lowercase letters ≤ `_SECRET_MAX_LOWER_RUN` (5), decided by `_lowercase_run_exceeds(token, cap)`, which stops as soon as a run reaches `cap + 1` instead of measuring the longest run in the whole token; (5) vowel ratio ≤ `_SECRET_MAX_VOWEL_RATIO` (0.30); (6) Shannon entropy ≥ `_SECRET_ENTROPY_MIN` (4.3 bits/char — real random keys average ~4.78 and rarely drop below ~4.4, while camelCase identifiers and file paths cluster at 4.0-4.3; the canonical AWS example scores 4.66); (7) does not base64-decode to ≥85% printable ASCII (`_decodes_to_printable_text` leaves encoded-text blobs to the decode-and-scan pass). **The order of gates 4-7 is a performance property, not a correctness one:** all four are pure predicates that return `False` on failure, so every permutation produces the same verdict on every input — which is exactly why a behavior test cannot pin it. The two structural gates reject more per microsecond than entropy does, so they run first and entropy is paid only on the windows that clear them. `TestSecretGateOrderIsCostOrdered` counts gate evaluations and fails if the order regresses to entropy-first; do not reorder these four back without re-measuring. Both structural gates apply to EVERY token: unlike a naive design, the presence of `/` or `+` is **not** a free pass to redact, so a 40-char mixed-case file path (e.g. `src/main/java/com/Example/FooBarBazClas1`) — which contains `/` yet is built from dictionary-word segments with long lowercase runs — stays intact. The pass scans the ORIGINAL text (stable offsets) and skips any run already redacted by pass 1/2. Tests (`test_security.py::TestBareSecretKeyRedaction`) prove true positives on real secret shapes and NO over-redaction of git SHAs, UUIDs, sha256/md5 hex, base32, prose, code identifiers, or slash-delimited file paths. **Glued-secret sliding window**: `_looks_like_secret_key()` only accepts an EXACTLY-40-char token (gate 1) — its documented boundary assumption — but `_BARE_SECRET_RUN_RE` captures the *longest* base64 run, so a real 40-char secret glued to an adjacent base64 char with no delimiter (`X`+secret, secret+`A`, `SECRET=`+secret+`ABC`, secret+`X`+secret) forms a 41+ char run that fails the exact-40 gate and would leak verbatim. Pass 3 therefore gates each captured run through `_contains_bare_secret()`, which slides a 40-char window across the run and redacts the whole run when ANY window clears every gate; this stays linear (the regex yields disjoint spans). A >40-char camelCase *identifier* run survives the slide (no window within it clears the structural gates), but a deep absolute *path* does not on its own: `/` is in the run alphabet, so a path such as `/Volumes/workplace/TRAM/QuickProp2/src/ATVTramQuickPropCDK/lib/config/consumerVpcs` is ONE run, and a window straddling several CamelCase components clears every gate (CamelCase caps its lowercase run, acronyms crush its vowel ratio, a version digit supplies the third class, the separators lift its entropy) — which redacted the whole path and left a file-viewer chip dereferencing `[REDACTED: credential].ts`. **Fragment separator ceiling** (`_SECRET_MAX_SLASHES`, 3): inside `_contains_bare_secret()`, a classifier-positive window is declined when it holds more than three `/` AND the run is longer than one key — separator density is what tells a path window (one `/` per component) from a key (`/` is 1 base64 character in 64, so a real key averages 0.6). Two conditions keep it a gate rather than a hole: it applies only to a FRAGMENT, so a standalone 40-char key is judged by the seven gates alone however many `/` it carries; and it is read AFTER `_looks_like_secret_key()` answers, so every offset is still classified and a key glued into a run is still found at its own offset. Measured on 200k uniformly random 40-char keys it declines 0.36% on its own, against 9.29% for the lowercase-run gate and 6.60% for the vowel-ratio gate. The accepted residual — a key carrying 4+ `/` AND glued into a longer run — is byte-identical to a benign path window at this layer and is pinned as a decision by `test_the_accepted_residual_is_a_separator_heavy_key_glued_into_a_run` (`TestPathWindowsAreNotBareSecrets`). **Fragment commit ceiling** (`_ROUTED_COMMIT_RE`, `_ROUTED_COMMIT_PIECE_MIN`): a commit permalink is one run too (`com/Owner/RepoName/blob/<commit>/src/file`), and its window straddling `RepoName/blob/` and the start of the commit clears every gate on two separators, with capitals from the repository name and lowercase and digits from the hex. A classifier-positive FRAGMENT window is declined when it crosses the opening `/` of a routed commit and takes eight of its digits (`_ROUTED_COMMIT_PIECE_MIN` = 8). A routed commit is a path segment of exactly 40 or 64 lowercase hex digits, as git prints one, right after a `blob`, `blobs`, `tree`, `trees`, `blame`, `raw`, `commit`, `commits` or `src` segment and ending at a `/` or the run's edge. The plural routes are what some code hosts print, under a deeper `packages/<name>/` path; that extra segment lets a firing window take fewer than twelve commit digits, so the floor of twelve the ceiling first shipped with left about a third of such links redacted. Eight is the highest floor that clears them: the widest firing window is `kages/`, a 19-character package name and `/blobs/`, which leaves exactly eight digits (none of 4,000 such links fire at eight, 766 at nine). The floor is not lower because each digit it drops frees one more character of a padded key: at one, a key needs only `/blob/` and a single hex digit to be declined. The same two conditions as the separator ceiling apply. The route is what keeps a key out: a key's own window crosses that `/` only when the key itself ends in a route word, that `/` and hex digits. A window starting inside a commit is judged as before, and so is hex a key carries anywhere else. Commits are a whole window long, so each window reads only the first commit starting after it, and a run full of them stays linear (`test_a_window_reads_only_the_commit_it_can_cross`). Measured on ten commits of each of the 1,000 most-starred GitHub repositories, 3.58% of their blob permalinks fired without the ceiling and 0.02% with it, and none of 20,000 key-shaped random keys is lost glued before, after or inside a commit, after a letter, after a route, or in a URL path, at either threshold. The residuals are a repository or package name whose own capitals fill most of a window (a package name longer than 19 characters can leave a firing window fewer than eight commit digits, so such a link can still be redacted), a window that starts inside the commit and runs into a path with capitals (1.08% of links to a capitalised file name such as File.py, against 4.64% without the ceiling), and a key that ends in a route word, a `/` and eight or more hex digits the text runs on into a commit (twelve or more before the floor dropped to eight), pinned by `test_the_accepted_residual_is_a_key_that_ends_in_a_routed_commit` and, at the floor itself, `test_the_accepted_residual_starts_at_the_floor`, with one to seven digits pinned as still redacted by `test_a_key_padded_into_a_route_below_the_floor_is_redacted` (`test/test_commit_permalink_redaction.py`). Not covered: raw.githubusercontent.com links, which put the commit straight after the repository name with no route word, and commits typed in upper or mixed case, which git never prints. **Document links** (`_DOCUMENT_LINK_RE`): a Google document id is ~44 random base64url characters, so a 40-char window inside it is byte-indistinguishable from a key and pass 3 would replace the whole `com/document/d/<id>/edit` run. Pass 3 therefore skips a run only when it lies wholly inside a link that matches a fixed route on a fixed host: HTTPS, a lowercase literal host right after the scheme (no userinfo, no port) of `docs.google.com`, `drive.google.com` or `<tenant>.atlassian.net`, and every path segment fixed or from a closed class (Google id `[A-Za-z0-9_-]{25,72}`, Confluence space key alphanumeric, page id digits); a piece of exactly 40 characters that `_looks_like_secret_key` accepts voids the match, with pieces cut once at `/` and the non-run characters `-_%.~` and once more at `+` (the space of a Confluence title slug), and a further base64-alphabet character after the route fails it. Query, fragment, userinfo, look-alike hosts and every pass 1, 2 and 4 hit are judged unchanged. The accepted residual is a key without `/` glued to more letters or digits inside the id or page title, or carrying its own `+` inside a title, which is indistinguishable from the id it sits in; about 2% of real Google ids carry a key-shaped 40-char piece between their random `-`/`_` and stay redacted (`test/test_document_link_redaction.py`). **PlantUML diagram links** (same regex): a PlantUML server link `https://<host>/[plantuml/]<png|svg|txt|uml>/<diagram>`, on a host whose first label is `plantuml` after an optional `www.`, carries its diagram as raw deflate in PlantUML's `0-9A-Za-z-_` alphabet, so nearly every one fires pass 3. Such a match is kept by decoding rather than by the 40-char piece check: `_plantuml_source` must see whole 4-character groups and inflate them to one complete stream of printable text, with nothing after it but the last group's padding (at most two zero bytes), so a stream cut through a key glued to a diagram never decodes, and `redact_credentials` must leave that text unchanged (a key, a base64-encoded assignment or a `?token=` value inside the diagram source voids it). Inflation is bounded at `_PLANTUML_RATIO_CAP` (16) times the encoded length per diagram and `_PLANTUML_SOURCE_CAP` (16 KiB) per call; past either bound the link is judged as before. While a decoded diagram is scanned, `_IN_DIAGRAM_SCAN` turns the route off, so a diagram link inside it is never decoded again. Query, fragment, userinfo, look-alike hosts and other path verbs are judged unchanged (`test/test_plantuml_link_redaction.py`). **SRI integrity digests** (`_SRI_INTEGRITY_RE`): a Subresource Integrity value (a `<script integrity=...>` attribute, npm's `package-lock.json`, Bazel's `integrity =`) is the algorithm name, `-`, and the standard-base64 digest — `sha256-<43 chars>=`, `sha384-<64 chars>` or `sha512-<86 chars>==`. The digest is a hash, so it is random base64 and a window inside it clears every gate; `-` and `=` are outside the run alphabet, so the digest is one whole run and pass 3 replaced it (84% of sha256 digests, more for the longer two). Pass 3 therefore skips a run only when it IS the digest of such a value: the lowercase algorithm name right after a non-run character, exactly that algorithm's digest length, exactly the padding that length takes, and no run or padding character after it. A 40-char key under the name (wrong length for every algorithm), the right length with the wrong padding or a glued character after it, the right length under another algorithm's name, a name glued to a run before it or written in upper case, a non-SRI name (`sha1-`, `md5-`), and a key beside the value in the same line or a later field are all judged as before; so is every pass-1, pass-2 and pass-4 hit, and the exfil URL scan (`_text_contains_bare_secret`), which does not consult the shape. The accepted residual is a 43-, 64- or 86-character secret a writer deliberately labels as a digest, byte-identical to one (`test/test_sri_integrity_redaction.py`). **macOS per-user directory id** (`_host_darwin_user_dir_id`, macOS only): `confstr` gives every process its temp and cache roots as `/var/folders/<2>/<30>/T` and `.../C`, whose two variable components are an OS-generated lowercase encoding of the user's UUID and uid. Scanned as one run, a window straddling that id and the `T` clears every gate, which turns every path under the temp dir into the tag, including a computer-use screenshot the model echoes as `` to show the user. Pass 3 scans the original run and exempts only windows that share at least `_HOST_ID_EXEMPT_OVERLAP` (24) bytes IN PLACE with the host id. The fast paths, fragment separator ceiling and printable-base64 exclusion all use the whole run's context, never a sliced piece's length or alignment. Any other positive window overlapping the id is still a hit, and pass 3 redacts every uncovered piece such a window INTERSECTS (not only one that wholly contains it), with earlier passes' spans subtracted as usual; the id and the prefix stay plaintext because they are withheld from the scan, not redacted. Every window the base scan classifies as a key is classified identically except one sharing ≥ 24 bytes with this host's id, because the run-level context remains the whole run's; the exemption gives up only windows that overlap the id that heavily. 24 exempts the screenshot spooler path (32), the bare root (33) and an `mkdtemp` `tmpXXXXXXXX` dir with a one-character leaf (24); a temp path whose run continues 15 or more run-alphabet bytes past the directory letter can still yield a positive window below 24 and stays redacted, exactly as without the exemption (over-redaction, never under-redaction), and a real key glued across the id with less overlap — the `<last-id-byte>/T/…` shape — is still judged and redacted. Only THIS HOST's id is withheld, read once from `confstr(_CS_DARWIN_USER_TEMP_DIR)`: in free text an id's bytes are otherwise the writer's to choose, and 33 chosen bytes plus seven after `/T` form a classifier-positive window the split would give up, whereas the host's own id is chosen by nobody who writes text. `confstr` refuses the name off Darwin, and a refusal or an off-grammar answer withholds nothing. The match also carries the path grammar: the prefix starts a path (no run-alphabet byte, `/` included, before it), and the byte after the directory letter does not continue the run -- `/` starts the next component, and any byte outside `[A-Za-z0-9+/]` ends the run there, so the bare root printed, quoted in JSON, inside a `PosixPath` repr, or followed by a newline is exempt the same as one that ends the text, while `/Tevil` is a chosen name and is not. Ending the run at the letter gives up nothing past it: the pieces left in that run are the prefix and the two-byte `/T`, each shorter than one key, and a key after `/T_evil/` or `/T_` is its own run and is found there. `dashboard.handlers.files._redact_project_path` keeps its own, wider split for resolved project paths, gated on `platform_compat.IS_MACOS`, where the bytes are a real directory the OS created. Pinned in `TestPathWindowsAreNotBareSecrets` on real-shaped ids and the path the spooler actually writes; widening the id to any string of its shape, loosening either anchor, dropping the withholding or classifying sliced pieces instead of original-run windows reds a test there |
There was a problem hiding this comment.
Optional: the "none of 20,000 key-shaped random keys is lost" sentence predates the plural routes and the floor of 8.
I fuzzed 5,000 classifier-positive random keys glued before a routed commit (<key>/blobs/<commit>/x). At this head 12 come through unredacted for /blobs/ and 12 for /trees/, against 5 and 6 on main. The singular /blob/ shape already loses 11 on main and 12 here, so this looks like the existing separator ceiling residual (a key with several / glued into a longer run) now reaching the plural routes, not a new hole. A standalone key loses none in either build.
Suggestion: qualify the sentence (for example, scope it to keys outside the separator ceiling residual) or point it at that residual, so the claim matches what the tests pin.
Rule: a measured claim in the spec should hold for the code it describes.
|
CI note for head 🤖 AI-assisted comment 🤖 |
|
@bolichen97 thanks. Your spec note is right, and I reproduced it. With 5,000 classifier-positive random keys glued as I have the wording fix ready locally. It scopes the "none of 20,000" sentence to keys with at most three CI on this head: 🤖 AI-assisted comment 🤖 |
…cret pass The commit ceiling recognised only singular route words (blob/, tree/). Accept blobs/ and trees/, and lower the commit-digit floor a window must take to be declined (_ROUTED_COMMIT_PIECE_MIN 12 -> 8): a deeper packages/<name>/ path leaves a firing window exactly eight commit digits. Eight is the highest floor that clears those links; a lower one would free more of a key padded into a route. One to seven digits after a route stay redacted, and the residual at eight is pinned as accepted. Closes #23131
d4b4a22 to
c1a7d67
Compare
Sensitive change review
|
|
@bolichen97 your spec note is addressed in 🤖 AI-assisted comment 🤖 |
bolichen97
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. Reviewed at c1a7d67.
The only change since d4b4a22 is the spec sentence my last review flagged. It now scopes the "none of 20,000 random keys is lost" claim to keys with at most three /, and names the four-or-more case as the separator ceiling residual reaching the plural routes. The code and tests are byte-identical to d4b4a22, where the test file passed locally.
What I checked on this head: I fuzzed 5,000 classifier-positive random keys per route, glued before /<route>/<commit>/x. For /blob/, /blobs/ and /trees/, no key with zero to three / came through (about 4,950 per route). Only keys with four or more / did (16 of 18, 13 of 17, 19 of 20). That matches the new wording. My sample counts differ from the 24 quoted in the spec, as expected for a different random draw, so I am not asking to change the number.
No open findings from me. This touches secret redaction and the checks on this head are still queued, so I am leaving the approval to a maintainer once CI and readiness are green.
Dismissing my earlier change request: the current head addresses it and all readiness checks and review lanes are green.
bolichen97
left a comment
There was a problem hiding this comment.
Approving head c1a7d67. Verified: readiness label passed, PR Readiness green, no failing required check, all AI review lanes green with no BLOCK, no outstanding change requests from other reviewers. Thanks for the contribution.
Problem / Motivation
Goal: A commit permalink on a code host that spells its routes
blobs//trees/stays a working link in agent output, and a secret in the same position is still redacted.A permalink such as
https://<host>/packages/<Package>/blobs/<40-hex commit>/--/<path>comes back ashttps://<host-prefix>[REDACTED: credential]--/<path>, so the link is broken. Nothing in it is secret. Reported as #20017 and #15565 (bare_aws_secret).Why it matters
Agents relay commit permalinks after almost every review, build or deploy. On main, about a third of such
/blobs/links and a quarter of/trees/links are blanked, depending only on the random bytes of the commit. The user cannot open or copy what the agent found.Not a goal
?commit=<sha>), which tripsexfil_query_patternand is fix(security): keep commit permalinks whose query carries a git object name #19540's scope.What changed (motivation → approach → change)
blobs/,trees/) commit permalink is redacted as a bare secret key.src/kiro_crew/security/redaction_entropy.py,/is in the bare-secret run alphabet, so a whole permalink is one run. A 40-character window spanning the CamelCase package name and the start of the commit clears every per-window gate. The commit ceiling (_ROUTED_COMMIT_RE, from [bug] Commit permalinks to repositories with capitals are redacted as credentials #16907) exists to decline exactly that window. It had two gaps for such hosts:blob/,tree/), notblobs/andtrees/.packages/<name>/path lets a firing window take fewer than 12; with the plurals alone, about a third of links to some CamelCase package names still fired._ROUTED_COMMIT_REacceptsblobs?andtrees?, and_ROUTED_COMMIT_PIECE_MINdrops from 12 to 8. The ceiling still runs only after_looks_like_secret_keyhas classified the window, and only on a fragment longer than one key, so a key at its own offset is still found. The comment above the regex is rewritten with the new measurements and stays inside the security package line budget (net 0 lines). The owning spec,docs/system-specs/modules/security.md(Fragment commit ceiling), is updated in the same commit: the route list gainsblobs/trees, the floor reads eight digits instead of twelve with the reason, and the accepted residual is restated.packages/<name>/blobs/<commit>link iskages/(a lowercase run of five;packagesis longer than the gate allows), a 19-character package name and/blobs/, which leaves exactly eight commit digits. Measured on 4,000 such links with 19-character names: 0 fire at a floor of 8, 766 at 9, 782 at 10./trees/links need only 10. An earlier revision of this PR used 1; maintainer review pointed out that every digit the floor drops frees one more character of a key padded into a route, so the floor is held at the value the fix needs.Accepted residual: a key that itself ends in a route word,
/and eight or more hex digits, glued to more hex that completes a 40- or 64-digit run. On main that took twelve digits (test_the_accepted_residual_is_a_key_that_ends_in_a_routed_commit); here it takes eight, pinned at the boundary bytest_the_accepted_residual_starts_at_the_floor. One, two and seven digits afterblob,tree,blobsandtreesare pinned as still redacted bytest_a_key_padded_into_a_route_below_the_floor_is_redacted. Such a key must literally contain a route word,/and eight hex digits, and none of 20,000 random keys in 10 glued shapes is lost at a floor of 8. The other residual: a package name longer than 19 characters can still leave a firing window fewer than eight digits, so some such links stay redacted (fail-safe).Backwards compatibility
Compatible: only windows that were redacted before can now pass. Every input that passed on main still passes, and no API, config key or stored data changes.
Removes nothing: the change only narrows what the bare-secret pass redacts. It hides no path, deletes no record and tightens no validator.
Tests
test/test_commit_permalink_redaction.py:git.example,blobs/,trees/) joinFIRING_LINK_TEMPLATES. They inherit the existing survives-in-six-wrappings test, the fires-without-the-ceiling test and the 200-seeded-commits test.test_a_plural_route_link_fires_on_singular_routes/..._when_twelve_digits_are_requiredshow that each half of the fix is necessary, andtest_a_plural_route_link_fires_one_digit_above_the_floorshows a floor of 9 is not enough.test_a_key_padded_into_a_route_below_the_floor_is_redacted(1, 2 and 7 digits) andtest_the_accepted_residual_starts_at_the_floor(8 digits) pin the boundary. At a floor of 1 the first goes red in all 12 cases.test_a_sha256_segment_after_a_plural_route_survives.test_a_key_in_a_plural_route_link_is_still_redacted,test_a_glued_key_after_a_plural_route_is_still_redactedandtest_seeded_keys_glued_to_a_plural_route_commit_are_redactedcheck that a key in the same position as the hash is still redacted.Determinism proof: the file passed 114/114 serially and under
-n8. The tests seedrandom.Random(<constant>)only.prove.py --per-hunkreverted the production hunk and the tests failed (PROVEN). Setting the floor to 1 reds the 12 padded-key cases; setting it to 9 reds the plural-route survival tests.Manual verification
Measured with a seeded fuzz corpus through
redact_credentials, at floors 12 (main), 8 (this PR) and 1 (the previous revision).packages/<name>/{blobs,trees,commits}/<sha>links, 14 package names incl. two of 19 charsblob/<sha>/src/<File>/<route>/+ 1-7 hex, padded to a commitRelated Issues
Closes #23131
Part of the false-positive class in #22552. Same report: #20017, #15565.
Relationship to #22887
#22887 deletes
src/kiro_crew/security/redaction_entropy.pyas part of the #22552 tier redesign. If #22887 lands first, it must carry this change: the pluralblobs?/trees?route words and_ROUTED_COMMIT_PIECE_MIN12 → 8, or an equivalent that keeps these tests green. If this PR lands first, #22887 rebases over a two-line production change.Pattern harvest
Rule candidate: review-prompt
Pattern: "a shape heuristic keyed on one host's URL vocabulary (singular route words) misses another code host's spelling. When a host-agnostic URL guard is added, test it against every major code host's route vocabulary (GitHub, GitLab, Bitbucket, and hosts that pluralise them)."
Checklist