为什么跨域AJAX请求打成"安全风险和QUOT;? [英] Why are cross-domain AJAX requests labelled as a "security risk"?

查看:141
本文介绍了为什么跨域AJAX请求打成"安全风险和QUOT;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认情况下,浏览器不允许跨站点AJAX请求。

By default, browsers don't allow cross-site AJAX requests.

据我所知,严重设想跨域请求的可以的是一个安全隐患。如果我参加了HTML或外部网站的JavaScript和刚刚渲染到我的网站,这是一个问题。外部code可以用于很多不好的事情 - 就像获得访问当前用户的会话数据

I understand that a badly envisioned cross-domain request can be a security risk. If I take the html or the javascript of an external site and just "render" it into my website, that's a problem. That external code could be used for lots of bad things - like getting access to the current user's session data.

但是,如果我只请求JSON或XML数据,我用一个适当的库来解析JSON(而不仅仅是使用EVAL)我怎么也想不到,这将是一个安全隐患。可能发生的糟糕的是,从该网站未来内容不正确呈现。

But if I only request JSON or XML data, and I use a proper library to parse the JSON (not just using eval) I can't imagine how that would be a security risk. The worse that can happen is that the content coming from that site doesn't render correctly.

我缺少什么?是否有可能危及页面,通过发送某种形式的恶意数据读取JSON / XML的简单?

Am I missing anything? Is it possible to compromise a page that reads json/xml simply by sending it some kind of malicious data?

推荐答案

的风险是不是该网站发出请求。

The risk isn't to the site making the request.

例如:

  1. 在爱丽丝访问她的银行和日志中。
  2. 然后,她访问邪恶网站。
  3. 在邪恶的网站使用JavaScript来使Alice的浏览器发出请求到她的银行
  4. 在她的银行响应Alice的账户详细信息,并将其传递给JavaScript
  5. 中的JavaScript,然后将它们传递到邪恶的网站
  6. 控制器

在简单地说 - 这prevents袭击者从(以及那些位于防火墙后面如爱丽丝的企业内联网),任何网站,Alice有凭据读取私人数据。

In a nutshell — it prevents attackers from reading private data from any site that Alice has credentials for (and ones that are behind a firewall, e.g. Alice's corporate Intranet).

请注意,这将不会prevent攻击不依赖于能够读取数据形成的网站(的 CSRF ),但没有同源策略对CSRF标准的防守会很容易可击败。

Note that this won't prevent attacks which don't depend on being able to read data form the site (CSRF), but without the Same Origin Policy the standard defence against CSRF would be easily defeatable.

这篇关于为什么跨域AJAX请求打成"安全风险和QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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