Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if a Request is coming from a Proxy?

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?

like image 462
Josh Stodola Avatar asked Mar 27 '09 14:03

Josh Stodola


2 Answers

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:

via:
forwarded:
x-forwarded-for:
client-ip: 

You could also look for the proxy or pxy in the client domain name.

like image 51
Darin Dimitrov Avatar answered Nov 06 '22 08:11

Darin Dimitrov


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

like image 34
Adam Davis Avatar answered Nov 06 '22 08:11

Adam Davis