Skip to content

Don't fall back to REMOTE_ADDR unless X_FORWARDED_FOR is empty#1160

Closed
KaptajnKold wants to merge 1 commit intorack:masterfrom
KaptajnKold:master
Closed

Don't fall back to REMOTE_ADDR unless X_FORWARDED_FOR is empty#1160
KaptajnKold wants to merge 1 commit intorack:masterfrom
KaptajnKold:master

Conversation

@KaptajnKold
Copy link
Copy Markdown

The previous, faulty behaviour was to remove all trusted ip addresses
from X_FORWARDED_FOR and returning the last one remaining, falling back
to the REMOTE_ADDR if none remain.

A problem arises if all the address in X_FORWARDED_FOR are trusted.
They can't all be proxies. One of them (the first one) is the ip that
made the request. The correct behaviour is to return the first one, but
the previous implementation would remove them all, and fall back to
REMOTE_ADDR.

This patch removes trusted ips only from the tail of X_FORWARDED_FOR,
and returns the last address in the resulting list, ensuring that we
don't fall back to REMOTE_ADDR if X_FORWARDED_FOR is non-empty.

The previous, faulty behaviour was to remove all trusted ip addresses
from X_FORWARDED_FOR and returning the last one remaining, falling back
to the REMOTE_ADDR if none remain.

A problem arises if all the address in X_FORWARDED_FOR are trusted.
They can't all be proxies. One of them (the first one) is the ip that
made the request. The correct behaviour is to return the first one, but
the previous implementation would remove them all, and fall back to
REMOTE_ADDR.

This patch removes trusted ips only from the tail of X_FORWARDED_FOR,
and returns the last address in the resulting list, ensuring that we
don't fall back to REMOTE_ADDR if X_FORWARDED_FOR is non-empty.
@timon
Copy link
Copy Markdown

timon commented Jun 30, 2017

Hi @KaptajnKold
I'm experiencing the same issue, thanks for the fix!

@SamSaffron
Copy link
Copy Markdown
Contributor

Almost the same PR was also submitted by me

#1224

Such a shame this is in the pipeline for so long

@mikegee
Copy link
Copy Markdown
Contributor

mikegee commented Apr 10, 2019

@KaptajnKold does #1224 resolve the issue for you too?

@KaptajnKold
Copy link
Copy Markdown
Author

@mikegee yes, it does.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants