In addition to the host-sources and scheme-sources inherited from
HostSourceDirective, a source-expression list may contain keyword
sources ('unsafe-inline', 'unsafe-eval', 'strict-dynamic',
'unsafe-hashes', 'report-sample', 'unsafe-allow-redirects',
'wasm-unsafe-eval'), nonce-sources ('nonce-...') and hash-sources
('sha256-...', 'sha384-...', 'sha512-...').
This class is used for most fetch directives (script-src, style-src,
default-src, img-src, etc.) as well as base-uri,
form-action, and navigate-to.
- Author:
- Salvation Team
-
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
ConstructorsConstructorDescriptionSourceExpressionDirective(List<String> values, Directive.DirectiveErrorConsumer errors) Parses a source-expression directive from the given list of values. -
Method Summary
Modifier and TypeMethodDescriptionReturns an unmodifiable list of hash-sources parsed from this directive.Returns an unmodifiable list of nonce-sources parsed from this directive.booleanReturns whether the'report-sample'keyword is present.booleanReturns whether the'strict-dynamic'keyword is present.booleanReturns whether the'unsafe-allow-redirects'keyword is present.booleanReturns whether the'unsafe-eval'keyword is present.booleanReturns whether the'unsafe-hashes'keyword is present.booleanReturns whether the'unsafe-inline'keyword is present.booleanReturns whether the'wasm-unsafe-eval'keyword is present.Methods inherited from class org.htmlunit.csp.directive.HostSourceDirective
addValue, getHosts, getNone, getSchemes, removeValueIgnoreCase, self, starMethods inherited from class org.htmlunit.csp.Directive
containsNonDirectiveCharacter, getValues
-
Constructor Details
-
SourceExpressionDirective
Parses a source-expression directive from the given list of values.Each token is classified as a keyword, nonce, hash, host-source, or scheme-source. Errors and warnings (duplicates, unrecognised tokens, empty lists, etc.) are reported through the supplied
errorsconsumer.- Parameters:
values- the raw string values for this directiveerrors- consumer that receives parsing errors and warnings
-
-
Method Details
-
unsafeInline
public boolean unsafeInline()Returns whether the'unsafe-inline'keyword is present.When present (and not neutralised by nonces/hashes), inline scripts and styles are permitted.
- Returns:
trueif'unsafe-inline'is present
-
unsafeEval
public boolean unsafeEval()Returns whether the'unsafe-eval'keyword is present.When present,
eval()and similar string-to-code mechanisms are permitted.- Returns:
trueif'unsafe-eval'is present
-
strictDynamic
public boolean strictDynamic()Returns whether the'strict-dynamic'keyword is present.When present, trust is propagated to scripts loaded by already-trusted scripts, and host-/scheme-based allowlists are ignored.
- Returns:
trueif'strict-dynamic'is present- See Also:
-
unsafeHashes
public boolean unsafeHashes()Returns whether the'unsafe-hashes'keyword is present.When present, inline event handlers and
javascript:URLs can be allowed by matching their content against the hash-sources in this directive.- Returns:
trueif'unsafe-hashes'is present
-
reportSample
public boolean reportSample()Returns whether the'report-sample'keyword is present.When present, violation reports include a sample of the violating code.
- Returns:
trueif'report-sample'is present
-
unsafeAllowRedirects
public boolean unsafeAllowRedirects()Returns whether the'unsafe-allow-redirects'keyword is present.When present in a
navigate-todirective, navigation is checked both before and after any redirect, rather than only before.- Returns:
trueif'unsafe-allow-redirects'is present
-
unsafeWasm
public boolean unsafeWasm()Returns whether the'wasm-unsafe-eval'keyword is present.When present, WebAssembly compilation and instantiation are permitted without requiring
'unsafe-eval'.- Returns:
trueif'wasm-unsafe-eval'is present- See Also:
-
getNonces
Returns an unmodifiable list of nonce-sources parsed from this directive.- Returns:
- the list of
Noncevalues
-
getHashes
Returns an unmodifiable list of hash-sources parsed from this directive.- Returns:
- the list of
Hashvalues
-