【问题标题】:CORS and CSRF to handle checkMarx XSRF attack issue ( spring boot microservice )CORS 和 CSRF 处理 checkMarx XSRF 攻击问题(spring boot 微服务)
【发布时间】:2021-10-10 16:32:45
【问题描述】:

我正在处理一个有待处理 checkmarx 问题(最近从 veracode 迁移)的项目,并且这个安全问题存在问题:

@Configuration
@EnableWebSecurity
public class Security extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {

        httpSecurity.cors().and().csrf().disable();       
    }
}

Checkmarx 不喜欢它并给我看这个:

SecurityConfiguration.java 从用户请求中获取参数 禁用。这个参数值流经代码,是 最终用于访问应用程序状态更改功能。 这可能会启用跨站点请求伪造 (XSRF)

另外补充一点,这个springboot中发出的请求是用idtoken处理的,根据我发现的快速阅读,应该很好地定义了这个类。 (希望如此)

如果有人有线索解决 checkmarx 不喜欢的问题,那将非常有帮助,美好的一天!

【问题讨论】:

    标签: spring-boot spring-security csrf checkmarx


    【解决方案1】:

    checkmarx 扫描不喜欢对所有 URL 完全禁用 csrf 的部分。如果您有任何特定的 url 想要启用 csrf,您可以添加以下代码。

        @Configuration
        @EnableWebSecurity
        public class Security extends WebSecurityConfigurerAdapter {
        
        
    
        @Override
            protected void configure(HttpSecurity httpSecurity) throws Exception {
                equestMatcher csrfRequestMatcher = new RequestMatcher() {
        
              // Disable CSFR protection on the following urls:
              private AntPathRequestMatcher[] requestMatchers = {
                  new AntPathRequestMatcher("/login"),
                  new AntPathRequestMatcher("/logout"),
                  new AntPathRequestMatcher("/verify/**")
              };
    
      
    
        @Override
          public boolean matches(HttpServletRequest request) {
            // If the request match one url the CSFR protection will be disabled
            for (AntPathRequestMatcher rm : requestMatchers) {
              if (rm.matches(request)) { return false; }
            }
            return true;
          } // method matches
    
        };
         
    
           httpSecurity.csrf()
                .requireCsrfProtectionMatcher(csrfRequestMatcher)
                .and()
        // other validations.      
            }
        }
    

    请尝试以下链接以获得详细答案。 Spring Security 3.2 CSRF disable for specific URLs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-22
      • 2013-04-29
      • 2019-07-31
      • 1970-01-01
      • 2018-03-05
      • 2018-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多