new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Deno · all subjects

permissions & security

14 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

File system operations require permissions

File system operations in Deno require --allow-read and --allow-write permissions to be granted. The Deno runtime comes with various functions for working with files and directories.

Permission descriptor structure for read access

In runtime JavaScript, read permission for /foo/bar is represented as { name: "read", path: "/foo/bar" } as const.

Permission descriptor structure for write access

Global write permission is represented as { name: "write" } as const. Write permission to a specific path like foo/bar is represented as { name: "write", path: "foo/bar" } as const.

Permission descriptor structure for network access

Global net permission is represented as { name: "net" } as const. Net permission to a specific host and port like 127.0.0.1:8000 is represented as { name: "net", host: "127.0.0.1:8000" } as const.

Permission descriptor for high-resolution time

High-resolution time permission is represented as { name: "hrtime" } as const.

Query permissions at runtime with Deno.permissions.query

Use Deno.permissions.query(descriptor) to check if a permission is granted or not. Returns a PermissionStatus object with state ("granted", "prompt", or "denied") and partial (boolean). Synchronous counterpart Deno.permissions.querySync also exists.

Permission partial flag indicates exclusions

The partial flag in PermissionStatus indicates whether all subpaths have permissions granted. If --deny-read flag was used to restrict some filepaths, the result will contain partial: true describing that not all subpaths have permissions granted.

Permission states: granted, prompt, denied

A permission state can be either "granted", "prompt" or "denied". Permissions granted from the CLI query to { state: "granted" }. Those not granted query to { state: "prompt" } by default. The state "denied" is reserved for those explicitly refused.

Permission strength concept

A permission descriptor can be stronger than another. For example, { name: "read" } is stronger than { name: "read", path: "/foo" }, and { name: "net", host: "127.0.0.1" } is stronger than { name: "net", host: "127.0.0.1:8000" }. If a stronger permission queries to granted, then weaker permissions must too. If a weaker permission queries to denied, then stronger permissions must too.

Request permissions from user at runtime

Use Deno.permissions.request(descriptor) to request an ungranted permission from the user via CLI prompt. If the permission state is "prompt", a prompt appears asking to grant [y/n]. If granted, execution continues as if the permission was specified on CLI. If denied, the permission state downgrades to "denied". If state is already "granted" or "denied", request behaves like query and returns current status without prompting.

Revoke permissions at runtime

Use Deno.permissions.revoke(descriptor) to downgrade a permission from "granted" to "prompt". When revoking a permission that is partial to one granted on CLI, all CLI-granted permissions that are stronger than the revoked permission are also revoked. For example, if --allow-read=/foo is granted, revoking { name: "read", path: "/foo/bar" } will also revoke { name: "read", path: "/foo" }.

Permission revocation algorithm removes stronger permissions

Deno's permission revocation algorithm works by removing every element from the internal set of explicitly granted permission descriptors which is stronger than the argument permission descriptor. Deno does not allow "fragmented" permission states where some strong permission is granted with exclusions of weak permissions implied by it.

File system functions require permissions

File system functions like Deno.readTextFile, Deno.writeTextFile, and stream operations require --allow-read and/or --allow-write permissions to gain access to the file system.

Run file server with required permissions

To run a file server, use: deno run --allow-read=. --allow-net file-server.ts. The --allow-read=. flag permits reading files from the current directory, and --allow-net allows network access.

Give your agent this brain