feat(workers): add support for trusted types - #837
Conversation
|
Thanks for this, the CSP gap is real and definitely should be fixed. Two blockers: 1. The published types break. 2. Two smaller ones: Also needs a rebase, |
b3198f6 to
9ac4e0a
Compare
Using `fuse.js/worker` currently fails for projects that use the `require-trusted-types-for` Content Security Policy directive: ``` This document requires 'TrustedScriptURL' assignment. The action has been blocked. _spawnWorker @fuse-worker.mjs:73 _init @fuse-worker.mjs:107 _ensureInit @fuse-worker.mjs:69 search @fuse-worker.mjs:130 ``` This patch fixes this by creating a `TrustedTypePolicy` called `fuse-trusted-worker-url` and spawning the web workers with a `TrustedTypeURL` instance created from the policy. It also changes the public API to allow `workerUrl` to be passed as a `TrustedScriptURL`, such that consumers can use their own policies. This change has should have no impact on consumers that don't make use of the `require-trusted-types-for` directive. See https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API. Inspired by sveltejs/svelte#16271.
9ac4e0a to
514d0dd
Compare
|
I've fixed the types.
The whole point is that it crashes - the consumer either has to add
I'm not sure that grouping these two concept (default URL, derived from inside the package and a user-supplied arbitrary URL) is a good idea. The identity transformation works for the default URL precisely because it's not an arbitrary URL - it's probably not appropriate for user-supplied one, which is precisely why consumers should bring their own policy.
Isn't |
Using
fuse.js/workercurrently fails for projects that use therequire-trusted-types-forContent Security Policy directive:This patch fixes this by creating a
TrustedTypePolicycalledfuse-trusted-worker-urland spawning the web workers with aTrustedTypeURLinstance created from the policy.It also changes the public API to allow
workerUrlto be passed as aTrustedScriptURL, such that consumers can use their own policies.This change should have no impact on consumers that don't make use of the
require-trusted-types-fordirective.See https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API.
Inspired by sveltejs/svelte#16271.