-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat/195: trust REMOTE_ADDR header only #198
Conversation
@Sidsector9 @dkotter what else is needed to get this PR open for review (and then merged and ready for release)? |
I've left some comments on things I think should be changed, though I haven't tested this out yet. I do think it's still worth discussing on if this is something we want to fix and if this is the best way to fix it. My concern still stands that this is a backwards compatibility break and I'm not super comfortable with that. I like this new approach of handling things as it is more secure but in essence this will potentially break (meaning not work as expected) any site that is running behind some sort of proxy (like a CDN). I almost like the idea of having this be opt in behavior, either through a filter or a new setting. So by default we keep things as-is and if individual sites want better security, they can turn this new approach on. |
New opt-in filter/setting seems like a good approach as well, in no way looking to introduce a breaking change without a user taking an educated action to trigger that change. |
@Sidsector9 checking back in to see if you're able to get this ready for review/merge? |
@jeffpaul I'll go through Darin's comments and then estimate how much time it'll take. |
@dkotter I've responded to your comments and refactored the logic a bit and updated the comments with more details. The code reflects the below flowchart. If this gets approved, then I'll proceed with adding this as an opt-in feature. |
…on function, instead of doing a strict match. Set the default for our trusted headers to match the current functionality to avoid backwards compat issues. Documentation changes
Thanks for all the work here @Sidsector9 (as well as continuing to remind me this needed my attention). I've made a few minor changes, mostly around maintaining backwards compatibility with the existing list of headers we support by default. For information sake, the approach here (or at least the approach I was looking at, don't want to speak for Sid) was based on how Symfony handles proxies (see docs, code). Here's an overview of how this should be working now:
There are two things I'd love some feedback on here (cc/ @jeffpaul @peterwilsoncc):
|
EDIT: I've left the above for posterity but I've gone ahead and made sure we try and always have a default IP that we return (this will be the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few notes inline.
It would be nice if the tests used data providers rather than multiple tests in a single block, but not a blocker.
*/ | ||
$trusted_proxies = apply_filters( 'rsa_trusted_proxies', array() ); | ||
|
||
if ( ! empty( $trusted_proxies ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty()
prevents developers disallowing any proxies. I'd expect the following to prevent proxy access:
add_filter( 'rsa_trusted_proxies', '__return_empty_array' );
It might be worht checking with has_filter()
but I could be convinced otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to make sure I'm following correctly. You're suggesting we replace the empty
check with a has_filter
check, allowing someone to use this filter to return an empty array, which would then pass our check but because there's no proxies to iterate over at that point, we would just return an empty string which should in essence block access to the site?
Guess I'm just wondering what the use case here would be for this, seems like this could be achieved already using the settings in the admin. I'm not opposed to making this change just having a hard time coming up with a scenario where this would be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible I am misunderstanding the purpose of the code. Let me do some testing during the day and get back to you. If needs be I will provide a test to clarify my thinking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had myself totally confused when I read this code yesterday. I see what it's doing and it all makes sense to me.
Fix our tests to ensure we set all headers first before asserting the value More test clean up More test clean up
@jeffpaul this is approved. As discussed yesterday in 1:1, this can go with 7.3.2. |
Note that I've updated the readmes with information on how to utilize these new filters |
@Sidsector9 can you please update the changelog entry in the PR description (I added the credit line folks), thanks! |
Description of the Change
This PR proposes a solution to prevent IP spoofing by trusting only the
REMOTE_ADDR
header.It adds 2 new filters to filter trusted proxies and; headers that the trusted proxies use to forward client IP information.
Alternate Designs
TBD.
Possible Drawbacks
This will be a breaking change.
Verification Process
Checklist:
Applicable Issues
Closes #195
Changelog
Credits
@Sidsector9, @dkotter, @peterwilsoncc, @marcS0H, @DanielRuf.