Nexory commented on code in PR #1880:
URL: https://github.com/apache/wicket/pull/1880#discussion_r4546266303
##########
wicket-core/src/main/java/org/apache/wicket/csp/CSPDirective.java:
##########
@@ -123,8 +124,82 @@ public void checkValueForDirective(CSPRenderable value,
throw new IllegalArgumentException("Illegal URI
for report-uri directive", urise);
}
}
+ },
+ /**
+ * Makes the browser reject strings at script injection sinks such as
{@code innerHTML}. The
+ * only value is {@code 'script'}.
+ *
+ * @since 12.0.0
+ * @see <a
href="https://www.w3.org/TR/trusted-types/">https://www.w3.org/TR/trusted-types/</a>
+ */
+ REQUIRE_TRUSTED_TYPES_FOR("require-trusted-types-for")
+ {
+ /**
+ * Only allow {@code 'script'}, and only once.
+ */
+ @Override
+ public void checkValueForDirective(CSPRenderable value,
+ List<CSPRenderable> existingDirectiveValues)
+ {
+ if (!existingDirectiveValues.isEmpty())
+ {
+ throw new IllegalArgumentException(
+ "A require-trusted-types-for directive
can only contain one value, it already "
+ + "contains " +
existingDirectiveValues);
+ }
+ if (!(value instanceof FixedCSPValue) ||
!"'script'".equals(value.toString()))
+ {
+ throw new IllegalArgumentException(
+ "A require-trusted-types-for directive
can only contain 'script', not "
+ + value);
+ }
+ }
+ },
+ /**
+ * Restricts the names of the Trusted Types policies a page may create.
The values are policy
+ * names, {@code 'allow-duplicates'}, {@code *} or a single {@code
'none'}.
+ *
+ * @since 12.0.0
+ * @see <a
href="https://www.w3.org/TR/trusted-types/">https://www.w3.org/TR/trusted-types/</a>
+ */
+ TRUSTED_TYPES("trusted-types")
+ {
+ /**
+ * Only allow policy names and the keywords of the directive,
and block {@code 'none'}
+ * next to other values.
+ */
+ @Override
+ public void checkValueForDirective(CSPRenderable value,
+ List<CSPRenderable> existingDirectiveValues)
+ {
+ if (!(value instanceof FixedCSPValue)
Review Comment:
Fixed in afcb17a: `TRUSTED_TYPES` accepts `CSPDirectiveSrcValue.NONE`, and
the test now asserts that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]