의미없는 블로그
[Spring] HSTS 설정 본문
HSTS 설정하면
HTTP > HTTPS 강제 리다이렉트 된다
설정방법은
Spring Security 컨피그 파일에서 하는 경우
import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .headers() .httpStrictTransportSecurity() .includeSubDomains(true) // 모든 하위 도메인에 대해 HSTS 활성화 .maxAgeInSeconds(31536000); // HSTS를 적용할 시간 설정 (예: 1년) } } |
application.properties 에서 설정하는 경우
# HSTS 활성화 server.ssl.hsts.enabled=true # HSTS를 적용할 시간 설정 (예: 1년) server.ssl.hsts.max-age=31536000 # 모든 하위 도메인에 대해 HSTS 활성화 (선택적) server.ssl.hsts.includeSubDomains=true |
application.yml 에서 설정하는 경우
server: ssl: hsts: enabled: true max-age: 31536000 include-subdomains: true |
'# 나 > source Code' 카테고리의 다른 글
[Spring] @Aspect 도 봐야됨 (0) | 2024.03.19 |
---|---|
[Spring] HttpOnly / Secure Cookie (0) | 2024.03.15 |
[Spring] Json XSS 필터 (escapeHTML4) (0) | 2024.03.11 |
[Spring] 스프링 설정파일 (개발/운영 Profile 분리) (0) | 2024.03.07 |
[Spring] 인터셉터로 JWT (0) | 2024.03.05 |
Comments