Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed Aug 22, 2024
1 parent b0af71f commit 41ce840
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/middleware/csrf/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ describe('CSRF by Middleware', () => {
expect(res.status).toBe(200)
expect(await res.text()).toBe('hono')
})

it('should be 403 for "Application/x-www-form-urlencoded" cross origin', async () => {
const res = await app.request('http://localhost/form', {
method: 'POST',
headers: Object.assign({
'content-type': 'Application/x-www-form-urlencoded',
}),
body: 'name=hono',
})
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 @@ -14,7 +14,7 @@ interface CSRFOptions {

const isSafeMethodRe = /^(GET|HEAD)$/
const isRequestedByFormElementRe =
/^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/plain)\b/
/^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/plain)\b/i

/**
* CSRF Protection Middleware for Hono.
Expand Down

0 comments on commit 41ce840

Please sign in to comment.