Deno permissions issue - Uncaught PermissionDenied: network access

拥有回忆 提交于 2020-06-29 04:26:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!