Repository navigation
fix(security): redact a two-segment link token that follows a '.' - #23293
Conversation
Sensitive change review
|
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. The redactor now removes more than before, the change takes nothing away, and nothing in it is platform-specific. Notes
[DESIGN-REVIEWED] 89354d2 Description read[DESCRIPTION-READ] bf573361413e7269f5eb9b8ad1df3d190472dca9acf4b08ffc715d87101279e0 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: this fixes a linked defect (#21550) where the redactor already decides what gets removed. All three copies of the pattern are accounted for. What this change shipsInventory (6 items) — 6 justifiedIntent: stop a dashboard link token from surviving redaction when it comes right after a
[FIRST-PRINCIPLES-REVIEWED] 89354d2 Description read[DESCRIPTION-READ] c757b0d1acc0835966033f2b8730f165cf84d11c56e2d2975f772245f6abf653 That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: The change widens one alternative in TIGHTENING: The start boundary of the two-segment link-token alternative in ADJUDICATED: 17 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: The diff assumes nothing about paths, separators, interpreters or executable names; it is a regex over text. I still wrote both spellings for each surface where one exists:
Both the posix and windows rows carry the full-length dotted member chain ( UNADJUDICATED: The same widened branch feeds several non-shell surfaces the classifier cannot judge:
These are the legitimate inputs I would have submitted:
None of these can be confirmed without a redaction-surface classifier. The narrowing I can argue but not confirm is the [SCOPE-REVIEWED] 89354d2 |
f86d12d to
ce70eba
Compare
|
Rebased once onto main for the #23264 Windows fix. |
Sensitive change review
|
bolichen97
left a comment
There was a problem hiding this comment.
HOLD
Removing the dot boundary makes the secret redactor consume valid dotted identifier chains. A member shaped as eyJ plus a long base64url name, followed by a second 43-character member, is redacted even though it is ordinary code. The new compatibility test never builds that two-segment shape, so it passes before and after the change.
Please add the exact dotted-chain regression and retain or replace the boundary with a discriminator. If this over-redaction is intentional, document and explicitly approve that contract.
[Security: the change closes a real token-redaction gap, but it also alters stored and displayed non-secret content while claiming compatibility. No new secret exposure was found.]
ce70eba to
84fb52c
Compare
Sensitive change review
|
|
@bolichen97 thanks, the finding held. Addressed in
|
bolichen97
left a comment
There was a problem hiding this comment.
Re-review at 84fb52c. The issue in my earlier review on ce70eba is fixed: a dotted member chain with the token's exact lengths (config.eyJ<102 char member>.<43 char member>(x)) is kept again, and test_a_full_length_dotted_member_chain_is_kept pins that shape.
What I checked on this head:
- The start guard reads correctly. After a
., a match starts only when the payload or signature holds a-, or every fourth payload character from the fifth on is inA-Za-f. That second property is true for base64url of ASCII bytes, andgenerate_tokenencodes its payload with the default ASCIIjson.dumps. - Each guard arm reads at most two segments from one start, and only at a position right after a
., so the scan stays linear. origin/mainstill has the old(?<![A-Za-z0-9_.-])boundary, so this change is not superseded.test/test_link_token_dot_boundary.py,test/test_redaction_mirror_parity.pyandtest/test_chat_runner_coverage.pypass locally on this head (122 passed).- The
_review_contract.pycopy has the same pattern as the backend, andwebsite/src/utils/sanitize.tshas no start boundary, so it is not affected.
On the GPT lane finding at test/test_link_token_dot_boundary.py:98: the assertion fails only if all 200 minted tokens fall in one category. Each token has no - with a probability of about one half, so the chance per run is near 2 x 0.5^200. I read this as not a real flake risk, but a maintainer has to decide on that lane.
One small comment inline. Nothing blocks from my side.
Status: this touches the redaction patterns, so it needs a maintainer approval. That approval and the GPT lane decision are still open, and some test shards were still running when I checked.
| @@ -31,7 +31,8 @@ | |||
| # HMAC-SHA256 digest), the payload bound is a generator-derived floor rather | |||
| # than a guess (a guessed floor is beatable by a verbose identifier), and the | |||
| # left boundary (incl. `.`, so attribute access is excluded) keeps ordinary | |||
There was a problem hiding this comment.
🟡 This comment still says the left boundary includes .
# left boundary (incl. `.`, so attribute access is excluded) keeps ordinary
# dotted code intact unless what follows the `.` carries a `-` or a payloadThe lookbehind is now (?<![A-Za-z0-9_-]), so it no longer includes .. A reader of this copy can think attribute access is still excluded by the boundary itself.
Suggestion: Reword it to match the backend comment: the lookbehind covers letters, digits, - and _, and a guard after a . keeps obj.eyJ... code unless the token has a - or a payload shaped as base64url of ASCII JSON.
84fb52c to
3c3f8ea
Compare
|
Sensitive change review
|
bolichen97
left a comment
There was a problem hiding this comment.
Re-review at 3c3f8ea.
Fixed since 84fb52c: the probabilistic assertion in test_minted_link_tokens_after_a_dot_are_redacted is gone, and the new test_an_ascii_json_payload_without_a_dash_is_redacted_after_a_dot pins the base64url-of-ASCII arm with fixed input. I checked that it is a real pin: with that arm removed from the pattern, the test's token is no longer matched after a ..
Still blocking: the copy in _review_contract.py is compiled inside _SECRET_RE, which starts with (?i). Under that flag the new [A-Za-f] class matches every letter, so the shape guard passes for any all-letter member. I reproduced it on this head: config. + an eyJ... member of 100, 102, 103, 104, 106 or 107 letters + .deserializeFromStringValueUsingMapperConfig(x) is redacted by the review script's redact() and kept by redact_credentials. This is the same dotted-chain over-redaction my earlier review raised, now only in the mirror. test_redaction_mirror_parity.py compares the pattern text, so it cannot see a flag difference.
Also still open: the stale boundary comment at _review_contract.py:33 from my previous review.
What I ran on this head: test/test_link_token_dot_boundary.py, test/test_redaction_mirror_parity.py and test/test_chat_runner_coverage.py (123 passed), plus the reproduction above. This PR changes redaction code, so approval will come from a maintainer, not from this review.
| # boundary is satisfied by a `.` and would leave `.signature` in the printed | ||
| # log. That shape is covered by a test. | ||
| r"|(?<![A-Za-z0-9_.-])eyJ[A-Za-z0-9_-]{96,}\.[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])" | ||
| r"|(?<![A-Za-z0-9_-])(?!(?<=\.)(?!eyJ[A-Za-z0-9_]*-)(?!eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_]*-)(?!eyJ[A-Za-z0-9_-](?:[A-Za-f][A-Za-z0-9_-]{3})*(?:[A-Za-f][A-Za-z0-9_-]{1,2})?\.))eyJ[A-Za-z0-9_-]{96,}\.[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])" |
There was a problem hiding this comment.
🔴 The ASCII shape guard is case-insensitive in this copy
_SECRET_RE is compiled from r"(?i)(...", so in this alternative [A-Za-f] matches every letter. The guard that should keep obj.eyJ... code then passes for any all-letter member whose length mod 4 is 0, 2 or 3, and the match starts after the ..
r"|(?<![A-Za-z0-9_-])(?!(?<=\.)...(?!eyJ[A-Za-z0-9_-](?:[A-Za-f][A-Za-z0-9_-]{3})*...Reproduced on this head: config. + a 102-letter eyJ... member + .deserializeFromStringValueUsingMapperConfig(x) becomes config.[REDACTED](x) through redact(), while redact_credentials keeps it unchanged. The verbatim text check in test_redaction_mirror_parity.py passes because the text is identical; only the flags differ.
Suggestion: wrap this alternative in (?-i:...) so it is case-sensitive like the backend, and add a behavior test that runs the dotted member chain cases through this script's redact() as well as redact_credentials.
Rule: two copies of a security pattern must behave the same, and a parity test should check behavior, not only text.
3c3f8ea to
89354d2
Compare
|
Sensitive change review
|
bolichen97
left a comment
There was a problem hiding this comment.
Re-review at 89354d2.
Fixed since 3c3f8ea: the two-segment alternative in _review_contract.py is now wrapped in (?-i:...), so [A-Za-f] is case-sensitive again inside the (?i) regex. The new test_the_review_script_copy_keeps_the_same_dotted_chains compares behaviour, not pattern text, across all four member lengths mod 4, and test_the_review_script_copy_redacts_a_token_after_a_dot keeps the positive case. I checked that these tests are a real pin: with the 3c3f8ea copy of _review_contract.py restored, 9 of them fail; on this head test_link_token_dot_boundary.py and test_redaction_mirror_parity.py pass (51 tests). This also covers the dotted-chain over-redaction from my first review, so I am dismissing my two earlier change requests.
One small thing left, inline: the comment at _review_contract.py:33 still says the left boundary includes .. It does not block.
Security path change, so approval stays with a maintainer.
| @@ -31,7 +31,8 @@ | |||
| # HMAC-SHA256 digest), the payload bound is a generator-derived floor rather | |||
| # than a guess (a guessed floor is beatable by a verbose identifier), and the | |||
| # left boundary (incl. `.`, so attribute access is excluded) keeps ordinary | |||
There was a problem hiding this comment.
🟡 This comment still says the left boundary includes .
# left boundary (incl. `.`, so attribute access is excluded) keeps ordinaryThe lookbehind is (?<![A-Za-z0-9_-]), which does not include .. Attribute access is kept by the guard that runs after a ., not by the boundary. A reader of this copy can think the boundary itself still excludes attribute access.
Suggestion: say that a start after a . is checked by the guard that follows, which is what keeps attribute access.
Rule: comments must describe the code as it is.
Fixed at 89354d2: the mirror alternative is case-sensitive again and behavioural tests pin it.
bolichen97
left a comment
There was a problem hiding this comment.
Approving head 89354d2. Verified on this head: readiness label passed, PR Readiness green, all review lanes and required checks green (cancelled runs were superseded by later green runs), no open change requests. Queuing squash auto-merge pinned to this head.
Problem / Motivation
Goal: The credential redactor removes a two-segment link token the same way whether it starts the text, follows a space, or follows a
., while a dotted member chain of the same lengths stays intact.The two-segment link-token alternative in the credential pattern had a left boundary that included
.. A token right after a.(prefix.<token>,see .<token>) was kept in full, while the same token at the start of a text or after a space was removed. A streamed reply hit the same split: a per-delta pass removed the token when a delta started with it, but the whole-text pass kept it.Why it matters
Any reply that holds such a token right after a
.is saved, copied and posted with the token in it. The dashboard chat save works around it today by withholding the reply.Not a goal
dashboard/chat_runner.pythat work around this; they still cover the glued-token case tracked in Credential redaction keeps most of a second token glued to the first #21595.What changed (motivation → approach → change)
The
.was in the boundary to keep dotted code intact. The lengths alone cannot do that: a chain such asconfig.eyJ<long member>.<43-char member>(x)has the token's exact shape. So insecurity/redaction_patterns.pythe lookbehind now covers letters, digits and-/_, and a start guard decides what follows a.. There the token starts a match only when it carries what an identifier chain never does:-in either segment, orA-Zora-f, because it encodes the top six bits of an ASCII byte. Everygenerate_tokenpayload is ASCII JSON, sincejson.dumpsescapes non-ASCII.Each guard arm reads one segment once, so the scan stays linear. The stdlib copy of the pattern in the prepare-pr skill's
_review_contract.pyand the owning spec,docs/system-specs/modules/security.md, are updated to match; in_review_contract.pythe alternative is wrapped in(?-i:…), because that file's regex runs under(?i)and the payload-shape class must stay case-sensitive as it is in the backend.test/test_redaction_mirror_parity.pynow tells the two JWT alternatives apart by the{2,4}repetition and splits the two-segment one at its payload floor, so the frontend mirror is still pinned on the body and exempt only on the boundary.Backwards compatibility
Compatible: against main the redactor removes more, never less. At every position not right after a
.the alternative is unchanged; after a.it now also removes a token that passes the guard. Dotted member chains are kept, as on main.Removes nothing: no path, record, key or function is removed.
Tests
test/test_link_token_dot_boundary.py, with neutral fixtures:prefix., after a lone., and after a sentence's.with no space;obj., and a fixed ASCII-JSON payload with a fixed--free signature is removed afterobj., so the payload-shape arm is covered without depending on a random nonce;eyJplus a 102-character member, then a 43-character member) is kept afterconfig.,self.cache.and a lone., followed by(x), nothing,.close()or= None;.are kept;redact()keeps the same dotted chain (member lengths covering every remainder mod 4) and still removes a fixed token afterobj.; 9 of those cases fail against the previous_review_contract.py;.eyJare scanned under a 60 s timeout.The 12 dotted-chain cases fail on the previous head and pass now. Disabling the ASCII-JSON arm fails both of those tests; disabling the
-arms fails the three filler after-.cases and the chat-save test below.test/test_chat_runner_coverage.py: two save-guard tests used a token after.as their example of a value only a per-delta pass removes, and the fix stops that example producing one.test_each_removed_value_is_checked_on_its_ownnow uses two glued tokens (#21595) and still fails closed, through the saved-text check.test_a_record_holding_a_value_only_a_per_delta_pass_removed_fails_closednow uses a token glued to a word (q=prefix<token>), still asserts the flush fails closed, and fails when the flush's_records_hold_removed_credentialcall is disabled.test_a_link_token_in_a_blocked_link_query_is_saved_in_neither_text_nor_recordis added for the after-.case: the token is in neither the saved text nor the link record. No credential-redaction test changes.220 redaction, credential, security, URL-check, stream, prepare-pr and chat-runner test files plus
test_redaction_mirror_parity.py: 13551 pass, including the security package line budget. isort, flake8, mypy, docs-lint and comment-history are clean.Manual verification
N/A — unit coverage sufficient: the change is the start guard of one regex alternative, exercised directly, with minted tokens, and through the streamed-save path.
Related Issues
Closes #21550
Sibling sweep
Swept: git grep -n "eyJ[A-Za-z0-9_-]{96,}" -- src/ website/src/
Sibling: src/kiro_crew/builtin_skills/kirocrew-dev/kirocrew-prepare-pr/scripts/_review_contract.py -- changed here
Sibling: website/src/utils/sanitize.ts -- not affected -- it carries no start boundary at all, so it already removes these tokens; the parity test pins its body.
Pattern harvest
Not generalizable: the guard reads properties of this one generator's output (base64url of ASCII JSON), and the parity test already pins the mirror.
Checklist