Repository navigation
fix(security): redact credentials by span in every pass - #11252
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the deliberate extra redaction of partly-claimed runs (documented "Behaviour change beyond the leak fix") is an acceptable false-positive trade — it errs toward redaction and is pinned by [DESIGN-REVIEWED] 09d6df5 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Confirm linked issue #8049 describes this leak; every other claim in the description is carried in CI by the verbatim legacy oracle. What this change shipsInventory (9 items) — 9 justifiedIntent: stop a real credential surviving redaction when its text also occurs inside an earlier, non-redactable run — a FIX (linked issue #8049; the leak is reproduced in CI against the retired code kept verbatim).
Root-cause check: the class ( [FIRST-PRINCIPLES-REVIEWED] 09d6df5 |
Opus 4.8 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: |
Security Scope Review -- 🟡 CONCERNSWhich legitimate operations does Verdict basis: the reviewer's own judgement; no confirmed regression. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: CONCERNS TIGHTENING: ADJUDICATED: 10 candidates, 0 confirmed newly-refused The candidates cannot probe the tightening itself, only its one coupling to the adjudicated surface: the diff touches none of the four tiers the classifier runs ( PLATFORM COVERAGE: posix, windows, and any. The diff itself is a pure-Python string algorithm — it adds no path, separator, interpreter, executable-name, or environment-variable assumption, so no platform spelling is assumed by the change. Candidates still carry both spellings wherever the row itself carries one: the test invocation ( UNADJUDICATED: The tightening lives in the output redactor, not in the tool-call deny composite, so no candidate row can obtain a verdict on it. The guard:
[SCOPE-REVIEWED] 09d6df5 |
`redact_credentials` passes 2 and 3 substituted by matched VALUE (`result.replace(matched, tag, 1)`), which rewrites the first textual occurrence of the value rather than the span the scan selected. A decodable base64 chunk, or a bare key, that also occurs inside an earlier, longer run which is itself not redactable had its tag land inside that host while the real standalone credential stayed in plaintext. All three passes now record `(start, end, tag)` spans against the immutable input and the string is spliced once, left to right. Precedence is positional (pass 1 > pass 2 > pass 3): a later pass redacts only the part of its span an earlier pass has not claimed, so nothing is redacted twice and a run partly consumed by a labelled match keeps no plaintext. The differential oracle in test_credential_prefilter.py is rewritten in the same by-span form without any of the live shortcuts, and the corpus gains the hosting shapes for both passes, the partly claimed runs, and an AST pin that no `.replace(` call remains in `redact_credentials`. Closes #8049
16213dd to
2801b3f
Compare
… one Keep the shipped by-value passes 2 and 3 verbatim in the test module as a second oracle, so both claims the rewrite makes are checked in CI instead of asserted off-CI: the by-span redactor is byte-identical to it (text and warning order) on every corpus shape where redacting by value landed on the right span, and on each of the four divergent shapes the legacy output keeps plaintext the by-span output removes. The by-span oracle shares its algorithm with the live function, so it cannot carry either claim alone. The linearity guard in test_security_regex_linearity.py pins its invariant (pass 1 scans with the shared compiled pattern, gated by the pre-filter on the same string) in the span-recording spelling instead of the retired `.sub(` one.
2801b3f to
09d6df5
Compare
|
Security Scope Review (advisory CONCERNS, 0 newly refused) — mapping each candidate input it could not adjudicate to the test that pins it on
|
iamwhatever
left a comment
There was a problem hiding this comment.
Approved after a full read of the diff on the current head: the change matches the linked issue and body, every load-bearing claim was spot-checked against main, tests pin the behaviour, all review lanes are clean and nothing is left undisposed on this head.
…1252) * fix(security): redact credentials by span in every pass `redact_credentials` passes 2 and 3 substituted by matched VALUE (`result.replace(matched, tag, 1)`), which rewrites the first textual occurrence of the value rather than the span the scan selected. A decodable base64 chunk, or a bare key, that also occurs inside an earlier, longer run which is itself not redactable had its tag land inside that host while the real standalone credential stayed in plaintext. All three passes now record `(start, end, tag)` spans against the immutable input and the string is spliced once, left to right. Precedence is positional (pass 1 > pass 2 > pass 3): a later pass redacts only the part of its span an earlier pass has not claimed, so nothing is redacted twice and a run partly consumed by a labelled match keeps no plaintext. The differential oracle in test_credential_prefilter.py is rewritten in the same by-span form without any of the live shortcuts, and the corpus gains the hosting shapes for both passes, the partly claimed runs, and an AST pin that no `.replace(` call remains in `redact_credentials`. Closes kirodotdev#8049 * test(security): pin the by-span redactor against the retired by-value one Keep the shipped by-value passes 2 and 3 verbatim in the test module as a second oracle, so both claims the rewrite makes are checked in CI instead of asserted off-CI: the by-span redactor is byte-identical to it (text and warning order) on every corpus shape where redacting by value landed on the right span, and on each of the four divergent shapes the legacy output keeps plaintext the by-span output removes. The by-span oracle shares its algorithm with the live function, so it cannot carry either claim alone. The linearity guard in test_security_regex_linearity.py pins its invariant (pass 1 scans with the shared compiled pattern, gated by the pre-filter on the same string) in the span-recording spelling instead of the retired `.sub(` one.
What
redact_credentials(src/kiro_crew/security/redaction.py) now positions every redaction by span in all three passes. Each pass records(start, end, tag)against the immutable input; the string is spliced once, left to right, at the end. Nostr.replaceon a matched value remains in the function.Why
Passes 2 (base64-encoded credential) and 3 (bare 40-char key) still substituted by matched value:
result.replace(chunk, tag, 1)andresult.replace(run, tag, 1).str.replace(x, tag, 1)rewrites the first textual occurrence ofx, not the span the scan selected. When a redactable value also occurs as a substring of an earlier, longer run that is itself not redactable, the tag lands inside that host and the real standalone credential survives in plaintext:Cdecodes to a credential;Q+Cis a 57-char run that cannot decode (length % 4 == 1) and is skipped, soreplace(C, …)hits the copy insideQ…Cand emits standaloneCverbatim;/+ key is a 41-char run every window of which exceeds the fragment slash ceiling, so the host is declined andreplace(run, …)hits it instead of the standalone key. Therun not in resultguard checks presence, not position, so it does not close this.Pass 1 was fixed the same way in #7941; this closes the class.
How
_uncovered(start, end, taken)subtracts the already-claimed spans (sorted, disjoint) from a candidate span with one bisect and a forward walk, returning the gaps still in plaintext._spliceapplies the final sorted span list in one pass.run not in resultskip). All pass-2 warnings still precede all pass-3 warnings.awsof a followingaws_secret_access_key=label, orsk-proj-…Z<key>where pass 1 consumed the head) previously fell throughrun not in resultand left the unclaimed portion of a key-shaped run in plaintext. The remainder is now redacted. The fuzz differential surfaced both shapes on the unmodified base.Tests
test/test_credential_prefilter.py, two commits:_reference_redact_credentialsis rewritten in the same by-span form with none of the live shortcuts (no pre-filter gate, separate_BARE_SECRET_RUN_REscan, generic_decode_b64_safe, linear bisect-free_reference_uncovered). New direct pins:test_hosted_encoded_credential_is_redacted_at_its_own_span(pass 2),test_hosted_bare_secret_is_redacted_at_its_own_span(pass 3),test_partly_claimed_run_keeps_no_plaintext,test_redact_credentials_never_substitutes_by_value(AST pin: no.replace(call inredact_credentials), plus corpus entries for the hosting, partly-claimed and same-value-twice shapes._legacy_redact_credentials, and two tests carry those claims in CI:test_by_span_agrees_with_legacy_wherever_legacy_landed_right(110 shapes, text and warning order identical) andtest_legacy_diverges_on_every_by_span_shape(the 4 divergent shapes, each paired with the plaintext the legacy output keeps and the by-span output removes). The by-span oracle shares its algorithm with the live function, so it could not carry either claim alone.test/test_security_regex_linearity.py::test_credential_pattern_module_still_compiles_one_alternationpinned pass 1's spelling (_CREDENTIAL_PATTERNS.sub(,_might_contain_credential(result)); it now pins the invariant it documents -- the shared compiled pattern scans the same string the pre-filter gated, and no localre.compile(-- in the span-recording spelling.main(git archive maininto a scratch dir). Green on this branch: 374 passed. Also green:test/test_credential_patterns.py,test/test_security.py,test/test_log_redaction.py,test/test_credential_redaction_notice.py.scripts/check_black_formatting.py,scripts/check_comment_history.py,scripts/check_subprocess_encoding.pyall pass.Other
Backend-only change to a pure string function; no UI surface is touched, so the
no-screenshotslabel is applied.bisect(..., key=)requires Python 3.10+; the package requires 3.12.Pattern harvest
Rule candidate: semgrep
Pattern: a
str.replace(<value>, <tag>, 1)whose first argument is the text of a regex match (m.group(), or a variable bound from it) inside a redaction/scrub function — flag as redact-by-value; the redaction must splicem.start()/m.end()instead.Closes #8049