CVE-2021-22942 Overview
CVE-2021-22942 is an open redirect vulnerability affecting the Host Authorization middleware in Ruby on Rails Action Pack. This security flaw exists in Action Pack versions 6.0.0 and later, allowing attackers to craft malicious URLs that redirect users to arbitrary external websites. Open redirect vulnerabilities are particularly dangerous in phishing campaigns, as they abuse the trust users place in legitimate domains.
Critical Impact
Attackers can exploit this vulnerability to redirect users from trusted Ruby on Rails applications to malicious websites, potentially leading to credential theft, malware distribution, or social engineering attacks.
Affected Products
- Ruby on Rails 6.0.0 and later versions (prior to 6.0.4.1)
- Ruby on Rails 6.1.x versions (prior to 6.1.4.1)
- Action Pack component in affected Rails versions
Discovery Timeline
- 2021-08-19 - Ruby on Rails releases security patches 6.0.4.1 and 6.1.4.1
- 2021-10-18 - CVE-2021-22942 published to NVD
- 2024-11-21 - Last updated in NVD database
Technical Details for CVE-2021-22942
Vulnerability Analysis
The vulnerability resides in the Host Authorization middleware, a security feature introduced in Rails 6.0 designed to protect against DNS rebinding attacks. The middleware validates incoming request hosts against a configured allowlist. However, a flaw in the validation logic allows attackers to bypass this protection and redirect users to external domains.
When a request fails host authorization, the middleware generates a response that can be manipulated to redirect users. The root cause is improper handling of certain URL patterns during the authorization failure response, which attackers can exploit to redirect users to attacker-controlled websites.
Root Cause
The vulnerability stems from insufficient validation in the Host Authorization middleware's redirect handling logic. When processing requests with invalid hosts, the middleware fails to properly sanitize or validate the redirect destination URL, allowing external URLs to be used as redirect targets. This is classified as CWE-601 (URL Redirection to Untrusted Site), commonly known as an open redirect vulnerability.
Attack Vector
The attack vector is network-based, requiring user interaction where a victim must click a malicious link. Attackers craft URLs that appear to point to a legitimate Rails application but include parameters that trigger the vulnerable redirect behavior. Since the initial URL appears trustworthy, users are more likely to click such links, making this vulnerability particularly effective in phishing campaigns.
The attack flow typically involves:
- An attacker crafts a URL pointing to a vulnerable Rails application with a specially crafted host or redirect parameter
- The victim clicks the seemingly legitimate link, trusting the Rails application's domain
- The Host Authorization middleware processes the request and generates a redirect
- Due to improper validation, the user is redirected to an attacker-controlled website
- The attacker can then harvest credentials, distribute malware, or conduct further social engineering
Detection Methods for CVE-2021-22942
Indicators of Compromise
- Unusual redirect responses from Rails applications to external domains
- Access logs showing requests with suspicious host headers or encoded redirect parameters
- User reports of unexpected redirects when clicking internal application links
- Network traffic analysis revealing redirects to known malicious domains
Detection Strategies
- Monitor application access logs for unusual Host header values in requests
- Implement web application firewall (WAF) rules to detect open redirect patterns
- Review HTTP response logs for 3xx status codes redirecting to external domains
- Deploy SIEM rules to correlate redirect activity with known phishing indicators
Monitoring Recommendations
- Enable detailed logging for the Host Authorization middleware in Rails applications
- Configure alerts for redirect responses containing external domain URLs
- Implement user reporting mechanisms for suspicious redirect behavior
- Conduct periodic security assessments of Rails application redirect functionality
How to Mitigate CVE-2021-22942
Immediate Actions Required
- Upgrade Ruby on Rails to version 6.0.4.1 or later for Rails 6.0.x installations
- Upgrade Ruby on Rails to version 6.1.4.1 or later for Rails 6.1.x installations
- Review and restrict Host Authorization middleware configuration
- Implement additional input validation for redirect-related parameters
Patch Information
The Ruby on Rails team addressed this vulnerability in security releases 6.0.4.1 and 6.1.4.1, announced on August 19, 2021. Organizations should update their Rails applications to these patched versions or later. For additional details, refer to the Ruby on Rails Release Announcement. Debian users should also review Debian Security Advisory DSA-5372 for distribution-specific guidance.
Workarounds
- Configure the Host Authorization middleware with an explicit allowlist of trusted hosts using config.hosts
- Implement a reverse proxy or WAF to validate and filter incoming Host headers
- Add application-level validation for any redirect destinations before processing
- Consider disabling the Host Authorization middleware's redirect functionality until patching is possible
# Configuration example - Add to config/environments/production.rb
# Restrict allowed hosts to prevent open redirect exploitation
config.hosts << "yourdomain.com"
config.hosts << /.*\.yourdomain\.com/
# Optionally, configure host authorization to raise exceptions instead of redirecting
config.host_authorization = { exclude: ->(request) { request.path =~ /^\/health/ } }
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


