-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[12.x] Fix security vulnerability in previousPath() method, preventing from returning external URLs #57487
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
Conversation
|
Great work on this fix! Validating the Referer origin and restricting previousPath() to same domain URLs is an important security improvement This change effectively closes potential open redirect and Malicious scheme vulnerabilities while keeping the behavior consistent for legitimate use cases. Thanks for prioritizing security and clarity here! |
|
Thank you for this! There is a |
|
@garygreen all the places that refer to the referrer should be patched then, no? So just previous and previousPath But maybe only previous should be changed and previousPath shouldn't? Or maybe previous should be called from previousPath.. |
@garygreen Thanks for supporting! And yes, it can be a great enhancement. I also thought of this fact but still kept my changes limited within this issue only for now.. but I can extend this validation check for other parts as well as per suitability further and that can handle things in a more cleaner way.
@macropay-solutions If we put the Let's see what Taylor thinks of this. |
|
@ahmad-cit22 have a look at this |
|
I'm not sure this is actually a security vulnerability? At the very least it's a breaking change as I'm not sure if people could be relying on this behavior. |
Returning the whole url of external (non-origin) source when the method is expected to return only the path - isn’t really a security vulnerability issue?! And talking about breaking change.. This is a concerning issue I agree. Then I will consider rePR with a more comprehensive solution regarding this to the |
|
@garygreen @ahmad-cit22 Thank you. We patched it for us. And like we said in the beginning. It is the developer's job to check the referer if it is valid or not. |
This PR improves and fixes the
previousPath()method inUrlGeneratorwith better security and origin validation, which solves the issue #57456.Problem Summary
The
previousPath()method is expected to return only the path of the previous URL (the doc SS attached for clarity). However, the existing implementation inpreviousPath()method had a security vulnerability where it returned a full external URL, when a malicious referrer header is sent.This happened because it extracted the path from the previous URL without validating that the request originated from the same origin or not and the path extracting logic only worked for the same origin requests. So, this was making applications vulnerable to security issues including:
javascript:,data:etc)Solution
So, I solved this with -
previousPath(), that validates Host matching (case-insensitive), Scheme consistency (http/https) and also Port validation.parse_url()) for reliabilityNew Changes Benefits
Test Coverage
Added comprehensive tests covering:
The changes made are fully backward compatible - existing functionality remains unchanged for legitimate same-origin requests while fixing the logic to match the expected behavior of the
previousPath()method and adding security protection that was needed.Even if a malicious referrer header is sent, it will return the fallback path or root path (e.g.,
/) instead of that external URL and thus handling this case silently and gracefully.Note: Why I think this change should be added into
12.x? because it's a security vulnerability, not a feature. - The current behavior is not what is expected (the documentation also states that). Anyone relying on it is unknowingly vulnerable. The method name ispreviousPath()notpreviousUrlOrPath().. so, current behavior also violates the naming contract.So this is surely a correctness fix, not any new feature or bringing breaking change. What we can do is -
@taylorotwell, Kindly let me know if we want to add/update anything in the documentation related to this change. Or if you have any disagreement on my thoughts, please inform me what can be improved. Thank you.