Skip to content
Myr

fix(csrf): exempt OPTIONS request from CSRF validation (#5250)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(csrf): exempt OPTIONS request from CSRF validation * test(csrf): add regression test for CORS middleware ordering * test(csrf): refactor test names to be more accurate * test(csrf): remove integration test

authored by John Emerson Requizo · committed by GitHub · parent a194628 · Browse files · 2 files+11 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−1 removed

  • tests:+10 added−0 removed
  • other:+1 added−1 removed

2 files+11 added−1 removed

modified:src/middleware/csrf/index.test.ts+10 added
31 unmodified lines
32 const app = new Hono()3334 app.use('*', csrf())35 app.get('/form', (c) => c.html('<form></form>'))36 app.options('/form', (c) => c.text('OK'))37 app.post('/form', simplePostHandler)38 app.put('/form', (c) => c.text('OK'))39 app.delete('/form', (c) => c.text('OK'))40 app.patch('/form', (c) => c.text('OK'))
14 unmodified lines
55 expect(res.status).toBe(200)56 })57 })5859 describe('OPTIONS /form', async () => {60 it('should be 200 for any request', async () => {61 const res = await app.request('http://localhost/form', { method: 'OPTIONS' })6263 expect(res.status).toBe(200)64 expect(await res.text()).toBe('OK')65 })66 })6768 describe('POST /form', async () => {69 it('should be 200 for local request', async () => {70 /*71 * <form action="/form" method="POST"><input name="name" value="hono" /></form>
463 unmodified lines
modified:src/middleware/csrf/index.ts+1 added-1 removed