Merge pull request #218 from TomAnthony/fix-whitespace-bypass

Fix whitespace bypass
This commit is contained in:
老雷
2021-05-06 11:22:53 +08:00
committed by GitHub
2 changed files with 17 additions and 2 deletions

View File

@@ -89,7 +89,7 @@ function parseTag(html, onTag, escapeHtml) {
var i = 1;
var ic = html.charAt(currentPos - i);
while ((ic === " ") || (ic === "=")) {
while ((ic.trim() === "") || (ic === "=")) {
if (ic === "=") {
quoteStart = c;
continue chariterator;

View File

@@ -360,7 +360,7 @@ describe("test custom XSS method", function() {
);
});
it("#onTag - sanitize html parameter", function() {
it("#onTag - sanitize html parameter space", function() {
var source = '<a target= " href="><script>alert(2)</script>"><span>';
var i = 0;
var html = xss(source, {
@@ -374,4 +374,19 @@ describe("test custom XSS method", function() {
debug(html);
assert.equal(html, '<a target= " href="><span>&lt;script&gt;alert(2)&lt;/script&gt;"&gt;<span>');
});
it("#onTag - sanitize html parameter tab", 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>&lt;script&gt;alert(2)&lt;/script&gt;"&gt;<span>');
});
});