8000 Add support for 'X-Forwarded-For' header by vbelov42 · Pull Request #87 · tinyproxy/tinyproxy · GitHub
[go: up one dir, main page]

Skip to content

Add support for 'X-Forwarded-For' header #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

vbelov42
Copy link
@vbelov42 vbelov42 commented Apr 1, 2017

Usually people care about privacy and anonymity on the Internet, so proxy software is frequently used to filter out or mange several headers, to hide client's identity. But sometimes situation is completely different and one needs to tell the server about client's real address. Here comes a 'X-Forwarded-For' header that was introduced by the Squid caching proxy server's developers.

The X-Forwarded-For (XFF) HTTP header field is a common method for identifying the originating IP address of a client connecting to a web server through an HTTP proxy or load balancer. [wikipedia]

'X-Tinyproxy' field serves the same target, but is much less recognized.

In a nutshell, I just mutated write_via_header() function into write_xff_header(). And placed a call for it after write_via_header() in processing. I'm not 100% positive that it's correct for process_server_headers() case.

Also I added an option to the configuration file to control this. It has some description and default value that disables this feature.

Copy link
Member
@obnoxxx obnoxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!
And apologies for taking almost 1 year to get back to you...

Overall this looks like a clean patch and a good addition. But I am wondering why we would enable this new header by default and giving an option to disable it, instead of leaving the default behaviour as is and giving an option to enable it. Could you explain?

@rofl0r
Copy link
Contributor
rofl0r commented Mar 24, 2018

instead of leaving the default behaviour as is and giving an option to enable it

i suppose you meant disable here ?

@vbelov42
Copy link
Author
vbelov42 commented Mar 24, 2018

I followed the path of 'Via' header, that serves similar task. It is controlled by 'disable' switch config.disable_viaheader. I was surprised by the way how it is done, as you were, but just copied the existing behaviour. More surprising is that there is no default setting for this, so without configuration file it'll be enabled. Manpage indicates that this might be intentional, but I don't completely follow that.

I see two ways: rename both options, or set a 'disable' default value. Remember, that changing a variable name for the option will call for a change of a field name in configuration file, and that requires updating of all configurations. So right now I'd suggest the latter way.

@vbelov42
Copy link
Author

Also I just realized that I forgot to add a proper line to initialize_with_defaults(...) for disable_xffheader.

@obnoxxx
Copy link
Member
obnoxxx commented Mar 26, 2018

@rofl0r wrote:

instead of leaving the default behaviour as is and giving an option to enable it

i suppose you meant disable here ?

No. The current patch enables the new header by default and offers a disable option. I was suggesting to do the reverse.

@obnoxxx
Copy link
Member
obnoxxx commented Mar 26, 2018

@vbelov42 wrote:

I followed the path of 'Via' header, that serves similar task. It is controlled by 'disable' switch config.disable_viaheader. I was surprised by the way how it is done, as you were, but just copied the existing behaviour. More surprising is that there is no default setting for this, so without configuration file it'll be enabled. Manpage indicates that this might be intentional, but I don't completely follow that.

I see two ways: rename both options, or set a 'disable' default value. Remember, that changing a variable name for the option will call for a change of a field name in configuration file, and that requires updating of all configurations. So right now I'd suggest the latter way.

Tinyproxy currently has no capability of adding the XFF header. So the default behaviour is not to set it. The reasonable way to introduce the new feature (according to me, quite generally) should be to not change the current behaviour but leave it as is and maybe change the default in a later release if desired. I.e. you would have to actively do a configuration change in order to trigger the new behaviour (setting the XFF header).

What adds to this, imho, is that the XFF header may not be universally desired, since it exposes the client IP to the server on the other side of the proxy. So if we take the behaviour proposed in the current patch, a user would suddenly get "unstealth-ed" by an upgrade.

The fact that the via header is enabled by default is not relevant: The via header is an existing capability. This here is about introducing a new capability. It is more about expected behaviour than about similarity of code.

Copy link
Member
@obnoxxx obnoxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As detailed in the comments, I would request to change the pattern to not enable the XFF header by default but give an option EnableXffHeader in the config.

@vbelov42
Copy link
Author
vbelov42 commented Apr 8, 2018

Just for the case, I did what you requested. It's in 5df3615.

@captn3m0
Copy link
captn3m0 commented Jun 2, 2018

Can this be merged?

(Aside: The via header is a requirement as per the RFC, which is why it needs to be enabled by default)

@rofl0r
Copy link
Contributor
rofl0r commented Jun 2, 2018

"the RFC" ? please be more specific.

@captn3m0
Copy link
captn3m0 commented Jun 3, 2018

RFC 7230 marks it as a MUST. CloudFlare has a nice blog post about why it is necessary.

@rofl0r
Copy link
Contributor
rofl0r commented Jun 3, 2018

both the RFC and the cloudflare blog talk about the Via header (which is already supported), not the XFF header...

@captn3m0
Copy link
captn3m0 commented Jun 3, 2018

Yeah, mentioned that in my comment. Was just giving reason why the Via header is default On. See above for some discussion around it.

@rofl0r
Copy link
Contributor
rofl0r commented Jun 3, 2018

oh, you're right. 👍

@juju4
Copy link
juju4 commented Mar 5, 2023

Is this PR still under consideration?
XFF header is good in company context and/or chaining proxies.

@dk-jsco
Copy link
dk-jsco commented Mar 25, 2024

TinyProxy is a great project - but it would be even better with XFF.

Especially when working with backend services running in k8s.
The X-Tinyproxy header is removed by Ingress - hence, it's not possible to preserve the client IP.
NOTE: This is not the case with X-Forwarded-For

It is perfectly fine to disable XFF by default

Therefore, please provide a status on this pull request

@rofl0r
Copy link
Contributor
rofl0r commented Mar 25, 2024

The X-Tinyproxy header is removed by Ingress - hence, it's not possible to preserve the client IP.

that sounds like an ingress problem then. maybe you should take it there.

Therefore, please provide a status on this pull request

it would need some work for infrastructure changes that happened related to conf parsing. as the internet gets more and more hostile against proxy users (thanks cloudflare) i personally am not eager to add yet another option that removes privacy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0