feat(workers): add support for trusted types - #837
Conversation
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.
|
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, |
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.