Skip to content

Commit

Permalink
Use RegExp objects instead of eval for creating regular expressions t…
Browse files Browse the repository at this point in the history
…o fix code execution vulnerability as pointed out by Shahar Tal and his team from Check Point Software Technologies.
  • Loading branch information
zaidka committed Jul 14, 2014
1 parent a4f1d0d commit 03f9a9e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lib/normalize.coffee
Expand Up @@ -30,20 +30,18 @@ stringToRegexp = (input) ->

output = input.replace(/[\[\]\\\^\$\.\|\?\+\(\)]/, "\\$&")
if output[0] == '*'
prefix = '/'
output = output.replace(/^\*+/g, '')
else
prefix = '/^'
output = '^' + output

if output[output.length - 1] == '*'
suffix = '/'
output = output.replace(/\*+$/g, '')
else
suffix = '$/'
output = output + '$'

output = output.replace(/[\*]/, '.*')

return eval(prefix + output + suffix)
return new RegExp(output)


normalizers = {}
Expand Down Expand Up @@ -88,9 +86,9 @@ normalizers.date = (input, normType) ->

normalizers.string = (input, normType) ->
if normType is 'query'
if /^\/(.*?)\/(g?i?m?y?)$/.test(input)
return [{'$regex' : eval(input)}, input]
input
if (m = /^\/(.*?)\/(g?i?m?y?)$/.exec(input))
return [{'$regex' : new RegExp(m[1], m[2])}, input]
return input


colonizeMac = (input) ->
Expand Down Expand Up @@ -123,7 +121,7 @@ normalizers.mac = (input, normType) ->
if input.length == 17
return input

return {'$regex' : eval('/' + input + '/')}
return {'$regex' : new RegExp(input)}


exports.normalize = (path, value, normType) ->
Expand Down

0 comments on commit 03f9a9e

Please sign in to comment.