使用 JavaScript 动态 XSRF
我只是想知道是否可以进行 xsrf 攻击:
<form ...>
<input type="hidden" name="token" value="xsrf-generated-token" />
... fields+submit button ...
</form>
使用 javascript - 就像:
- 攻击者让我访问他的网站
- ,然后他使用 GET /admin/users/test/edit 调用 javascript,
- 他解析 xsrf 令牌(使用正则表达式 - dom 不会)由于同源策略而无法工作)
- 并发送签名的编辑...
不应该也由令牌签名 GET /admin/users/test/edit 吗?
I'm just wondering if it's possible to xsrf-attack this:
<form ...>
<input type="hidden" name="token" value="xsrf-generated-token" />
... fields+submit button ...
</form>
using javascript - like:
- attacker gets me to his site
- then he calls javascript with GET /admin/users/test/edit
- he parses xsrf token (using regexes - dom wouldn't work because of same-origin-policy)
- and send signed edit...
shouldn't be GET /admin/users/test/edit signed by token as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因是正常的ajax请求(使用XHR)受到同源策略的限制。因此,这意味着要使其发挥作用,您首先需要利用 XSS 漏洞,然后才能执行 CSRF 漏洞。
现在,JSONP 似乎可以解决这个问题。但事实并非如此。由于 JSONP 使用脚本标签,因此请求的结果将直接输入。并且由于结果是 HTML 而不是 JS,因此应该抛出语法错误。
因此,如果不先损害网站本身,就不可能获得令牌。但应该注意两件事,这一切都取决于:
所有浏览器都正确实现同源策略保护
您没有将令牌传递给表单通过 JSON(如果您是,JSONP 将能够读取它)。
The reason is that normal ajax requests (Using XHR) are limited by the same origin policy. So that means that in order for this to work, you'd first need to exploit a XSS vulnerability before you could execute the CSRF vulnerability.
Now, it may appear that JSONP might be a way around that. But it's not. Since JSONP uses script tags, the result of the request would be fed right in. And since the result is HTML and not JS, a syntax error should be thrown.
So there should be no way to ever get the token without first compromising the site itself. But two things should be noted that this all depends upon:
All browsers all correctly implement same origin policy protection
You're not passing the token to the form via JSON (for if you were, JSONP would be able to read it).