[스프링 시큐리티] HttpSecurity vs WebSecurity

2023. 2. 5. 12:53·Spring
반응형

스프링 시큐리티 로고

HttpSecurity vs WebSecurity

SpringBuilder는 웹 보안을 구성하는 빌더 클래스로서 웹 보안을 구성하는 빈 객체와 설정 클래스들을 생성하는 역할을 한다.
이 빌더의 종류로는 HttpSecurity와 WebSecurity가 있다. 오늘은 이 둘에 대해서 알아보려고 한다.

@Configuration
@EnableWebSecurity
public class CustomWebSecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring()
        .antMatchers("/health", "/health/**")
        .antMatchers("/publics/**");
    }
    @Override
    public void configure(HttpSecurity http) throws Exception {
         http.csrf().disable()
            .authorizeRequests()
            .antMatchers("/health", "/health/**").hasRole('USER') // 무시된다.
            .anyRequest().authenticated();
}

WebSecurity는 HttpSecurity의 상위에 있다. WebSecurity의 `ignoring`에 endpoint를 만들면, Security Filter Chain이 적용되지 않는다.
이 경우 Cross-Site Scripting, XSS 공격, content-sniffing에 취약해진다. 

 

HttpSecurity의 `permitAll`에 endpoint를 지정하면 인증처리의 결과를 무시하지만 Security Filter Chain이 적용되어 Cross-Site Scripting, XSS 공격, content-sniffing에 대한 검사를 할 수 있다.

 

위의 예제의 경우 WebSecurity에 `ignoring`에 설정된 `/publics/**` 엔드포인트에 대하여 HttpSecurity 부분은 동작하지 않는다.

 

실무에서 HttpSecurity의 `permitAll`이 설정된 endpoint에 잘못된 BearerToken 값이 들어오면 Security Filter Chain를 거치면서 에러를 반환하지만, WebSecurity는 `ignoring`이 설정된 잘못된 BearerToken 값이 들어와도 통과된다.

그래서 WebSecurity는 보안과 전혀 상관없는 로그인 페이지, 공개 페이지(어플리캐이션 소개 페이지 등), 어플리캐이션의 health 체크를 하기위한 API에 사용하고, 그 이외에는 HttpSecurity를 사용하는 것이 좋다.


References

SpringBoot : Security Configuration using HTTPSecurity vs WebSecurity - https://ravthiru.medium.com/springboot-security-configuration-using-httpsecurity-vs-websecurity-1a7ec6a23273

반응형
저작자표시 동일조건 (새창열림)
'Spring' 카테고리의 다른 글
  • [Spring AI] 준비 (기본 개념, OpenAI API Key, 크레딧 충전)
  • [스프링 시큐리티] WebSecurityConfigurerAdapter deprecated 대응
  • [스프링 시큐리티] AuthenticationManager, AuthenticationProvider
  • [스프링 시큐리티] 필터(DelegatingFilterProxy, FilterChainProxy)
SooJae
SooJae
코드는 효율적으로, 공부는 비효율적으로
    반응형
  • SooJae
    이수재 블로그
    SooJae
  • 전체
    오늘
    어제
    • 분류 전체보기 (60)
      • Spring (8)
      • Next.JS (4)
      • React (3)
      • Angular (1)
      • Language (6)
        • Java (1)
        • Kotlin (1)
        • Javascript (4)
      • Keycloak (5)
      • Knowledge (16)
        • Test (4)
        • Web (9)
        • Security (2)
        • Data Structure (1)
      • Infra (9)
        • Proxmox (2)
        • AWS (0)
        • Kubernetes (3)
      • Tools (1)
        • IntelliJ (1)
      • Algorithm (2)
      • Tistory (4)
      • ETC (1)
  • 블로그 메뉴

    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    spring ai
    test
    keycloak
    Functional Programming
    deepl api
    Next.js
    ai
    Kotlin
    오블완
    Auth
    티스토리챌린지
    GPT
    javascript
    스프링 ai
    React
    springboot
    웹 마스터 도구
    스프링 번역
    ChatGPT
    openAI
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
SooJae
[스프링 시큐리티] HttpSecurity vs WebSecurity
상단으로

티스토리툴바