简体   繁体   English

如何在Spring Security中发送一些没有csrf令牌的jsp表单

[英]How can I send some jsp forms without csrf token in spring security

I am using <csrf/> tag in my spring security xml file for a web project. 我在Web项目的Spring Security xml文件中使用<csrf/>标记。 By this tag I have to send csrf token in each form used in the jsp page. 通过这个标签,我必须以jsp页面中使用的每种形式发送csrf令牌。

Spring security xml code: Spring Security xml代码:

    <http auto-config="false" use-expressions="true" disable-url-rewriting="true">

    <intercept-url pattern="/**" access="isAuthenticated()" />

    <form-login
    <!--login tags -->
    </>

    <csrf/>
    </http>

But there is a scenario where I don't want to send the csrf token for a particular form in a jsp page, How could I do that. 但是在某些情况下,我不想在jsp页面中发送特定表单的csrf令牌,我该怎么做。

I used the following tag in my xml file 我在xml文件中使用了以下标记

<http pattern="/specific_url/**">
  <csrf disabled="true"/>
</http>

and got error: " cvc-complex-type.3.2.2: Attribute 'disabled' is not allowed to appear in element 'csrf' " 并得到错误:“ cvc-complex-type.3.2.2:不允许在元素'csrf'中出现'disabled'属性

For Spring Security version 3.2.x, the CSRF protection is disabled by default when using XML configuration. 对于Spring Security版本3.2.x,使用XML配置时默认情况下禁用CSRF保护。 So just remove the csrf element from the config, and it will be off. 因此,只需从配置中删除csrf元素,它就会关闭。

From version 4, CSRF protection is enabled by default, so if you upgrade you will need the snippet suggested in question. 从版本4开始,CSRF保护默认情况下处于启用状态 ,因此,如果升级,则需要有问题的建议代码段。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM