Skip to content

Commit

Permalink
Merge pull request #14 from commenthol/fix-regex-xss
Browse files Browse the repository at this point in the history
  • Loading branch information
commenthol committed Dec 6, 2019
2 parents 39f6ddf + 181d7d5 commit d0234d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -75,7 +75,7 @@ function serialize (source, opts) {
out += !/^\s*(function|\([^)]*\)\s*=>)/m.test(tmp) ? 'function ' + tmp : tmp
} else if (util.isObject(source)) {
if (util.isRegExp(source)) {
out += source.toString()
out += 'new RegExp("' + source.source + '", "' + source.flags + '")'
} else if (util.isDate(source)) {
out += 'new Date("' + source.toJSON() + '")'
} else if (util.isError(source)) {
Expand Down
10 changes: 9 additions & 1 deletion test/fixtures.js
Expand Up @@ -33,7 +33,7 @@ module.exports = {
],
'regex': [
/test(?:it)?/ig,
'/test(?:it)?/gi'
'new RegExp("test(?:it)?", "gi")'
],
'object': [
{ a: 1, b: 2 },
Expand Down Expand Up @@ -138,6 +138,14 @@ module.exports = {
new Float64Array([1e12, 2000000, 3.1415, -4.9e2, 5]),
'new Float64Array([1000000000000, 2000000, 3.1415, -490, 5])',
'toString'
],
'regexXss': [
/[</script><script>alert('xss')//]/i,
'new RegExp("[</script><script>alert(\'xss\')//]", "i")'
],
'regex no flags': [
/abc/,
'new RegExp("abc", "")'
]
}

Expand Down

0 comments on commit d0234d3

Please sign in to comment.