Skip to content

Commit

Permalink
Fix slashes as separators.
Browse files Browse the repository at this point in the history
  • Loading branch information
hensleysecurity committed Dec 29, 2022
1 parent c339c1f commit 843beed
Show file tree
Hide file tree
Showing 7 changed files with 3,229 additions and 13 deletions.
12 changes: 6 additions & 6 deletions dist/xss.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ var _ = require("./util");
* @return {String}
*/
function getTagName(html) {
var i = _.spaceIndex(html);
var i = _.separatorIndex(html);
var tagName;
if (i === -1) {
tagName = html.slice(1, -1);
Expand Down Expand Up @@ -681,8 +681,8 @@ function parseAttr(html, onAttr) {
}
}
}
if (/\s|\n|\t/.test(c)) {
html = html.replace(/\s|\n|\t/g, " ");
if (/\s|\//.test(c)) {
html = html.replace(/\s|\//g, " ");
if (tmpName === false) {
j = findNextEqual(html, i);
if (j === -1) {
Expand Down Expand Up @@ -800,8 +800,8 @@ module.exports = {
}
return str.replace(/(^\s*)|(\s*$)/g, "");
},
spaceIndex: function (str) {
var reg = /\s|\n|\t/;
separatorIndex: function (str) {
var reg = /\s|\b\/[^>]/;
var match = reg.exec(str);
return match ? match.index : -1;
},
Expand Down Expand Up @@ -840,7 +840,7 @@ function isNull(obj) {
* - {Boolean} closing
*/
function getAttrs(html) {
var i = _.spaceIndex(html);
var i = _.separatorIndex(html);
if (i === -1) {
return {
html: "",
Expand Down
2 changes: 1 addition & 1 deletion dist/xss.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ = require("./util");
* @return {String}
*/
function getTagName(html) {
var i = _.spaceIndex(html);
var i = _.separatorIndex(html);
var tagName;
if (i === -1) {
tagName = html.slice(1, -1);
Expand Down Expand Up @@ -166,8 +166,8 @@ function parseAttr(html, onAttr) {
}
}
}
if (/\s|\n|\t/.test(c)) {
html = html.replace(/\s|\n|\t/g, " ");
if (/\s|\//.test(c)) {
html = html.replace(/\s|\//g, " ");
if (tmpName === false) {
j = findNextEqual(html, i);
if (j === -1) {
Expand Down
4 changes: 2 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module.exports = {
}
return str.replace(/(^\s*)|(\s*$)/g, "");
},
spaceIndex: function (str) {
var reg = /\s|\n|\t/;
separatorIndex: function (str) {
var reg = /\s|\b\/[^>]/;
var match = reg.exec(str);
return match ? match.index : -1;
},
Expand Down
2 changes: 1 addition & 1 deletion lib/xss.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function isNull(obj) {
* - {Boolean} closing
*/
function getAttrs(html) {
var i = _.spaceIndex(html);
var i = _.separatorIndex(html);
if (i === -1) {
return {
html: "",
Expand Down
10 changes: 10 additions & 0 deletions test/test_xss.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ describe("test XSS", function() {
xss('<a\n\n\n\ttarget="_blank"\t\t\t\ntitle="bbb">'),
'<a target="_blank" title="bbb">'
);

// 属性用斜杠分隔
assert.equal(
xss('<img/width=100/height=200/src="#"/>'),
'<img width="100" height="200" src="#" />'
);
assert.equal(
xss('<a/target="_blank"///title="bbb">'),
'<a target="_blank" title="bbb">'
);
});

// 自定义白名单
Expand Down
Loading

0 comments on commit 843beed

Please sign in to comment.