Redirect
ID |
ruby.checkredirect |
Severity |
low |
Resource |
Redirect |
Language |
Ruby |
Description
URL redirection to untrusted site ('Open Redirect').
Open Redirect vulnerabilities occur when web applications dynamically construct URLs for redirection using user inputs, without proper validation or constraints. These vulnerabilities can be exploited by attackers to redirect users to phishing sites, steal personal information, or perform malicious actions.
Remediation
If possible, avoid using (client-side) redirects and (server-side) forwards unless strictly necessary.
Otherwise, to mitigate Open Redirect vulnerabilities, apply these best practices:
-
Whitelist URLs: Restrict redirection targets to a predefined list of trusted URLs. Only allow redirections to URLs that have been explicitly marked as safe or necessary for application functionality. Another option is to use a map of allowed URLs or domains and use an indirect reference from the request to choose a valid redirect URL from the map.
-
Input Validation and Normalization: When constructing redirection URLs, validate and normalize the user inputs. Ensure the inputs conform to expected patterns, such as being a relative URL and not containing prohibited protocols or domains.
-
Avoid Using
sendRedirectfor User-Controlled Paths: Prefer using server-side routing logic that does not involve dynamic user-generated paths or URLs for redirection purposes. -
Security Awareness and User Warnings: Inform users of potential risks when following redirects, and warn them against entering sensitive information on unfamiliar sites.
-
Regular Security Audits and SAST: Conduct periodic security audits of the codebase and utilize SAST tools to detect and address Open Redirect vulnerabilities throughout the software development lifecycle.
By implementing these strategies, you can effectively reduce the risk of open redirect vulnerabilities, thereby safeguarding user interactions and maintaining the integrity of your application’s navigational logic.
References
-
CWE-601 : URL Redirection to Untrusted Site ('Open Redirect').
-
OWASP - Top 10 2021 Category A01 : Broken Access Control.
-
Unvalidated Redirects and Forwards Cheat Sheet, in OWASP Cheat Sheet Series.