fix(redact): strip complete CSI sequences before prefix masking (#81012) - #81062
Closed
Enough1122 wants to merge 1 commit into
Closed
fix(redact): strip complete CSI sequences before prefix masking (#81012)#81062Enough1122 wants to merge 1 commit into
Enough1122 wants to merge 1 commit into
Conversation
…Research#81012) A vendor-prefix token wrapped in ANSI color codes (e.g. \x1b[32msk-…) leaked ENTIRELY through redact_sensitive_text. The previous control-char strip removed only the bare ESC byte, leaving the trailing [32m chars intact — and the literal 'm' defeated _PREFIX_RE's (?<![A-Za-z0-9_-]) lookbehind on a prefix token that followed immediately after the sequence. Fix: compile _CSI_SEQUENCE_RE that matches the complete CSI leg of ECMA-48 (parameter / intermediate / final byte ranges, including the '?' private-mode prefix), strip CSI sequences as a unit before the control-char pass, and treat CSI-internal bytes as collapsible in the span validation so the join doesn't get rejected when a CSI sequence sits inside the matched token span. Reuses the CSI leg of tools/ansi_strip.py so the two scrubbers cannot drift. Regression tests cover the leak shapes from the issue: CSI directly glued to sk-, CSI after the prefix, bold + color SGR, 256-color SGR, true-color SGR, DEC private-mode CSI, OSC hyperlink wrap, ghp_ prefix, prose preservation across CSI, and a colored prose-only no-op case. Fixes NousResearch#81012
Contributor
Author
|
Duplicate of #81060 (same issue #, opened earlier). Closing in favor of the earlier PR to avoid double-fixing the same issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #81012
A vendor-prefix token wrapped in ANSI color codes (e.g.
\x1b[32msk-…) leaked ENTIRELY throughredact_sensitive_text. The previous control-char strip removed only the bare ESC byte, leaving the trailing[32mchars intact — and the literalmdefeated_PREFIX_RE's(?<![A-Za-z0-9_-])lookbehind on a prefix token that followed immediately after the sequence.Fix
Compile
_CSI_SEQUENCE_REmatching the complete CSI leg of ECMA-48 (parameter / intermediate / final byte ranges, including the?private-mode prefix), strip CSI sequences as a unit before the control-char pass, and treat CSI-internal bytes as collapsible in the span validation so the join isn't rejected when a CSI sequence sits inside the matched token span.Reuses the CSI leg of
tools/ansi_strip.pyso the two scrubbers cannot drift.Regression tests
The new
TestCSISplitTokensclass covers the leak shapes from the issue:sk-(no space) — the primary leak from the reportsk-\x1b[32mbody\x1b[0m)\x1b[1;31m) — multi-byte param leg\x1b[38;5;196m) — even more param bytes\x1b[38;2;255;0;0m) — boundary on the 5/6 char leg\x1b[?25h) —?param byteghp_prefix wrapped in CSI — confirms fix is notsk--specific\x1b]8;;url\x1b\)All 12 new tests pass; the 97 pre-existing
test_redact.pytests continue to pass.Files changed
agent/redact.py: 4-line regex addition, ~15-line function updatetests/agent/test_redact.py: newTestCSISplitTokensclass with 12 cases