-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: add --allow-import=<allow_list> for checking dynamic imports/workers #8266
Comments
Also CC @nayeemrmn @teleclimber |
First, I think it would be far more common for people to use
Because I can't really think of a better name. I do believe it makes a lot more sense then |
Neither do I,
Sounds good to me |
The proposal sounds good to me. It would cleanly solve the issue I had in #8109. My only concern is what this does to the UX for Deno users. It's already a lot to have to specify all the permissions, now they also have to specifically allow the script to run its workers and dynamic imports. This requires the user to know what these scripts are and carefully type them in at the command line every time they want to use it. |
@teleclimber thanks for raising this, I'm aware of the problem and have recently started discussions on Discord around this problem. There are numerous proposals to solve problem of describing the workflow: |
In my mind |
The fact that it's already a lot is exactly why this shouldn't be a factor. It's already a reality that shortcuts are essential. Suddenly worrying about length of commands at this point will just lead to design inconsistencies, unless the solution is general-purpose with respect to flags as a whole. |
Ok, glad to see that there are proposals to address this.
Agreed. Better to have a consistent set of flags and deal with the length of commands separately. |
I also would like it to be available for non-dynamic imports and for I wrote some of my thoughts here: #11052 |
I'm also interested in applying
Of course, all of the above could be addressed at other levels, e.g. at the process level but the permission model of Deno already makes a lot of things easier so I think this is the right direction. Furthermore, IMO, imports should be treated as an indirect access to file system/network, so in that sense, they should also have the same permissions as existing |
To make the UX a bit better, we could also have reasonable defaults for |
The ability to load JSON makes Deno's Come to think of it, it also works over the network. What if you have an HTTP server for JWK serving on a port, with Basic Auth in a reverse proxy server, and are running a script intended to be sandboxed on the same server? JWK uses JSON. To use Deno for sandboxing, you now have to do
Now that I think about it, I wish importing JSON was blocked by default. sigh I know secrets can be stored in |
Another complication for trying to allowlist imports: it appears JSON modules aren't cached and
There is one way that might work, but perhaps shouldn't be depended upon, to check all the imports, including json:
|
The lockfile unintentionally The fix makes it clear that So this is another use case for this feature – making it so eval and similar things can be disabled, in conjunction with |
It doesn't look like #25469 allows blocking file imports or restricting them to a directory. |
* Deno-v2.0.0-rc7+ is now requiring "import" permissions - JSDelivr and SkyPack are not on the Deno-2.0 default allowlist - esm.sh *is* included in the "allow-import" default domain list - ref: [Proposal/discussion](denoland/deno#8266) - ref: [Merged solution](denoland/deno#25469)
* Deno-v2.0.0-rc7+ is now requiring "import" permissions - JSDelivr and SkyPack are not on the Deno-2.0 default allowlist - esm.sh *is* included in the "allow-import" default domain list - ref: [Proposal/discussion](denoland/deno#8266) - ref: [Merged solution](denoland/deno#25469)
* Deno-v2.0.0-rc7+ is now requiring "import" permissions - JSDelivr and SkyPack are not on the Deno-2.0 default allowlist - esm.sh *is* included in the "allow-import" default domain list - ref: [Proposal/discussion](denoland/deno#8266) - ref: [Merged solution](denoland/deno#25469)
* Deno-v2.0.0-rc7+ is now requiring "import" permissions - JSDelivr and SkyPack are not on the Deno-2.0 default allowlist - esm.sh *is* included in the "allow-import" default domain list - ref: [Proposal/discussion](denoland/deno#8266) - ref: [Merged solution](denoland/deno#25469)
Context: Currently loading dynamic imports or worker code requires
--allow-read
and/or--allow-net
flags. Appropriate permissions are checked for entry point as well as all dependent modules. This leads to a situation where even quite simple scenarios require to grant a lot of permissions.Example 1:
I above example one needs to run with following flags:
Similarly for workers, example 2:
I above example one needs to run with following flags:
In other words, doing dynamic imports or using workers requires to open up the sandbox by providing
read
and/ornet
permissions to load ES modules that will be executed. Of course one could revoke those permissions after the load is done, but with top-level-await this becomes quite tricky.My proposal:
Introduce new flag
--allow-import=<allow_list>
and change semantics of permission check for loading modules. Instead of verifying permissions for each static import we should only check permission of entry point. User could specify--allow-import
to allow all dynamic imports and workers. So invocations for above examples would look as follows:Example 1:
Example 2:
Notice that no runtime permissions were given (no
--allow-read
, nor--allow-net
).Going forward with this proposal would be a huge breaking change in semantics and require profound refactors. IMO we could start by introducing
--allow-import
and its semantics in next minor release, while keeping old semantics working (and showing warnings about it being deprecated). Then after one or two minor releases completely remove old semantics. Alternatively it could be 2.0 material.This issue is directly related to #8109 and #8215
CC @kitsonk @ry @lucacasonato @piscisaureus
The text was updated successfully, but these errors were encountered: