5.9medium
Bypass of CSRF Middleware in Astro
- Severity
- 5.9medium CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.24% (higher than 15% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-c4pw-33h3-35xw
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.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| withastro astro | < 4.16.17 | CVE List |
| astro (npm) | before 4.16.17 | GitHub Advisory Database |
| astro astro | before 4.16.17 | NVD |
All scores
| GitHub_M | 5.9medium CVSS:3.1 | CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:N |
| GitHub | 5.9medium CVSS:3.1 | CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:N |
| NVD | 6.5medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N |
Classification
SSVC (CISA-ADP): exploitation poc, automatable no, technical impact partial.
What each source says
CVE List
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.
GitHub Advisory Database
Summary
A bug in Astro’s CSRF-protection middleware allows requests to bypass CSRF checks.
Details
When the security.checkOrigin configuration option is set to true, Astro middleware will perform a CSRF check. (Source code: https://github.com/withastro/astro/blob/6031962ab5f56457de986eb82bd24807e926ba1b/packages/astro/src/core/app/middlewares.ts)
For example, with the following Astro configuration:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
export default defineConfig({
output: 'server',
security: { checkOrigin: true },
adapter: node({ mode: 'standalone' }),
});
A request like the following would be blocked if made from a different origin:
// fetch API or <form action="https://test.example.com/" method="POST">
fetch('https://test.example.com/', {
method: 'POST',
credentials: 'include',
body: 'a=b',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
// => Cross-site POST form submissions are forbidden
However, a vulnerability exists that can bypass this security.
Pattern 1: Requests with a semicolon after the Content-Type
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.
fetch('https://test.example.com', {
method: 'POST',
credentials: 'include',
body: 'test',
headers: { 'Content-Type': 'application/x-www-form-urlencoded; abc' },
});
// => Server-side functions are executed (Response Code 200).
Pattern 2: Request without Content-Type header
The Content-Type header is not required for a request. The following examples are sent without a Content-Type header, resulting in CSRF.
// Pattern 2.1 Request without body
fetch('http://test.example.com', { method: 'POST', credentials: 'include' });
// Pattern 2.2 Blob object without type
fetch('https://test.example.com', {
method: 'POST',
credentials: 'include',
body: new Blob(['a=b'], {}),
});
Impact
Bypass CSRF protection implemented with CSRF middleware.
[!Note] Even with
credentials: 'include', browsers may not send cookies due to third-party cookie blocking. This feature depends on the browser version and settings, and is for privacy protection, not as a CSRF measure.
NVD (es)
Astro es un framework para sitios web basados en contenido. En las versiones afectadas, un error en el middleware de protección CSRF de Astro permite que las solicitudes eludan las comprobaciones CSRF. Cuando la opción de configuración `security.checkOrigin` se establece en `true`, el middleware Astro realizará una comprobación CSRF. Sin embargo, existe una vulnerabilidad que puede eludir esta seguridad. Se permite un parámetro delimitado por punto y coma después del tipo en `Content-Type`. Los navegadores web tratarán un `Content-Type` como `application/x-www-form-urlencoded; abc` como una `solicitud simple` y no realizarán una validación previa. En este caso, CSRF no se bloquea como se esperaba. Además, el encabezado `Content-Type` no es necesario para una solicitud. Este problema se ha solucionado en la versión 4.16.17 y se recomienda a todos los usuarios que actualicen. No existen workarounds conocidos para esta vulnerabilidad.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2024-56140 changed 2024-12-18 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-c4pw-33h3-35xw changed 2025-11-27 | CC-BY-4.0 |
| NVD | CVE-2024-56140 changed 2026-06-17 | Public domain |