Express/Node js-api SameSite=None和Secure for cookies,尝试访问api



我使用express/node创建了以下api,但当我尝试从浏览器访问它时"如果应在跨站点请求中发送cookie,请指定SameSite=None和Secure。这允许第三方使用"该警告显示在控制台中,并且没有检索到任何数据,api如下

let express = require("express");
let app = express();
let bodyparser = require("body-parser")
let jwt = require("jsonwebtoken");
const student = require('./student')

app.use(bodyparser.json)
//used to authenticate the user and create the token
app.get("/auth",(req,res)=>{
console.log("sdsdsds")
var token = jwt.sign({email: user.email}, 'hubDemo', {expiresIn: '1h'});
res.send({token})
})
//fetches the student data and returns 
app.get("/student",(req,res)=>{
console.log("tst");
return res.status(200).json({
ok: true,
data: student
});
});

app.listen(3000,()=>{console.log("listening")})

我应该改变什么才能让它工作?

因此,在您给定的场景中,没有cookie被签名,我们使用您的express api。但是,对于您的代币,我强烈建议您查看http-only cookies,而不是localStorage。这可以防止对令牌进行任何客户端调整,而localStorage更容易受到攻击。但根据您的原始url,在创建cookie时仅指示SameSite属性就可以解决警告。

最新更新