Repository navigation
fix(#5705): preserve escaping backslashes in JSON strings during redaction - #9555
andrewevansrh wants to merge 24 commits into
Conversation
PR Summary by QodoPreserve JSON escaping during secret redaction
AI Description
Merge Risk
|
|
🤖 Review · ❌ Terminated · Started 3:11 PM UTC · Ended 3:19 PM UTC Commit: |
Code Review by Qodo
1.
|
|
🤖 Finished Review · ❌ Failure (post-script /home/runner/work/fullsend/fullsend/.fullsend/.fullsend-cache/resources/sha256/a6187c1674b4bf35e1a9af44b2ff497577f8f36b64fed30b33e89edcb2cff224/scripts/post-review.sh failed: exit status 5) · Started 3:11 PM UTC · Completed 3:18 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.26 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…and validate JSON integrity
When redacting patterns such as env_assignment, auth_header, and
db_connection_password, matching up to an escaped quote (") previously
consumed the escaping backslash while leaving the unescaped quote
delimiter in the sanitized output, producing corrupted JSON syntax.
Update the value capture character classes to stop before backslashes
that escape delimiter quotes while continuing to redact credentials that
legitimately contain backslashes.
In addition, add post-sanitization JSON structural integrity validation
to scanOutputFiles in the CLI so that if sanitization produces invalid
JSON from a previously valid JSON file, the original file is preserved
instead of corrupting downstream tools.
Closes fullsend-ai#5705
Signed-off-by: anevans <anevans@redhat.com>
497b404 to
2ff063a
Compare
|
🤖 Finished Review · ✅ Success · Started 3:54 PM UTC · Completed 4:07 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.52 |
waynesun09
left a comment
There was a problem hiding this comment.
Review notes on head 2ff063a. The JSON-escape handling in the structural patterns is a good direction, but the new fallback in scanOutputFiles fails open, and a few redaction paths can still break JSON and reach that fallback. Details are inline.
Review Update & Changes AddressedA new commit ( Changes Made:
Verification:
Note: Generated with assistance from Gemini |
The diff supports the commit What changed in the redactor
What remains open
The finding's status will only update after a fresh review. If you want, I can rerun the Qodo review, or you can dismiss |
|
Risk Assessment: moderate (2/5) DetailsRemoval of .pre-commit-config.yaml from the net diff eliminates protected-path changes and yields a 0.50 test ratio, but persistent high churn, author contention, and regression history in internal/cli/run.go maintain a moderate risk score of 2. Previous runRisk Assessment: moderate (2/5) DetailsWell-aligned linked issue context and 0.40 test ratio across 5 files balance high churn and author contention in internal/cli/run.go and the modification of one protected path (.pre-commit-config.yaml). Previous run (2)Risk Assessment: moderate (2/5) DetailsWell-aligned linked issue context and 0.40 test ratio across 5 files balance high churn and author contention in internal/cli/run.go and the modification of one protected path (.pre-commit-config.yaml). Previous run (3)Risk Assessment: moderate (2/5) DetailsWell-aligned linked issue context and 0.40 test ratio across 5 files balance high churn and author contention in internal/cli/run.go and the modification of one protected path (.pre-commit-config.yaml). Previous run (4)Risk Assessment: moderate (2/5) DetailsWell-aligned linked issue context and 0.40 test ratio across 5 files balance high churn and author contention in internal/cli/run.go and the modification of one protected path (.pre-commit-config.yaml). Previous run (5)Risk Assessment: moderate (2/5) DetailsWell-aligned linked issue context and 0.40 test ratio across 5 files balance high churn and author contention in internal/cli/run.go and the modification of one protected path (.pre-commit-config.yaml). Previous run (6)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate): despite the addition of one protected path (.pre-commit-config.yaml) and a 0.40 test ratio across 5 files, well-aligned linked issue context and comprehensive test coverage balance high churn and author contention in internal/cli/run.go to keep the composite score at moderate. Previous run (7)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate) anchored to prior review: 4 changed files with no protected paths or dependency changes and a 0.50 test ratio, with well-aligned linked issue context, balanced against elevated churn and author contention in internal/cli/run.go. Previous run (8)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate) anchored to the prior review: four-file change with zero protected paths and no dependency changes, a 50% test file ratio, and alignment with issue #5705, balanced against elevated churn and author contention in internal/cli/run.go. Previous run (9)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate) anchored to the prior review as the four-file set is unchanged with zero protected paths or dependency changes and a 50% test file ratio aligning with issue #5705, balanced against elevated churn and author contention in internal/cli/run.go. Previous run (10)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate) anchored to the prior review as the four-file set is unchanged with zero protected paths or dependency changes and a 50% test file ratio aligning with issue #5705, balanced against elevated churn and author contention in internal/cli/run.go. Previous run (11)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate) anchored to the prior review as the file set is unchanged with zero protected paths or dependency changes and a 50% test file ratio aligning with issue #5705, balanced against elevated churn and author contention in internal/cli/run.go. Previous run (12)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate) anchored to the prior review as the file set is unchanged with zero protected paths or dependency changes and a 50% test file ratio aligning with issue #5705, balanced against elevated churn and author contention in internal/cli/run.go. Previous run (13)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate) anchored to the prior review as PR files are unchanged, preserving a 50% test-file ratio with zero protected paths or dependency changes and close alignment to issue #5705, balanced against elevated churn and author contention in internal/cli/run.go. Previous run (14)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate) anchored to the prior review as PR files are unchanged, preserving a 50% test-file ratio with zero protected paths or dependencies and close alignment to issue #5705, balanced against elevated churn and author contention in internal/cli/run.go. Previous run (15)Risk Assessment: moderate (2/5) DetailsScore remains 2 (moderate) anchored to the prior review as PR files are unchanged, preserving a 50% test-file ratio with zero protected paths or dependencies and close alignment to issue #5705, balanced against elevated churn and author contention in internal/cli/run.go. Previous run (16)Risk Assessment: moderate (2/5) DetailsAlthough the diff grew from 72 to 491 changed lines (medium blast radius) to implement structural JSON sanitization, the score stays 2 because the change keeps a 50% test-file ratio, touches no protected paths or dependencies, and closely matches linked issue #5705, balanced against high churn and multi-author contention in internal/cli/run.go. Previous run (17)Risk Assessment: moderate (2/5) DetailsSmall 72-line targeted bugfix with a 50% test ratio and no protected paths aligns with issue scope, but touches internal/cli/run.go which exhibits high recent churn and multi-author contention, yielding a moderate risk score. |
ReviewFindingsMedium
Low
Earlier findings
Next steps:
|
… escape-splitting redactions When redacting secret patterns in JSON outputs, raw string replacements could consume escaping backslashes or split escape sequences, corrupting JSON syntax. Implement structural JSON sanitization in scanOutputFiles by parsing JSON files and sanitizing string leaves rather than performing raw text replacement across the entire file, guaranteeing that valid JSON files remain syntactically valid and completely redacted (failing closed). In addition, update the json_field regex to capture escaped characters within quotes, and update mask() to avoid creating dangling or invalid escape sequences when masking secrets. Signed-off-by: anevans <anevans@redhat.com>
Review Feedback Addressed (Commit
|
waynesun09
left a comment
There was a problem hiding this comment.
Review notes on head 69b46b7. The structural JSON path removes the fail-open fallback, which is a good change. Three follow-ups are inline: object keys are never scanned, re-marshalling rewrites numbers and formatting, and the PR description does not mention the structural path.
Scan object keys and string leaves in sanitizeJSONStructure to avoid leaking credentials in JSON map keys. Decode JSON using dec.UseNumber() and encode with SetEscapeHTML(false) to prevent precision loss on large integers and HTML escaping. Restore character-based quantifier classes in redactor.go while safely preserving quote-escaping backslashes via delimiter inspection. Add boundary tests for env_assignment, auth_header, and db_connection_password at minimum lengths with backslashes. Add test coverage in scan_output_telemetry_test.go for key sanitization, large numbers, and float formatting. Signed-off-by: anevans <anevans@redhat.com>
Review Feedback Summary & Changes ImplementedAll outstanding review feedback from @waynesun09 and automated reviewers on PR #9555 has been addressed in commit 1. Addressed Review Findings
2. Commits Created and Pushed
3. Verification
Note: Generated with assistance from Gemini |
waynesun09
left a comment
There was a problem hiding this comment.
Review notes on head 12a4652. The structural JSON path is a good change, but three gaps remain. Duplicate keys can carry a secret past redaction. Backstop findings can be dropped silently. Single-record JSONL files get rewritten as multi-line. Details are inline.
…p findings Detect duplicate JSON keys while decoding and fall back to plain-text sanitization so all occurrences of duplicate keys are redacted. Ensure backstop findings are always recorded and sanitized output is written even when re-encoding is not valid JSON. Fall back to plain-text sanitization on JSON marshal errors instead of failing open. Preserve line count for single-record .jsonl files and compact JSON files by skipping the structural path for .jsonl/.ndjson and omitting indentation on compact JSON documents. Add regression tests for duplicate JSON keys, single-record JSONL line count preservation, and duplicate key token decoding. Signed-off-by: anevans <anevans@redhat.com>
Review Follow-Up Summary & Changes Addressed (Commit
|
|
🤖 Finished Review · ❌ Failure (post-script /home/runner/work/fullsend/fullsend/.fullsend/.fullsend-cache/resources/sha256/a6187c1674b4bf35e1a9af44b2ff497577f8f36b64fed30b33e89edcb2cff224/scripts/post-review.sh failed: exit status 5) · Started 7:17 PM UTC · Completed 7:26 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.62 |
|
🤖 Finished Review · ✅ Success · Started 9:13 PM UTC · Completed 9:24 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.35 |
Superseded by updated review
|
🤖 Finished Review · ✅ Success · Started 4:17 PM UTC · Completed 4:28 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.32 |
|
🤖 Finished Review · ✅ Success · Started 5:10 PM UTC · Completed 5:25 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.52 |
Signed-off-by: anevans <anevans@redhat.com>
|
🤖 Review · ❌ Terminated · Started 7:00 PM UTC · Ended 7:12 PM UTC Commit: |
Review follow-up — commit
|
Review follow-up — commit
|
waynesun09
left a comment
There was a problem hiding this comment.
Two MEDIUM findings from a review of head 701dae6. Details are inline.
| if privateKey { | ||
| line = []byte(`{"error":"output removed because backstop redaction would invalidate JSON"}`) | ||
| } else { | ||
| line = bytes.TrimSuffix(encodedOriginal.Bytes(), []byte("\n")) |
There was a problem hiding this comment.
MEDIUM: The JSONL backstop logs a finding as sanitized but writes the line back unredacted
Checked on head 701dae6. In sanitizeJSONLines, suppose the per-leaf pass finds nothing (needsRewrite == false), but the backstop scan of the re-encoded line finds a secret that is not a private key. Then:
- The findings are added to
findingsandallFindings(L7326-7327). lineis set tobytes.TrimSuffix(encodedOriginal.Bytes(), ...)(here). That is the original value re-encoded, with nothing redacted.- Because
jsonLineFindings > 0, the caller (L7041-7057) printsSanitized [<pattern>] in <file>for each finding, adds each one to findings.jsonl as ahost_outputfinding, and rewrites the file.
So the audit trail says the secret was sanitized, but the secret is still in the file.
The single-document JSON path treats the same case differently. Its else branch (around L7162-7171) returns nil and records nothing when the backstop finds no private key. The two paths follow different policies, and the JSONL one reports success while failing open.
The existing LOW thread at L7169 (f_659737f9e6b7a9fb) says that non-private-key backstop findings are discarded. It does not cover this JSONL branch, which counts the finding and logs it as sanitized while writing the secret back unchanged.
Suggestion: Use one policy for both paths.
- If cross-leaf findings matter, write
backstop.Sanitizedwhen it is still valid JSON, and the fail-closed marker otherwise. TheneedsRewritebranch already does this. - If they don't matter, don't count or record them.
Also add a test that checks the bytes written to disk match the logged outcome.
| // space, as in the PostToolUse hook. | ||
| {"env_assignment", `(?i)(?:^|\s)(?:export\s+)?((?:[A-Za-z0-9]+_)*(?:KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL|PASSWD|AUTH|API_KEY)(?:_[A-Za-z0-9]+)*)\s*=\s*(?:['"](?:(?:basic|bearer|token)[ \t]+)?)?([^\s"'}\]),;]{8,})['"]?`}, | ||
| {"json_field", `(?:"[^"]*(?i:key|token|secret|password|credential|auth)[^"]*"|'[^']*(?i:key|token|secret|password|credential|auth)[^']*')\s*:\s*(?:"([^"]{8,})"|'([^']{8,})')`}, | ||
| {"json_field", `(?i)(?:"[^"]*(?:key|token|secret|password|credential|auth)[^"]*"|'[^']*(?:key|token|secret|password|credential|auth)[^']*')\s*:\s*(?:"((?:\\[\s\S]|[^"\\])*)"|'((?:''|\\[\s\S]|[^'\\])*)'|` + "'" + `([^\r\n]*\\)` + "'" + `)`}, |
There was a problem hiding this comment.
MEDIUM: The PR body, which becomes the squash commit message, describes a json_field regex and an output format the code does not have
Checked on head 701dae6.
The regex. The PR body says json_field uses (?:\\.|[^"\\]){8,}. The pattern on this line has no {8,}, and it has three alternatives:
"((?:\\[\s\S]|[^"\\])*)"- a single-quoted
'((?:''|\\[\s\S]|[^'\\])*)', which also handles YAML-style doubled apostrophes - a greedy
'([^\r\n]*\\)'fallback
The 8-character minimum is now a separate check, originalLen < minLen (L184-206), which counts raw escaped bytes.
The output format. The body says rewritten JSON uses "standard indentation". In fact:
scanOutputFilesWithWriteruses a 2-space indent only when the original had more than one line, and compact output otherwise (run.go L7098-7100).- Re-encoding a decoded map sorts the object keys.
So rewritten files keep neither their original indentation nor their key order. The body doesn't mention either.
The earlier thread about the body (original run.go L6802) said the structural path was missing, and that was fixed. These newer mismatches came in with later commits.
Suggestion: Update the PR body to match the shipped code:
- List the
json_fieldalternatives, including the doubled-apostrophe and trailing-backslash branches, and the separate byte-length check. - Say that rewritten JSON is re-encoded with sorted keys and normalised whitespace, and indented only when the original had more than one line.
|
🤖 Finished Review · ✅ Success · Started 7:00 PM UTC · Completed 7:12 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.13 |
…ntime secrets Signed-off-by: anevans <anevans@redhat.com>
Review follow-up — commit
|
|
🤖 Finished Review · ✅ Success · Started 7:36 PM UTC · Completed 7:47 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.15 |
|
🤖 Finished Review · ✅ Success · Started 8:26 PM UTC · Completed 8:37 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.05 |
…e keys, and YAML fields Fail closed on raw multiline PEM blocks in JSONL streams regardless of whether individual lines parse as JSON. Replace duplicate-key JSONL records with an error marker when structural findings cannot be safely serialized. Trim trailing newline from the JSONL no-structural-findings backstop encoder to prevent extra blank lines. Prevent trailing literal backslashes in single-quoted YAML fields from consuming adjacent fields in json_field regex. Remove detect-private-key pre-commit exclusion by concatenating test PEM fixture strings. Signed-off-by: anevans <anevans@redhat.com>
Review Feedback AddressedAll findings from the latest review pass have been resolved in commit
Verification
Note: Generated with assistance from Gemini |
|
🤖 Finished Review · ✅ Success · Started 8:48 PM UTC · Completed 9:04 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.50 |
|
|
||
| // Non-JSON files or fallback: run plain text pipeline scan. | ||
| text := string(content) | ||
| result := pipeline.Scan(text) |
There was a problem hiding this comment.
[medium] logic-error
Duplicate-key JSON documents still skip structural scanning (the structural path is gated on !hasDuplicateJSONKeys) and receive only a raw-text pipeline.Scan. A duplicate-key .json file containing a Unicode-escaped token (a \u0067-spelled token prefix) under a non-sensitive key keeps the credential unchanged, because the raw scanner has no JSON-escape decoding while downstream consumers such as jq decode it. The new JSONL duplicate-key handling does not cover this ordinary-JSON path.
Suggested fix: Inspect decoded keys and values without discarding duplicate members, or fail closed (replace the document with an error marker) when duplicate-key JSON cannot be structurally scanned. Add a regression with an escaped token in a duplicate-key .json file.
| sanitized, fs := sanitizeJSONStructure(value, pipeline) | ||
| findings += len(fs) | ||
| allFindings = append(allFindings, fs...) | ||
| if hasDuplicateJSONKeys(trimmed) { |
There was a problem hiding this comment.
[medium] data-exposure
Duplicate-key JSONL records can still retain encoded credentials. Decoding keeps only the last duplicate member, so sanitizeJSONStructure never sees the overwritten value; the duplicate-key branch then runs only a raw-text scan, which does not recognise a Unicode-escaped token prefix. fs and result.Findings can both be empty and the credential-bearing record is written unchanged. The non-JSONL duplicate-key fallback has the same gap.
Suggested fix: Scan keys and values with a token-stream traversal that preserves duplicate occurrences, or replace duplicate-key records and documents with a fail-closed marker. Add regressions with an escaped token in an overwritten occurrence for both JSON and JSONL.
| // space, as in the PostToolUse hook. | ||
| {"env_assignment", `(?i)(?:^|\s)(?:export\s+)?((?:[A-Za-z0-9]+_)*(?:KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL|PASSWD|AUTH|API_KEY)(?:_[A-Za-z0-9]+)*)\s*=\s*(?:['"](?:(?:basic|bearer|token)[ \t]+)?)?([^\s"'}\]),;]{8,})['"]?`}, | ||
| {"json_field", `(?:"[^"]*(?i:key|token|secret|password|credential|auth)[^"]*"|'[^']*(?i:key|token|secret|password|credential|auth)[^']*')\s*:\s*(?:"([^"]{8,})"|'([^']{8,})')`}, | ||
| {"json_field", `(?i)(?:"[^"]*(?:key|token|secret|password|credential|auth)[^"]*"|'[^']*(?:key|token|secret|password|credential|auth)[^']*')\s*:\s*(?:"((?:\\[\s\S]|[^"\\])*)"|'((?:''|\\\r?\n|\\.|[^'\r\n\\])*[^'\r\n\\])'|'((?:''|[^'\r\n])*\\)')`}, |
There was a problem hiding this comment.
[low] data-exposure
The revised single-quoted json_field alternative still consumes an adjacent sensitive field on the same line when a YAML scalar ends in a literal backslash. For {'password': 'abcd...', 'secret': '***'} the escaped-character alternative treats the first closing apostrophe as escaped and swallows the opening quote of 'secret', leaving ijklmnop unredacted. The new regression only covers newline-separated fields.
Suggested fix: Separate YAML single-quote semantics from backslash-escaped string semantics (or use format-aware parsing) and add a same-line flow-mapping regression asserting both values are masked.
| findingCount += jsonLineFindings | ||
| for _, f := range jsonLineDetails { | ||
| if !quiet { | ||
| printer.StepWarn(fmt.Sprintf("Sanitized [%s] in %s: %s", f.Name, filepath.Base(path), f.Detail)) |
There was a problem hiding this comment.
[low] pattern-inconsistency
In scanOutputFilesWithWriter the JSONL branch reports paths with filepath.Base(path), whereas the other branches use the output-dir-relative path (relPath), dropping subdirectory context.
Suggested fix: Compute relPath once per file and use it in the JSONL branch warnings and write errors.
|
|
||
| relPath, _ := filepath.Rel(outputDir, path) | ||
|
|
||
| ext := strings.ToLower(filepath.Ext(path)) |
There was a problem hiding this comment.
[low] pattern-inconsistency
The JSONL extension is checked with strings.EqualFold earlier in scanOutputFilesWithWriter and then recomputed with strings.ToLower after the JSONL branch has already returned, so the recomputed isJSONL is always false and the later !isJSONL checks are redundant.
Suggested fix: Remove the recomputation of ext/isJSONL and the redundant !isJSONL checks that depend on it.
|
Closing to reopen this work as a fresh PR against upstream main. The replacement PR will use the same description. |
|
Reopened as #9699 against upstream main with the same description. |
Summary
Fixes #5705 by preventing the post-agent output sanitizer from corrupting JSON syntax during secret redaction, while guaranteeing fail-closed security for all output files.
The fix introduces a dual-layer strategy:
internal/cli/run.go): Primary defense-in-depth fix for JSON files (such asagent-result.json). Outputs that parse as JSON are decoded into data structures, where object keys and string leaves are recursively scanned and redacted individually before re-encoding. This guarantees that redaction within string values never alters JSON framing syntax.internal/security/redactor.go): Fix for non-JSON files (markdown, JSONL streams, plaintext) and raw text scans. Delimiter-escaping backslashes (such as\"or\') are detected and excluded from credential capture spans so that escaping is preserved without breaking string delimiters, while credentials containing interior or trailing backslashes remain fully matched and redacted.Root cause & background
In the post-agent output scanning pipeline (
scanOutputFiles), regex patterns were previously executed as a raw text find-and-replace across all output files. When an agent's output included code discussion containing environment assignments or credentials inside a JSON string value—for example:{"remediation": "Guard against null values with token_usage = metrics.get(\"token_usage\") or {}"}the raw regex matched up to the quote delimiter (
metrics.get(\), eating the escaping backslash. The redacted replacement produced:swallowing the backslash and leaving an unescaped quote delimiter inside the JSON string. This corrupted the JSON structure and caused downstream tools (
jqinpost-review.sh) to fail with exit status 5 (e.g. in konflux-ci/scribe4jira#32 / workflow run 30361396360 and fullsend-ai/fullsend#7553 / run 42022572317).What changed in this PR
1. Structural JSON Path (
internal/cli/run.go)json.NewDecoderand validates EOF to prevent JSONL streams from being misclassified.dec.UseNumber()to decode numbers asjson.Number, avoidingfloat64precision loss for integers above 2^53 (e.g.12345678901234567891) and preserving float formatting like1.0.sanitizeJSONStructurerecursively visits all object keys and string leaves:pipeline.Scan(k). If a key contains secrets, unicode anomalies, or bidi markers, it is redacted. Key collision handling (<key>_<N>) prevents properties from clobbering each other.key,token,secret,password,credential,auth) are detected and redacted.json.NewEncoderwithenc.SetEscapeHTML(false)(preserving literal<,>,&) and standard indentation. Files with zero findings remain completely untouched byte-for-byte.2. Regex Redaction & Quote Escape Preservation (
internal/security/redactor.go)[^\s"'}\]),;]{N,}) forenv_assignment(8),auth_header(12), anddb_connection_password(4), ensuring credentials with multiple backslashes meet required length thresholds."or'), the redactor counts trailing backslashes. If odd, the trailing backslash escapes the delimiter quote and is trimmed from the secret span so the escape remains intact in the text.json_fieldEscape Handling: Updatesjson_fieldvalue patterns to(?:\\.|[^"\\]){8,}, properly spanning embedded escaped quotes without terminating early.Mask()Safety: Exported assecurity.Maskand updated to output"***"whenever a prefix contains a backslash, avoiding dangling escape sequences.3. Expanded Test Coverage
internal/cli/scan_output_telemetry_test.go: Added multi-case suite (TestScanOutputFiles_PreservesJSONStructuralValidity) verifying:<,>,&) are not escaped.internal/security/scanner_test.go: Added boundary tests forenv_assignment,auth_header, anddb_connection_passwordat exact minimum lengths with interior and trailing backslashes.Verification
go test -v ./internal/security/...passed.go test -v -run TestScanOutputFiles ./internal/cli/...passed.make lint/ pre-commit passed cleanly (gofmt,go vet,semgrep security audit,gitlint, secrets, and link checks).Closes #5705
Checklist
!for breaking changes)