问题
I'm trying out Deno and while running an example, I ran into error:
$ deno run https://deno.land/std/examples/curl.ts https://example.com
Download https://deno.land/std/examples/curl.ts
Warning Implicitly using master branch https://deno.land/std/examples/curl.ts
Compile https://deno.land/std/examples/curl.ts
error: Uncaught PermissionDenied: network access to "https://example.com/", run again with the --allow-net flag
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendAsync ($deno$/ops/dispatch_json.ts:98:10)
at async fetch ($deno$/web/fetch.ts:591:27)
at async https://deno.land/std/examples/curl.ts:3:13
I've tried doing
$ deno run https://deno.land/std/examples/curl.ts https://example.com --allow-net
but still get the same error. What am I doing wrongly?
回答1:
The --allow-net
flag has to be after deno run
and before the file name, not appended at the end.
deno run --allow-net https://deno.land/std/examples/curl.ts https://example.com
Read more about Deno permissions here.
回答2:
--allow-env
Allow environment access
--allow-hrtime
Allow high resolution time measurement
--allow-net=<allow-net>
Allow network access
--allow-plugin
Allow loading plugins
--allow-read=<allow-read>
Allow file system read access
--allow-run
Allow running subprocesses
--allow-write=<allow-write>
Allow file system write access
example
deno run --allow-net app.ts //give a network permission
deno run --allow-all app.ts //give an all permission
回答3:
Deno is a runtime which is secure by default. This means you need to explicitly give programs the permission to do certain 'privileged' actions, such as access the network.
Make use of --allow-net=<domain>
permission flag: in your case deno run --allow-net=example.com https://deno.land/std/examples/curl.ts https://example.com
If you don't provide domain name it will allow for all domains which can be again a security compromise. See here Permission.
回答4:
You made the order wrong. It should be
deno run --allow-net https://deno.land/std/examples/curl.ts https://example.com
Also you can read this blog post for more info on deno: https://noobieprogrammer.blogspot.com/2020/06/how-to-destroy-nodejs-in-60-seconds-with-deno.html
来源:https://stackoverflow.com/questions/61847371/deno-permissions-issue-uncaught-permissiondenied-network-access