Merge pull request #201 from TomAnthony/fix-bypass-issue
Update handling of quoteStart to prevent sanitization bypass
This commit is contained in:
@@ -55,7 +55,7 @@ function parseTag(html, onTag, escapeHtml) {
|
|||||||
var currentTagName = "";
|
var currentTagName = "";
|
||||||
var currentHtml = "";
|
var currentHtml = "";
|
||||||
|
|
||||||
for (currentPos = 0; currentPos < len; currentPos++) {
|
chariterator: for (currentPos = 0; currentPos < len; currentPos++) {
|
||||||
var c = html.charAt(currentPos);
|
var c = html.charAt(currentPos);
|
||||||
if (tagStart === false) {
|
if (tagStart === false) {
|
||||||
if (c === "<") {
|
if (c === "<") {
|
||||||
@@ -85,9 +85,17 @@ function parseTag(html, onTag, escapeHtml) {
|
|||||||
tagStart = false;
|
tagStart = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((c === '"' || c === "'") && html.charAt(currentPos - 1) === "=") {
|
if ((c === '"' || c === "'")) {
|
||||||
quoteStart = c;
|
var i = 1;
|
||||||
continue;
|
var ic = html.charAt(currentPos - i);
|
||||||
|
|
||||||
|
while ((ic === " ") || (ic === "=")) {
|
||||||
|
if (ic === "=") {
|
||||||
|
quoteStart = c;
|
||||||
|
continue chariterator;
|
||||||
|
}
|
||||||
|
ic = html.charAt(currentPos - ++i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (c === quoteStart) {
|
if (c === quoteStart) {
|
||||||
|
|||||||
@@ -359,4 +359,19 @@ describe("test custom XSS method", function() {
|
|||||||
'<div style="width:50%; vertical-align:top;">hello</div>'
|
'<div style="width:50%; vertical-align:top;">hello</div>'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("#onTag - sanitize html parameter", function() {
|
||||||
|
var source = '<a target= " href="><script>alert(2)</script>"><span>';
|
||||||
|
var i = 0;
|
||||||
|
var html = xss(source, {
|
||||||
|
onTag: function(_, E, S) {
|
||||||
|
if (S.isWhite && "a" === _) {
|
||||||
|
if (S.isClosing) return "</span></a>";
|
||||||
|
return "".concat(E, '<span>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
debug(html);
|
||||||
|
assert.equal(html, '<a target= " href="><span><script>alert(2)</script>"><span>');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user