Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
How to properly configure csurf with cookie-session in express?

I'm trying to setup csrf protection using cookie-session as the csurf docs mention it explicitly, but loading my /form page returns a 500 and 'misconfigured csrf' is logged to the console.

import csrf from 'csurf'
import express from 'express'
import cookieSession from 'cookie-session'

const app = express()
const CookieSettings = {
  name: 'session',
  keys: ['keyone', 'keytwo'],
  httpOnly: true
}
//template engine stuff
app.use(cookieSession(CookieSettings))
app.use(csrf({ cookie: true }))
app.use(express.urlencoded({ extended: true }))

app.get('/form', (req, res) => {
  res.render('form.html', { csrf: req.csrfToken() })
}
app.post('/form', (req, res) => {
  console.log('CSRF: ', req.body._csrf)
  res.redirect(303, '/form')
}

app.listen(3000)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!