docs: document that Web Workers require --allow-read for local scripts#3423
Merged
Conversation
Canary broke typechecking of several unrelated example scripts (npm
specifier resolution, 'with { type: bytes }' imports, worker lib globals,
'await using' disposal), turning the lint job red on every PR. Pin the
lint and freshness workflows to the latest stable 2.x release instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The permissions reference explains that the entrypoint module and its
statically analyzable import graph are read by default, which is why
deno run script.tsneeds no--allow-read. It does not mention that WebWorkers are an exception to this rule, and the Worker API reference only covers
WorkerOptions.deno.permissions(what the worker may do once running), not thepermission required to load the worker script in the first place.
A worker's script is loaded as if it were a dynamic import rather than a static
root, so loading a worker whose script is a local file requires
--allow-read.This is verifiable at runtime:
new Worker(new URL("./worker.ts", import.meta.url).href)run without
--allow-readfails withRequires read access to ".../worker.ts".The requirement covers the worker's entry script and its entire static import
graph, and the read access is checked against the permissions of the thread
that created the worker. Workers loaded from
https:URLs require--allow-importinstead, whiledata:andblob:URLs need no permission.This adds a bullet to the "During module loading" list in the File system
access section, where the static-analysis read exemption is already described,
and tightens the wording of the related sentence in the "Importing from the
Web" section so the local
--allow-readrequirement reads clearly alongsidethe remote
--allow-importone.