package com.baeldung.xss; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration public class SecurityConf extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) { // Ignoring here is only for this example. Normally people would apply their own authentication/authorization policies web.ignoring().antMatchers("/**"); } @Override protected void configure(HttpSecurity http) throws Exception { http .headers() .xssProtection() .and() .contentSecurityPolicy("script-src 'self'"); } }