Unsanitized user input in redirect
- Rule ID: ruby_rails_open_redirect
- Languages: ruby
- Source: open_redirect.yml
Description
Using unsanitized user input to perform redirects can make your application vulnerable to phishing attacks. This occurs when user input is directly used to determine the destination of a redirect without proper validation or sanitization, allowing attackers to redirect users to malicious sites, potentially compromising their security.
Remediations
- Do not use unsanitized user input when constructing URLs for redirects. Directly incorporating user input without validation can lead to phishing attacks and malicious site redirection.
- Do validate user input by employing a safe list or a mapping strategy for constructing URLs. This ensures that the redirection is to a known, safe location.
transport_path = case params[:transport_type]
when "planes"
planes_path
when "trains"
trains_path
when "automobiles"
automobiles_path
else
root_path
end
redirect_to transport_path
References
Associated CWE
OWASP Top 10
Configuration
To skip this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --skip-rule=ruby_rails_open_redirect
To run only this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --only-rule=ruby_rails_open_redirect