Why not eval() JSON?

拜拜、爱过 提交于 2019-11-28 10:13:30

There are a number of ways that your security may be compromised.

  • Man in the middle attacks could theoretically alter the contents of data being delivered to the client.
  • Your server traffic could be intercepted elsewhere and different content could be provided (not quite the same as a MIM attack)
  • Your server could be compromised and the data source could be tampered with.

and these are just the simple examples. XSS is nasty.

"an ounce of prevention is worth a pound of cure"

In your scenario, the question becomes, where is PHP getting the javascript to execute from? Is that channel secure, and free from potential user manipulation? What if you don't control that channel directly?

Besides the obvious security issues:

  1. Native JSON is faster
  2. You don't need to "load" a JSON parser it's just another function call to the JavaScript engine

Tip: in asp.net using JSON is considered bad becuase parsing of DateTime differs between the server and the client so we use a special function to deserialize the date in javascript. I'm not sure if PHP has the same issue but its worth mentioning though.

check out this:http://blog.mozilla.com/webdev/2009/02/12/native-json-in-firefox-31/

so at least for firefox you can use the built in json parser

Seriously? Some of the guys here are paranoid. If you're delivering the JSON and you know it's safe, it's ok to fallback(*) to eval(); instead of a js lib for IE. After all, IE users have much more to worry about.

And the man-in-the-middle argument is bullsh*t.

(*) the words fallback and safe are in bold because some people here didn't see them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!