Skip to main content

CVE-2022-31151: CWE-601: URL Redirection to Untrusted Site ('Open Redirect') in nodejs undici

Medium
Published: Wed Jul 20 2022 (07/20/2022, 23:00:15 UTC)
Source: CVE
Vendor/Project: nodejs
Product: undici

Description

Authorization headers are cleared on cross-origin redirect. However, cookie headers which are sensitive headers and are official headers found in the spec, remain uncleared. There are active users using cookie headers in undici. This may lead to accidental leakage of cookie to a 3rd-party site or a malicious attacker who can control the redirection target (ie. an open redirector) to leak the cookie to the 3rd party site. This was patched in v5.7.1. By default, this vulnerability is not exploitable. Do not enable redirections, i.e. `maxRedirections: 0` (the default).

AI-Powered Analysis

AILast updated: 06/22/2025, 00:12:12 UTC

Technical Analysis

CVE-2022-31151 is a medium-severity vulnerability classified under CWE-601 (URL Redirection to Untrusted Site, commonly known as an open redirect) affecting the 'undici' HTTP client library used in Node.js environments. The vulnerability arises because, during cross-origin HTTP redirects, the undici client clears authorization headers but fails to clear cookie headers. Cookies are sensitive headers often containing session tokens or authentication information. If an application using an affected undici version (< 5.7.1) enables automatic redirections (i.e., sets maxRedirections > 0), an attacker who can control the redirection target URL could exploit this behavior to leak cookies to a malicious third-party site. This could lead to session hijacking or unauthorized access if the leaked cookies contain authentication credentials. By default, undici disables redirections (maxRedirections: 0), so the vulnerability is not exploitable without explicit configuration changes. The issue was patched in version 5.7.1 by ensuring that cookie headers are cleared on cross-origin redirects, preventing accidental leakage. No known exploits have been reported in the wild, and the vulnerability requires that the application both uses an affected undici version and enables redirections, which somewhat limits the attack surface. However, given the widespread use of undici in Node.js applications and the sensitivity of cookie data, this vulnerability poses a tangible risk if left unpatched in environments that enable redirects.

Potential Impact

For European organizations, the impact of this vulnerability primarily concerns confidentiality breaches through cookie leakage. If exploited, attackers could hijack user sessions or gain unauthorized access to internal or customer-facing applications, potentially leading to data breaches, fraud, or further lateral movement within networks. Organizations in sectors such as finance, healthcare, e-commerce, and government, which often rely on Node.js-based services and handle sensitive personal or financial data, are particularly at risk. The vulnerability could undermine trust in digital services and lead to regulatory consequences under GDPR if personal data is compromised. Since the vulnerability requires enabling redirects, organizations that use undici with automatic redirections for microservices communication or API calls are more exposed. The lack of known exploits reduces immediate risk, but the potential for cookie leakage to malicious domains makes timely patching critical to prevent targeted attacks or abuse by threat actors leveraging open redirectors.

Mitigation Recommendations

1. Upgrade undici to version 5.7.1 or later, where the vulnerability is patched. 2. Audit all Node.js applications using undici to identify if automatic redirections are enabled (maxRedirections > 0). If redirections are not necessary, explicitly set maxRedirections to 0 to disable them. 3. Implement strict validation and sanitization of any user-controllable URLs that might influence redirection targets to prevent open redirect scenarios. 4. Employ Content Security Policy (CSP) headers to restrict the domains to which cookies and other sensitive data can be sent. 5. Use HttpOnly and Secure flags on cookies to reduce the risk of client-side script access and ensure cookies are only sent over HTTPS. 6. Monitor application logs for unusual redirect patterns or unexpected outbound requests to untrusted domains. 7. Conduct regular security reviews of third-party dependencies and keep them up to date. 8. Consider implementing additional application-layer protections such as Web Application Firewalls (WAFs) configured to detect and block suspicious redirect chains.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
GitHub_M
Date Reserved
2022-05-18T00:00:00.000Z
Cisa Enriched
true

Threat ID: 682d9849c4522896dcbf6704

Added to database: 5/21/2025, 9:09:29 AM

Last enriched: 6/22/2025, 12:12:12 AM

Last updated: 8/9/2025, 2:18:03 PM

Views: 14

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats