Class ServerHttpSecurity.HeaderSpec.ContentSecurityPolicySpec
java.lang.Object
org.springframework.security.config.web.server.ServerHttpSecurity.HeaderSpec.ContentSecurityPolicySpec
- Enclosing class:
ServerHttpSecurity.HeaderSpec
Configures
Content-Security-Policy response header.- Since:
- 5.1
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionexchangeMatcher(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher matcher) Specifies theServerWebExchangeMatcherto use for determining when CSP should be applied.exchangeMatchers(String... pathPatterns) Specifies the matching path patterns for determining when CSP should be applied.nonceAttributeName(String nonceAttributeName) Sets the name of theexchange attributefor the generated nonce.policyDirectives(String policyDirectives) Sets the security policy directive(s) to be used in the response header.reportOnly(boolean reportOnly) Whether to include theContent-Security-Policy-Report-Onlyheader in the response.
-
Method Details
-
reportOnly
Whether to include theContent-Security-Policy-Report-Onlyheader in the response. Otherwise, defaults to theContent-Security-Policyheader.- Parameters:
reportOnly- whether to only report policy violations- Returns:
- the
ServerHttpSecurity.HeaderSpecto continue configuring
-
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
ServerHttpSecurity.HeaderSpecto continue configuring
-
nonceAttributeName
public ServerHttpSecurity.HeaderSpec.ContentSecurityPolicySpec nonceAttributeName(String nonceAttributeName) Sets the name of theexchange attributefor the generated nonce. Views can read this attribute to render the nonce in HTML.- Parameters:
nonceAttributeName- the name of the nonce attribute- Returns:
- the
ServerHttpSecurity.HeaderSpec.ContentSecurityPolicySpecto continue configuring - Throws:
IllegalArgumentException- ifnonceAttributeNameisnullor empty- Since:
- 7.2
-
exchangeMatcher
public ServerHttpSecurity.HeaderSpec.ContentSecurityPolicySpec exchangeMatcher(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher matcher) Specifies theServerWebExchangeMatcherto use for determining when CSP should be applied. The default is to enable CSP in every response ifServerHttpSecurity.HeaderSpec.contentSecurityPolicy(Customizer)is configured.- Parameters:
matcher- theServerWebExchangeMatcherto use- Returns:
- the
ServerHttpSecurity.HeaderSpec.ContentSecurityPolicySpecto continue configuring - Throws:
IllegalArgumentException- ifmatcherisnull- Since:
- 7.2
- See Also:
-
exchangeMatchers
public ServerHttpSecurity.HeaderSpec.ContentSecurityPolicySpec exchangeMatchers(String... pathPatterns) Specifies the matching path patterns for determining when CSP should be applied. The default is to enable CSP in every response ifServerHttpSecurity.HeaderSpec.contentSecurityPolicy(Customizer)is configured.- Parameters:
pathPatterns- the path patterns to be matched with aPathPatternParserServerWebExchangeMatcher- Returns:
- the
ServerHttpSecurity.HeaderSpec.ContentSecurityPolicySpecto continue configuring - Throws:
IllegalArgumentException- if any path pattern is rejected byPathPatternParserServerWebExchangeMatcher- Since:
- 7.2
- See Also:
-