-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow redirects to whitelisted hosts with ports #280
Allow redirects to whitelisted hosts with ports #280
Conversation
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.
Thank you and congrats on your first contribution! 🎉
@kamaln7 Thanks for submitting this PR, I've got an idea about potential improvements, I wonder if we could define some logic so that the whitelist domains could include the port? If no port is set we assume there should be no port set on the request for redirection (ie it's a standard port), if a port is set on the redirect then it must match a whitelisted domain/port combination, WDYT?
If you could add some invalid host tests that would be great! Finally, please make sure to update the changelog and documentation before this gets merged 🙂 |
Thanks for the feedback! I'll be sure to update the documentation and changelog, but I want to confirm that the current behavior is what you were looking for. Provided that the redirect URL matches a whitelisted domain:
I've added some more tests which I believe cover all cases but an extra set of eyes is never a bad idea. Now, there's something I'm not 100% sure about. Because the whitelisted domains aren't proper URLs, only hosts, I don't use The code for I'm not sure how deep you want to go into this so I'd like to hear your thoughts. |
I think if there is no port set on the whitelist domain then we should assume that the request must be on the default port for the protocol (so 80 for http, 443 for https). Though I would assume that the request wouldn't have a port set when you form it if it's to the default port so I think the check would be to check for an empty port, might be worth testing that assumption though 🤔 |
Yes, good point about the port being empty. I’ll update the code. For wildcard ports I guess we could use “*” as the port assuming that wouldn’t cause issues with parsing. That way it would be backwards compatible too. |
That sounds like a really good approach! Please make sure there are sufficient tests for all the cases when you make these changes |
Let me know what you think. I had to copy I also took some time to refactor the tests. |
Hey @JoelSpeed any updates? 😄 |
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.
Found one minor thing, but other than that it looks great! Apologies for the delay btw 🙈
No worries, thanks for reviewing! |
This is super useful and it seems to have been forgotten till it hit merge conflict. Perhaps @kamaln7 could be kind enough to rebase and we can help land this? :) |
Once conflicts are fixed we can merge. |
Fixed! 😃 |
@syscll can this be merged now? :) |
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.
LGTM 👍
Can you give this a final review @JoelSpeed @steakunderscore |
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.
LGTM, thanks @kamaln7
This updates
IsValidRedirect
to allow redirects to whitelisted hosts if a port is set on the redirect URL. Fixes #279.Description
Use
URL.Hostname()
instead ofURL.Host
to strip the port when validating the host against the list of whitelisted domain.How Has This Been Tested?
Added tests to cover the new use cases. I wasn't sure if I needed to add tests for invalid hosts with ports but let me know and I can add that in.
Checklist: