CSRF保护
关于阻止 CSRF 的文章有很多。
但我就是不明白:为什么我不能只解析目标页面表单中的 csrf 令牌并通过我的 forge 请求提交它?
There are quite a lot written about preventing CSRF.
But I just don't get it: why I can't just parse the csrf token in the target page form and submit it with my forge request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您能够将脚本代码注入目标页面(XSS),那么是的,您可以这样做,从而使 CSRF 预防变得毫无用处。
CSRF 令牌必须存储在最终用户收到的页面中(否则他也不会知道)。
事实上,在安全评估中,XSS 通常不是评估其自身的潜在损害,而是评估其在此类攻击中的使用情况。
If you are able to inject script code into the target page (XSS) then yes, you can do that thus rendering the CSRF prevention useless.
The CSRF token has to be stored in the page the end-user receives (or he won't know it either).
In fact, in security assessments, XSS usually evaluated not for its own damage potential but for its use in just such attacks.
CSRF 攻击是盲目的。他们进行会话骑行,攻击者无法直接控制,除非他可以通过 XSS 漏洞提取令牌。通常可以使用会话范围的令牌。针对每个请求轮换令牌可能是一种矫枉过正的行为,并且可能会导致误报。我更喜欢将每个资源的令牌与主会话令牌一起使用。
CSRF attacks are blind. They do session riding and the attacker has no direct control unless he can extract the token via an XSS vulnerability. Normally a session wide token can be used. Rotating tokens per request might be an overkill and could lead to false alarms. I prefer to use tokens per resource with a master session token.
CSRF 令牌每次对于每个用户和每个请求都应该是完全不同的令牌,因此攻击者永远无法猜到它。
对于 php、.net 和 javascript,请查看 OWASP CSRFGuard 项目 - 如果您正在使用 java 和 jsf 2.x,它已经针对 CSRF 进行了保存(只要您使用 POST 而不是 GET - 为此您将不得不等待 JSF 2.2)如果您没有使用 JSF,则使用 HTTPUtillities Interface<来自 OWASP ESAPI 的 /a> 也非常有帮助!
The CSRF token should be everytime for every user and for every request a totally different token, so it can never be guessed from an attacker.
For php, .net and javascript have a look in the OWASP CSRFGuard Project - if you are working with java and jsf 2.x its already save against CSRF (as long as you use POST and not GET - for this you will have to wait for JSF 2.2) else if you work without JSF the HTTPUtillities Interface from the OWASP ESAPI could be also very helpful!
因为 CSRF 令牌的价值事先并不知道。
Because the value of the CSRF token isn't known in advance.