Deno Permissions & Security Model
Intermediatev1.0.0
Master Deno's permission-based security model — configuring granular file, network, and environment access for secure-by-default TypeScript applications.
Content
Overview
Deno is secure by default — scripts run with zero permissions unless explicitly granted. This prevents supply chain attacks, accidental data exposure, and malicious code execution from dependencies.
Why This Matters
- -Zero trust — dependencies cannot access filesystem or network without permission
- -Supply chain safety — malicious packages cannot exfiltrate data
- -Principle of least privilege — grant only the access your app needs
- -Audit trail — permissions are visible in your run command
Permission Flags
| Flag | Access Granted | Example |
|---|---|---|
| `--allow-read` | Filesystem read | `--allow-read=./data,./config` |
| `--allow-write` | Filesystem write | `--allow-write=./output` |
| `--allow-net` | Network access | `--allow-net=api.example.com` |
| `--allow-env` | Environment variables | `--allow-env=DATABASE_URL,API_KEY` |
| `--allow-run` | Subprocess execution | `--allow-run=git,npm` |
| `--allow-ffi` | Foreign function interface | (use with caution) |
| `--allow-sys` | System information | `--allow-sys=hostname,osRelease` |
Step 1: Granular Permissions
Step 2: Configure in deno.json
Step 3: Runtime Permission Requests
Best Practices
- -Never use
--allow-allor-Ain production deployments - -Specify paths and hosts explicitly —
--allow-read=./datanot--allow-read - -List specific environment variables —
--allow-env=PORTnot--allow-env - -Document required permissions in README
- -Use
deno.jsontasks to define permission sets for different environments - -Audit third-party modules for permission requirements
Common Mistakes
- -Using
--allow-allfor convenience (defeats security model) - -Not scoping network access to specific hosts
- -Granting write access to the entire filesystem
- -Forgetting to include permissions when deploying to Deno Deploy
FAQ
Discussion
Loading comments...