# CVE-2024-21631: Integer overflow in URI leading to potential host spoofing

> An integer overflow in Vapor's URI parser allows attackers to spoof hosts, potentially bypassing security checks in applications relying on this library.

- **Severity:** Medium 6.5 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 3 Jan 2024
- **Updated:** 18 Sep 2024
- **Also known as:** GHSA-r6r4-5pr8-gjcp

## What is CVE-2024-21631?

CVE-2024-21631 is a medium-severity vulnerability in vapor, published on 3 Jan 2024. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

Vapor is an HTTP web framework for Swift. Prior to version 4.90.0, Vapor's `vapor_urlparser_parse` function uses `uint16_t` 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.

Weakness: CWE-20 (Improper Input Validation), CWE-190 (Integer Overflow or Wraparound), CWE-1104 (Use of Unmaintained Third Party Components)

## Which versions are affected by CVE-2024-21631?

2 open source packages ship an affected version, including github.com/vapor/vapor. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/vapor/vapor` | SwiftURL | All versions | 4.90.0 |
| `github.com/vapor/vapor` | SwiftURL | All versions | 4.90.0 |

Products: Vapor Vapor.

## How do I fix CVE-2024-21631?

Upgrade github.com/vapor/vapor to 4.90.0 or later.

## Is CVE-2024-21631 being exploited?

There is no known exploitation of CVE-2024-21631 in the wild and no public exploit code.

## Other vulnerabilities in vapor

- [CVE-2022-31019](https://insights.sbomify.com/CVE-2022-31019/): DoS Vulnerability in URLEncodedFormDecoder in Vapor (high 7.5)
- [CVE-2022-31005](https://insights.sbomify.com/CVE-2022-31005/): Integer Overflow in Vapor's HTTP Range Request (high 7.5)
- [CVE-2023-44386](https://insights.sbomify.com/CVE-2023-44386/): Incorrect request error handling triggers server crash in Vapor (medium 5.3)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-21631 and fix it if it is affected.

What it is: CVE-2024-21631 is a medium-severity vulnerability in vapor, published on 3 Jan 2024. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2024-21631 in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/vapor/vapor (SwiftURL): affected all versions; fixed in 4.90.0
- github.com/vapor/vapor (SwiftURL): affected all versions; fixed in 4.90.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-21631/ (Markdown: https://insights.sbomify.com/CVE-2024-21631/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-21631
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-21631
- OSV: https://osv.dev/vulnerability/CVE-2024-21631

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-21631/
Summaries are generated and may contain mistakes; the official description above is the record.
