TrustedTypesDirectives Class

The Trusted Types directives of a content security policy (https://w3c.github.io/trusted-types/dist/spec/#integration-with-content-security-policy): require-trusted-types-for and trusted-types. Trusted Types are enforced for the documents whose Document.TrustedTypesDirectives contain directives (there are none by default).

public sealed class TrustedTypesDirectives

Remarks

The violations are reported as violations of the content security policy of the directives: the securitypolicyviolation event and the report-uri reports of the policy delivered with the document (a Content-Security-Policy header or a meta element).

Constructors

NameDescription
TrustedTypesDirectives()

TrustedTypesDirectives()

public TrustedTypesDirectives()

No documentation is available.

Properties

NameDescription
ReportOnlyWhether the disposition of the policy is "report" (Content-Security-Policy-Report-Only): the directives do not block anything, but the default policy is still applied to the values of the sinks.
RequireTrustedTypesForScriptWhether the policy contains the require-trusted-types-for 'script' directive (https://w3c.github.io/trusted-types/dist/spec/#require-trusted-types-for-csp-directive): the DOM XSS injection sinks only accept trusted types (or the values of the default policy).
TrustedTypesThe value of the trusted-types directive (https://w3c.github.io/trusted-types/dist/spec/#trusted-types-csp-directive): the policy names that can be created, * (any name), 'allow-duplicates' and 'none'. null when the policy has no trusted-types directive (any policy can be created).

Whether the disposition of the policy is "report" (Content-Security-Policy-Report-Only): the directives do not block anything, but the default policy is still applied to the values of the sinks.

public bool ReportOnly { get; init; }

Property value

bool

RequireTrustedTypesForScript

TrustedTypesDirectives.cs

Whether the policy contains the require-trusted-types-for 'script' directive (https://w3c.github.io/trusted-types/dist/spec/#require-trusted-types-for-csp-directive): the DOM XSS injection sinks only accept trusted types (or the values of the default policy).

public bool RequireTrustedTypesForScript { get; init; }

Property value

bool

The value of the trusted-types directive (https://w3c.github.io/trusted-types/dist/spec/#trusted-types-csp-directive): the policy names that can be created, * (any name), 'allow-duplicates' and 'none'. null when the policy has no trusted-types directive (any policy can be created).

public IReadOnlyList<string>? TrustedTypes { get; init; }

Methods

NameDescription
Parse(string, bool)Returns the Trusted Types directives of a serialized content security policy (e.g. the value of a Content-Security-Policy header, https://w3c.github.io/webappsec-csp/#parse-serialized-policy). The other directives are ignored.

Parse(string, bool)

TrustedTypesDirectives.cs

Returns the Trusted Types directives of a serialized content security policy (e.g. the value of a Content-Security-Policy header, https://w3c.github.io/webappsec-csp/#parse-serialized-policy). The other directives are ignored.

public static TrustedTypesDirectives Parse(string serializedPolicy, bool reportOnly = false)

Parameters

serializedPolicy string
The serialized policy, e.g. require-trusted-types-for 'script'; trusted-types one two.
reportOnly bool
Whether the disposition of the policy is "report" (Content-Security-Policy-Report-Only).

Returns

TrustedTypesDirectives