如何知道从哪个站点服务器收到请求?

发布于 2024-12-03 05:06:36 字数 33 浏览 2 评论 0原文

如何通过了解用户从哪个站点请求数据来避免跨站点脚本?

How i can avoid cross-site-scripting, by knowing, from what site user is requesting data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

橘寄 2024-12-10 05:06:36

如何避免跨站点脚本

您无法通过了解用户从哪个站点请求数据来避免跨站点脚本。

您可以通过正确转义来避免跨站点脚本。

How i can avoid cross-site-scripting

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.

对你的占有欲 2024-12-10 05:06:36
$_SERVER['HTTP_REFERER']

应包含请求源自的 URL。

编辑:如果您实际上是在尝试防止 XSS,那么主要是必须确保在打印未过滤的用户数据的任何地方都使用 htmlentities(),并且实际上应该在几乎所有不打算打印的数据上使用它被视为原始 HTML。

虽然编写 PHP 代码时也有很多注意事项,但在没有任何指导的情况下,它们太多了,无法在这里讨论。

$_SERVER['HTTP_REFERER']

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.

葬心 2024-12-10 05:06:36

我不确定知道引用网址是否对您有用,但是

大多数时候,XSS 攻击来自于输入或数据
在将其显示给浏览器之前没有很好地过滤或清理,例如
cookie/会话。

请阅读下面的文章,其中介绍了库如何防止 XSS 攻击。

链接: http://oozman.com/php-教程/避免跨站点脚本攻击-in-php/

I am not sure whether knowing the referrer URL will work for you but

And most of the time, XSS attacks came from an input or data that are
not well filtered or cleaned before showing it to a browser, like
cookies/sessions.

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/

泡沫很甜 2024-12-10 05:06:36

使用$_SERVER["HTTP_REFERER"],但请参阅对问题的回复。

Use $_SERVER["HTTP_REFERER"], but see the responses to this question.

不打扰别人 2024-12-10 05:06:36

在基本情况下的 $_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文