Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wasm-unsafe-eval source expression directive #5

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/org/htmlunit/csp/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public final class Constants {
/** UNQUOTED_KEYWORD_PATTERN. */
public static final Pattern UNQUOTED_KEYWORD_PATTERN
= Pattern.compile("^(?:self|unsafe-inline|unsafe-eval|unsafe-redirect"
+ "|none|strict-dynamic|unsafe-hashes|report-sample|unsafe-allow-redirects)$");
+ "|none|strict-dynamic|unsafe-hashes|report-sample|unsafe-allow-redirects|"
+ "wasm-unsafe-eval)$");

// port-part constants
/** WILDCARD_PORT = -200. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ public class SourceExpressionDirective extends HostSourceDirective {
private static final String UNSAFE_ALLOW_REDIRECTS = "'unsafe-allow-redirects'";
private static final String UNSAFE_EVAL = "'unsafe-eval'";
private static final String UNSAFE_HASHES = "'unsafe-hashes'";
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_webassembly_execution
private static final String WASM_UNSAFE_EVAL = "'wasm-unsafe-eval'";
private boolean unsafeInline_;
private boolean unsafeEval_;
private boolean strictDynamic_;
private boolean unsafeHashes_;
private boolean reportSample_;
private boolean unsafeAllowRedirects_;
private boolean unsafeWasm_;

// In practice, these are probably small enough for Lists to be faster than LinkedHashSets
private final List<Nonce> nonces_ = new ArrayList<>();
Expand Down Expand Up @@ -84,6 +87,14 @@ public SourceExpressionDirective(final List<String> values, final DirectiveError
errors.add(Policy.Severity.Warning, "Duplicate source-expression 'unsafe-hashes'", index);
}
break;
case WASM_UNSAFE_EVAL:
if (!unsafeWasm_) {
unsafeWasm_ = true;
}
else {
errors.add(Policy.Severity.Warning, "Duplicate source-expression " + WASM_UNSAFE_EVAL, index);
}
break;
case REPORT_SAMPLE:
if (!reportSample_) {
reportSample_ = true;
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/htmlunit/csp/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ public void warnings() {
e(Policy.Severity.Warning, "Duplicate source-expression 'strict-dynamic'", 0, 1)
);

roundTrips(
"script-src 'wasm-unsafe-eval' 'WASM-UNSAFE-EVAL'",
e(Policy.Severity.Warning, "Duplicate source-expression 'wasm-unsafe-eval'", 0, 1)
);

roundTrips(
"default-src 'unsafe-hashes' 'UNSAFE-HASHES'",
e(Policy.Severity.Warning, "Duplicate source-expression 'unsafe-hashes'", 0, 1)
Expand Down
Loading