【发布时间】:2014-02-03 08:51:44
【问题描述】:
配置 Spring Security 3.2 后,_csrf.token 未绑定请求或会话对象。
这是 Spring Security 配置:
<http pattern="/login.jsp" security="none"/>
<http>
<intercept-url pattern="/**" access="ROLE_USER"/>
<form-login login-page="/login.jsp"
authentication-failure-url="/login.jsp?error=1"
default-target-url="/index.jsp"/>
<logout/>
<csrf />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="test" password="test" authorities="ROLE_USER/>
</user-service>
</authentication-provider>
</authentication-manager>
login.jsp 文件
<form name="f" action="${contextPath}/j_spring_security_check" method="post" >
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<button id="ingresarButton"
name="submit"
type="submit"
class="right"
style="margin-right: 10px;">Ingresar</button>
<span>
<label for="usuario">Usuario :</label>
<input type="text" name="j_username" id="u" class="" value=''/>
</span>
<span>
<label for="clave">Contraseña :</label>
<input type="password"
name="j_password"
id="p"
class=""
onfocus="vc_psfocus = 1;"
value="">
</span>
</form>
它会渲染下一个 html:
<input type="hidden" name="" value="" />
结果是 403 HTTP 状态:
Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.
更新 经过一些调试,请求对象从 DelegatingFilterProxy 中得到了很好的结果,但是在 CoyoteAdapter 的第 469 行它执行了 request.recycle();删除所有属性...
我在 Tomcat 6.0.36、7.0.50 和 JDK 1.7 中进行测试。
我不理解这种行为,而不是,如果有人指出我与 Spring Security 3.2 与 CSRF 一起使用的一些应用程序示例战争的方向,那将是可能的。
【问题讨论】:
-
你使用什么 Spring 版本?这同样适用于我(但在
spring-security.xml中存在差异)与 Spring 4.0.0 RELEASE (GA)、Spring Security 3.2.0 RELEASE (GA)(尽管它与 Struts 2.3.16 集成。我没有单独使用 Spring MVC 试试)。但是,当请求 multipart 用于上传状态为 403 的文件时,它会失败。我正在努力寻找解决方案。 -
Spring 3.2.6,Spring Security 3.2.0,CSRF,token被添加到http-request对象中,session对象和请求线程一样,但是出去的时候直到它渲染 jsp 删除所有属性,只留下一个属性 ...filter_applied
-
@Tiny:你有没有找到解决多部分问题的方法?我遇到了 exact 同样的问题。
标签: spring spring-security csrf csrf-protection