- All Implemented Interfaces:
CspQueries
A serialized CSP list (e.g. the value of a Content-Security-Policy
HTTP header) may contain multiple policies separated by commas. Each policy
is parsed independently, and a resource is blocked if any policy
in the list blocks it — equivalently, allows* methods return
true only when every member policy allows the resource.
See
CSP3
multiple policies.
Implements CspQueries: each query method AND-delegates to member
Policy instances (short-circuit on the first deny). An empty list
is unrestricted (all allows* return true).
Instances are created by
Policy.parseSerializedCSPList(String, PolicyListErrorConsumer)
or ofSerialized(List, PolicyListErrorConsumer).
Empty policies (those with no directives) are omitted during parsing.
- Author:
- Ronald Brill, Rick Mitchell, Salvation Team
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanallowsApplicationManifest(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether an application manifest is allowed.booleanallowsConnection(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether a connection is allowed.booleanReturns whether eval is allowed.booleanallowsExternalScript(Optional<String> nonce, Optional<String> integrity, Optional<? extends URLWithScheme> scriptUrl, Optional<Boolean> parserInserted, Optional<? extends URLWithScheme> origin) Returns whether an external script is allowed.booleanallowsExternalStyle(Optional<String> nonce, Optional<? extends URLWithScheme> styleUrl, Optional<? extends URLWithScheme> origin) Returns whether an external stylesheet is allowed.booleanallowsFont(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether a font is allowed.booleanallowsFormAction(Optional<? extends URLWithScheme> to, Optional<Boolean> redirected, Optional<? extends URLWithScheme> redirectedTo, Optional<? extends URLWithScheme> origin) Returns whether a form action is allowed.booleanallowsFrame(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether a frame is allowed.booleanallowsFrameAncestor(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether a frame ancestor is allowed.booleanallowsImage(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether an image is allowed.booleanallowsInlineScript(Optional<String> nonce, Optional<String> source, Optional<Boolean> parserInserted) Returns whether an inline script is allowed.booleanallowsInlineStyle(Optional<String> nonce, Optional<String> source) Returns whether an inline style is allowed.booleanallowsJavascriptUrlNavigation(Optional<String> source, Optional<? extends URLWithScheme> origin) Returns whether ajavascript:URL navigation is allowed.booleanallowsMedia(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether media is allowed.booleanallowsNavigation(Optional<? extends URLWithScheme> to, Optional<Boolean> redirected, Optional<? extends URLWithScheme> redirectedTo, Optional<? extends URLWithScheme> origin) Returns whether navigation is allowed.booleanallowsObject(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether an object is allowed.booleanallowsPlugin(Optional<? extends MediaType> mediaType) Returns whether a plugin type is allowed.booleanallowsPrefetch(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether a prefetch is allowed.booleanallowsScriptAsAttribute(Optional<String> source) Returns whether a script event-handler attribute is allowed.booleanallowsStyleAsAttribute(Optional<String> source) Returns whether a style attribute is allowed.booleanallowsWorker(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Returns whether a worker is allowed.Returns the member policies (unmodifiable).static PolicyListofSerialized(List<String> serializedPoliciesOrLists, Policy.PolicyListErrorConsumer policyListErrorConsumer) Parses and combines multiple serialized CSP strings into one policy list.toString()Serializes this policy list back to its string representation.
-
Constructor Details
-
PolicyList
Ctor.- Parameters:
policies- the list of parsedPolicyinstances (empty policies excluded)- Throws:
NullPointerException- ifpoliciesisnullor containsnull
-
-
Method Details
-
ofSerialized
public static PolicyList ofSerialized(List<String> serializedPoliciesOrLists, Policy.PolicyListErrorConsumer policyListErrorConsumer) Parses and combines multiple serialized CSP strings into one policy list.Each element may itself be a comma-separated CSP list (as with a single header field value). Values are joined with
","and parsed viaPolicy.parseSerializedCSPList(java.lang.String, org.htmlunit.csp.Policy.PolicyListErrorConsumer)(always as header delivery —deliveredViaMeta = false). For meta policies, parse withPolicy.parseSerializedCSP(String, Policy.PolicyErrorConsumer, boolean)and pass the results toPolicyList(List). Report-Only policies should be kept in a separatePolicyList.- Parameters:
serializedPoliciesOrLists- header field values (not metacontentstrings that needdeliveredViaMeta = true)policyListErrorConsumer- consumer for parse errors/warnings- Returns:
- the combined
PolicyList - Throws:
NullPointerException- ifserializedPoliciesOrListsorpolicyListErrorConsumerisnull, or if any element ofserializedPoliciesOrListsisnull- Since:
- 5.4.0
-
getPolicies
Returns the member policies (unmodifiable).- Returns:
- an unmodifiable list of all policies
-
toString
Serializes this policy list back to its string representation.Individual policies are separated by
", ". Each policy is serialized usingPolicy.toString(). This is not an intersected / merged policy. -
allowsExternalScript
public boolean allowsExternalScript(Optional<String> nonce, Optional<String> integrity, Optional<? extends URLWithScheme> scriptUrl, Optional<Boolean> parserInserted, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether an external script is allowed.- Specified by:
allowsExternalScriptin interfaceCspQueries- Parameters:
nonce- script nonce, if anyintegrity- SRI metadata, if anyscriptUrl- script URL, if knownparserInserted- whether the script is parser-insertedorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsInlineScript
public boolean allowsInlineScript(Optional<String> nonce, Optional<String> source, Optional<Boolean> parserInserted) Description copied from interface:CspQueriesReturns whether an inline script is allowed.- Specified by:
allowsInlineScriptin interfaceCspQueries- Parameters:
nonce- script nonce, if anysource- inline script text, if knownparserInserted- whether the script is parser-inserted- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsScriptAsAttribute
Description copied from interface:CspQueriesReturns whether a script event-handler attribute is allowed.- Specified by:
allowsScriptAsAttributein interfaceCspQueries- Parameters:
source- attribute text, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsEval
public boolean allowsEval()Description copied from interface:CspQueriesReturns whether eval is allowed.- Specified by:
allowsEvalin interfaceCspQueries- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsFormAction
public boolean allowsFormAction(Optional<? extends URLWithScheme> to, Optional<Boolean> redirected, Optional<? extends URLWithScheme> redirectedTo, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether a form action is allowed.- Specified by:
allowsFormActionin interfaceCspQueries- Parameters:
to- form action URL, if knownredirected- whether the submission redirectsredirectedTo- final URL after redirect, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsExternalStyle
public boolean allowsExternalStyle(Optional<String> nonce, Optional<? extends URLWithScheme> styleUrl, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether an external stylesheet is allowed.- Specified by:
allowsExternalStylein interfaceCspQueries- Parameters:
nonce- style nonce, if anystyleUrl- stylesheet URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsInlineStyle
Description copied from interface:CspQueriesReturns whether an inline style is allowed.- Specified by:
allowsInlineStylein interfaceCspQueries- Parameters:
nonce- style nonce, if anysource- inline style text, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsStyleAsAttribute
Description copied from interface:CspQueriesReturns whether a style attribute is allowed.- Specified by:
allowsStyleAsAttributein interfaceCspQueries- Parameters:
source- attribute text, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsFrame
public boolean allowsFrame(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether a frame is allowed.- Specified by:
allowsFramein interfaceCspQueries- Parameters:
source- framed resource URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsFrameAncestor
public boolean allowsFrameAncestor(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether a frame ancestor is allowed.- Specified by:
allowsFrameAncestorin interfaceCspQueries- Parameters:
source- ancestor frame URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsConnection
public boolean allowsConnection(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether a connection is allowed.- Specified by:
allowsConnectionin interfaceCspQueries- Parameters:
source- connection URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsFont
public boolean allowsFont(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether a font is allowed.- Specified by:
allowsFontin interfaceCspQueries- Parameters:
source- font URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsImage
public boolean allowsImage(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether an image is allowed.- Specified by:
allowsImagein interfaceCspQueries- Parameters:
source- image URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsApplicationManifest
public boolean allowsApplicationManifest(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether an application manifest is allowed.- Specified by:
allowsApplicationManifestin interfaceCspQueries- Parameters:
source- manifest URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsMedia
public boolean allowsMedia(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether media is allowed.- Specified by:
allowsMediain interfaceCspQueries- Parameters:
source- media URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsObject
public boolean allowsObject(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether an object is allowed.- Specified by:
allowsObjectin interfaceCspQueries- Parameters:
source- object URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsPrefetch
public boolean allowsPrefetch(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether a prefetch is allowed.- Specified by:
allowsPrefetchin interfaceCspQueries- Parameters:
source- prefetch URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsWorker
public boolean allowsWorker(Optional<? extends URLWithScheme> source, Optional<? extends URLWithScheme> origin) Description copied from interface:CspQueriesReturns whether a worker is allowed.- Specified by:
allowsWorkerin interfaceCspQueries- Parameters:
source- worker URL, if knownorigin- protected-resource origin, if known- Returns:
trueif allowed under this query target's rules- See Also:
-
allowsPlugin
Description copied from interface:CspQueriesReturns whether a plugin type is allowed.- Specified by:
allowsPluginin interfaceCspQueries- Parameters:
mediaType- plugin media type, if known- Returns:
trueif allowed under this query target's rules- See Also:
-