Yangshun Tay
Yangshun Tay

Reputation: 53169

Deno permissions issue - Uncaught PermissionDenied: network access

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?

Upvotes: 0

Views: 1572

Answers (3)

Yangshun Tay
Yangshun Tay

Reputation: 53169

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.

Upvotes: 3

Soham
Soham

Reputation: 725

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.

Upvotes: 0

Parth Kharecha
Parth Kharecha

Reputation: 6503

--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

Upvotes: 0

Related Questions