相关疑难解决方法(0)

如何使用 csurf 保护我的 react app api?

我正在尝试向我的 React 应用程序添加 csrf 保护,但我一直收到错误无效令牌

import bodyParser from 'body-parser';
import cookieSession from 'cookie-session';
import passport from 'passport';
import csrf from 'csurf'
import config from '../../config'
import AuthRoutes from "./routes/AuthRoutes";

/* Test only */
import cookieParser from 'cookie-parser';


const session = cookieSession({
    maxAge:24 * 60 * 60 * 1000,
    keys:[config.COOKIE_KEY],
    name:'authentication',

});



export default app => {

    app.use(bodyParser.urlencoded({
        extended: true
    }));
    app.use(bodyParser.json());
    app.use(session);
    app.use(passport.initialize());
    app.use(passport.session());

    /* Test */
    app.use(cookieParser());
    app.use(csrf({ cookie: true }));

    app.use(function (err, req, res, next) {
        if (err.code …
Run Code Online (Sandbox Code Playgroud)

csrf node.js express reactjs

9
推荐指数
1
解决办法
3431
查看次数

标签 统计

csrf ×1

express ×1

node.js ×1

reactjs ×1