What are capabilities?
A capability is an unforgeable reference to a resource that grants the holder permission to access that resource. In workerd, capabilities are expressed as bindings in the worker configuration. Traditional access control uses:- Global namespaces: Access resources by name (URLs, file paths, database names)
- Ambient authority: Programs have implicit access to many resources
- Separate authorization: Permission checks happen at access time
- Explicit bindings: Resources must be explicitly granted
- Least privilege: Workers start with zero access
- Unforgeable references: Cannot fabricate access to resources
How capabilities work in workerd
Configuration defines capabilities
Capabilities are granted in the worker configuration:Workers receive capabilities as bindings
The worker receives capabilities through theenv parameter:
env (except through fetch() if globalOutbound is configured).
Preventing SSRF attacks
Server-Side Request Forgery (SSRF) is a common vulnerability where an attacker tricks a server into making requests to unintended destinations.Traditional approach (vulnerable)
Capability-based approach (secure)
Controlled internet access
If a worker needs internet access, grant it explicitly with restrictions:allow = ["public"]: Only publicly-routable IP addressesdeny = [...]: Explicitly block specific ranges- Private networks are blocked by default
Service isolation
Capabilities enable strong isolation between services.Example: Multi-tenant architecture
Composability through capabilities
Capabilities make workers highly composable.Parameter bindings
Define workers that require specific capabilities without specifying what they are:Testing with mock services
Easily inject mock services for testing:Capability types
workerd supports various types of capabilities:Service capabilities
Access to another worker or service:Storage capabilities
Access to persistent storage:Network capabilities
Access to network resources:Data capabilities
Configuration and secrets:Cryptographic capabilities
Cryptographic keys:extractable = false, the worker can use the key but cannot extract the raw key material - the key never leaves the runtime in plaintext.