Coding a website or application with the ability to process unvalidated redirects and forwards can be extremely dangerous for both your users and your organization.
Coding a website or application with the ability to process unvalidated redirects and forwards can be extremely dangerous for both your users and your organization. This common mistake is often exploited by hackers looking to perpetrate phishing scams, or to gain access to pages and information that would normally be restricted.
Whenever a web application is designed to forward users to new pages, there is the danger that those requests can be manipulated or hijacked. This can happen if there is no validation process in place to prevent forwarding parameters from pointing at unintended destinations.
The good news is that unvalidated redirects and forwards are one of the easier vulnerabilities to eliminate from your environment. Once removed, you can take a few simple steps to ensure that they are never generated in the future.
In this episode, we will learn:
Attackers must first find a web application that is set to forward users to a specific page or pages. If the destination page is defined in the code, there is no vulnerability. For example, in Java, this would be a safe, pre-defined way of sending a user to a new location without requiring them to perform any actions, such as clicking on a hyperlink.
The vulnerability occurs if the site is programmed to instead accept user input for the redirect, or if the parameter is left open, perhaps to obtain the information from another source. For example, a developer could use the "url'GET parameter.
While this gives more flexibility, it also creates the unvalidated redirects and forwards vulnerability. Hackers can add information after the forward slashes to trigger a redirect to whatever site they choose, perhaps as part of a phishing e-mail. Users see the trusted domain in the first part of a link and don't realize that the website may forward them to the hacker's site.
The danger posed by allowing unvalidated redirects and forwards can be significant. For users, the biggest danger is that they can become victims of phishing attacks. Because they see the top-level URL, they are more likely to trust a phishing e-mail or other communication and click on a link. And if the page they are redirected to looks like the real page, the deception can be quite effective. They might share their user name, passwords or other credentials and never suspect that they are being manipulated.
Unvalidated redirects and forwards begin life while an application is being developed. They can be eliminated after the fact, but the easiest way to eliminate them is simply not allowing user parameters or open strings as part of any redirect or forward function in the first place. Instead, tightly define the URLs where users will be forwarded, eliminating variables and denying attackers room to maneuver. Better yet, consider not using redirects and forwards at all.
If there is absolutely no way to avoid having variables as part of a redirect or forward process, then there must be a validation process put in place to ensure that the redirect is going to one of a set of valid destinations. Finally, use mapping values instead of actual URLs. Hackers will instead try to use URL information, and likely wont be able to guess at the mapping scheme even if they suspect one is in use.
For further reading, you can take a look at the OWASP reference pages on unvalidated redirects and forwards. You can also put your newfound defensive knowledge to the test with the free demo of the Secure Code Warrior platform, which trains cybersecurity teams to become the ultimate cyber warriors. To learn more about defeating this vulnerability, and a rogues'gallery of other threats, visit the Secure Code Warrior blog.
Take care of unvalidated redirects and forwards once and for all. Apply your new knowledge and test your skills on our gamified training platform: [Start Here]