implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'

@Configuration @EnableWebSecurity public class SecurityConfig { @Bean SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http .authorizeHttpRequests((authorizeHttpRequests) -> authorizeHttpRequests .requestMatchers(new AntPathRequestMatcher("/**")).permitAll())
http .authorizeHttpRequests((authorizeHttpRequests) -> authorizeHttpRequests .requestMatchers(new AntPathRequestMatcher("/**")).permitAll()) ;

.csrf((csrf) -> csrf .ignoringRequestMatchers(new AntPathRequestMatcher("/h2-console/**")))
해당 코드를 추가함으로써 설정 된 경로 /h2-console/ 로 시작되는 모든 URL은 CSRF 검증을 하지 않게된다.

H2 console의 화면이 프레임(Frame)구조로 되어있기에 발생하는 문제
스프링 시큐리티는 X-Frame-Options 헤더의 기본값을 DENY로 사용
스프링 부트에서 X-Frame-Options 헤더는 클릭재킹 공격을 막기 위해 사용
.headers((headers) -> headers
.addHeaderWriter(new XFrameOptionsHeaderWriter(
XFrameOptionsHeaderWriter.XFrameOptionsMode.SAMEORIGIN)))
