Granular flags vs prompt mode for Deno permissions with untrusted imports
0 reputation · 28 Jan 2021, 17:09 UTC
0 reputation · 28 Jan 2021, 17:09 UTC
Goal is to run a local Deno script that imports third-party modules while keeping host access limited to the principle of least privilege.
Deno is secure by default and requires explicit permission flags for file, network, and environment access. Granular flags such as --allow-read and --allow-net can restrict to specific paths or domains, but permission grants are process-wide and apply to the entire import tree. The runtime also supports a prompt-based interaction mode where permission requests are presented at execution time.
The unresolved decision is whether to rely on startup granular flags for a predictable permission surface, or to use prompt mode to approve requests interactively and avoid over-granting. Prompt mode may reduce upfront specification but can introduce repeated interactions for modules with many accesses.
Can prompt mode be used without granting a blanket permission to all imports in the process? Does combining startup granular flags with prompt mode create duplicate or conflicting requests? Which approach preserves least privilege when the script’s dependency graph includes untrusted code?
35775 reputation · 29 Jan 2021, 03:32 UTC
Prompt mode can be used without granting a blanket permission to all imports. When you start Deno with specific granular flags (e.g. --allow-read=./src, --allow-net=api.example.com) and also enable --prompt, the runtime will only prompt for permissions that are not already covered by those flags. The final permission set is the union of flag‑granted and prompt‑granted rights, so there is no conflict—only possible duplicate prompts for the same capability.
deno run --allow-read=./data --allow-net=trusted.example.com --prompt script.ts.--allow-read=* or --allow-net=*; they defeat the least‑privilege goal regardless of prompt usage.# 1. Create a test module that reads outside the allowed directory
# file: ./mod.ts
export async function leak() {
const data = await Deno.readTextFile('/etc/passwd');
console.log(data.slice(0, 20));
}
# 2. Main script imports the module
# file: ./main.ts
import { leak } from './mod.ts';
await leak();
# 3. Run with a narrow flag and prompt mode (Deno ≥1.28)
denon run --allow-read=./data --prompt main.ts
You should see a prompt only for /etc/passwd. Granting it adds that single path to the process permission set; the original ./data flag remains unchanged.
What Deno version are you running? Fine‑grained prompts require ≥ 1.28; older releases fall back to a single “allow all” prompt.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.