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

2023. 2. 5. 12:53·Spring
목차
  1. HttpSecurity vs WebSecurity
  2. References
반응형

스프링 시큐리티 로고

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

반응형
저작자표시 동일조건 (새창열림)
  1. HttpSecurity vs WebSecurity
  2. References
'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)
  • 블로그 메뉴

    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

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

  • 최근 글

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

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.