防止从远程站点进行 POST
我只是想知道你如何防止人们试图欺骗你的脚本和内容从远程站点发布类似的表单。例如尝试&将额外的值放入您没有的选定字段或类似性质的字段中。
I'm just wondering how you go about preventing people trying to fool your script & POST'ing a similar looking form from a remote site.. say for example to try & put in extra values into select fields you don't have in yours or something of that nature.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的想法是创建一个根据用户代理、IP 和时间范围生成的 md5 密钥。然后将其存储在数据库中并将其填充到隐藏文本字段中,以便在提交时您可以重新验证该值。
您还可以使用 $_SERVER['HTTP_REFERER'] 获取请求的来源,并根据您网站的 URL 对其进行验证。请记住,这是由用户网络浏览器设置的,因此可能会被欺骗。以下是可用的 $_SERVER 变量及其描述的列表。
http://www.php.net/manual/en/reserved.variables .server.php
The best idea would be to create a md5 key generated from the user agent, ip and a time frame. Then store that in a database and populate it in a hidden text field so on submit you can revalidate the value.
You can also use $_SERVER['HTTP_REFERER'] to get were the request came from and validate it against the url of your site. Remember this is set by the user web browser so it can be spoofed. Here is a list of available $_SERVER variables and their descriptions.
http://www.php.net/manual/en/reserved.variables.server.php
为了防止跨站请求伪造 (CSRF),您应该使用所谓的 CSRF 令牌验证请求的真实性。此外,您可以检查 HTTP Referer,并且仅在其为空(不存在)或您的地址之一时才允许交易。
另请参阅OWASP 的跨站请求伪造 (CSRF) 预防备忘单 了解更多信息。
To prevent Cross-Site Request Forgery (CSRF), you should use a so called CSRF token that verifies the authenticity of the request. Additionally, you can check the HTTP Referer and only allow the transaction if it’s empty (not existing) or one of your addresses.
See also OWASP’s Cross-Site Request Forgery (CSRF) Prevention Cheat Sheet for further information.