CVE-2024-21631: Integer overflow in URI leading to potential host spoofing
Vapor is an HTTP web framework for Swift. Prior to version 4.90.0, Vapor's vaporurlparserparse function uses uint16t indexes when parsing a URI's components, which may cause integer overflows when parsing untrusted inputs. This vulnerability does not affect Vapor directly but could impact applications relying on the URI type for validating user input. The URI type is used in several places in Vapor. A developer may decide to use URI to represent a URL in their application (especially if that URL is then passed to the HTTP Client) and rely on its public properties and methods. However, URI may fail to properly parse a valid (albeit abnormally long) URL, due to string ranges being converted to 16-bit integers. An attacker may use this behavior to trick the application into accepting a URL to an untrusted destination. By padding the port number with zeros, an attacker can cause an integer overflow to occur when the URL authority is parsed and, as a result, spoof the host. Version 4.90.0 contains a patch for this issue. As a workaround, validate user input before parsing as a URI or, if possible, use Foundation's URL and URLComponents utilities.
Other sources
Vapor's vaporurlparserparse function uses uint16t indexes when parsing a URI's components, which may cause integer overflows when parsing untrusted inputs.
This vulnerability does not affect Vapor directly but could impact applications relying on the URI type for validating user input.
The URI type is used in several places in Vapor. A developer may decide to use URI to represent a URL in their application (especially if that URL is then passed to the HTTP Client) and rely on its public properties and methods. However, URI may fail to properly parse a valid (albeit abnormally long) URL, due to string ranges being converted to 16-bit integers. An attacker may use this behaviour to trick the application into accepting a URL to an untrusted destination.
By padding the port number with zeros, an attacker can cause an integer overflow to occur when the URL authority is parsed and, as a result, spoof the host.
Impact Users attempting to treat untrusted input as a URI are vulnerable to a host spoofing attack due to an integer overflow.
Workarounds Validate user input before parsing as a URI or, if possible, use Foundation's URL and URLComponents utilities.
— GitHub
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
swift/github.com/vapor/vaporto a version that resolves this vulnerability.Fixed in 4.90.0 - Upgrade
Upgrade
vaporto a version that resolves this vulnerability.Fixed in 4.90.0 - Configuration
Before treating user-supplied data as a URI, validate it first; if possible, use Foundation `URL` and `URLComponents` rather than parsing untrusted strings as Vapor URI/authority components.
URI/URL parsing in application URI parsing validation strategy = Validate user input before parsing as a URI; where possible use Foundation's `URL` and `URLComponents` utilities instead of directly parsing with Vapor's URI handling
Event History
Frequently Asked Questions
What is the severity of CVE-2024-21631?
CVE-2024-21631 has not been assigned a specific CVSS score, but it poses a moderate risk due to potential integer overflows.
How do I fix CVE-2024-21631?
To fix CVE-2024-21631, update to Vapor version 4.90.0 or later.
Which versions of Vapor are affected by CVE-2024-21631?
CVE-2024-21631 affects Vapor versions before 4.90.0, including 4.89.3 and earlier.
What causes CVE-2024-21631?
CVE-2024-21631 is caused by the use of uint16_t indexes in the vapor_urlparser_parse function leading to possible integer overflows.
Who is impacted by CVE-2024-21631?
Applications relying on the URI type in Vapor for validating untrusted inputs may be impacted by CVE-2024-21631.