- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Spring 框架版本 4.3.5.RELEASE。Spring 安全版本是 4.2.2.RELEASE。
我遇到了一个与 CSRF 相关的奇怪问题。每当我提交表单(来自 JSP 文件)时,有时它工作正常,提交表单时没有错误,但有时在提交表单后,它显示 Http Status 405 ?不支持的方法。我也在隐藏字段中包含了 csrf token ,并将其作为查询字符串附加在表单的操作标签中。
这是我项目中的一个示例 POST 表单:
<form:form class="form-horizontal" method="POST" modelAttribute="dealerVisit" enctype="multipart/form-data"
action="http://localhost:8080/update/edit.html?${_csrf.parameterName}=${_csrf.token}">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}">
</form:form>
这是我提交上述表格的 Controller :
@RequestMapping(value = "/update/edit.html", method = RequestMethod.POST)
public String saveEdit(ModelMap map, @Valid @ModelAttribute(MODEL_KEY) DealerVisitVO dealerVisitVO, BindingResult result,
@RequestParam(required = false, name="followup") Boolean followup) {
//my codes here
}
问题是随机出现的。它有时有效,有时无效。代码或形式没有变化。禁用 CSRF 不是可行的解决方案,因为这是我客户的一项要求。
如果有人能够解决,请帮忙。
最佳答案
在 spring security 中,CSRF token 在每个 session 基础上生成并保持不变,直到您的 session 未过期。这是您收到 405 方法不允许的一种情况,因为您的 session 将在某个时间间隔到期(您可以检查一下)。其次,如果您使用的是 spring 的表单,则无需显式将 token 放入隐藏字段中,spring 默认会这样做,也无需将其放入查询字符串中。你的代码应该是这样的......
<form:form class="form-horizontal" method="POST" modelAttribute="dealerVisit" enctype="multipart/form-data" action="http://localhost:8080/update/edit.html">
<!-- Spring will add by default -->
<!-- <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"> -->
关于java - 尽管以表单形式发送 CSRF token ,但不支持 Spring Security CSRF 405 方法 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46231871/
假设我的 Web 应用程序使用 CSRF token 防止 CSRF 攻击,此外,它使用 SSL 并防止 XSS 攻击。此外,出于这个问题的目的,假设它仅在最近的浏览器中使用并且它们没有错误。我可以使
很多人都在谈论实现 CSRF 来阻止对网页的跨站点攻击。但我认为破坏 CSRF 并向服务器发出请求非常容易。 那么它是如何工作的呢? 您从一个页面开始,呈现一个表单并使用 CSRF token 保留一
在阅读了许多有关 CSRF 的文档后,我仍然有点困惑。所以我希望有人可以向我解释一下: 假设我有一个仅供经过身份验证的用户使用的个人资料页面,比如说 abc.com/profile,它会显示我所有的私
我们基于 Angular 的 web 应用程序与在不同域和上下文路径上运行的企业门户集成。我正在使用基于 Spring Security 的 CSRF token 来验证传入的请求。该应用程序在本地完
我正在开发一个 Web API。身份验证是通过 cookie 进行的。所有端点通过JSON接收参数在请求正文中。 我需要实现 CSRF token保护他们?这怎么可能被利用呢?是否可以通过正常发送JS
我正在开发一个从 cookie header 解析 CSRF token 的应用程序。我想知道 CSRF token 是否使用 URL 安全字符进行 base64 编码(参见 https://simp
我知道当提交时表单中未包含 csrf token 时会发生此错误,但这次并非如此。 我正在尝试登录管理站点。管理员登录表单包含 csrf token ,我可以看到该 csrf token 的值与 cs
有没有办法对 Controller 的某些操作禁用 CSRF 验证,同时对其他操作保持启用状态? 就我而言,我有几个可配置的 Action 类,它们旨在注入(inject)到 Controller 中
我正在编写一个应用程序(Django,确实如此),我只想了解“CSRF token ”实际上是什么以及它如何保护数据。 如果不使用CSRF token ,发布数据不安全吗? 最佳答案 简单来说跨站请求
来自维基百科关于同源政策 https://en.wikipedia.org/wiki/Same-origin_policy The same-origin policy helps protect s
我在 Vue 环境中使用 axios 与用 Symfony 编写的网络服务对话。每个请求都需要设置一个 X-Auth-Token header 。该值存储在 auth_token cookie 中。
我想保护我的 REST 调用免受 XSRF 攻击。我正在做的是: 服务器在用户成功登录后向浏览器发送一个记录的 cookie。 在每个请求(GET、POST、DELETE)上,我将登录的 cookie
我知道这个问题以前有人问过。我已经尝试了人们给出的几乎所有选项,但我似乎无法解决它。我是一个完整的新手,所以请让我知道我哪里出错了。 我正在尝试编写一个简单的原始表单。到目前为止,我还没有实现任何身份
似乎 Laravel 5 默认将 CSRF 过滤器应用于所有非获取请求。这对于表单 POST 是可以的,但对于 POST DELETE 等的 API 可能是一个问题。 简单的问题: 如何设置没有 CS
当我从客户端向服务器发出 DELETE 请求时,我遇到了错误。 “CSRF token 已关联到此客户端”。响应代码:403 和响应头 { "cache-control": "no-cache,
to prevent CSRF attacks, a random CSRF secret has been generated. 以上内容来自 symfony: http://www.symfony
我正在使用 Django Rest Framework还有 django-rest-auth . 我有标准的 API 端点(/login、/logout、/registration...) 使用我的浏
这个问题在这里已经有了答案: OAuth2.0 Server stack how to use state to prevent CSRF? for draft2.0 v20 (3 个回答) 4年前关
我需要知道如何在 Impresspages cms 中禁用 CSRF 功能。我在之前的帖子中看到了一个可能的答案,但没有完全分类。当我的客户在 cleanwaterpartnership.co.uk
我正在使用 Django 1.7 和 django-rest-framework。 我制作了一个 API,它返回一些 JSON 数据并将其放入我的 settings.py REST_FRAMEWORK
我是一名优秀的程序员,十分优秀!