fix: problem with not closed tag (#262)

This commit is contained in:
Sviataslau Shchaurouski
2022-08-16 15:50:26 +02:00
committed by GitHub
parent c2419c4d14
commit 72844ddc6f
4 changed files with 6 additions and 5 deletions

4
dist/xss.js vendored
View File

@@ -586,7 +586,7 @@ function parseTag(html, onTag, escapeHtml) {
lastPos = currentPos;
continue;
}
if (c === ">") {
if (c === ">" || currentPos === len - 1) {
rethtml += escapeHtml(html.slice(lastPos, tagStart));
currentHtml = html.slice(tagStart, currentPos + 1);
currentTagName = getTagName(currentHtml);
@@ -621,7 +621,7 @@ function parseTag(html, onTag, escapeHtml) {
}
}
}
if (lastPos < html.length) {
if (lastPos < len) {
rethtml += escapeHtml(html.substr(lastPos));
}

2
dist/xss.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -71,7 +71,7 @@ function parseTag(html, onTag, escapeHtml) {
lastPos = currentPos;
continue;
}
if (c === ">") {
if (c === ">" || currentPos === len - 1) {
rethtml += escapeHtml(html.slice(lastPos, tagStart));
currentHtml = html.slice(tagStart, currentPos + 1);
currentTagName = getTagName(currentHtml);
@@ -106,7 +106,7 @@ function parseTag(html, onTag, escapeHtml) {
}
}
}
if (lastPos < html.length) {
if (lastPos < len) {
rethtml += escapeHtml(html.substr(lastPos));
}

View File

@@ -88,6 +88,7 @@ describe("test XSS", function() {
assert.equal(xss("<img src//>"), "<img src />");
assert.equal(xss("<br/>"), "<br />");
assert.equal(xss("<br />"), "<br />");
assert.equal(xss("<img src=x onerror=alert('XSS')"), "<img src>");
// 畸形属性格式
assert.equal(