← Java / Spring · Contents

JAVA-058 / Intermediate

Disabling default Spring Security headers

A05:2021 Security Misconfiguration · CWE-693 Protection Mechanism Failure

Why is this a problem?

Clickjacking, MIME sniffing and downgrade protections disappear.

How to fix it

java
http.headers(h -> h
  .contentSecurityPolicy(c -> c.policyDirectives("default-src 'self'"))
  .frameOptions(f -> f.deny())
  .httpStrictTransportSecurity(hsts -> hsts.includeSubDomains(true).maxAgeInSeconds(31536000)));

Further reading