Skip to content

fix: escape comment content that abruptly closes the comment - #40

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
SkyZeroZx:fix-comment-markup
Aug 28, 2026
Merged

fix: escape comment content that abruptly closes the comment#40
alan-agius4 merged 1 commit into
angular:mainfrom
SkyZeroZx:fix-comment-markup

Conversation

@SkyZeroZx

Copy link
Copy Markdown

Escape a leading > or -> in comment data during HTML serialization, so that #comment('><img src=x onerror=xss()>') is emitted as <!--&gt;<img src=x onerror=xss()>--> rather than <!--><img src=x onerror=xss()>-->.

The parser treats > and -> immediately after <!-- as an abrupt-closing-of-empty-comment parse error and emits the comment right away, so everything that followed was parsed as live markup. An inert comment node therefore became an XSS vector once an SSR response was de-serialized by the browser.

Closes angular/angular#70439

Escape a leading `>` or `->` in comment data during HTML serialization, so
that `#comment('><img src=x onerror=xss()>')` is emitted as
`<!--&gt;<img src=x onerror=xss()>-->` rather than
`<!--><img src=x onerror=xss()>-->`.

The parser treats `>` and `->` immediately after `<!--` as an
abrupt-closing-of-empty-comment parse error and emits the comment right
away, so everything that followed was parsed as live markup. An inert
comment node therefore became an XSS vector once an SSR response was
de-serialized by the browser.

Closes angular/angular#70439
alan-agius4
alan-agius4 approved these changes Aug 28, 2026
@alan-agius4
alan-agius4 merged commit 7df6545 into angular:main Aug 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSR serialization of Comment nodes can produce unexpected markup

2 participants