what are the issues javascript eval can pose

后端 未结 4 975
梦谈多话
梦谈多话 2021-01-22 22:15

i tried googling but didnt get a very specific answer.. then again, i might be not using the right keywords.. can someone point out the \"security\" issues javascript eval can c

4条回答
  •  时光取名叫无心
    2021-01-22 23:07

    eval() may be a sign of poor design. For instance, sometimes people use it to access object properties because they don't know you can use the [] notation, i.e., eval('obj.' + prop_name). It's also a source of XSS holes if you eval() user content, since it might be interpreted as JS. It also tends to be slower than the alternatives.

    This would be the most basic example of XSS while using eval() to parse JSON:

    eval({"a": "b", 'c': "d" + alert("xss") + ""})
    

    To get a hole like this you would have to be lazy about building your JSON and not escape quotes, but there are more complex examples, and using a specialized library like Douglas Crockford's (json.org) one would avoid it.

提交回复
热议问题