首页 > 解决方案 > 未找到基本域的严格传输安全标头

问题描述

我有一个 Spring Boot 应用程序,我想在我的域上启用 HSTS(比如 https:example.com)。我在 WebSecurityConfigurerAdapter 中编写了脚本。代码片段如下所示。

@EnableWebSecurity
    @Configuration
    @Order(1)
    public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            // @formatter:off           
            http
                .authorizeRequests()
                .antMatchers(HttpMethod.TRACE, "/**").denyAll()
                .antMatchers("/**").permitAll();
            http
                .antMatcher("/**").httpBasic()
                .and().csrf().disable()
                .headers().httpStrictTransportSecurity()
                .includeSubDomains(true)
                .maxAgeInSeconds(31536000);
            // @formatter:on
        }
    }

Spring Boot 应用程序的部署发生在 Azure 云中。部署后,当我点击基域时,我没有看到 HSTS 标头。但是我可以在点击整个 URL 时看到标题(比如https://example.com/questions/ask)。任何帮助,将不胜感激。谢谢!

标签: javaazurespring-boothsts

解决方案


推荐阅读