# CVE-2024-56140: Bypass of CSRF Middleware in Astro

> Attackers can bypass CSRF protections in Astro when origin checks are enabled, allowing unauthorized state-changing requests.

- **Severity:** Medium 5.9 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/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:** 18 Dec 2024
- **Updated:** 18 Dec 2024
- **Also known as:** GHSA-c4pw-33h3-35xw

## What is CVE-2024-56140?

CVE-2024-56140 is a medium-severity vulnerability in withastro astro, published on 18 Dec 2024. 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

Astro is a web framework for content-driven websites. In affected versions a bug in Astro’s CSRF-protection middleware allows requests to bypass CSRF checks. When the `security.checkOrigin` configuration option is set to `true`, Astro middleware will perform a CSRF check. However, a vulnerability exists that can bypass this security. A semicolon-delimited parameter is allowed after the type in `Content-Type`. Web browsers will treat a `Content-Type` such as `application/x-www-form-urlencoded; abc` as a `simple request` and will not perform preflight validation. In this case, CSRF is not blocked as expected. Additionally, the `Content-Type` header is not required for a request. This issue has been addressed in version 4.16.17 and all users are advised to upgrade. There are no known workarounds for this vulnerability.

Weakness: CWE-352 (Cross-Site Request Forgery)

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

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `astro` | npm | All versions | 4.16.17 |
| `astro` | npm | All versions | 4.16.17 |

Products: Astro Astro.

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

Upgrade astro to 4.16.17 or later.

## Is CVE-2024-56140 being exploited?

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

## Other vulnerabilities in withastro astro

- [CVE-2024-56159](https://insights.sbomify.com/CVE-2024-56159/): Server source code is exposed to the public if sourcemaps are enabled (high 7.8)
- [CVE-2026-54299](https://insights.sbomify.com/CVE-2026-54299/): Astro: Host header SSRF in prerendered error page fetch (high 7.5)
- [CVE-2025-59837](https://insights.sbomify.com/CVE-2025-59837/): astro allows bypass of image proxy domain validation leading to SSRF and potential XSS (high 7.2)
- [CVE-2026-50146](https://insights.sbomify.com/CVE-2026-50146/): Astro: Reflected XSS via unescaped slot name (high 7.1)
- [CVE-2025-64764](https://insights.sbomify.com/CVE-2025-64764/): Astro is vulnerable to Reflected XSS via the server islands feature (high 7.1)

## Fix prompt for AI coding agents

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

What it is: CVE-2024-56140 is a medium-severity vulnerability in withastro astro, published on 18 Dec 2024. 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-2024-56140 exists.

Affected packages and fixed versions:
- astro (npm): affected all versions; fixed in 4.16.17
- astro (npm): affected all versions; fixed in 4.16.17

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

## Sources

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

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