Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slashes as separators. #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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