1. '왜 최초 로그인 화면에서 CSRF 토큰이 발급되지 않았을까?'
2. 공식 문서에 따르면 CSRF 토큰을 lazy하게 발급하는게 디폴트라고 한다.
(https://docs.spring.io/spring-security/reference/servlet/exploits/csrf.html#deferred-csrf-token)
3. '아 그러면 모든 요청에 대해 CSRF 토큰을 발급하도록 설정하면 되겠구나!'
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
XorCsrfTokenRequestAttributeHandler requestHandler = new XorCsrfTokenRequestAttributeHandler();
// set the name of the attribute the CsrfToken will be populated on
requestHandler.setCsrfRequestAttributeName(null);
http
// ...
.csrf((csrf) -> csrf
.csrfTokenRequestHandler(requestHandler)
);
return http.build();
}
}
팀장님이 서버 끄신거 아니었어요...? (1) | 2024.08.28 |
---|---|
예외처리 프로세스 | ControllerAdvice, AOP (0) | 2024.03.05 |
Aspose Words 라이센스 등록 (0) | 2024.03.04 |
[Meta ESG] SmartEditor2 에디터 내 이미지 추가 구현 | SpringBoot, Azure blob storage (0) | 2024.01.18 |
[Meta ESG] 현재 작성한 글자수 보여주기 기능 구현 (0) | 2024.01.16 |