Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Oct 15, 2024
1 parent f9e6ea7 commit aa50e0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/middleware/csrf/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ describe('CSRF by Middleware', () => {
expect(res.status).toBe(403)
expect(simplePostHandler).not.toHaveBeenCalled()
})

it('should be 403 if the content-type is not set', async () => {
const res = await app.request('/form', {
method: 'POST',
body: new Blob(['test'], {}),
})
expect(res.status).toBe(403)
expect(simplePostHandler).not.toHaveBeenCalled()
})
})

describe('with origin option', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/csrf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const csrf = (options?: CSRFOptions): MiddlewareHandler => {
return async function csrf(c, next) {
if (
!isSafeMethodRe.test(c.req.method) &&
isRequestedByFormElementRe.test(c.req.header('content-type') || '') &&
isRequestedByFormElementRe.test(c.req.header('content-type') || 'text/plain') &&
!isAllowedOrigin(c.req.header('origin'), c)
) {
const res = new Response('Forbidden', {
Expand Down

0 comments on commit aa50e0a

Please sign in to comment.