权限

权限白名单

Deno 也提供了权限白名单。

这是一个通过白名单来限制文件系统访问的例子。

  1. $ deno run --allow-read=/usr https://deno.land/std/examples/cat.ts /etc/passwd
  2. error: Uncaught PermissionDenied: read access to "/etc/passwd", run again with the --allow-read flag
  3. $deno$/dispatch_json.ts:40:11
  4. at DenoError ($deno$/errors.ts:20:5)
  5. ...

你可以给 /etc 路径设置权限。

  1. $ deno run --allow-read=/etc https://deno.land/std/examples/cat.ts /etc/passwd

--allow-write--allow-read 的用法一样。

这是一个限制 host 的例子。

  1. const result = await fetch("https://deno.land/");
  1. $ deno run --allow-net=deno.land https://deno.land/std/examples/curl.ts https://deno.land/