Bird
Raised Fist0
Denoframework

Granular permission scoping in Deno - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is granular permission scoping in Deno?
It means giving a program only the exact permissions it needs, like access to specific files or network addresses, instead of all permissions. This keeps programs safer.
Click to reveal answer
beginner
How do you allow read access only to a specific file in Deno?
Use the flag --allow-read=path/to/file when running the program. This lets the program read only that file, not others.
Click to reveal answer
beginner
Why is it better to use granular permissions instead of broad permissions?
Because it limits what a program can do, reducing risks if the program has bugs or is attacked. It’s like giving a key to only one room, not the whole house.
Click to reveal answer
intermediate
Which Deno flag allows network access only to a specific domain?
The flag --allow-net=example.com lets the program connect only to example.com, blocking other network access.
Click to reveal answer
beginner
What happens if you run a Deno program without any permission flags?
The program runs with no permissions. It cannot read files, write files, access the network, or run subprocesses unless you explicitly allow it.
Click to reveal answer
Which flag grants read access to the entire file system in Deno?
A--allow-read=/specific/path
B--allow-read
C--allow-net
D--allow-write
How do you restrict network access to only example.com in Deno?
A--allow-net=example.com
B--allow-net
C--allow-net=example.net
D--allow-read=example.com
What is the default permission level when running a Deno script without flags?
ANo permissions
BNetwork access only
CRead-only permissions
DFull permissions
Why should you use granular permission scoping?
ATo make the program run faster
BTo allow all features by default
CTo avoid writing permission flags
DTo reduce security risks by limiting access
Which flag allows writing only to a specific directory?
A--allow-read=/path/to/dir
B--allow-net=/path/to/dir
C--allow-write=/path/to/dir
D--allow-run=/path/to/dir
Explain how granular permission scoping improves security in Deno.
Think about giving keys to only some rooms instead of the whole house.
You got /4 concepts.
    Describe how to run a Deno script that can read only one file and connect only to one website.
    Combine file and network flags with specific paths or domains.
    You got /4 concepts.

      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