koajs / csrf

CSRF tokens for koa
MIT License
264 stars 32 forks source link

Enable csrf per route example #47

Closed linxea closed 5 years ago

linxea commented 6 years ago

Currently i am mounting csrf middleware per route like the example below,

routes.js

const csrf = new CSRF({
  invalidSessionSecretMessage: 'Invalid session secret',
  invalidTokenMessage: 'Invalid CSRF token',
  invalidTokenStatusCode: 403,
});

const router = new Router();
route.get('/', csrf, Controller.getPage);

Is this the correct way of doing it or is there a better way? I can't find any example to validate it as the README.md only shows example of applying csrf to all routes.

linxea commented 5 years ago

i think so. :<