我越來越Error: misconfigured csrf
當我試圖訪問我的登錄頁面。我執行csurf到路由器,但我只是得到響應的StatusCode 500錯誤:錯誤地配置了CSRF - Express.js
實現:
let router = require("express").Router();
let PostLoginResource = require("./../resources/PostLoginResource");
let RateLimit = require("express-rate-limit");
let csrf = require("csurf");
let csrfProtection = csrf({ cookie: true });
router.route("/login")
.get(csrfProtection, function(req, res) {
// Do some stuff
})
.post(loginLimiter, function(req, res) {
PostLoginResource(req, function(success, err) {
// Do some stuff
})
});
我開始我使用這個模塊之前會話cookie的app.js:
// Parse the request body as JSON
app.use(bodyParser.json());
// Parse the URL encoded data
app.use(bodyParser.urlencoded({extended: true}));
// Set up session-cookie
app.use(session({
secret: "secret",
resave: false,
saveUninitialized: true,
cookie: {secure: true,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24
}
}));
不過,這是行不通的。任何人都知道是什麼問題?
是真實的是,路徑正確:./../resources/PostLoginResource? – Remario
是的,否則那將是錯誤的消息,而不是錯誤:錯誤地配置了CSRF – Jesper
但你也有一個500,這意味着內部錯誤。不正確的語句導致it.Where是否要求會話對象> – Remario