Commit 3c28543
fix: prevent sentinel collision XSS and document closing-fence deviation
Security fix: Add NUL byte (0x00) to shouldRemoveRune so that
FilterInvisibleCharacters strips NUL bytes before protectCodeAngleBrackets
runs. Without this, an attacker can inject literal sentinel strings
(\x00LT\x00script\x00GT\x00) that bypass FilterHTMLTags and get restored
to <script> by restoreCodeAngleBrackets.
Also add a comment documenting the CommonMark closing-fence deviation:
the implementation treats any run of >= fenceLen backticks as a closing
fence even mid-line, which is more permissive than CommonMark (requires
own line, no info string). This is a soft-fail (some angle brackets may
be unprotected) rather than a security issue.
Tests added:
- sentinel collision: verifies NUL-byte injection does not produce <script>
- NUL bytes in code blocks: verifies code content is preserved after stripping
- NUL byte in shouldRemoveRune: verifies 0x00 is in the removal set1 parent ac2718a commit 3c28543
2 files changed
Lines changed: 19 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
195 | 200 | | |
196 | 201 | | |
197 | 202 | | |
| |||
333 | 338 | | |
334 | 339 | | |
335 | 340 | | |
336 | | - | |
| 341 | + | |
| 342 | + | |
337 | 343 | | |
338 | 344 | | |
339 | 345 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| |||
337 | 338 | | |
338 | 339 | | |
339 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
340 | 351 | | |
341 | 352 | | |
342 | 353 | | |
| |||
0 commit comments