0

I am trying to set Strict Transport Security header to my Spring Webflow App.

This is the code that I have written to set the response header

@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();       
    }
}

Now, I am checking the response headers for the urls and although the other two headers (cache-control and frame-options) are being set, but I am not seeing Strict Transport Security header anywhere.

enter image description here

Thank you

Rahul Vala
  • 695
  • 8
  • 17

1 Answers1

0

The default RequestMatcher used in HstsConfig is checking if a request is HTTPS HttpServletRequest.isSecure(). If it's not working for you due to some reasons, you can use another matcher.

The code below ensures that the Strict-Transport-Security header is set in all responses:

    http.headers()
          .httpStrictTransportSecurity()
          .requestMatcher(AnyRequestMatcher.INSTANCE)
          ...
Alexander Pranko
  • 1,859
  • 17
  • 20