Commit cc613c7
committed
Reject all browser-recognized comment-closing sequences in Comment::set_text.
Previously `Comment::set_text` only rejected the canonical `-->` terminator, but a
WHATWG-conformant browser also closes a comment on three more byte sequences:
1. `--!>` anywhere in the body (comment-end-bang state).
2. A leading `>` (abrupt-closing-of-empty-comment from comment-start).
3. A leading `->` (abrupt-closing-of-empty-comment from comment-start-dash).
Since `serialize_self()` emits `<!--` + text + `-->` verbatim, a caller passing
attacker-influenced data through `set_text` could let the attacker break out of the
comment and inject live markup that lol-html never tokenized. Any sanitizer built on
lol-html that mutates comment text on attacker data was bypassable for stored/reflected
XSS. The error-returning shape of the existing `-->` check implied that the API was
designed to prevent this, just incompletely.
We add a private `contains_comment_closing_sequence(&str)` predicate covering all four
cases and route `set_text` through it. The error variant
`CommentTextError::CommentClosingSequence` keeps its name (so this is API-compatible);
its rustdoc and error message are updated to describe the broader rule.
The existing `comment_closing_sequence_in_text` test is extended to iterate over all
four representative payloads with a per-payload failure message. Existing
`sanitizer_bypass`, `sanitizer_bypass2`, and `modified_text` pass benign text to
`set_text` and continue to pass unchanged.
We do not touch `Comment::before` / `::after` / `::replace`: those insert content
outside the `<!--...-->` envelope under explicit `ContentType` opt-in, with a
different contract.1 parent e97d16c commit cc613c7
2 files changed
Lines changed: 50 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
39 | 54 | | |
40 | 55 | | |
41 | 56 | | |
| |||
68 | 83 | | |
69 | 84 | | |
70 | 85 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
86 | 100 | | |
| 101 | + | |
87 | 102 | | |
88 | 103 | | |
89 | 104 | | |
| |||
329 | 344 | | |
330 | 345 | | |
331 | 346 | | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
337 | 361 | | |
338 | 362 | | |
339 | 363 | | |
| |||
0 commit comments