![](/img/trans.png)
[英]HSTS header (strict-transport-security) is not getting always. (sometimes getting and sometimes not)
[英]Can't set the Strict-Transport-Security header in Spring Boot
我正在嘗試將 Strict Transport Security 標頭設置為我的 Spring Webflow 應用程序。
這是我為設置響應標頭而編寫的代碼
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers()
.httpStrictTransportSecurity()
.includeSubDomains(true).maxAgeInSeconds(31536000).and()
.cacheControl().disable()
.frameOptions().disable();
}
}
現在,我正在檢查 url 的響應標頭,盡管正在設置其他兩個標頭(緩存控制和幀選項),但我沒有在任何地方看到嚴格傳輸安全標頭。
謝謝
HstsConfig
中使用的默認RequestMatcher
是檢查請求是否為 HTTPS HttpServletRequest.isSecure()
。 如果由於某些原因它不適合您,您可以使用另一個匹配器。
下面的代碼確保在所有響應中都設置了Strict-Transport-Security
標頭:
http.headers()
.httpStrictTransportSecurity()
.requestMatcher(AnyRequestMatcher.INSTANCE)
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.