Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF support #27

Closed
kethinov opened this issue Jun 21, 2014 · 0 comments · Fixed by #1351
Closed

CSRF support #27

kethinov opened this issue Jun 21, 2014 · 0 comments · Fixed by #1351
Assignees
Labels
enhancement Planned feature

Comments

@kethinov
Copy link
Member

kethinov commented Jun 21, 2014

Some general interesting info on the topic:

After due consideration, we've decided to adopt malibu at the framework level.

Will also need to add express-session as a dependency as well.

From malibu docs:

Import deps:

import session from 'express-session'
import { csrf } from 'malibu'

Load the middleware:

const csrfProtection = csrf({ middleware: 'session' })
app.use(session({ secret: 'secret key', resave: false, saveUninitialized: false }))

Note app will already be defined by roosevelt.

Then each route will need to receive the csrfProtection variable. We'll need to document examples in the Roosevelt docs. Here's some examples from malibu:

// this lets you acquire CSRF token on response body
app.get('/', csrfProtection, (req, res) => {
  res.status(200).json({ token: req.csrfToken() })
})

// you may only access this if you give a previously acquired CSRF token
app.post('/', csrfProtection, (req, res) => {
  res.status(200).json({ message: 'hello' })
})

I'm assuming that if a route omits csrfProtection then it simply won't populate req.csrfToken and that isn't necessary to modify every route declaration to include the middleware unless the user decides they want CSRF protection on that route. That assumption needs to be tested.

@kethinov kethinov added P4 Low Priority and removed P3 Medium Priority labels Dec 9, 2016
@kethinov kethinov removed the P4 Low Priority label Mar 2, 2017
@kethinov kethinov self-assigned this Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Planned feature
Development

Successfully merging a pull request may close this issue.

1 participant