Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/NodeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ function serializeOne(kid, parent) {
var ss = kid.serialize();
// If an element can have raw content, this content may
// potentially require escaping to avoid XSS.
if (hasRawContent[tagname.toUpperCase()]) {
var upperTag = tagname.toUpperCase();
if (hasRawContent[upperTag] ||
(upperTag === 'NOSCRIPT' && kid.ownerDocument._scripting_enabled)) {
ss = escapeMatchingClosingTag(ss, tagname);
}
if (html && extraNewLine[tagname] && ss.charAt(0)==='\n') s += '\n';
Expand Down
20 changes: 20 additions & 0 deletions test/xss.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,26 @@ exports.styleMatchingClosingTagSkipsUnclosedCommentedContent = function () {
return alertFired(html).should.eventually.be.false('alert fired for: ' + html);
};

exports.noscriptMatchingClosingTagInRawText = function () {
// Use a parsed document so `_scripting_enabled` is true, matching how
// Angular SSR / platform-server uses domino. With scripting enabled,
// <noscript> is a raw-text element on serialization and its text data
// must have any `</noscript` closing-tag prefix escaped, otherwise an
// attacker-controlled text payload can break out and inject a live
// <script> sibling in the receiving browser.
const document = domino.createDocument('<!doctype html><html><body></body></html>');
const noscript = document.createElement('noscript');
noscript.textContent = 'abc</noscript><script>alert(1)</script>';
document.body.appendChild(noscript);

document.body
.serialize()
.should.equal('<noscript>abc&lt;/noscript><script>alert(1)</script></noscript>');

const html = document.serialize();
return alertFired(html).should.eventually.be.false('alert fired for: ' + html);
};

exports.scriptMatchingClosingTagInRawText = function () {
const document = domino.createDocument('');
const script = document.createElement('script');
Expand Down
Loading