Gav*_*nry 3 csrf axios x-xsrf-token
X-XSRF-TOKEN如果我设置了XSRF-TOKENcookie 服务器端,我是否必须设置任何东西来发送标头?
https://github.com/axios/axios/blob/master/lib/defaults.js#L74 https://github.com/axios/axios/blob/master/dist/axios.js#L1072
它读起来好像我没有,但我没有看到有人出去。
我要补充一点,我已设置withCredentials为 true,因此我确实遇到了 OR 中的第一次检查:
var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
cookies.read(config.xsrfCookieName) :
undefined;
if (xsrfValue) {
requestHeaders[config.xsrfHeaderName] = xsrfValue;
}
Run Code Online (Sandbox Code Playgroud)
所以如果config.xsrfCookieName是默认.....
更新:
所以,我的OPTIONS预检CORS工作和POST现在一样,但没有X-XSRF-TOKEN被发送。
methods: {
onSubmit(e) {
this.axios
.post(
e.target.action,
{ data: this.form },
{
withCredentials: true,
xsrfCookieName: "XSRF-TOKEN",
xsrfHeaderName: "X-XSRF-TOKEN"
}
)
.then(res => {
console.log(res)
})
.catch(err => {
this.errors.push(err)
})
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢。
小智 5
我有同样的问题,是关于 cookie 上的“安全”标志,可以在请求的 cookie 选项卡上看到,但没有显示在“应用程序”选项卡下的 cookie 上:
就我而言,我不得不要求后端将其设置下来。发生这种情况是因为,为了安全,您无法通过 javascript 访问它。
document.cookie // is empty
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13541 次 |
| 最近记录: |