Class ContentSecurityPolicy

All Implemented Interfaces:
HttpHeader

Represents an HTTP Content-Security-Policy (or Content-Security-Policy-Report-Only) response header.

A Content Security Policy lets a server declare which content sources a browser may load and execute for a page, mitigating cross-site-scripting (XSS) and data-injection attacks. This bean carries an already-rendered policy value; use ContentSecurityPolicy.Builder to assemble the value from typed directives.

Example:

// Build a static policy and emit it as a response header. ContentSecurityPolicy csp = ContentSecurityPolicy.create() .defaultSrc(ContentSecurityPolicy.Builder.SELF) .objectSrc(ContentSecurityPolicy.Builder.NONE) .toHeader(); // => "Content-Security-Policy: default-src 'self'; object-src 'none'"

Because this is an HttpStringHeader, an instance can be added directly to the REST server's defaultResponseHeaders HttpHeaderList (e.g. via a @Bean(name="defaultResponseHeaders") factory method) and is emitted through the normal response-header path.

See Also:
Since:
10.0.0