【问题标题】:Using enctype="multipart/form-data" ends with csrf error使用 enctype="multipart/form-data" 以 csrf 错误结束
【发布时间】:2019-05-15 00:14:55
【问题描述】:

我正在使用 multer 和 csurf 包。
问题是当我在表单中添加 enctype="multipart/form-data" 时,我得到了无效的 csrd 令牌。

app.js

// CSRF BEFORE ROUTES!!!
app.use(bodyParser.urlencoded({
  extended: false
}))
app.use(cookieParser())
app.use(csrf());
app.use(function (req, res, next) {
  res.locals.csrfToken = req.csrfToken();
  next();
});

// Routes
app.use("/", webRoutes);
app.use("/cms", cmsRoutes);

以及我的 cmsRoutes 中的部分用户路由

router.post("/edit", isAuthenticated, upload.single('avatar'), profile.user_edit_profile);

我发现其他人也有同样的问题。但是找不到任何解决方案。

【问题讨论】:

    标签: node.js forms csrf multer


    【解决方案1】:

    解决了。只需将 MULTER 放在 CSRF 之前。

    【讨论】:

      猜你喜欢
      • 2016-11-11
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-12-17
      • 2016-04-02
      • 1970-01-01
      • 2022-06-25
      • 2018-04-07
      相关资源
      最近更新 更多