如何判断请求是否来自代理?
是否可以检测传入请求是否是通过代理服务器发出的? 如果 Web 应用程序通过 IP 地址“禁止”用户,他们可以使用代理服务器绕过此操作。 这只是阻止这些请求的原因之一。 如何才能实现这一目标?
Is it possible to detect if an incoming request is being made through a proxy server? If a web application "bans" users via IP address, they could bypass this by using a proxy server. That is just one reason to block these requests. How can this be achieved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
恕我直言,没有 100% 可靠的方法来实现此目的,但以下任何标头的存在都强烈表明该请求是从代理服务器路由的:
您还可以查找代理或 >pxy 位于客户端域名中。
IMHO there's no 100% reliable way to achieve this but the presence of any of the following headers is a strong indication that the request was routed from a proxy server:
You could also look for the proxy or pxy in the client domain name.
如果代理服务器设置正确以避免代理服务器的检测,您将无法分辨。
正如其他人提到的那样,大多数代理服务器提供标头,但这些标头不存在于旨在完全隐藏用户的代理上。
您将需要采用多种检测方法,例如 cookie、代理标头检测,或许还可以使用 IP 启发式方法来检测此类情况。 查看 http://www.osix.net/modules/article/?id=765 有关此情况的一些信息。 还可以考虑使用代理黑名单 - 它们由许多组织发布。
然而,没有什么是 100% 确定的。 您可以采用上述策略来避免大多数简单的情况,但最终它只是形成 TCP/IP 事务的一系列数据包,并且 TCP/IP 协议并不是按照当今的安全、身份验证等理念开发的请
记住,许多公司出于各种原因部署公司范围的代理,如果您只是简单地阻止代理作为一般规则,那么您必然会限制您的受众,而这可能并不总是令人满意的。 然而,这些代理通常会使用适当的标头来声明自己 - 您最终可能会阻止合法用户,而不是善于隐藏自己的用户。
-亚当
If a proxy server is setup properly to avoid the detection of proxy servers, you won't be able to tell.
Most proxy servers supply headers as others mention, but those are not present on proxies meant to completely hide the user.
You will need to employ several detection methods, such as cookies, proxy header detection, and perhaps IP heuristics to detect such situations. Check out http://www.osix.net/modules/article/?id=765 for some information on this situation. Also consider using a proxy blacklist - they are published by many organizations.
However, nothing is 100% certain. You can employ the above tactics to avoid most simple situations, but at the end of the day it's merely a series of packets forming a TCP/IP transaction, and the TCP/IP protocol was not developed with today's ideas on security, authentication, etc.
Keep in mind that many corporations deploy company wide proxies for various reasons, and if you simply block proxies as a general rule you necessarily limit your audience, and that may not always be desirable. However, these proxies usually announce themselves with the appropriate headers - you may end up blocking legitimate users, rather than users who are good at hiding themselves.
-Adam
在我的域名托管在 Google 的 AppSpot.com 上并注入了漂亮的硬核色情广告后,对此进行了一些挖掘(感谢 Google)。
借鉴这个htaccess 想法< /a> 我正在执行以下操作,这似乎有效。 我为 AppSpot 添加了一条特定规则,该规则注入 HTTP_X_APPENGINE_COUNTRY ServerVariable。
Did a bit of digging on this after my domain got hosted up on Google's AppSpot.com with nice hardcore porn ads injected into it (thanks Google).
Taking a leaf from this htaccess idea I'm doing the following, which seems to be working. I added a specific rule for AppSpot which injects a HTTP_X_APPENGINE_COUNTRY ServerVariable.
您可以在请求对象中查找这些标头,并相应地确定请求是否通过代理
1) 通过
2) X-Forwarded-For
请注意,这不是 100% 确定的技巧,取决于这些代理服务器是否选择添加上述标头。
You can look for these headers in the Request Object and accordingly decide whether request is via a proxy/not
1) Via
2) X-Forwarded-For
note that this is not a 100% sure shot trick, depends upon whether these proxy servers choose to add above headers.