Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

throw error when the user repeatedly call csurf in same middleware #230

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ function csurf (options) {
var ignoreMethod = getIgnoredMethods(ignoreMethods)

return function csrf (req, res, next) {
if (req.isInitialized) {
console.warn('[Warning] csurf() is duplicately called with same middleware in the cooke mode, first validation will result in the invalid token.')
}

if (!req.isInitialized && cookie) {
req.isInitialized = true
}

// validate the configuration against request
if (!verifyConfiguration(req, sessionKey, cookie)) {
return next(new Error('misconfigured csrf'))
Expand Down