Repository navigation
fix(security): an ml.sh.read range that cuts a GitHub token is scrubbed by its shape, text and bytes alike - #2227
wanderdev0 wants to merge 6 commits into
Conversation
…ts body Seven rows on `ml.sh.read`. Six fail on this branch: 1. a text range that starts inside an unregistered `ghp_` token returns its body (`forModel` needs the prefix and 36 body characters in the same text); 2. a text range that ends inside returns the token's front, prefix included; 3. and 4. the same two cuts on the bytewise path, which never reaches `forModel`; 5. the same start-cut on a `github_pat_` token; 6. two ranges that split a token leave neither half scrubbed. The seventh pins what holds: a range holding the whole (line-delimited) token still reads `[a GitHub token]`. A refusal counts as an answer that keeps the token, so the rows assert the property over both shapes of answer. Fixtures put the token on its own line, because the shape rule anchors on `\b`. Co-Authored-By: Claude Code <noreply@anthropic.com>
…ed by its shape, text and bytes alike The range scrub matched registered forms only and widened by the longest of them, so a range cut inside an unregistered ghp_/github_pat_ token handed back its part, and a binary range never met the shape rule. margin() now floors at the longest token (266), scrubRange matches the token's shape over the window, and a token counts in `scrubbed`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # docs/spec/SECRET_HANDLES.md
…gistered GitHub token's body Fails on 4a1bbff: scrubbedHead holds back the start of a registered form only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed GitHub token's body tokenTail, beside heldTail: a tail of gh?_ (or github_pat_) and a body short of the shape's minimum, 39 characters at most. scrubbedHead holds back the larger of the two; heldTail and forLive are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verdict at Failing first: at d173c02 (built fresh) six of seven rows in tests/redteam-sh-read-token-range.test.mjs fail, row 5 (the whole-token pin) passes; at 308a1de the new head row in tests/secret-scrub-crossings.test.mjs fails; at 326a0df the three files (crossings, secret-registry, redteam-sh-read-token-range) pass, 71 of 71. Margin: Head cut, probed with an 82-character Not asked: the held tail is dropped from both the head and the next read. With an output of 65527
|
ml.sh.readwidened a range by the longest registered form and range-scrubbed registered values only; the GitHub token's shape rule ran later, inforModel, on the cut slice. The rule needs the prefix and 36 body characters in one text, so a range that started or ended inside an unregisteredghp_/github_pat_token handed back that part of it unscrubbed, and the bytewise branch (binary ranges) never ran the shape rule at all. e4's rows intests/redteam-sh-read-token-range.test.mjs(d173c02) pin it: six failed on the branch tip, all seven pass here.The fix
margin()(src/secret-registry.ts) is never less thanGITHUB_TOKEN_MAX(266, now exported fromsrc/secret-scrub.ts), so a token the range cuts is whole in the window.scrubRangematchesGITHUB_TOKENby shape over the whole window, first (asscrubSecretsdoes), dropping a registered hit that overlaps a token. A token that overlaps the slice becomes[a GitHub token]once, its outside part dropped, the same rule as a registered form. Token hits are returned astokens, apart from the namedcounts, because a token has no registered name.shRead(src/sw/sw-shell-call.ts) addstokenstoscrubbed, so a range changed only by a token says it was touched. The bytewise branch's early return of the raw bytes when nothing is registered is gone: with the 266 floor the margin is never 0.A cut head (
scrubbedHead, the first 64 KiB anml.shcall returns) held back only a tail that begins a registered form, so a head cut inside an unregistered token ended inghp_and up to 35 of its 36 body characters, which the shape never matches.tokenTail(src/secret-registry.ts, besideheldTail) holds back a tail ofgh?_orgithub_pat_and a body short of the shape's minimum;scrubbedHeadholds back the larger of the two. The most held back isghp_and 35 characters, 39 bytes.heldTailandforLiveare unchanged. The rows came first, in 308a1de: a cut head ending inghp_orgithub_pat_and 30 body characters, and a whole output ending inghp_abc, which the model reads as printed withcomplete: true(nothing follows it, so it is no token's front).One existing assertion changes because the rule did:
tests/secret-registry.test.mjs"margin: …" assertedmargin([]) === 0; it now asserts 266 for no forms, 266 when every form is shorter, and the longest form when one is longer than 266.This was the smaller of the two candidate fixes. Wiring
src/secret-scrub-range.tsinstead would need an async source adapter over the host read and its separate config-secret path.What a binary range now costs and reads as
Every binary range is widened by 266 bytes a side and scrubbed, where before, with nothing registered, it was returned as read. Measured on this laptop (
scrubRange+ latin1 + bytes back, median of 200), the default 64 KiB range adds 2.8 ms (p90 3.1 ms) and a 4 KiB range adds 0.18 ms. A binary range holding a token-shaped run of bytes reads[a GitHub token]in their place, withscrubbed: 1andlengthstill the raw range's byte count. A range with no match is the bytes as read, with noscrubbed. Both are pinned by a new row intests/secret-scrub-crossings.test.mjs("a binary read range holding an unregistered GitHub token…"), since e4's binary rows cover the two cuts only.Docs
docs/spec/SECRET_HANDLES.md: the token row names the cut read range and points at the new limit. "A cut never lets a prefix through" gives the 266 floor, the shape match, and a head cut before a token's body (39 bytes at most).scrubbed: <n>counts tokens too. Known limits gains:forLiveapplies the registered forms only, so an unregistered GitHub token shows in a live output's stream until the step settles. The settled step, what is stored and what the model reads carry[a GitHub token]. Ruling 39's shape detector is where it is repaired, not this PR.docs/dev/site-access.md:43: a host with a port is always a scrubbed form; a name without one is skipped when it is dotless or loopback (the wording of fix(security): a step's In render crosses the stored scrub at the START, the approval card and the DONE #2223's fix).src/secret-scrub-range.tsand its two test files are left as they are: no source file imports it, and whether it has a caller coming is the session-store lane's to answer.Tests: npm test (full), e4's seven rows, check-doc-links.
🤖 Generated with Claude Code