这对于 CSRF 保护来说足够了吗?
这对于 CSRF 保护来说是否足够:
- 生成一个随机字符串,
$_SESSION['hash']
将其存储在 - 一个隐藏值(在
$_POST['thing']
中)表单包含随机字符串 - 提交表单时,它会检查
$_SESSION['hash']
是否等于$_POST['thing']
,如果匹配则继续
我网站的一位用户不断告诉我,我的网站容易受到攻击,但我无法判断他是否只是在恶搞我。我还有什么可以做的吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您缺少的是将令牌限制在很小的时间范围内。
您应该看看Chris 的 CRSF 文章。快速总结:
What I think you are missing is limiting token to small window of time.
You should have a look at Chris's CRSF-article. A quick summary:
如果它对每个用户来说都是唯一的,那么就足够了。即使用户会话持续时间相同,它仍然可以,但我建议定期重新生成它。
此外,您可能希望每个表单使用不同的令牌。例如,如果您有登录表单和评论表单,最好为它们使用不同的令牌,但这并不是 100% 必要的。
为什么您认为仅仅因为有人说您的网站容易受到攻击,就与 CSRF 附加有关?它们还有很多其他可能的漏洞。
也许您的 Web 服务器已经过时且容易受到攻击,也许 php 版本不是最新的。也许用户能够通过 ssh 或 telnet 登录到您的服务器。也许用户能够猜测管理员密码。
也许是为了让人们通过 cookie 登录并在 cookie 中存储登录凭据。
除了 CSRF 之外,还有太多可以被利用的东西。也有可能用户是错误的,或者不知道他在谈论什么,或者他只是想让你紧张。
If it's unique to every user, then it should be enough. Even if it's the same for duration of user session, it's still OK, but I would suggest to re-generate it periodically.
Also you may want to use different tokens per each form. For example, if you have login form and comments form, it's better to use different tokens for them, but it's not 100% necessary.
Why do you assume that just because someone says your site is vulnerable, it has to do with CSRF attach? They are so many other possible vulnerabilities.
Maybe your web server outdated and vulnerable, maybe the php version is not the most recent one. Maybe the user was able to login to your server via ssh or telnet. Maybe the user was able to guess admin password.
Maybe to let people login by cookie and store login credentials in cookies.
There are just too many things other than CSRF that could be exploited. There is also a possibility that the user is wrong or does not know that he is talking about or maybe he just wants to make your nervous.
好吧,这就是你的问题。一旦检索到令牌,所有操作都可以轻松地进一步执行。我通常将令牌实现为对单个请求有效,然后重新生成它。
Well there is your problem. Once a token is retrieved all the actions can be easily performed further one. I usually implement the token to be valid for one single request and afterwards regenerate it.
来自:http://en.wikipedia.org/wiki/Cross-site_request_forgery
,但是您使用密钥的操作仍然比没有好......
from : http://en.wikipedia.org/wiki/Cross-site_request_forgery
however your acion with secret key is still better than nothing...