1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-12 17:09:00 -05:00
denoland-deno/docs/getting_started/permissions.md

49 lines
1.1 KiB
Markdown
Raw Normal View History

2020-05-06 18:21:13 -04:00
## Permissions
<!-- TODO(lucacasonato): what are permissions -->
<!-- TODO(lucacasonato): description of all permissions -->
### Permissions whitelist
Deno also allows you to control the granularity of permissions with whitelists.
2020-05-06 18:21:13 -04:00
This example restricts file system access by whitelisting only the `/usr`
directory:
2020-05-06 18:21:13 -04:00
```shell
$ deno run --allow-read=/usr https://deno.land/std/examples/cat.ts /etc/passwd
error: Uncaught PermissionDenied: read access to "/etc/passwd", run again with the --allow-read flag
► $deno$/dispatch_json.ts:40:11
at DenoError ($deno$/errors.ts:20:5)
...
```
Try it out again with the correct permissions by whitelisting `/etc` instead:
2020-05-06 18:21:13 -04:00
```shell
$ deno run --allow-read=/etc https://deno.land/std/examples/cat.ts /etc/passwd
```
`--allow-write` works the same as `--allow-read`.
2020-05-06 18:21:13 -04:00
2020-05-21 06:54:09 -04:00
### Network access:
_fetch.ts_:
2020-05-06 18:21:13 -04:00
```ts
const result = await fetch("https://deno.land/");
```
2020-05-21 06:54:09 -04:00
This is an example on how to whitelist hosts/urls:
```shell
$ deno run --allow-net=github.com,deno.land fetch.ts
```
Allow net calls to any host/url:
2020-05-06 18:21:13 -04:00
```shell
2020-05-21 06:54:09 -04:00
$ deno run --allow-net fetch.ts
2020-05-06 18:21:13 -04:00
```