Use RegExp objects instead of eval for creating regular expressions to fix code execution vulnerability as pointed out by Shahar Tal and his team from Check Point Software Technologies.
This commit is contained in:
1 parent
a4f1d0dc2a
commit
03f9a9e628
1 file changed
+7
-9
@@ -30,20 +30,18 @@ stringToRegexp = (input) ->
|
|||||||
|
|
||||||
output = input.replace(/[\[\]\\\^\$\.\|\?\+\(\)]/, "\\$&")
|
output = input.replace(/[\[\]\\\^\$\.\|\?\+\(\)]/, "\\$&")
|
||||||
if output[0] == '*'
|
if output[0] == '*'
|
||||||
prefix = '/'
|
|
||||||
output = output.replace(/^\*+/g, '')
|
output = output.replace(/^\*+/g, '')
|
||||||
else
|
else
|
||||||
prefix = '/^'
|
output = '^' + output
|
||||||
|
|
||||||
if output[output.length - 1] == '*'
|
if output[output.length - 1] == '*'
|
||||||
suffix = '/'
|
|
||||||
output = output.replace(/\*+$/g, '')
|
output = output.replace(/\*+$/g, '')
|
||||||
else
|
else
|
||||||
suffix = '$/'
|
output = output + '$'
|
||||||
|
|
||||||
output = output.replace(/[\*]/, '.*')
|
output = output.replace(/[\*]/, '.*')
|
||||||
|
|
||||||
return eval(prefix + output + suffix)
|
return new RegExp(output)
|
||||||
|
|
||||||
|
|
||||||
normalizers = {}
|
normalizers = {}
|
||||||
@@ -88,9 +86,9 @@ normalizers.date = (input, normType) ->
|
|||||||
|
|
||||||
normalizers.string = (input, normType) ->
|
normalizers.string = (input, normType) ->
|
||||||
if normType is 'query'
|
if normType is 'query'
|
||||||
if /^\/(.*?)\/(g?i?m?y?)$/.test(input)
|
if (m = /^\/(.*?)\/(g?i?m?y?)$/.exec(input))
|
||||||
return [{'$regex' : eval(input)}, input]
|
return [{'$regex' : new RegExp(m[1], m[2])}, input]
|
||||||
input
|
return input
|
||||||
|
|
||||||
|
|
||||||
colonizeMac = (input) ->
|
colonizeMac = (input) ->
|
||||||
@@ -123,7 +121,7 @@ normalizers.mac = (input, normType) ->
|
|||||||
if input.length == 17
|
if input.length == 17
|
||||||
return input
|
return input
|
||||||
|
|
||||||
return {'$regex' : eval('/' + input + '/')}
|
return {'$regex' : new RegExp(input)}
|
||||||
|
|
||||||
|
|
||||||
exports.normalize = (path, value, normType) ->
|
exports.normalize = (path, value, normType) ->
|
||||||
|
|||||||
Reference in new issue
Block a user