Repository navigation
fix(agent): escape-aware JSON field redaction for embedded quotes - #69196
fangliquanflq wants to merge 4 commits into
Conversation
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused redaction fix. The current matcher on main still uses ([^\"]+) at agent/redact.py:260, so the escaped-quote leak is real, and the proposed escape-aware matcher addresses it.
Problems
tests/agent/test_redact.py:236(and the adjacent new fixtures) uses raw strings with\"around the JSON field names and structural value quotes. Those backslashes become part of the input. Since_JSON_FIELD_RErequires the value quote immediately after:\s*, it cannot match this pseudo-JSON, so the assertions do not exercise the new regex and will fail.
Suggested changes
- Use unescaped structural JSON quotes in the raw literals, retaining escapes only inside the value:
r'{"password": "foo\\"bar_secret_value"}'.
Automated hermes-sweeper review.
|
not enough evidence Revision-isolated probes show that the escape-aware JSON sensitive-field matcher on the submitted head prevents the escaped-quote suffix disclosure reproduced on current main. The required run-owned deterministic patch replay against current GitHub The stale/conflict status was not treated as a standalone blocker. This assessment is inconclusive because the integrated runtime and regression tests could not be validated on a resolved current-main tree, so I cannot classify the PR as mergeable or suggest source changes. Signed: GPT-5.6-sol-xhigh in Codex |
Naive [^"]+ stopped at \" inside JSON string values, masking only the
prefix and leaking the remainder while corrupting shape ("***"bar...).
Use non-raw literals so structural quotes stay plain and only the embedded value escape is written as \\", matching the intended input.
b2a3044 to
42d115b
Compare
|
Rebased onto current Force-pushed head: Focused verification on the integrated tree: Escaped-quote / escaped-backslash probes match the intended mask behavior (whole value masked; no |
|
suggesting changes Security evidence:
Please adjust masking so preserved prefixes cannot end inside an escape sequence, and add a regression for an escaped quote at that boundary. Not checked:
Signed: GPT-5.6-sol-xhigh in Codex |
Head/tail cuts on escaped JSON field values must not land mid-sequence (e.g. on the backslash of \"), or re-quoted output becomes unparseable.
|
Addressed the prefix/escape-boundary corruption on head
Boundary probe on the updated head: Regression: Focused verification: Ready for re-probe / patch replay against current main. |
|
suggesting changes The changed JSON path introduces two separate linear-allocation amplifiers on attacker-controlled values: Security evidence:
Not checked:
Signed: GPT-5.6-sol-xhigh in Codex |
|
Addressed the bounded-memory review on The JSON field regex now matches only the field prefix; a linear scanner finds the closing quote without retaining regex state proportional to the value. Escape-safe mask cuts are computed in one pass with constant auxiliary state instead of storing every boundary. Verification:
I have not claimed the new GitHub CI run is complete. |
|
looks mergeable The escape-aware JSON scanner follows escaped characters through the unescaped closing quote and masks sensitive values without leaking suffixes or breaking serialized JSON, while preserving the environment-lookup exception. Focused regression, fuzz, Unicode and escape, and long-input checks found no source-backed security regression in the reviewed change. Security evidence:
Not checked:
Signed: GPT-5.6-luna-max in Codex |
What does this PR do?
Makes
_JSON_FIELD_REescape-aware so JSON string values that contain embedded\"are masked as a whole, instead of truncating at the first raw quote character.Failure mode (before)
_JSON_FIELD_REused([^"]+)for the value. In a JSON dump / log line like:the engine treats the
"inside\"as the end of the value. Only the prefixfoo\is masked; the suffix stays in cleartext and the surrounding quotes no longer form a closed string:Two bad outcomes at once:
bar_secret_valueremains readable in logs / tool output / transcripts."***"bar...is no longer valid JSON-looking text, which can confuse downstream parsers while still exposing the remainder.Control without an escaped quote still worked:
Fix
Change the value capture to
(?:\\.|[^"\\])+(same escape-aware class already used by sibling JSON matchers for secret headers / cookies in #50514)._redact_jsonstill wraps the masked token in quotes, so the whole field value is replaced and the suffix cannot leak outside the mask.Short values with an embedded escape fully mask to
***:Related Issue
Related #50514 (escape-aware JSON value matching for Cookie / secret-header JSON forms; does not change general
_JSON_FIELD_REforpassword/token/secret/ …).Type of Change
Changes Made
agent/redact.py:_JSON_FIELD_REvalue group is escape-aware; comment documents the\"truncation / remainder-leak failure mode.tests/agent/test_redact.py: regression coverage for escaped quote (long + short) and escaped backslash JSON field values.How to Test
scripts/run_tests.sh tests/agent/test_redact.py -k TestJsonFields -qChecklist
Code
fix(scope):,feat(scope):, etc.)scripts/run_tests.shand they passDocumentation & Housekeeping
docs/, docstrings) — N/Acli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/A