Spring/Spring Security
[Spring Security] 5-3. 보안: HTTP Requests
noahkim_
2023. 10. 14. 02:03
1. Redirect to HTTPS
- Spring Security에서 HTTP 요청을 자동으로 HTTPS로 리다이렉트시키는 설정
설정
더보기
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
// ...
.requiresChannel(channel -> channel
.anyRequest().requiresSecure()
);
return http.build();
}
2. Strict Transport Security
3. Proxy Server Configuration
- 프록시나 로드 밸런서를 사용하는 환경에서 클라이언트의 실제 요청 정보를 애플리케이션이 올바르게 인식하도록 설정하는 방법
- 프록시릍 통해 서버에 요청이 전달되는 경우, 요청 정보가 왜곡됨
X-Forwarded-* 헤더
RFC7239에 따라, 로드 밸런서가 X-Forwarded-* 헤더를 추가해야 함
예시
더보기
X-Forwarded-For: 203.0.113.195
X-Forwarded-Proto: https
X-Forwarded-Host: example.com
설정
더보기
server.forward-headers-strategy: native
- ForwardedHeaderFilter를 추가함
출처