Skip to content

Commit

Permalink
Add req.csrfToken to every url rendered.
Browse files Browse the repository at this point in the history
  • Loading branch information
RailonA committed Sep 29, 2023
1 parent 1bfd937 commit eba3563
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/setExpressConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ async function csrfProtection (app) {
const csrfProtection = csrf({ middleware: 'session' })
app.use(csrfProtection)
app.use((req, res, next) => {
req.csrfToken()
app.get(req.url, csrfProtection, (req, res) => {
res.sendFile(req.url, { csrfToken: req.csrfToken() })
})

app.post(req.url, csrfProtection, (req, res) => {
res.sendFile(req.url)
})

next()
})
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eba3563

Please sign in to comment.