Normalize NUL bytes to U+FFFD at parse entry#248
Merged
Conversation
A raw NUL (U+0000) must never reach rendered output. Replace it with the
U+FFFD replacement character at the parse entry (WHATWG-style, decided
cross-impl behavior), so a control byte cannot survive into HTML.
SafeMode now also strips U+FFFD from a URL scheme, so a `java\x00script:`
evasion - which arrives as `java\u{FFFD}script:` after normalization - is
still detected and blocked (empty href).
Ported from carve-php commit ff40264.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #248 +/- ##
=========================================
Coverage 92.06% 92.06%
- Complexity 3571 3572 +1
=========================================
Files 107 107
Lines 10118 10120 +2
=========================================
+ Hits 9315 9317 +2
Misses 803 803 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
A raw NUL (U+0000) must never reach rendered output. This replaces it with the U+FFFD replacement character at the parse entry (WHATWG-style normalization, for cross-impl conformance), so a control byte cannot survive into the produced HTML.
What changed
BlockParser: at the parse entry, any NUL in the input is replaced with U+FFFD before line splitting.SafeMode: the URL-scheme normalization now also strips the U+FFFD replacement character. A NUL-in-scheme evasion such asjava\x00script:arrives asjava\u{FFFD}script:after normalization; stripping U+FFFD keeps that evasion detected and blocked (empty href), preserving the existing SafeMode guarantee.The dangerous-scheme detection regex itself was kept intact; the change only extends the set of stripped characters so the upstream NUL normalization does not open a new bypass.
Ported from carve-php commit ff40264.