Class HeadersConfigurer.ContentSecurityPolicyConfig
java.lang.Object
org.springframework.security.config.annotation.web.configurers.HeadersConfigurer.ContentSecurityPolicyConfig
- Enclosing class:
HeadersConfigurer<H extends HttpSecurityBuilder<H>>
- Since:
- 3.2
-
Method Summary
Modifier and TypeMethodDescriptionnonceAttributeName(String nonceAttributeName) Sets the name of the servlet request attribute for the generated nonce.policyDirectives(String policyDirectives) Sets the security policy directive(s) to be used in the response header.Enables (includes) the Content-Security-Policy-Report-Only header in the response.requestMatcher(org.springframework.security.web.util.matcher.RequestMatcher requestMatcher) Specifies theRequestMatcherto use for determining when CSP should be applied.requestMatchers(String... pathPatterns) Specifies the matching path patterns for determining when CSP should be applied.
-
Method Details
-
policyDirectives
Sets the security policy directive(s) to be used in the response header. ThepolicyDirectivesmay contain{nonce}as placeholders for a generated secure random nonce, e.g.,script-src 'self' 'nonce-{nonce}'.- Parameters:
policyDirectives- the security policy directive(s)- Returns:
- the
HeadersConfigurer<H extends HttpSecurityBuilder<H>>.ContentSecurityPolicyConfigfor additional configuration - Throws:
IllegalArgumentException- if policyDirectives is null or empty
-
reportOnly
Enables (includes) the Content-Security-Policy-Report-Only header in the response.- Returns:
- the
HeadersConfigurer<H extends HttpSecurityBuilder<H>>.ContentSecurityPolicyConfigfor additional configuration
-
nonceAttributeName
public HeadersConfigurer<H>.ContentSecurityPolicyConfig nonceAttributeName(String nonceAttributeName) Sets the name of the servlet request attribute for the generated nonce. Views can read this attribute to render the nonce in HTML.- Parameters:
nonceAttributeName- the name of the nonce attribute- Returns:
- the
HeadersConfigurer<H extends HttpSecurityBuilder<H>>.ContentSecurityPolicyConfigfor additional configuration - Throws:
IllegalArgumentException- ifnonceAttributeNameisnullor empty- Since:
- 7.2
-
requestMatcher
public HeadersConfigurer<H>.ContentSecurityPolicyConfig requestMatcher(org.springframework.security.web.util.matcher.RequestMatcher requestMatcher) Specifies theRequestMatcherto use for determining when CSP should be applied. The default is to enable CSP in every response ifHeadersConfigurer.contentSecurityPolicy(Customizer)is configured.- Parameters:
requestMatcher- theRequestMatcherto use- Returns:
- the
HeadersConfigurer<H extends HttpSecurityBuilder<H>>.ContentSecurityPolicyConfigfor additional configuration - Throws:
IllegalArgumentException- ifrequestMatcheris null- Since:
- 7.2
- See Also:
-
requestMatchers
Specifies the matching path patterns for determining when CSP should be applied. The default is to enable CSP in every response ifHeadersConfigurer.contentSecurityPolicy(Customizer)is configured.- Parameters:
pathPatterns- the path patterns to be matched with aPathPatternRequestMatcher- Returns:
- the
HeadersConfigurer<H extends HttpSecurityBuilder<H>>.ContentSecurityPolicyConfigfor additional configuration - Throws:
IllegalArgumentException- if any path pattern if rejected byPathPatternRequestMatcher.Builder.matcher(String)- Since:
- 7.2
- See Also:
-