Json:PHP到JavaScript的安全与否? [英] Json: PHP to JavaScript safe or not?

查看:84
本文介绍了Json:PHP到JavaScript的安全与否?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解在客户端上使用eval(json_str)容易受到恶意代码的攻击.我的问题是,如果json_str是由PHP函数json_encode构造的数组,那么我会安全吗?

I understand that the use of eval(json_str) on the client is vulnerable to malicious code. My question is, if json_str was an array constructed by the PHP function json_encode, would I be safe?

例如,

json_str = json_encode(array(record1, 
                             record2, 
                             record3));

现在在客户端代码中使用eval(json_str)是否完全安全?

would it now be entirely safe to use eval(json_str) inside client-side code?

推荐答案

是,不是:

是:PHP生成有效的JSON

Yes: PHP produces valid JSON

否:PHP可能会像JSON一样返回恶意代码.

No: PHP may as well return malicious code as in JSON.

如果您可以信任来源,或者甚至可以完全控制它(因为它是您的),那么就没有问题.

If you can trust the source, or if you even have full control over it (because its yours), there is no problem.

这篇关于Json:PHP到JavaScript的安全与否?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆