Strip bare control characters from CSP report terminal output - #1405
Merged
Merged
Conversation
_sanitize_terminal() only removed ESC-prefixed ANSI sequences, so bare C0 controls (CR, LF, BS, BEL, ...), DEL, C1 controls (e.g. 0x9B 8-bit CSI) and a stray ESC in unauthenticated /__csp__ report fields reached the operator's terminal, allowing log lines to be overwritten or forged. Strip all remaining control characters and Unicode bidi overrides after the ANSI escape pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019b8mWRK1bS7PUszC6SQKGB
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.
_sanitize_terminal()only removed ESC-prefixed ANSI sequences. Bare control characters in the unauthenticated/__csp__report fields were still printed to the operator's terminal, so an attacker could overwrite or forge log lines. This covers:0x9B(8-bit CSI)Changes
_sanitize_terminal()now also strips all remaining C0, DEL and C1 control characters, plus Unicode bidi override characters (U+200E/F, U+202A–202E, U+2066–2069). Ordinary non-ASCII text is kept.ruff formatcan't rewrite the escapes into invisible literal characters in the source.Tests
/__csp__test uses CR and LF injection payloads.mesop/serverpass, andruff check/ruff format --check(v0.5.4) pass.Reported by zx (@manus-pi).
🤖 Generated with Claude Code
https://claude.ai/code/session_019b8mWRK1bS7PUszC6SQKGB
Generated by Claude Code