document.createComment rejects "--" in violation of the specification
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
People
(Reporter: amnonaar, Assigned: ayg)
References
()
Details
Attachments
(2 files)
|
6.88 KB,
patch
|
bzbarsky
:
review+
|
Details | Diff | Splinter Review |
|
1.09 KB,
text/html
|
Details |
Updated•18 years ago
|
Updated•15 years ago
|
| Assignee | ||
Comment 1•15 years ago
|
||
Comment 2•15 years ago
|
||
Comment 3•15 years ago
|
||
| Assignee | ||
Comment 5•14 years ago
|
||
Comment 6•14 years ago
|
||
| Assignee | ||
Comment 7•14 years ago
|
||
Comment 9•14 years ago
|
||
| Assignee | ||
Comment 10•14 years ago
|
||
Comment 11•14 years ago
|
||
Updated•7 years ago
|
Comment 12•4 years ago
|
||
The current document.createComment() goes against the spec by writing to the document. This effect can be observed by creating a comment with a comment-closing string followed by a newline, selecting Edit As HTML.. in Inspector, observing the raw fake comment closure, then folding the edit inset by clicking outside of it. An alert pops up. I do not know if any intermediary layer (such as Edit as HTML editor) allowed the unexpected interpretation or if this was a result of createComment() writing into the to-be-interpreted document.
document.getElementById("dom-document-createcomment").append(document.createComment("foobar-->\x0D\x0A<img src=. onerror=alert(22)>"))
Creating a text node appears to behave properly. The following will add content safely (i.e. preventing it from further interpretation). Clicking Edit as HTML will show the angle brackets of the embedded img tag as HTML-encoded < and >.
document.getElementById("dom-document-createcomment").append(document.createTextNode("foobar\x0D\x0A<img src=. onerror=alert(22)>"))
The same "attack" can be observed in Chrome. This finding is inspired by an Angular's createComment() XSS vulnerability that lacks a proof-of-concept. I did not try creating one.
Comment 13•4 years ago
|
||
I used this site's browser console for my experiment,
https://dom.spec.whatwg.org/#dom-document-createcomment
(many other sites disable inline javascript with their CSP).
Comment 14•4 years ago
|
||
Clicking "Show DOM Properties" on the injected comment shows a proper encapsulation of the entire comment, but clicking "Edit as HTML" on the surrounding tag, then closing the editor's inset re-interprets the comment. So I guess it's a bug a part of which has to do with proper encapsulation (as createTextNode() does) and another part has to do with the HTML editor.
Attaching the self-contained site test-create-comment.html to be used follows,
Description
•