Bird
Raised Fist0
Denoframework~10 mins

Granular permission scoping in Deno - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check read permission for a file.

Deno
const status = await Deno.permissions.query({ name: [1] });
Drag options to blanks, or click blank then click option'
A"env"
B"write"
C"read"
D"net"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "write" instead of "read" will check the wrong permission.
Forgetting the quotes around the permission name causes syntax errors.
2fill in blank
medium

Complete the code to request network access permission for example.com.

Deno
const status = await Deno.permissions.request({ name: "net", host: [1] });
Drag options to blanks, or click blank then click option'
A"example.com"
B"http://example.com"
C"https://example.com"
D"example"
Attempts:
3 left
💡 Hint
Common Mistakes
Including the protocol like "https://" causes the permission request to fail.
Using incomplete host names like "example" is not valid.
3fill in blank
hard

Fix the error in the code to revoke write permission correctly.

Deno
const status = await Deno.permissions.[1]({ name: "write" });
Drag options to blanks, or click blank then click option'
Arevoke
Bquery
Crequest
Dgrant
Attempts:
3 left
💡 Hint
Common Mistakes
Using request instead of revoke does not remove permissions.
Using query only checks permission status.
4fill in blank
hard

Fill both blanks to check if the program has read permission for a specific file path.

Deno
const status = await Deno.permissions.query({ name: [1], path: [2] });
Drag options to blanks, or click blank then click option'
A"read"
B"write"
C"/home/user/data.txt"
D"/var/log/syslog"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "write" instead of "read" checks the wrong permission.
Providing an invalid or missing path causes the check to fail.
5fill in blank
hard

Fill all three blanks to request environment variable read permission for the variable 'HOME'.

Deno
const status = await Deno.permissions.request({ name: [1], variable: [2], [3]: true });
Drag options to blanks, or click blank then click option'
A"env"
B"HOME"
Crecursive
Dread
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like "recursive" instead of "read".
Forgetting to set the read flag to true.

Practice

(1/5)
1. What does the --allow-read=./data flag do when running a Deno script?
easy
A. Allows the script to read any file on the system
B. Allows the script to read files only inside the ./data directory
C. Blocks all file reading operations
D. Allows the script to write files inside the ./data directory

Solution

  1. Step 1: Understand the --allow-read flag

    The --allow-read flag grants permission to read files. When given a path, it limits reading to that path.
  2. Step 2: Analyze the given path ./data

    Since the flag is --allow-read=./data, the script can only read files inside the ./data directory, not outside.
  3. Final Answer:

    Allows the script to read files only inside the ./data directory -> Option B
  4. Quick Check:

    --allow-read=path limits read to that path [OK]
Hint: Remember: --allow-read=path restricts reading to that path only [OK]
Common Mistakes:
  • Thinking it allows reading all files
  • Confusing read permission with write permission
  • Assuming it blocks all reading
2. Which of the following is the correct syntax to allow network access only to example.com in Deno?
easy
A. deno run --allow-net=example.com script.ts
B. deno run --allow-net example.com script.ts
C. deno run --allow-net:example.com script.ts
D. deno run --allow-net[example.com] script.ts

Solution

  1. Step 1: Recall the correct flag format for network permission

    The correct syntax to allow network access to a specific host is --allow-net=host.
  2. Step 2: Match the options with the correct syntax

    deno run --allow-net=example.com script.ts uses --allow-net=example.com, which is correct. Other options use incorrect separators or missing equals sign.
  3. Final Answer:

    deno run --allow-net=example.com script.ts -> Option A
  4. Quick Check:

    Use --allow-net=host for specific network access [OK]
Hint: Use equals sign (=) to specify hosts in --allow-net flag [OK]
Common Mistakes:
  • Using space instead of equals sign
  • Using colon or brackets instead of equals
  • Omitting the host after --allow-net
3. Consider this command: deno run --allow-read=./files --allow-net=api.example.com script.ts. What will happen if script.ts tries to read ./files/data.txt and fetch from api.example.com?
medium
A. Both reading the file and fetching will fail
B. Reading the file will fail, fetching will succeed
C. Reading the file will succeed, fetching will fail
D. Both reading the file and fetching from the API will succeed

Solution

  1. Step 1: Check read permission for ./files/data.txt

    The flag --allow-read=./files allows reading any file inside ./files, so reading data.txt is allowed.
  2. Step 2: Check network permission for api.example.com

    The flag --allow-net=api.example.com allows network requests only to api.example.com, so fetching from that API is allowed.
  3. Final Answer:

    Both reading the file and fetching from the API will succeed -> Option D
  4. Quick Check:

    Permissions match actions, so both succeed [OK]
Hint: Match file path and host exactly with permission flags [OK]
Common Mistakes:
  • Assuming read permission covers all files
  • Assuming --allow-net allows all hosts
  • Confusing read and write permissions
4. You run deno run --allow-read=./data script.ts but your script tries to read ./config/settings.json and fails. What is the most likely cause?
medium
A. The script has no network permission
B. The script has no permission to write to ./config
C. The script has no permission to read outside the ./data directory
D. The script has a syntax error in reading files

Solution

  1. Step 1: Understand the --allow-read=./data scope

    This flag only allows reading files inside the ./data directory, not outside.
  2. Step 2: Analyze the attempted file path ./config/settings.json

    The script tries to read a file outside the allowed ./data directory, so permission is denied.
  3. Final Answer:

    The script has no permission to read outside the ./data directory -> Option C
  4. Quick Check:

    Permission scope limits file access [OK]
Hint: Check if file path is inside allowed read directory [OK]
Common Mistakes:
  • Confusing read and write permissions
  • Assuming network permission affects file reading
  • Blaming syntax errors for permission issues
5. You want to run a Deno script that reads files only from ./logs and ./configs directories and fetches data only from api.service.com and cdn.service.com. Which command correctly grants these permissions?
hard
A. deno run --allow-read=./logs,./configs --allow-net=api.service.com,cdn.service.com script.ts
B. deno run --allow-read=./logs --allow-read ./configs --allow-net=api.service.com --allow-net=cdn.service.com script.ts
C. deno run --allow-read=./logs ./configs --allow-net=api.service.com cdn.service.com script.ts
D. deno run --allow-read=./logs --allow-net=api.service.com,cdn.service.com script.ts

Solution

  1. Step 1: Understand how to specify multiple paths or hosts

    Deno allows multiple paths or hosts in a single flag separated by commas, e.g., --allow-read=path1,path2.
  2. Step 2: Analyze each option for correct syntax

    deno run --allow-read=./logs,./configs --allow-net=api.service.com,cdn.service.com script.ts correctly uses commas to list multiple directories and hosts in one flag. deno run --allow-read=./logs --allow-read ./configs --allow-net=api.service.com --allow-net=cdn.service.com script.ts has incorrect syntax (missing = after second --allow-read). Options C and D have incorrect syntax or missing permissions.
  3. Final Answer:

    deno run --allow-read=./logs,./configs --allow-net=api.service.com,cdn.service.com script.ts -> Option A
  4. Quick Check:

    Use commas to list multiple paths or hosts in one flag [OK]
Hint: Use commas to separate multiple paths or hosts in permission flags [OK]
Common Mistakes:
  • Missing the equals sign (=) in permission flags
  • Using spaces instead of commas to separate paths
  • Omitting one of the required permissions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard