HTTP_ORIGIN 的安全性如何?
我想查明来自第三方网站的传入 HTTP_REQUEST 调用是否来自我定义的域列表。
我知道可以使用HTTP_REFERER来查找第三方域在哪里,但它不够安全。人们可以欺骗它或使用 Telnet 来伪造它。
那么,HTTP_ORIGIN 怎么样?它是从所有浏览器发送的吗?安全吗?
另外,人们可以在 HTTP_REQUEST 调用中伪造 REMOTE_ADDR 吗?
I want to find out whether an incoming HTTP_REQUEST call from a third party website is coming from the list of domains that I defined.
I know that HTTP_REFERER can be used to find out where the third party domain is, but it is not secure enough. People can spoof it or use Telnet to fake it.
So, how about HTTP_ORIGIN? Is it sent from all browsers? Is it secure?
Also, can people fake the REMOTE_ADDR in a HTTP_REQUEST call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
HTTP_ORIGIN
是一种防范 CSRF(跨站请求伪造)请求的方法。目前它仅由 Chrome 实现(截至 2011 年 11 月)。我测试了 Firefox 和 Opera,但都失败了。它在请求标头中的名称是
Origin
。在我的 PHP 脚本的服务器上,我将其视为$_SERVER
数组中的HTTP_ORIGIN
。仅在某些情况下,当需要针对 CSRF 的保护时才发送此标头(仅 POST 就足够了)。以下是所有请求的列表,无论是否设置:https://wiki.mozilla.org/Security /Origin
不幸的是,
Origin
标头仅在 Chrome 中实现。它于 2010 年 1 月在 Google Chrome 博客上首次发布:http://blog.chromium.org/2010/01/security-in-deep-new-security-features.html
我只是在我的 PHP 脚本中实现 CSRF 保护,我个人使用 Chrome,所以这对我来说已经足够了,我希望其他浏览器很快就能赶上 Chrome。
有趣的是,Mozilla 发明了该安全功能,因为您可以在其网站上阅读大量有关
Origin
标头的文档,但他们仍然没有时间实现它;-)HTTP_ORIGIN
似乎只包含protocol
和domain
,末尾没有斜杠:“http://www.example.com” - 即使您从“http://www.example.com/myform/”提交表单。
PHP 脚本中针对 CSRF 的简单保护:
该脚本仍然可以升级以支持 80 以外的端口(Origin 包含与 80 不同的端口)、HTTPS 连接以及从不同子域(例如 sub.example.com)提交表单。 com => 向 www.example.com 发布请求)。
HTTP_ORIGIN
is a way to protect against CSRF (Cross Site Request Forgery) requests. Currently it is implemented only by Chrome (as of Nov 2011). I tested Firefox and Opera, but they failed.Its name in the request header is
Origin
. On the server in my PHP script I see it asHTTP_ORIGIN
in the$_SERVER
array. This header is sent only in some cases, when protection against CSRF is required (only POST should be sufficient). Here is list of all requests whether it is set or not:https://wiki.mozilla.org/Security/Origin
The
Origin
header is implemented only in Chrome, unfortunately. It was announced first in January 2010 on Google Chrome's blog:http://blog.chromium.org/2010/01/security-in-depth-new-security-features.html
I am just implementing CSRF protection in my PHP script, I personally use Chrome, so that is sufficient for me, I hope other browsers will catch up with Chrome soon.
What is funny is that Mozilla invented that security feature, as you can read lots of documentation of that
Origin
header on its website, but they still didn't have time to implement it ;-)HTTP_ORIGIN
seems to contain onlyprotocol
anddomain
, without slash at the end:"http://www.example.com" - even if you submit the form from "http://www.example.com/myform/".
A simple protection against CSRF in PHP script:
This script could still be upgraded to support PORT other than 80 (Origin contains the port when it's different than 80), HTTPS connections, and submitting the forms from different subdomains (ex. sub.example.com => posting request to www.example.com).
HTTP_ORIGIN
既不是由所有浏览器发送,也不安全。浏览器发送的任何内容都不能被认为是安全的。
HTTP_ORIGIN
is neither sent by all browsers nor is it secure.Nothing sent by the browser can ever be considered safe.
这里的人们的想法都是错误的——“CORS”标准并不是为了让服务器不会被黑客攻击,即使它除了它所做的之外还有帮助。目的是让“浏览器”能够减轻违反同源策略的请求。如果客户端和服务器位于同一页面,则“客户端”可以决定是否允许该请求。
显然,通过让服务器参与决策,您可以帮助安全过程。
但它不能保护服务器免受未经授权的访问——这就是密码和 cookie 的用途。
客户端可以是(正如有人提到的)一个telnet工具,其中制作的每一个东西都是假的。
但是 Chrome 和 FF 等的卖点之一是,它们将通过不允许 Javascript 超出同源沙箱来帮助您,这意味着默认情况下唯一可能受到损害的是“攻击者自己的网站。或其他决定不安全的网站。
CORS 技术可以让您说——嘿,我希望用户能够通过他们使用的其他网站上的 javascript 来使用我的时髦服务。所以我要把这个网站添加到我的例外中。这意味着您正在帮助您的授权用户在该特定站点的浏览器安全性中找出漏洞。这意味着黑客可以利用一个漏洞。因此,您在设置服务时非常谨慎,对吗?
这意味着,默认情况下,任何未设置 CORS 的站点都可以免受来自兼容浏览器的跨站点脚本攻击(当然,排除错误和黑客攻击)。浏览器会询问该服务是否要参与源站点的 javascript,如果跨站点说“我对这个该死的站点一无所知”,那么浏览器的 javascript 引擎将关闭连接并转储数据。
综上所述,CORS 并不能帮助您确保安全。它可以帮助您在浏览器的能力上造成漏洞,从而使用户更加安全。但希望以一种托管的方式..并且仅适用于特定网站..
People here are thinking about this all wrong -- the 'CORS' standard isn't so the server doesn't get hacked, even if it helps that in addition to what it does. The purpose is to allow 'THE BROWSER' to have a way of easing up on requests that go against the same origin policy. If the client and the server are on the same page, then the 'CLIENT' can decide whether or not to allow the request.
Obviously by having the server participate in the decision you are helping in the security process.
But it won't protect the server from unauthorized access - that is what passwords and cookies are for.
The client can be (as someone mentioned) a telnet tool, where every single thing crafted is fake.
But one of Chrome's, and FF's, etc, selling points is that they will help you by not allowing Javascript to go outside of the same origin sandbox, which means the only thing by default that can be compromised is the stuff that is on the 'attackers' own website. Or other sites that decide to not be secure.
CORS is the technology that allows you to say -- hey, I want users to be able to consume my snazzy service from the javascript on this other site they use. So I'm gonna add this site to my exceptions. Which means you are helping your authorized users poke a hole in their browser security for that particular site. Which means a hole that a hacker can exploit. Thus the care with which you set up the service, right?
This means that any site that doesn't have CORS set up is by default secure from Cross Site Scripting from a compliant browser (barring bugs and hacks of course). The browser will ask if this service wants to participate in the origin site's javascript, and if the cross site says "I don't know nothing about this damn site", then the browser's javascript engine will close the connection and dump the data.
So just to summarize -- CORS doesn't help you make thing secure. It helps you make a hole in your browsers ability to make a user more secure. But hopefully in a managed way.. and only for particular sites..
HTTP 是一种纯文本协议。 ENTIRE 请求标头/正文结构可以伪造为您想要的任何内容。
HTTP is a plain-text protocol. The ENTIRE request header/body structure can be faked to say anything you want.
HTTP 请求中的一切都可以伪造。
Everything in the HTTP request can be faked.
升级:
示例:
Upgraded:
Example:
更新,截至 2021 年:
HTTP_ORIGIN
几乎得到所有浏览器的完全支持,请参阅:https://developer.mozilla.org/en- US/docs/Web/HTTP/Headers/Origin#browser_compatibility
Update, as of 2021:
HTTP_ORIGIN
is almost fully supported by all browsers, see:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin#browser_compatibility