trusted-types icon indicating copy to clipboard operation
trusted-types copied to clipboard

CSP syntax for `require-trusted-types-for` should be forgiving

Open lukewarlow opened this issue 8 months ago • 4 comments
trafficstars

Currently the spec has an unforgiving syntax for require-trusted-types-for if you have an invalid sink group in your list it invalidates the whole directive. This isn't what's actually implemented in Chromium (or WebKit). The spec should instead have the value syntax as a space separated list and we simply discard values we don't recognise, this is how other CSP directives work and is better for forward compatibility.

lukewarlow avatar Feb 24 '25 14:02 lukewarlow

I'm not sure this is actually an issue in the Trusted Types spec per se. More a CSP issue in general. Because all of them are defined by strict grammars but script-src for example will parse as forgiving in all browsers.

cc @fred-wang

lukewarlow avatar Mar 04 '25 15:03 lukewarlow

See also https://github.com/w3c/webappsec-csp/pull/363 for the general issue.

Mirko commented about trusted-types too in https://github.com/w3c/webappsec-csp/pull/363#issuecomment-2160193577

fred-wang avatar Mar 27 '25 08:03 fred-wang

So another case considered invalid by tests is "'script''script'" (missing required-ascii-whitespace). But it seems Chromium and WebKit are forgiving for that case too and after my changes at https://phabricator.services.mozilla.com/D243259 I see the same for Firefox too.

I see other directives parsed similarly like https://w3c.github.io/webappsec-csp/#directive-sandbox so I assume they are accepting a missing whitespace too.

fred-wang avatar Mar 27 '25 09:03 fred-wang

That specific case we should treat as invalid.

Chromium reports it as invalid but then treats it as valid because of a bug in their parser.

lukewarlow avatar Mar 27 '25 10:03 lukewarlow