csrf 속성

인철·2023년 10월 17일
0

Spring

목록 보기
36/48

csrf 속성

disable

  • 보호기능 비활성화
@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .csrf().disable()
        // 다른 설정
}

csrfTokenRepository

  • CSRF 토큰을 저장하고 검색하는데 사용되는 저장소
@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .csrf()
            .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
        // 다른 설정
}

ignoringAntMatchers

  • CSRF 보호를 비활성화할 요청 경로 정의
@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .csrf().ignoringAntMatchers("/path1", "/path2")
        // 다른 설정
}

requireCsrfProtectionMatcher

  • CSRF 보호를 활성화할 특정 요청 경로 정의
@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .csrf().requireCsrfProtectionMatcher(new AntPathRequestMatcher("/path"))
        // 다른 설정
}

accessDeniedHandler

  • CSRF 공격을 감지했을 때 호출되는 접근 거부 처리기 정의

csrfTokenRepository()and()를 사용하여 CSRF 토큰의 저장소와 관련된 설정을 추가

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .csrf()
            .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
        .and()
        // 다른 설정
}
profile
같은글이있어도양해부탁드려요(킁킁)

0개의 댓글