如何知道从哪个站点服务器收到请求?
如何通过了解用户从哪个站点请求数据来避免跨站点脚本?
How i can avoid cross-site-scripting, by knowing, from what site user is requesting data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何通过了解用户从哪个站点请求数据来避免跨站点脚本?
How i can avoid cross-site-scripting, by knowing, from what site user is requesting data?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
您无法通过了解用户从哪个站点请求数据来避免跨站点脚本。
您可以通过正确转义来避免跨站点脚本。
You can't avoid cross-site-scripting by knowing from what site a user is requesting data.
You can avoid cross-site-scripting by properly escaping.
应包含请求源自的 URL。
编辑:如果您实际上是在尝试防止 XSS,那么主要是必须确保在打印未过滤的用户数据的任何地方都使用 htmlentities(),并且实际上应该在几乎所有不打算打印的数据上使用它被视为原始 HTML。
虽然编写 PHP 代码时也有很多注意事项,但在没有任何指导的情况下,它们太多了,无法在这里讨论。
should contain the URL from which the request originates from.
EDIT: If you are actually trying to prevent XSS then it's mostly down to having to make sure you use htmlentities() everywhere you print unfiltered user data, and should really be using it on pretty much all data you print that isn't meant to be viewed as raw HTML.
Although there are bunch of considerations when writing PHP code as well, but they are far too many to discuss here without any pointers.
我不确定知道引用网址是否对您有用,但是
请阅读下面的文章,其中介绍了库如何防止 XSS 攻击。
链接: http://oozman.com/php-教程/避免跨站点脚本攻击-in-php/
I am not sure whether knowing the referrer URL will work for you but
Please read the article below which teaches a library to prevent XSS attacks.
Link: http://oozman.com/php-tutorials/avoid-cross-site-scripting-attacks-in-php/
使用
$_SERVER["HTTP_REFERER"]
,但请参阅对此问题的回复。Use
$_SERVER["HTTP_REFERER"]
, but see the responses to this question.在基本情况下的 $_SERVER 数组中,这是 $_SERVER['HTTP_REFERER'] - 但如果用户通过 js 方法访问您的网站,例如 document.location.href = 'yoursite.com'。 IE(在IE7上测试)出于安全原因不会向您发送有关Referer的信息。
in $_SERVER array in base case this is $_SERVER['HTTP_REFERER'] - but if user go to your site from js method like document.location.href = 'yoursite.com'. IE (test on IE7) does not sent to you information about referer through security reason.