# CVE-2023-29401: Improper handling of filenames in Content-Disposition HTTP header in github.com/gin-gonic/gin

> Attackers can manipulate Content-Disposition headers via unsanitized filenames, potentially tricking users into executing malicious files.

- **Severity:** Medium 4.3 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 8 Jun 2023
- **Updated:** 6 Jan 2025
- **Also known as:** CLEANSTART-2026-UO59647, DEBIAN-CVE-2023-29401, GHSA-2c4m-59x9-fr2g, GO-2023-1737, MINI-c496-28jp-3pcm, UBUNTU-CVE-2023-29401

## What is CVE-2023-29401?

CVE-2023-29401 is a medium-severity vulnerability in github.com/gin-gonic/gin, published on 8 Jun 2023. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

The filename parameter of the Context.FileAttachment function is not properly sanitized. A maliciously crafted filename can cause the Content-Disposition header to be sent with an unexpected filename value or otherwise modify the Content-Disposition header. For example, a filename of "setup.bat&quot;;x=.txt" will be sent as a file named "setup.bat". If the FileAttachment function is called with names provided by an untrusted source, this may permit an attacker to cause a file to be served with a name different than provided. Maliciously crafted attachment file name can modify the Content-Disposition header.

Weakness: CWE-494 (Download of Code Without Integrity Check)

## Which versions are affected by CVE-2023-29401?

3 open source packages ship an affected version, including github.com/gin-gonic/gin. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/gin-gonic/gin` | Go | From 1.3.1-0.20190301021747-ccb9e902956d | 1.9.1 |
| `github.com/gin-gonic/gin` | Go | From 1.3.1-0.20190301021747-ccb9e902956d | 1.9.1 |
| `github.com/gin-gonic/gin` | Go | From 1.3.1-0.20190301021747-ccb9e902956d | 1.9.1 |

Products: Gin-Gonic Gin.

## How do I fix CVE-2023-29401?

Upgrade github.com/gin-gonic/gin to 1.9.1 or later.

## Is CVE-2023-29401 being exploited?

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

Public exploit code:

- Demo consumer for gin v1.7.0 (CVE-2023-29401) — Context.FileAttachment with user input. endorctl scan target. (github_poc): https://github.com/dannyEndorTest/gin-vulnerable

## Other vulnerabilities in github.com/gin-gonic/gin

- [CVE-2020-36567](https://insights.sbomify.com/CVE-2020-36567/): Arbitrary log line injection in github.com/gin-gonic/gin (high 7.5)
- [CVE-2020-28483](https://insights.sbomify.com/CVE-2020-28483/): HTTP Response Splitting (high 7.1)
- [CVE-2023-26125](https://insights.sbomify.com/CVE-2023-26125/): Improper input validation in github.com/gin-gonic/gin (medium 5.6)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-29401 and fix it if it is affected.

What it is: CVE-2023-29401 is a medium-severity vulnerability in github.com/gin-gonic/gin, published on 8 Jun 2023. An attacker can exploit it over the internet without logging in, 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-2023-29401 exists.

Affected packages and fixed versions:
- github.com/gin-gonic/gin (Go): affected from 1.3.1-0.20190301021747-ccb9e902956d; fixed in 1.9.1
- github.com/gin-gonic/gin (Go): affected from 1.3.1-0.20190301021747-ccb9e902956d; fixed in 1.9.1
- github.com/gin-gonic/gin (Go): affected from 1.3.1-0.20190301021747-ccb9e902956d; fixed in 1.9.1

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-2023-29401/ (Markdown: https://insights.sbomify.com/CVE-2023-29401/index.md)
```

## Sources

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

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