Class TrustedTypesDirective

java.lang.Object
org.htmlunit.csp.Directive
org.htmlunit.csp.directive.TrustedTypesDirective

public class TrustedTypesDirective extends Directive
Represents the 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:
  • Constructor Details

    • TrustedTypesDirective

      public TrustedTypesDirective(List<String> values, Directive.DirectiveErrorConsumer errors)
      Parses a trusted-types directive from the given list of values.

      Recognised tokens include the keywords 'none', 'allow-duplicates', the wildcard *, and policy names matching the tt-policy-name grammar. Errors and warnings (duplicates, invalid names, conflicting combinations) are reported through the supplied errors consumer.

      Parameters:
      values - the raw string values for this directive
      errors - 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:
      true if 'none' is present
    • setNone

      public void setNone(boolean none)
      Sets whether the 'none' keyword is present.

      Setting to true adds 'none' to the directive values; setting to false removes it.

      Parameters:
      none - true to add 'none', false to 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:
      true if 'allow-duplicates' is present
    • setAllowDuplicates_

      public void setAllowDuplicates_(boolean allowDuplicates)
      Sets whether the 'allow-duplicates' keyword is present.

      Setting to true adds 'allow-duplicates' to the directive values; setting to false removes it.

      Parameters:
      allowDuplicates - true to add, false to remove
    • star

      public boolean star()
      Returns whether the wildcard (*) is present.

      When present, any Trusted Type policy name is permitted.

      Returns:
      true if 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 true adds * to the directive values; setting to false removes it.

      Parameters:
      star - true to add, false to remove
    • getPolicyNames

      public List<String> 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-name grammar.

      Returns:
      the list of policy name strings