Class ContentSecurityPolicy
- All Implemented Interfaces:
HttpHeader
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:
Because this is an HttpStringHeader, an instance can be added directly to the REST server's
HttpHeaderList (e.g. via a
See Also:
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFluent builder for assembling aContent-Security-Policy header value. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionContentSecurityPolicy(String value) Constructor with an eager value (enforcing "Content-Security-Policy" header).protectedContentSecurityPolicy(String name, String value) Constructor allowing the header name to be chosen (enforcing vs. report-only).protectedContentSecurityPolicy(String name, Supplier<String> valueSupplier) Constructor allowing the header name to be chosen, with a lazy value supplier.ContentSecurityPolicy(Supplier<String> valueSupplier) Constructor with a lazy value supplier (enforcing "Content-Security-Policy" header). -
Method Summary
Modifier and TypeMethodDescriptioncreate()Creates a new emptyContentSecurityPolicy.Builder.static ContentSecurityPolicyStatic factory method for an enforcing ("Content-Security-Policy") header with an eager value.static ContentSecurityPolicyStatic factory method for an enforcing ("Content-Security-Policy") header with a lazy value supplier.static ContentSecurityPolicyofReportOnly(String value) Static factory method for an observe-only ("Content-Security-Policy-Report-Only") header with an eager value.static ContentSecurityPolicyofReportOnly(Supplier<String> valueSupplier) Static factory method for an observe-only ("Content-Security-Policy-Report-Only") header with a lazy value supplier.Creates aContentSecurityPolicy.Builderpre-populated with the nonce-based strict starter preset.Methods inherited from class org.apache.juneau.http.header.HttpStringHeader
of, of, ofPairMethods inherited from class org.apache.juneau.http.header.HttpHeaderBean
equals, equalsIgnoreCase, getName, getValue, hashCode, toString
-
Field Details
-
NAME
The enforcing header name: "Content-Security-Policy".- See Also:
-
REPORT_ONLY_NAME
The observe-only header name: "Content-Security-Policy-Report-Only".- See Also:
-
-
Constructor Details
-
ContentSecurityPolicy
Constructor with an eager value (enforcing "Content-Security-Policy" header).- Parameters:
value- The header value. May benull .
-
ContentSecurityPolicy
Constructor with a lazy value supplier (enforcing "Content-Security-Policy" header).- Parameters:
valueSupplier- Supplier for the header value. Must not benull .
-
ContentSecurityPolicy
Constructor allowing the header name to be chosen (enforcing vs. report-only).- Parameters:
name- The header name. Must not benull .value- The header value. May benull .
-
ContentSecurityPolicy
Constructor allowing the header name to be chosen, with a lazy value supplier.- Parameters:
name- The header name. Must not benull .valueSupplier- Supplier for the header value. Must not benull .
-
-
Method Details
-
of
Static factory method for an enforcing ("Content-Security-Policy") header with an eager value.- Parameters:
value- The header value. May benull .- Returns:
- A new instance. Never
null .
-
of
Static factory method for an enforcing ("Content-Security-Policy") header with a lazy value supplier.- Parameters:
valueSupplier- Supplier for the header value. Must not benull .- Returns:
- A new instance. Never
null .
-
ofReportOnly
Static factory method for an observe-only ("Content-Security-Policy-Report-Only") header with an eager value.Browsers report violations against this header but do not block anything, letting operators tune a policy before enforcing it.
- Parameters:
value- The header value. May benull .- Returns:
- A new instance. Never
null .
-
ofReportOnly
Static factory method for an observe-only ("Content-Security-Policy-Report-Only") header with a lazy value supplier.- Parameters:
valueSupplier- Supplier for the header value. Must not benull .- Returns:
- A new instance. Never
null .
-
create
Creates a new emptyContentSecurityPolicy.Builder.- Returns:
- A new builder. Never
null .
-
strictStarter
Creates aContentSecurityPolicy.Builderpre-populated with the nonce-based strict starter preset.- Returns:
- A new builder pre-populated with the strict-starter directives. Never
null . - See Also:
-