{"id":"CVE-2024-56140","aliases":["CVE-2024-56140","GHSA-c4pw-33h3-35xw"],"related":[],"kind":"vulnerability","state":"published","title":"Bypass of CSRF Middleware in Astro","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"### 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.","format":"markdown","source":"ghsa"},{"lang":"es","text":"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.","source":"nvd"}],"published":"2024-12-18T15:02:37.000Z","modified":"2026-06-17T08:11:45.220Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:N","score":5.9,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:N","score":5.9,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:N","score":5.9,"rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N","score":6.5,"rating":"MEDIUM"}],"cwes":["CWE-352"],"affected":[{"ranges":[{"version":"< 4.16.17","status":"affected"}],"vendor":"withastro","product":"astro","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"4.16.17"}],"ecosystem":"npm","package":"astro","purl":"pkg:npm/astro","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"4.16.17"}],"vendor":"astro","product":"astro","cpe":"cpe:2.3:a:astro:astro:*:*:*:*:*:node.js:*:*","source":"nvd"}],"references":[{"url":"https://github.com/withastro/astro/security/advisories/GHSA-c4pw-33h3-35xw","tags":["vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/withastro/astro/commit/e7d14c374b9d45e27089994a4eb72186d05514de","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests","tags":["technical-description","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/withastro/astro/blob/6031962ab5f56457de986eb82bd24807e926ba1b/packages/astro/src/core/app/middlewares.ts","tags":["product","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2024-56140","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/withastro/astro","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2024-12-18T21:03:26.338Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2024-56140","url":"https://www.cve.org/CVERecord?id=CVE-2024-56140","licence":"CVE Terms of Use","modified":"2024-12-18T21:03:36.201Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-c4pw-33h3-35xw","url":"https://github.com/advisories/GHSA-c4pw-33h3-35xw","licence":"CC-BY-4.0","modified":"2025-11-27T08:18:05.038Z"},{"source":"nvd","name":"NVD","id":"CVE-2024-56140","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-56140","licence":"Public domain","modified":"2026-06-17T08:11:45.220Z"}],"updatedAt":"2026-11-25T22:58:50.247Z","epss":{"score":0.00236,"percentile":0.15642,"date":"2026-12-01T12:00:22.000Z"}}