# CVE-2024-45302: CRLF Injection in RestSharp's `RestRequest.AddHeader` method

> CRLF injection in RestSharp allows attackers to inject headers or split requests, potentially leading to Server-Side Request Forgery in consuming applications.

- **Severity:** Medium 6.1 (`CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Local or same network only
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 29 Aug 2024
- **Updated:** 30 Aug 2024
- **Also known as:** GHSA-4rr6-2v9v-wcpc

## What is CVE-2024-45302?

CVE-2024-45302 is a medium-severity server-side request forgery vulnerability in RestSharp, published on 29 Aug 2024. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

### Official description

RestSharp is a Simple REST and HTTP API Client for .NET. The second argument to `RestRequest.AddHeader` (the header value) is vulnerable to CRLF injection. The same applies to `RestRequest.AddOrUpdateHeader` and `RestClient.AddDefaultHeader`. The way HTTP headers are added to a request is via the `HttpHeaders.TryAddWithoutValidation` method which does not check for CRLF characters in the header value. This means that any headers from a `RestSharp.RequestHeaders` object are added to the request in such a way that they are vulnerable to CRLF-injection. In general, CRLF-injection into a HTTP header (when using HTTP/1.1) means that one can inject additional HTTP headers or smuggle whole HTTP requests. If an application using the RestSharp library passes a user-controllable value through to a header, then that application becomes vulnerable to CRLF-injection. This is not necessarily a security issue for a command line application like the one above, but if such code were present in a web application then it becomes vulnerable to request splitting (as shown in the PoC) and thus Server Side Request Forgery. Strictly speaking this is a potential vulnerability in applications using RestSharp, not in RestSharp itself, but I would argue that at the very least there needs to be a warning about this behaviour in the RestSharp documentation. RestSharp has addressed this issue in version 112.0.0. All users are advised to upgrade. There are no known workarounds for this vulnerability.

Weakness: CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component), CWE-93 (Improper Neutralization of CRLF Sequences)

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

2 open source packages ship an affected version, including RestSharp. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `RestSharp` | NuGet | From 107.0.0-preview.1 | 112.0.0 |
| `RestSharp` | NuGet | From 107.0.0-preview.1 | 112.0.0 |

Products: Restsharp Restsharp.

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

Upgrade RestSharp to 112.0.0 or later.

## Is CVE-2024-45302 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-45302 exists.

## Other vulnerabilities in RestSharp

- [CVE-2021-27293](https://insights.sbomify.com/CVE-2021-27293/): Incorrect Regular Expression in RestSharp (high 7.5)

## Fix prompt for AI coding agents

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

What it is: CVE-2024-45302 is a medium-severity server-side request forgery vulnerability in RestSharp, published on 29 Aug 2024. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-45302 exists.

Affected packages and fixed versions:
- RestSharp (NuGet): affected from 107.0.0-preview.1; fixed in 112.0.0
- RestSharp (NuGet): affected from 107.0.0-preview.1; fixed in 112.0.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-45302/ (Markdown: https://insights.sbomify.com/CVE-2024-45302/index.md)
```

## Sources

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

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