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

Figure out if we need `'trusted-script'` in `script-src`

Open koto opened this issue 6 years ago • 8 comments
trafficstars

trusted-script keyword is used now for javascript: navigations and eval guarding. Since we've integrated with CSP logic, perhaps the keyword is now superfluous?

If a website uses eval or javacsript: and it uses script-src, it needs to set appropriate unsafe-* keywords anyhow, for browsers with no trusted-types support.

We are close to having working downgrades. See #218 for a working downgrade-to-string for eval; for javascript: navigation, the default policy will simply not be created, and therefore called.

It seems like a combination of script-src ... 'unsafe-inline' 'unsafe-eval'; trusted-types ... correctly limits the unsafe behavior to Trusted Types, with a working downgrade to string for non-supporting browsers. IOW, trusted-types directive adds additional restrictions independent of script-src, which seems to be not violating CSP principles, and is conceptually simpler.

cc @mikesamuel @mikewest

koto avatar Sep 19 '19 06:09 koto

/cc @mikewest , Do you have an opinion here? Essentially, it all boils down to whether trusted-types directive (and a JS code conforming to it) should be able to bypass existing restrictions in script-src, or would we require a new keyword in script-src as well.

koto avatar Oct 18 '19 14:10 koto

Pingy ping @mikewest

koto avatar Nov 06 '19 13:11 koto

I think you're right that script-src 'trusted-script' ...; trusted-types name is less backwards-compatible than script-src 'unsafe-eval' ...; trusted-types name. I think I'm comfortable treating trusted-types name as an attenuation of 'unsafe-eval' without a separate keyword.

mikewest avatar Nov 14 '19 09:11 mikewest

I'm reopening this issue to restart this conversation. I think something that's been missed in previous considerations is that some use cases might care more about security than compatability.

think you're right that script-src 'trusted-script' ...; trusted-types name is less backwards-compatible than script-src 'unsafe-eval' ...; trusted-types name

This lack of backwards compatability is a desired characterstic. Currently to use eval in TT envs you have to add a keyword that means browsers without TT allow you full unmitigated eval. Which is not always desirable.

If we added a new trusted-script (or trusted-eval or some other name) keyword then that would allow you access to eval where supported and degrade to smaller feature set where it's not provided.

lukewarlow avatar Feb 21 '24 15:02 lukewarlow

@lukewarlow thanks for reopening this. we certainly need this resolved to be able to move forward with the regulations in Europe.

cc @gregwhitworth

caridy avatar Feb 21 '24 18:02 caridy

As part of https://github.com/w3c/trusted-types/pull/464 - we get the raw arguments to eval and new Function() so we can ensure they are trusted types which would make this easier

lukewarlow avatar Feb 29 '24 18:02 lukewarlow

A worry I have here is that with Trusted Types the definition of trust lies with the website. And while I suppose a website could always bypass its own policies (e.g., to bypass unsafe-eval you could have a <script src> proxy of sorts I think) this seems easier with Trusted Types (have a no-op policy).

In particular because regulation around security policies might encourage perverse incentives.

annevk avatar Mar 13 '24 12:03 annevk

@annevk I think the main incentive here is to prevent evaluation in browsers without TT, as this constitutes a security problem today with no way to mitigate it without introducing UA sniffing.

caridy avatar Mar 13 '24 17:03 caridy

Closing this to focus discussions in https://github.com/w3c/webappsec-csp/pull/665

lukewarlow avatar Jul 17 '24 11:07 lukewarlow