OAuth2::Client Redirection Vulnerability Leaks Bearer Tokens
The `OAuth2::Client` in the `oauth2` Ruby gem is vulnerable to credential disclosure and Server-Side Request Forgery (SSRF) due to improper handling of protocol-relative redirect URLs, allowing an attacker to steal bearer tokens and access internal network resources.
A critical vulnerability (CVE-2026-54603) exists in the OAuth2::Client component of the oauth2 Ruby gem, affecting versions from 0.4.0 up to and including 2.0.21. This flaw stems from improper resolution of protocol-relative redirect URIs within the OAuth2::Client#request method. When an OAuth2 application makes a request and its configured Identity Provider (IdP) or an open-redirect vulnerability can be influenced to return a 30x redirect with a Location header such as //attacker.example/leak, the OAuth2::Client incorrectly merges this URI. As a result, the subsequent request, including the Authorization: Bearer <access-token> header, is redirected to the attacker-controlled host instead of remaining with the trusted IdP. This vulnerability leads to both cross-origin credential disclosure and potential Server-Side Request Forgery (SSRF) from the application server, allowing attackers to steal sensitive tokens and probe internal networks.
Attack Chain
- An application, using
OAuth2::AccessTokenviaOAuth2::Client, initiates a request to a trusted Identity Provider (IdP) or resource server, including anAuthorization: Bearer <access-token>header. - An attacker, by exploiting an open redirect vulnerability on the IdP, configuring a malicious tenant in a multi-tenant setup, or through a network compromise, causes the IdP to issue an HTTP 30x redirect response.
- The crafted redirect response's
Locationheader contains a protocol-relative URI pointing to an attacker-controlled host (e.g.,//attacker.example/leak). - The
OAuth2::Client#requestmethod attempts to resolve this redirect by callingresponse.response.env.url.merge(location). Per RFC 3986 §5.2,URI#mergeinterprets the protocol-relative URI as a network-path reference, which overrides the authority (scheme and host) of the base URL. - The library then recursively re-invokes
request(verb, full_location, req_opts)using the newly resolved attacker-controlled URL. Crucially, thereq_optsdictionary, containing the original request headers, is passed verbatim. - The
Authorization: Bearer <access-token>header, initially set byOAuth2::AccessToken#configure_authentication!, is preserved and transmitted in the request to the attacker's host. - The attacker-controlled server receives the application's bearer token, achieving immediate cross-origin credential disclosure without further user interaction.
- Alternatively, if the
LocationURI specifies an internal network address (e.g.,//169.254.169.254/), the application server acts as a Server-Side Request Forgery (SSRF) proxy, allowing the attacker to interact with internal resources.
Impact
Successful exploitation of this vulnerability results in two primary impacts:
- Cross-origin credential disclosure: The immediate consequence is the theft of
Authorization: Bearertokens. Any application utilizing the vulnerableoauth2gem to communicate with an IdP susceptible to such redirection risks having its access tokens exfiltrated to an attacker-controlled server. This can lead to unauthorized access to user data or resources that the stolen token grants access to. - Server-Side Request Forgery (SSRF): The ability to redirect the application's requests to an arbitrary host also enables SSRF. Attackers can leverage this to force the application server to make requests to internal network services, cloud metadata endpoints (e.g.,
169.254.169.254), or other restricted resources that are typically inaccessible from the internet. This could facilitate reconnaissance, lateral movement, or further exploitation within an organization's internal infrastructure. Given the widespread use of OAuth2 in modern applications, the potential number of affected services and organizations is substantial across all sectors.
Recommendation
- Upgrade the
oauth2gem to version2.0.22or later immediately to address CVE-2026-54603. - Apply the suggested patch logic to
OAuth2::Client#requestas an interim measure if immediate gem upgrade is not possible. This involves forcing protocol-relativeLocationvalues to be interpreted as relative paths by prepending./beforeURI#merge. - Developers should review their Identity Provider (IdP) and resource server configurations to ensure they do not expose open redirect vulnerabilities that could be abused to supply malicious
Locationheaders. - Implement defense-in-depth measures to strip credential-bearing headers (like
Authorization) from requests when a redirect crosses origin boundaries, similar to how robust HTTP clients handle such scenarios.
Indicators of compromise
1
domain
1
ip
1
url
| Type | Value |
|---|---|
| domain | attacker.example.test |
| url | http://idp.example.test |
| ip | 169.254.169.254 |