Challenge - 5 Problems
Deno Permission Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat is the output when running this Deno script with limited permissions?
Consider this Deno script that tries to read a file and access the network. What will it output if run with
--allow-read=./data but without network permissions?Deno
import { readTextFile } from "https://deno.land/std/fs/mod.ts"; async function main() { try { const content = await readTextFile("./data/info.txt"); console.log("File content:", content); } catch (e) { console.log("Read error:", e.message); } try { const response = await fetch("https://example.com"); console.log("Network response status:", response.status); } catch (e) { console.log("Fetch error:", e.message); } } main();
Attempts:
2 left
💡 Hint
Think about which permissions are granted and which are missing.
✗ Incorrect
The script has permission to read files in ./data, so reading info.txt succeeds. But it lacks network permission, so fetch throws a permission error.
📝 Syntax
intermediateWhich Deno permission flag syntax correctly grants read access only to the 'logs' directory?
Select the correct command line flag to run a Deno script with read permission limited to the 'logs' directory.
Attempts:
2 left
💡 Hint
Deno uses glob patterns for directory permission scoping.
✗ Incorrect
The correct syntax uses a glob pattern with a wildcard to specify all files inside the 'logs' directory: --allow-read=logs/*
🔧 Debug
advancedWhy does this Deno script fail to write a file despite using --allow-write?
This script tries to write to './output/result.txt' but fails with a permission error. The script is run with
deno run --allow-write=./output/data. Why?Deno
import { writeTextFile } from "https://deno.land/std/fs/mod.ts"; await writeTextFile("./output/result.txt", "Hello World");
Attempts:
2 left
💡 Hint
Check the exact path allowed by the permission flag.
✗ Incorrect
The permission flag limits write access to './output/data' directory only. Writing to './output/result.txt' is outside that scope, causing a permission error.
❓ state_output
advancedWhat is the output of this Deno script with combined scoped permissions?
Given this script and running with
--allow-read=./config --allow-net=example.com, what will it output?Deno
async function main() { try { const data = await Deno.readTextFile("./config/settings.json"); console.log("Config loaded"); } catch { console.log("Failed to load config"); } try { const res = await fetch("https://example.com/api"); console.log("API status", res.status); } catch { console.log("API fetch failed"); } try { const res2 = await fetch("https://deno.land/std"); console.log("Deno.land status", res2.status); } catch { console.log("Deno.land fetch failed"); } } main();
Attempts:
2 left
💡 Hint
Check which URLs and files are allowed by the scoped permissions.
✗ Incorrect
The script can read './config/settings.json' and fetch from 'example.com' but not from 'deno.land'. So the first two try blocks succeed, the last fails.
🧠 Conceptual
expertWhich statement best describes Deno's granular permission scoping behavior?
Select the most accurate description of how Deno handles granular permission scoping.
Attempts:
2 left
💡 Hint
Think about how Deno controls access to files and network resources.
✗ Incorrect
Deno enforces security by requiring explicit permission flags for file, network, environment, and other resources. These flags can be scoped to specific paths or hosts to limit access.
