Repository navigation
fix(#5705)!: stop JSON redaction from eating escaping backslashes - #10082
andrewevansrh wants to merge 6 commits into
Conversation
PR Summary by QodoFix JSON output redaction corrupting escaped backslashes (#5705)
AI Description
Merge Risk
|
|
🤖 Finished Review · ✅ Success · Started 3:49 PM UTC · Completed 4:03 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.45 |
Code Review by Qodo
1. JSON output is still redacted as raw text
|
Site previewPreview: https://dba39af9-site.fullsend-ai.workers.dev Commit: |
|
Risk Assessment: moderate (2/5) DetailsLarge diff driven predominantly by test suites and schemas with elevated historical churn in modified files, balanced by zero protected path or dependency changes, an established contributor, and close alignment with linked issue #5705. |
ReviewFindingsHigh
Medium
Low
Labels: The PR changes the output secret-redaction layer. Next steps:
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
429a03d to
7153974
Compare
Thanks for the update. I checked the fix against the current code, and it matches what you described.
This corresponds to finding 2 ("A later password escapes redaction"), which is already marked resolved ( |
|
🤖 Finished Review · Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.17 This review was superseded by a newer commit. Check the current pull request HEAD's review status before merging. |
…slashes The output sanitizer ran every pattern as a raw text replace over all output files. When an agent quoted code inside a JSON string value, a pattern matched up to the quote delimiter and swallowed the backslash escaping it, so the rewritten document was no longer valid JSON and downstream jq in post-review.sh failed with exit status 5. Three changes address that: - The redactor no longer includes a delimiter-escaping backslash in a captured value, and Mask returns "***" when the prefix it would keep carries an escape or a quote delimiter, so the mask itself can never break the string it is spliced into. A double-quoted json_field value that ends in a literal backslash is matched by a bounded branch that keeps the closing quote out of the capture, so an adjacent field's delimiter and credential are no longer swallowed. - The json_field pattern spans escaped and multiline quoted values without running on to a later field's quote. - SanitizeJSONDocument and SanitizeJSONLines add a structural path: JSON output is rewritten by a token-preserving walk instead of a text replace. Every object key and scalar leaf is scanned on its own and re-encoded, so redaction inside a value cannot touch the framing. Member order, duplicate keys and exact number literals survive, a leading UTF-8 BOM is stripped and restored, and a clean document comes back byte for byte. An array under a sensitive member keeps that member's name for its elements, so a token list is masked even when an element matches no pattern of its own; a nested object does not, since its members carry their own names. Content that cannot be redacted in place is replaced with a valid fail-closed JSON marker rather than corrupted JSON, and a cross-record match replaces only the records it covers. The structural path is a library primitive at this commit: the CLI output scan still calls the text pipeline, and wiring it in, with the operator alert for a replaced file, lands in the stacked PR that changes scanOutputFiles (fullsend-ai#10085). BREAKING CHANGE: a value masked as json_field now yields "***" instead of its first four bytes plus "..." whenever that prefix would carry a backslash or a quote delimiter, and json_field matches escaped-quote and multiline quoted values that it previously did not, so sanitized output text and finding details differ for those inputs. Signed-off-by: anevans <anevans@redhat.com>
7153974 to
f6dc2ce
Compare
|
🤖 Finished Review · ✅ Success · Started 4:44 PM UTC · Completed 5:00 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.24 |
ReviewFindingsHigh
Medium
Low
Earlier findings
Labels: PR changes Go code in internal/security. Next steps:
2 finding(s) below the |
|
🤖 Finished Review · Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.01 This review was superseded by a newer commit. Check the current pull request HEAD's review status before merging. |
…y markers Address the review findings on fullsend-ai#10082: - json_field accepts an optional CR before the line end in the bounded branches, so a double-quoted value ending in a literal backslash is masked on a CRLF line instead of going out in clear text. - A last-resort double-quoted branch masks a trailing-backslash value that is followed by neither a field nor a line end, such as `"password": "Abc123xyzQ\" (rotated)`, which matched no branch at all. - scan re-reads a double-quoted value whose closing \" is ambiguous: when the escape reading closes the string at a JSON value boundary it covers the whole value and wins, so `{"password":"ab\",cdefgh"}` is masked whole and stays valid JSON instead of losing the part after the escaped quote. Raw text such as `"api_key": "abcdefghi\", "password": ...` still takes the bounded reading, so the separator and the second field survive. - SanitizeJSONDocument scans the rebuilt document for whole-value secrets instead of the bytes it received, and does so even when no leaf produced a finding. A private-key block whose markers are JSON-escaped and split across leaves is now detected and the document fails closed, instead of the key material being returned unchanged. - failClosedCrossRecordJSON states the reason outputRemovalMarkers maps it to. - The whole-value rescan is unexported again: nothing outside the package called it, and the pipeline reaches it through wholeValueScanner. BREAKING CHANGE: sanitized output differs for two inputs. A double-quoted value that ends in a literal backslash is now masked on a CRLF line or before trailing text, and a valid JSON value whose escaped quote is followed by a separator is masked whole rather than up to the escaped quote. Note: Generated with assistance from DeepSeek V4.1 Flash Signed-off-by: Andrew Evans <andrewevansrh@users.noreply.github.com>
|
🤖 Finished Review · ✅ Success · Started 7:10 PM UTC · Completed 7:28 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.94 |
|
Risk Assessment: moderate (2/5) DetailsModerate risk score of 2 preserved for this split PR: large diff driven predominantly by test suites and schemas with elevated regression churn in modified security files, balanced by zero protected path or dependency changes, an established contributor, and close alignment with linked issue #5705. |
ReviewFindingsMedium
Low
Earlier findings
Next steps:
2 finding(s) below the |
…anning secrets
SanitizeJSONDocument scanned only the rebuilt document, but a document with no
findings is written back as the bytes that came in. The rebuilt form compacts
whitespace, so a registered runtime value that spans JSON framing plus
whitespace exists only in the original and was returned unredacted — the old
text scan matched it.
The backstop now scans the original bytes as well, but only when the rebuilt
scan is clean, so nothing is reported twice: the rebuilt form still catches
escaped markers and values the decoder can see, and the original form catches
what only its whitespace and escaping spell.
Regression test:
TestSanitizeJSONDocument_FramingSecretAcrossWhitespaceFailsClosed, a registered
value `foo", "b":"bar` inside `{"a":"foo", "b":"bar"}`.
Note: Generated with assistance from DeepSeek V4.1 Flash
Signed-off-by: Andrew Evans <andrewevansrh@users.noreply.github.com>
|
🤖 Finished Review · ✅ Success · Started 7:47 PM UTC · Completed 8:00 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.77 |
|
Risk Assessment: moderate (2/5) DetailsModerate risk score of 2 preserved for this split PR: large diff driven predominantly by test suites and schemas with elevated regression churn in modified security files, balanced by zero protected path or dependency changes, an established contributor, and close alignment with linked issue #5705. |
ReviewFindingsMedium
Low
Earlier findings
Next steps:
|
waynesun09
left a comment
There was a problem hiding this comment.
Two findings from a review pass at 4911942. Both were reproduced with go test at that head. Neither one leaks a secret on its own, but each undoes a guarantee that an earlier thread on this PR says is fixed.
…tied records Address the remaining review findings on fullsend-ai#10082: - jsonValueBoundaryRe is anchored with \A instead of (?m)^. It runs against the remainder after the escape reading, so the old pattern accepted a boundary on any later line: when unrelated text further down started with }, ] or a blank line, the escape reading won and swallowed `", `, dropping the next key's opening quote. Raw text such as `"api_key": "ZZvalue12\", "passwd_key": "QQother99" more\n}` keeps its separator and both values are masked again. - nextAnchor prefers the later original record on a run-length tie, so a cross-record match no longer pairs the record it covered with an identical clean copy further down the stream. The records `{"v":"aaa"}`, `{"v":"bbb"}`, `{"v":"aaa"}` now keep the clean third record and replace the two the match covered, instead of keeping the covered first copy. - The JSONL stream-scan comment states the one gap it still leaves — a JSON-escaped PEM marker split across records is not joined here — and that fullsend-ai#10084 closes it by scanning a decoded view of the stream before any rewrite. Regression tests: the `\n}` and blank-line separator subtests in TestSecretRedactor, and TestSanitizeJSONLines_TiedDuplicateKeepsLaterCleanCopy. Both fail on 4911942 and pass with this change. Note: Generated with assistance from DeepSeek V4.1 Flash Signed-off-by: anevans <anevans@redhat.com>
|
🤖 Finished Review · Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.15 This review was superseded by a newer commit. Check the current pull request HEAD's review status before merging. |
|
🤖 Finished Review · ✅ Success · Started 8:36 PM UTC · Completed 8:51 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.18 |
|
Risk Assessment: moderate (2/5) DetailsModerate risk score of 2 preserved for this split PR: large diff driven predominantly by test suites and schemas with elevated regression churn in modified security files, balanced by zero protected path or dependency changes, an established contributor, and close alignment with linked issue #5705. |
ReviewFindingsMedium
Low
Earlier findings
Next steps:
1 finding(s) below the |
| } | ||
| return affected | ||
| } | ||
| for ; i < k; i++ { |
There was a problem hiding this comment.
[medium] logic-error
affectedRecords picks the longest surviving run across the whole stream and marks every record before it as affected, so clean records sitting between two disjoint cross-record matches are replaced with a removal marker. Traced against TestSanitizeJSONLines_DisjointCrossRecordMatchesKeepCleanRecord with two clean trailing records: the clean middle record is a run of 1, the trailing pair a run of 2, the loop at line 413 marks the middle record affected. The new later-record tie-break causes the same loss with a single trailing clean record. The failure is fail-safe (content removed, not leaked) but breaks the guarantee the doc comment and existing test claim.
Suggested fix: Keep surviving anchors that precede the chosen run instead of treating the whole skipped prefix as changed (e.g. align the prefixes recursively, or localize replacements with exact match spans). Add regressions with clean records both between and after disjoint cross-record matches.
| // literal -----BEGIN here, so the block is not joined. Closing it needs a | ||
| // decoded view of the whole stream, built before any record is rewritten; | ||
| // #10084 adds that together with the cross-member case. | ||
| stream := p.scanWholeValueSecrets(string(rebuilt)) |
There was a problem hiding this comment.
[medium] logic-error
SanitizeJSONLines scans the encoded rebuilt stream for cross-record private keys, so a JSON-escaped PEM BEGIN marker (\u002d----BEGIN) in one record and the END marker in another are never joined and come back unchanged with no findings. The new comment at lines 311-318 acknowledges the gap and defers it to #10084, but the defect remains in this PR.
Suggested fix: Build the cross-record scan input from the decoded form of every record, keep the mapping to the original records, and fail closed for each record a detected block touches. Add a JSONL regression with an escaped BEGIN marker and an END marker in separate records.
| // literal -----BEGIN here, so the block is not joined. Closing it needs a | ||
| // decoded view of the whole stream, built before any record is rewritten; | ||
| // #10084 adds that together with the cross-member case. | ||
| stream := p.scanWholeValueSecrets(string(rebuilt)) |
There was a problem hiding this comment.
[medium] secret-exposure
JSON-escaped PEM markers split across records still bypass redaction: each record is clean on its own, and the stream backstop scans encoded bytes whose private_key pattern needs a literal -----BEGIN, so the key material is returned in clear. Literal cross-record markers are covered; escaped ones are not. The comment at lines 311-318 defers this to #10084. The primitives have no non-test caller yet, which limits immediate exposure.
Suggested fix: Scan a decoded view of the entire stream before per-record rewriting and replace every record that intersects a detected private-key block. Add a regression with an escaped BEGIN marker and its END marker in separate records.
| // keeps a raw newline inside the value matchable, as it was before the | ||
| // escape handling was added. The minimum length is enforced in scan, not | ||
| // here. | ||
| {"json_field", `(?i)(?:"[^"]*(?:key|token|secret|password|credential|auth)[^"]*"|'[^']*(?:key|token|secret|password|credential|auth)[^']*')\s*:\s*(?:"([^"\r\n]*\\)"[ \t]*(?:,|\}|\]|\r?$)|"((?:\\[\s\S]|[^"\\\r\n])*)"|'((?:''|[^'\r\n])*\\)'[ \t]*(?:,|\}|\]|\r?$)|'((?:''|\\\r?\n|\\.|[^'\r\n\\])*[^'\r\n\\])'|'([^']*)'|"((?:\\[\s\S]|[^"\\])*)"[ \t]*(?:,|\}|\]|\r?$)|"([^"\r\n]*\\)")`}, |
There was a problem hiding this comment.
[medium] secret-exposure
The rewritten json_field expression no longer redacts a double-quoted multiline credential when prose follows its closing quote, e.g. "password": "firs..." (rotated). The ordinary double-quoted branch excludes raw newlines, the multiline branch requires a comma, bracket, brace or line end after the closing quote, and the last-resort branch requires a trailing backslash. The base pattern "([^"]{8,})" matched this input, so this is a regression for every existing Pipeline.Scan caller.
Suggested fix: Handle multiline double-quoted values followed by prose without consuming adjacent fields, and add a regression asserting that both lines of the credential are removed while the trailing annotation survives.
| # | ||
| # The vendored review-result schema is a test fixture copied from | ||
| # fullsend-ai/agents, the repository that defines the review result contract. | ||
| # Nothing checks it automatically: re-vendor the schema and update this pin by |
There was a problem hiding this comment.
[low] design-smell
The vendored review-result schema fixture is re-vendored by hand only; the pin file itself says nothing checks it automatically, so test constraints can silently diverge from the upstream contract in fullsend-ai/agents.
Suggested fix: Add an automated check (CI or a test) that verifies the vendored review-result.schema.json against the pinned upstream commit, or reports drift.
| // write it back must place it inside a string literal (writeJSONString does this | ||
| // for the structural path); a caller that rebuilds raw framing must re-escape | ||
| // the surrounding text itself. | ||
| func mask(value string) string { |
There was a problem hiding this comment.
[low] backward-incompatible
Redacted output is no longer byte-identical to earlier releases (escape handling and the *** fallback mask changed). Declared by the ! marker and BREAKING CHANGE footer; keep the note in release notes.
Suggested fix: No code change; keep the breaking-change note in the PR and release notes.
| // write it back must place it inside a string literal (writeJSONString does this | ||
| // for the structural path); a caller that rebuilds raw framing must re-escape | ||
| // the surrounding text itself. | ||
| func mask(value string) string { |
There was a problem hiding this comment.
[low] backward-incompatible
mask() returns *** instead of the first four bytes plus ... when the kept prefix carries a backslash or quote delimiter, so placeholder text differs for those inputs. The package is internal; only artifact placeholder text changes, and the change is declared with !.
Suggested fix: No code change needed beyond the declared breaking-change marker.
| // write it back must place it inside a string literal (writeJSONString does this | ||
| // for the structural path); a caller that rebuilds raw framing must re-escape | ||
| // the surrounding text itself. | ||
| func mask(value string) string { |
There was a problem hiding this comment.
[low] backward-incompatible
The fallback *** mask changes sanitized output text and finding details for values whose four-byte prefix carries an escape or quote delimiter. Declared as a breaking change.
Suggested fix: No code change needed; name the placeholder change in the release note.
| // keeps a raw newline inside the value matchable, as it was before the | ||
| // escape handling was added. The minimum length is enforced in scan, not | ||
| // here. | ||
| {"json_field", `(?i)(?:"[^"]*(?:key|token|secret|password|credential|auth)[^"]*"|'[^']*(?:key|token|secret|password|credential|auth)[^']*')\s*:\s*(?:"([^"\r\n]*\\)"[ \t]*(?:,|\}|\]|\r?$)|"((?:\\[\s\S]|[^"\\\r\n])*)"|'((?:''|[^'\r\n])*\\)'[ \t]*(?:,|\}|\]|\r?$)|'((?:''|\\\r?\n|\\.|[^'\r\n\\])*[^'\r\n\\])'|'([^']*)'|"((?:\\[\s\S]|[^"\\])*)"[ \t]*(?:,|\}|\]|\r?$)|"([^"\r\n]*\\)")`}, |
There was a problem hiding this comment.
[low] backward-incompatible
json_field now matches escaped-quote and multiline quoted values it previously did not, changing sanitized output for those inputs. Declared as a breaking change in the title and commit footer.
Suggested fix: No code change needed beyond the declared breaking-change marker.
| // keeps a raw newline inside the value matchable, as it was before the | ||
| // escape handling was added. The minimum length is enforced in scan, not | ||
| // here. | ||
| {"json_field", `(?i)(?:"[^"]*(?:key|token|secret|password|credential|auth)[^"]*"|'[^']*(?:key|token|secret|password|credential|auth)[^']*')\s*:\s*(?:"([^"\r\n]*\\)"[ \t]*(?:,|\}|\]|\r?$)|"((?:\\[\s\S]|[^"\\\r\n])*)"|'((?:''|[^'\r\n])*\\)'[ \t]*(?:,|\}|\]|\r?$)|'((?:''|\\\r?\n|\\.|[^'\r\n\\])*[^'\r\n\\])'|'([^']*)'|"((?:\\[\s\S]|[^"\\])*)"[ \t]*(?:,|\}|\]|\r?$)|"([^"\r\n]*\\)")`}, |
There was a problem hiding this comment.
[low] backward-incompatible
The json_field pattern was rewritten (7 capture groups instead of 2; the 8-rune minimum moved from the quantifier into scan). Only scan reads the groups, so nothing in the module breaks, but callers depending on finding counts or exact sanitized text from Pipeline.Scan can see different output.
Suggested fix: Call out the changed matching behavior in the release notes; nothing outside scan depends on the old group layout.
waynesun09
left a comment
There was a problem hiding this comment.
Two MEDIUM findings from a review-only pass, posted inline.
| // body is split across array members into short chunks is neutralized member by | ||
| // member instead of dropping the whole document: no chunk of the body and no | ||
| // marker survives (#5705). | ||
| func TestSanitizeJSONDocument_ShortBodyChunksMasked(t *testing.T) { |
There was a problem hiding this comment.
[MEDIUM] These per-member masking tests pass only because the whole document is replaced with the fail-closed marker
The comment on TestSanitizeJSONDocument_ShortBodyChunksMasked says a private key split across array members is "neutralized member by member instead of dropping the whole document". TestSanitizeJSONDocument_ChunkedBodyBetweenMarkersMasked and TestSanitizeJSONDocument_BodyLineAsKeyBetweenMarkersMasked make similar per-member claims.
At head, SanitizeJSONDocument returns {"error":"output removed because redaction would invalidate JSON"} for all three inputs. The json.Valid, NotContains and NotEmpty(findings) assertions all pass against that marker. So these tests cannot catch a regression in the per-member masking they describe. Per your earlier replies, the joined-run logic arrives in #10084.
Suggestion: Make the tests prove what their names say: assert that the output is not a fail-closed marker (for example, no output removed because and no OutputRemoval). Otherwise, move the per-member cases to #10084 with the joined-run code, and change the comments here to say the document fails closed at this commit.
Verified: reproduced with a go test probe calling SanitizeJSONDocument with the three test inputs; all three return the fail-closed marker at 364b1ff; raised by: DeepSeek
| } | ||
|
|
||
| // mask returns a redacted representation of a secret value. | ||
| // |
There was a problem hiding this comment.
[MEDIUM] mask() can split a UTF-8 rune and write invalid UTF-8, even though the new doc comment says the result is safe to splice
mask keeps value[:4], which is the first four bytes, not runes. For a non-ASCII value the cut can land inside a multi-byte character. At head, Scan on "password": "日本語のパスワードです" produces "password": "日\xe6...", and utf8.ValidString on the result is false.
The new doc comment says the returned text is safe to splice into a JSON or YAML string. jq rejects invalid UTF-8, which is the kind of failure #5705 is about. The PR now counts the json_field minimum in runes but still slices the mask prefix in bytes, and text-path Pipeline.Scan callers write the result back without re-encoding it.
Suggestion: Trim the prefix back to a rune boundary (for example, take the first 4 runes, or step back with utf8.RuneStart), or return *** when value[:4] is not valid UTF-8. Add a utf8.ValidString assertion to the "json_field minimum counts runes, not bytes" subtest in scanner_test.go.
Verified: reproduced with a go test probe; NewSecretRedactor().Scan on a Japanese password gives invalid UTF-8 日\xe6... at 364b1ff; raised by: DeepSeek
jflowers
left a comment
There was a problem hiding this comment.
Council verdict: REQUEST CHANGES (7 runs: 2 REQUEST CHANGES, 2 APPROVE WITH ADVISORIES, 3 APPROVE). This review is pinned to commit 4911942. b5f395b ("anchor the JSON boundary check and keep clean tied records") landed while the council ran and appears to target both blocking findings; a fresh review of that commit is the natural next step.
from what I can tell, the structural approach is right: escape-aware bounded matching in the redactor, token-preserving re-encoding in the sanitizer, fail-closed markers, and honest BREAKING CHANGE labeling. The happy paths carry strong coverage.
two findings block at 4911942:
- HIGH
jsonsanitize.go:436: thenextAnchortie-break keeps the earliest run, so a covered duplicate record is written back verbatim while the clean copy is replaced; part of the runtime secret survives, contradicting thefailClosedRecordSpansdoc comment (adversary + fullsend; escalates waynesun09's open MEDIUM). - HIGH
jsonsanitize_test.go: no contract test fails on the current implementation for either defective branch; both functions sit at CRAP over 30 with low contract coverage, andadd_testsis the cheapest risk reduction (gaze-testing).
four MEDIUM and four LOW findings round out the review (line anchors folded into this body because the PR head moved mid-review; inline positions no longer resolve):
- MEDIUM
redactor.go:299:jsonValueBoundaryRecompiles with(?m), so^matches after every newline and the escape-reading check scans the whole remaining suffix; in multiline raw textjson_fieldswallows the separator and the next field (adversary + fullsend, waynesun09's other open MEDIUM). - MEDIUM
jsonsanitize_test.go:8andscanner_test.go:1: testify imports and test naming versus the loaded Go pack (gaze-testing). The repo already depends on testify across 688 test files, so this reads as a pack versus repo question. - MEDIUM
jsonsanitize_test.go:1606: the closing comment pins the error-wrap contract toTestScanOutputFiles_SanitizerErrorContainsFileAndContinues, which exists only in stacked draft #10085 (testing). - LOW
jsonsanitize.go:652: no assertion pins HTML-character preservation through a rewrite (the #9555 cases were not carried over). - LOW
jsonsanitize.go:467:dec.UseNumber()passthrough is unpinned; every numeric fixture formats identically as float64. - LOW
jsonsanitize.go:424: theanchorSearchBudgetexhaustion branch has no test. - LOW
jsonsanitize_test.go:267: the JSONL split/require.Len idiom repeats roughly 16 times; asplitJSONLRecordshelper would centralize the framing convention.
CI: all non-skipped checks pass at 4911942. Local gates did not run (UNTRUSTED_HEAD: fork PR whose author has read permission); this review proceeds on CI evidence.
This review was generated by /uf.review-pr (AI-assisted).
Summary
Refs #5705. The post-agent output sanitizer ran every pattern as a raw text
find-and-replace over all output files. When an agent quoted code inside a JSON
string value, a pattern matched up to the quote delimiter and swallowed the
backslash escaping it, so the rewritten document was no longer valid JSON and
jqinpost-review.shfailed with exit status 5.This PR is the first of three split out of #9699, and the stack lands in this
order:
SanitizeJSONDocument/SanitizeJSONLineslibrary primitives (Refs Output sanitizer should validate JSON structural integrity after redaction #5705)scanOutputFileswiring, therun.gopost-script andquietcomment changes, and the docs that describe them
2 and 3 are drafts until they are unblocked: each is based on the branch below it,
so its diff is cumulative today. After this one lands I rebase #10084 onto
main,its diff drops to its own commit and it goes ready for review; the same then
happens for #10085. Reviewing this one is unblocked.
Runtime reach at this commit. The redactor changes take effect immediately in
every existing
Pipeline.Scancaller (the text output scan, prompt scanning andthe finding details). The structural sanitizers are library primitives here: the
CLI output scan still calls the text pipeline, so JSON output is not yet routed
through them and #5705 is not closed until #10085 wires them in. The docs that
describe the structural output scan live in #10085 with the code that implements
it, and this PR no longer documents or claims that behaviour.
What changed
internal/security/redactor.go: a delimiter-escaping backslash is excludedfrom the captured value, and the mask falls back to
***when the prefix itwould keep carries an escape or a quote delimiter, so the mask itself cannot
break the string it is spliced into.
json_fieldpattern matches escaped and multiline quoted values withoutrunning on to a later field's quote. A double-quoted value that ends in a
literal backslash is matched by a bounded branch that keeps the closing quote
out of the capture, so an adjacent field's delimiter — and its credential — is
no longer swallowed.
trailing-backslash value that is followed by neither a field nor a line end, and
scanprefers the escape reading when that reading closes the string at a JSONvalue boundary and covers more than the bounded one — so
{"password":"ab\",cdefgh"}is masked whole instead of up to the escapedquote.
internal/security/jsonsanitize.go: JSON output is rewritten by atoken-preserving walk instead of a text replace. Every object key and scalar
leaf is scanned on its own and re-encoded, so redaction inside a value cannot
touch the framing. Member order, duplicate keys and exact number literals
survive; a leading UTF-8 BOM is stripped before the walk and restored on write;
a clean document comes back byte for byte. An array under a sensitive member
keeps that member's name for its elements, so
{"tokens": ["…"]}is masked eventhough an element matches no pattern of its own; a nested object does not, since
its members carry their own names. Content that cannot be redacted in
place is replaced with a valid
{"error":"output removed because …"}markerrather than corrupted JSON, and a cross-record match replaces only the records
it covers — a clean record between two disjoint matches, duplicates included,
is written back unchanged.
received, and does so even when no leaf produced a finding, so a private-key
block whose markers are JSON-escaped and split across leaves is detected and
the document fails closed instead of being returned unchanged. When that scan
is clean it also scans the original bytes, which are what a clean document
writes back: the rebuilt form compacts whitespace, so a registered runtime
value spanning framing plus whitespace exists only there.
internal/security/testdata/review-result.schema.jsonvendors the harnessschema so the tests assert that a sanitized review keeps the shape the harness
validates.
review-result.schema.pinrecords the upstream revision it wascopied from; refreshing it is a manual step, as the pin comment says.
Breaking change
A masked value is written
***instead of its first four bytes plus...whenever that prefix would carry a backslash or a quote delimiter, and
json_fieldnow matches escaped-quote and multiline quoted values it previouslydid not. A double-quoted value that ends in a literal backslash is now masked on
a CRLF line or before trailing text, and a valid JSON value whose escaped quote is
followed by a separator is masked whole rather than up to the escaped quote.
Sanitized output text and finding details therefore differ for those inputs.
Verification
go test ./internal/security/(also with-race)go test ./internal/cli/ -run 'TestScanOutput|TestContentCollector'make lintNote: Generated with assistance from DeepSeek V4.1 Flash