我正在尝试将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的响应头,尽管其他两个头(cache-control和frame-options)正在设置,但我在任何地方都没有看到Strict Transport Security头。
谢谢你
1条答案
按热度按时间cngwdvgl1#
HstsConfig
中使用的默认RequestMatcher
检查请求是否为HTTPSHttpServletRequest.isSecure()
。如果由于某些原因它对你来说还不够,你可以使用另一个匹配器。下面的代码确保在所有响应中设置
Strict-Transport-Security
头: