trusted-types CSP directive.
The trusted-types directive restricts the creation of Trusted Type
policies, which are used to guard DOM XSS sink functions. It can specify
an explicit allow-list of policy names, the keyword 'none' to forbid
all policies, the keyword 'allow-duplicates' to permit policies
with the same name to be created more than once, and the wildcard *
to allow any policy name.
- Author:
- Salvation Team, Michael Smith
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.htmlunit.csp.Directive
Directive.DirectiveErrorConsumer -
Field Summary
Fields inherited from class org.htmlunit.csp.Directive
IS_DIRECTIVE_NAME -
Constructor Summary
ConstructorsConstructorDescriptionTrustedTypesDirective(List<String> values, Directive.DirectiveErrorConsumer errors) Parses atrusted-typesdirective from the given list of values. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the'allow-duplicates'keyword is present.booleanIndicates if wildcard policy names are permitted.Returns an unmodifiable list of the explicitly named Trusted Type policy names (excluding keywords and wildcard).booleannone()Returns whether the'none'keyword is present.voidsetAllowDuplicates_(boolean allowDuplicates) Sets whether the'allow-duplicates'keyword is present.voidsetNone(boolean none) Sets whether the'none'keyword is present.voidsetStar(boolean star) Sets whether the wildcard (*) is present.booleanstar()Returns whether the wildcard (*) is present.Methods inherited from class org.htmlunit.csp.Directive
addValue, containsNonDirectiveCharacter, getValues, removeValueIgnoreCase
-
Constructor Details
-
TrustedTypesDirective
Parses atrusted-typesdirective from the given list of values.Recognised tokens include the keywords
'none','allow-duplicates', the wildcard*, and policy names matching thett-policy-namegrammar. Errors and warnings (duplicates, invalid names, conflicting combinations) are reported through the suppliederrorsconsumer.- Parameters:
values- the raw string values for this directiveerrors- consumer that receives parsing errors and warnings
-
-
Method Details
-
none
public boolean none()Returns whether the'none'keyword is present.When
'none'is present, no Trusted Type policies may be created.- Returns:
trueif'none'is present
-
setNone
public void setNone(boolean none) Sets whether the'none'keyword is present.Setting to
trueadds'none'to the directive values; setting tofalseremoves it.- Parameters:
none-trueto add'none',falseto remove it
-
allowDuplicates
public boolean allowDuplicates()Returns whether the'allow-duplicates'keyword is present.When present, Trusted Type policies with the same name may be created more than once.
- Returns:
trueif'allow-duplicates'is present
-
setAllowDuplicates_
public void setAllowDuplicates_(boolean allowDuplicates) Sets whether the'allow-duplicates'keyword is present.Setting to
trueadds'allow-duplicates'to the directive values; setting tofalseremoves it.- Parameters:
allowDuplicates-trueto add,falseto remove
-
star
public boolean star()Returns whether the wildcard (*) is present.When present, any Trusted Type policy name is permitted.
- Returns:
trueif the wildcard is present
-
allowsWildcardPolicyNames
public boolean allowsWildcardPolicyNames()Indicates if wildcard policy names are permitted. When true, any policy name is allowed, which may reduce security.- Returns:
- true if wildcard policy names (*) are permitted, false otherwise
-
setStar
public void setStar(boolean star) Sets whether the wildcard (*) is present.Setting to
trueadds*to the directive values; setting tofalseremoves it.- Parameters:
star-trueto add,falseto remove
-
getPolicyNames
Returns an unmodifiable list of the explicitly named Trusted Type policy names (excluding keywords and wildcard).Policy names are case-sensitive and match the
tt-policy-namegrammar.- Returns:
- the list of policy name strings
-