Skip to content

When all IPs are trusted, use the furthest away#38150

Merged
rafaelfranca merged 2 commits intorails:masterfrom
kbrock:all_trusted_ips
Jan 3, 2020
Merged

When all IPs are trusted, use the furthest away#38150
rafaelfranca merged 2 commits intorails:masterfrom
kbrock:all_trusted_ips

Conversation

@kbrock
Copy link
Copy Markdown
Contributor

@kbrock kbrock commented Jan 3, 2020

Summary

This is a rebase of the stale #14600.

From reading the thread, it looked like no logic changes need to be made, it just needed style and merge updates.

/cc @indirect @jeremy @matthewd

Other Information

As far as I could tell, the merge conflicts were from an added test (bf14a8e) and style changes (e8ba0c0 and 35b3de8). I did move 2 asserts a few lines up, but besides that it should be unchanged.

Original PR Summary

Scenario: we have a REMOTE_ADDR of 127.0.0.1, and X-Forwarded-For is
A, B, C.

Without any relevant trust, the remote_ip is C.

If C is trusted, then the remote_ip is B.

If B and C are trusted, then the remote_ip is A.

If all of A, B, and C are trusted, then the remote_ip should
still be A: if our trust was sufficient to get that far out before,
trusting something else should not have us fall back to 127.0.0.1.

It is this last situation that we're correcting here:

We trust A to give us accurate X-Forwarded-For information, yet it has
chosen to leave it unset. Therefore, A is telling us that it is itself
the client.

Scenario: we have a REMOTE_ADDR of `127.0.0.1`, and X-Forwarded-For is
`A, B, C`.

Without any relevant trust, the `remote_ip` is `C`.

If `C` is trusted, then the `remote_ip` is `B`.

If `B` and `C` are trusted, then the `remote_ip` is `A`.

If all of `A`, `B`, and `C` are trusted, then the `remote_ip` should
still be `A`: if our trust was sufficient to get that far out before,
trusting something else should not have us fall back to `127.0.0.1`.

It is this last situation that we're correcting here:

We trust `A` to give us accurate X-Forwarded-For information, yet it has
chosen to leave it unset. Therefore, `A` is telling us that it is itself
the client.
@rafaelfranca
Copy link
Copy Markdown
Member

Can you add a CHANGELOG entry?

@kbrock
Copy link
Copy Markdown
Contributor Author

kbrock commented Jan 3, 2020

@rafaelfranca thanks for looking at it. let me know if you want something else in the change log.

Happy weekend

rafaelfranca added a commit that referenced this pull request Jan 3, 2020
When all IPs are trusted, use the furthest away
@rafaelfranca rafaelfranca merged commit b17aaae into rails:master Jan 3, 2020
@kbrock kbrock deleted the all_trusted_ips branch January 6, 2020 21:37
@kbrock
Copy link
Copy Markdown
Contributor Author

kbrock commented Jan 6, 2020

Thanks so much @rafaelfranca (and @matthewd for putting this together)

@jimbali
Copy link
Copy Markdown

jimbali commented Feb 28, 2020

So glad someone has resurrected this! 😄 Is it likely to be in a 5.x release any time soon? We are upgrading a Rails app to v5 atm but I'm not sure if we'll get as far as 6.

@jimbali
Copy link
Copy Markdown

jimbali commented Aug 4, 2020

What is the process for getting this into a release?

@jonathanhefner
Copy link
Copy Markdown
Member

@jimbali This will be released in Rails 6.1. In accordance with Rails' Maintenance Policy, Rails 5.2 receives only security patches, and Rails 5.1 and below are unsupported.

@jimbali
Copy link
Copy Markdown

jimbali commented Dec 1, 2020

All the more reason to upgrade! 😊

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.

5 participants