Spring Security CSRF Disable

NuJey·2025년 2월 12일
0

CSRF, 웹 보안 취약점 중 하나로, 공격자가 조작한 요청을 신뢰할 수 있는 사이트에 대해 보내도록 만드는 공격.

CSRF Disable

  • 세션과 쿠키를 통한 인증 방식은 CSRF 공격에 취약, 쿠키가 CSRF 공격의 매개체가 되고 사용자 정보를 쿠키에 저장 했기 때문에.
  • OAuth2, 토큰 방식은 기존 방식에 비해 CSRF 공격에 대한 설정을 비활성화해도 무방.

Security 6.1 이상

@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
    return http
            .csrf().disable()  //
            .authorizeExchange()
            .pathMatchers("/auth/**").permitAll()
            .anyExchange().authenticated()
            .and()
            .build();
}

.csrf().disable() // Deprecated

  1. CSRF 비활성화를 쉽게 남용할 가능성
    • 세션 기반 인증에선 필요함
  2. Spring Security의 설정 방식이 체인 형식으로 변경됨
    • .csrf(csrf -> csrf.disable())
    • .csrf(ServerHttpSecurity.CsrfSpec::disable) 같은 새로운 방식을 도입.
  • 람다 표현식 csrf -> csrf.disable() 대신 메서드 참조 사용
  • CsrfSpec 클래스의 disable() 메서드를 직접 참조하여 가독성 향상

0개의 댓글