CVE-2024-56140: Astro Atro CSRF Middleware Bypass (security.checkOrigin) Vulnerability

MODERATE
Advisory Identifier: GHSA-c4pw-33h3-35xw
CVSS 5.9
CWE-352
Published
Advisory Summary

CVE-2024-56140 is a MODERATE (CVSS 5.9) atro csrf middleware bypass (security.checkorigin) vulnerability (CWE-352: Cross-Site Request Forgery (CSRF)) affecting Astro libraries in the npm ecosystem. The issue involves atro csrf middleware bypass (security.checkorigin). Remediation is available by upgrading affected packages to version 4.16.17.

CVE-2024-56140 at a Glance

CVE Identifier CVE-2024-56140
GHSA Identifier GHSA-c4pw-33h3-35xw
Severity MODERATE
CVSS v3.1 Base Score 5.9
CWE Classification CWE-352: Cross-Site Request Forgery (CSRF)
Affected Product Astro
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.9

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2024-56140

To remediate this vulnerability, upgrade all affected Astro dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

astro fixed: 4.16.17
npm install astro@4.16.17
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls astro

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2024-56140, inspect your project dependencies using npm:

npm ls astro

Analyze the terminal output to locate any version of Astro in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.16.17), your application is affected.

Note: The npm ls astro command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-352: Cross-Site Request Forgery (CSRF), where the web application does not, or cannot, sufficiently verify whether a request was intentionally provided by the user who sent the request, which could have originated from an unauthorized actor. In Astro, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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: ```js // 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: ```js // 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](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests) and will not perform preflight validation. In this case, CSRF is not blocked as expected. ```js 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. ```js // 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.

CVE-2024-56140 Affected Astro Versions

1 component(s)
Fixed Versions:
4.16.17
Product / Package Ecosystem Affected Versions Fixed Version
astro
npm
< 4.16.17
4.16.17

References

Frequently Asked Questions

What is CVE-2024-56140?
CVE-2024-56140 is a security vulnerability in Astro involving Atro CSRF Middleware Bypass (security.checkOrigin) under CWE-352: Cross-Site Request Forgery (CSRF).
Which Astro versions are affected?
Affected versions include releases prior to 4.16.17 across affected packages: astro.
What version fixes CVE-2024-56140?
Upgrading to 4.16.17 (or the latest patched release for your respective branch) resolves the vulnerability.
Is astro affected?
Yes, astro is affected in releases prior to 4.16.17. Upgrade your dependency to 4.16.17 or later.
What is the CVSS score of CVE-2024-56140?
CVE-2024-56140 has a CVSS v3.1 base score of 5.9 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:N.
What CWE is associated with CVE-2024-56140?
CVE-2024-56140 is classified under CWE-352: Cross-Site Request Forgery (CSRF) (The web application does not, or cannot, sufficiently verify whether a request was intentionally provided by the user who sent the request, which could have originated from an unauthorized actor.).
How can I check npm dependencies for CVE-2024-56140?
Run the dependency tree command: 'npm ls astro'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-c4pw-33h3-35xw",
  "modified" : "2025-11-27T08:01:13Z",
  "published" : "2024-12-18T15:02:37Z",
  "aliases" : [ "CVE-2024-56140" ],
  "summary" : "Atro CSRF Middleware Bypass (security.checkOrigin)",
  "details" : "### Summary\n\nA bug in Astro’s CSRF-protection middleware allows requests to bypass CSRF checks.\n\n### Details\n\nWhen 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)\n\nFor example, with the following Astro configuration:\n\n```js\n// astro.config.mjs\nimport { defineConfig } from 'astro/config';\nimport node from '@astrojs/node';\n\nexport default defineConfig({\n\toutput: 'server',\n\tsecurity: { checkOrigin: true },\n\tadapter: node({ mode: 'standalone' }),\n});\n```\n\nA request like the following would be blocked if made from a different origin:\n\n```js\n// fetch API or <form action=\"https://test.example.com/\" method=\"POST\">\nfetch('https://test.example.com/', {\n\tmethod: 'POST',\n\tcredentials: 'include',\n\tbody: 'a=b',\n\theaders: { 'Content-Type': 'application/x-www-form-urlencoded' },\n});\n// => Cross-site POST form submissions are forbidden\n```\n\nHowever, a vulnerability exists that can bypass this security.\n\n#### Pattern 1: Requests with a semicolon after the `Content-Type`\n\nA semicolon-delimited parameter is allowed after the type in `Content-Type`.\n\nWeb browsers will treat a `Content-Type` such as `application/x-www-form-urlencoded; abc` as a [simple request](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests) and will not perform preflight validation. In this case, CSRF is not blocked as expected.\n\n```js\nfetch('https://test.example.com', {\n\tmethod: 'POST',\n\tcredentials: 'include',\n\tbody: 'test',\n\theaders: { 'Content-Type': 'application/x-www-form-urlencoded; abc' },\n});\n// => Server-side functions are executed (Response Code 200).\n```\n\n#### Pattern 2: Request without `Content-Type` header\n\nThe `Content-Type` header is not required for a request. The following examples are sent without a `Content-Type` header, resulting in CSRF.\n\n```js\n// Pattern 2.1 Request without body\nfetch('http://test.example.com', { method: 'POST', credentials: 'include' });\n\n// Pattern 2.2 Blob object without type\nfetch('https://test.example.com', {\n\tmethod: 'POST',\n\tcredentials: 'include',\n\tbody: new Blob(['a=b'], {}),\n});\n```\n\n### Impact\n\nBypass CSRF protection implemented with CSRF middleware.\n\n> [!Note]\n> 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.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "astro"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.16.17"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/withastro/astro/security/advisories/GHSA-c4pw-33h3-35xw"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-56140"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/withastro/astro/commit/e7d14c374b9d45e27089994a4eb72186d05514de"
  }, {
    "type" : "WEB",
    "url" : "https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/withastro/astro"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/withastro/astro/blob/6031962ab5f56457de986eb82bd24807e926ba1b/packages/astro/src/core/app/middlewares.ts"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-352" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-12-18T15:02:37Z",
    "nvd_published_at" : "2024-12-18T21:15:08Z"
  }
}