How to add Content-Security-Policy header in rest api-response spring-boot?

Viewed 39

I tried with the below code

@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends
   WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http
      // ...
      .headers()
        .addHeaderWriter(new StaticHeadersWriter("X-Content-Security-Policy","script-src 'self'"))
      // ...
  }
}

when I am hitting any endpoint from swagger in response I am getting the X-Content-Security header

the same when I am testing with my local UI getting the below error kindly help. http://localhost:4200 . Has been blocked by CORS policy: response to pre flight request does not pass access control check.

0 Answers
Related