-
spring security 403 Forbidden Errorspring boot 2023. 1. 12. 21:28
스프링 시큐리티를 이용하여 Restful Api 를 만들던 중에 GetMapping은 잘 실행되는데 PostMapping은 계속 403 Forbidden 이라는 error가 났다. 그 이유는 스프링 시큐리티가 csrf 공격으로 부터 defualt 값으로 보호되도록 설정되어 있기 때문이다.
CSRF는 인증된 사용자가 웹 애플리케이션에 요청을 보내도록 유도하는 공격 행위를 말하는데 스프링 시큐리티에서는 csrf 공격에 대비해 defualt 값으로 csrf(protection)이 가능하게 되어있다. 따라서 csrf.disable()을 해주면 PostMapping()이 가능해진다.
@Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception{ http.authorizeRequests().anyRequest().permitAll() .and().csrf().disable(); } }
'spring boot' 카테고리의 다른 글
[Spring boot] Logback에 대해서 알아보자. (0) 2024.02.12 [spring boot] 에러 핸들링 @ExceptionHandler @ControllerAdvice (0) 2024.01.25 [Spring Boot] ResponseEntity란? (0) 2024.01.24 [Spring] 다양한 매핑 방법 (1) 2024.01.22 JPA 연관관계 매핑 (0) 2023.01.12