Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

의미없는 블로그

[Spring] HSTS 설정 본문

# 나/source Code

[Spring] HSTS 설정

SaltLee 2024. 3. 15. 13:42

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
Comments