简体   繁体   English

我怎样才能使 spring 安全接受通过 json 发送的 csrf 令牌。它目前通过 multipart/form-data 但不是 application/json 工作

[英]How can I make spring security accept csrf tokens that are sent via json. It's currently working via multipart/form-data but not application/json

I believe the issue lies in the spring security module not being setup by default to parse json input.我认为问题在于 spring 安全模块未默认设置为解析 json 输入。 Issue is i have no clue where to look as i've been duckduckgo-ing this problem on and off for the last couple weeks to no avail.问题是我不知道去哪里看,因为在过去的几周里,我一直在断断续续地解决这个问题,但无济于事。 This is specifically for the logout button.这是专门用于注销按钮的。 It requires a form submission to logout and the form submission requires the csrf token.它需要提交表单才能注销,并且提交表单需要 csrf 令牌。 The form will submit and logout successfully if the enctype is multipart/formdata but fails on any other type.如果 enctype 是 multipart/formdata 但在任何其他类型上失败,则表单将成功提交和注销。 The request is being sent via fetch.正在通过获取发送请求。 The return status code is 403 forbidden as it would be if there was a csrf issue.返回状态代码是 403 forbidden,因为如果存在 csrf 问题,就会出现这种情况。

Any help would be much appreciated.任何帮助将非常感激。 Thanks Joseph谢谢约瑟夫

I have tried to use https://ckinan.com/blog/spring-security-credentials-from-json-request/ but it wasn't what I needed.我尝试使用https://ckinan.com/blog/spring-security-credentials-from-json-request/但这不是我需要的。 It let me change the credentials into json but I don't believe it's what i need unless i'm thinking of this wrong and there is a way I can use it.它让我将凭据更改为 json 但我不相信这是我需要的,除非我认为这是错误的并且有一种方法可以使用它。

The answer was to add the csrf token to the header instead of the body with the name X-CSRF-TOKEN答案是将 csrf 令牌添加到 header 而不是名称为 X-CSRF-TOKEN 的正文

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 JSON 转换为 multipart/form-data - how to convert JSON into multipart/form-data 如何通过sails.js中的表单获取数组/对象(使用enctype multipart / form-data) - How to get arrays/objects sent via form in sails.js (with enctype multipart/form-data) 如何提取通过 multipart/form-data 发送的文件的 Content-Type - How to extract the Content-Type of a file sent via multipart/form-data Javascript将图像作为URI数据,如何通过multipart / form-data表单上传此图像? - Javascript has an image as URI data, how do I upload this image via a multipart/form-data form? 使用 axios 在 POST 多部分/表单数据请求中发送文件和 json - sending file and json in POST multipart/form-data request with axios 管理通过ajax发送到php的表单数据和其他变量 - Manage form-data + other variable sent via ajax to php Django(REST 框架)到 JSON。 如何在 JavaScript 中通过我的 API 获取数据? - Django (REST Framework) to JSON. How to fetch the Data via my API in JavaScript? 使用JQuery AJAX发送包含文件和其他json表单数据的multipart / form-data - Send multipart/form-data including a file and additional json form-data with JQuery AJAX 如何使用 vue 在一个请求中发送 json 参数和 multipart/form-data 文件 - How to send json parameter and multipart/form-data file in one request with vue php 不解析来自 ajax 发送的 multipart/form-data 表单数据的数据 - php doesn't parse data from multipart/form-data form's data sent by ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM