, , , javascript, eval() .
eval() , JavaScript. , , JavaScript , eval() . , , , . , :
, .
, eval() JavaScript , . . , eval() , , eval() , , .
eval(), , , Felix Kling. , eval() , :
function compare(a, op, b)
{
if (typeof a != 'number' || typeof b != 'number' || typeof op != 'string')
return
if (['<', '>', '<=', '>=', '==', '!='].indexOf(op) == -1)
return
if (eval(a + op + b))
doSomething();
}
, , . . https://www.owasp.org/index.php/Input_Validation_Cheat_Sheet#White_List_Input_Validation .
: http://jsfiddle.net/YrQ4C/ ( ):
function doSomething()
{
alert('done something!')
}
function compare(a, op, b)
{
if (typeof a != 'number' || typeof b != 'number' || typeof op != 'string')
return
if (['<', '>', '<=', '>=', '==', '!='].indexOf(op) == -1)
return
if (eval(a + op + b))
doSomething();
}
compare(2, '<', 3)
compare(2, '<=', 3)
compare(2, '>', 3)
compare(2, '>=', 3)
compare('alert(', '"attack!"', ')')
compare(1, ';console.log("executed code");2==', 2)
: : http://jsfiddle.net/99eP2/