| name | security-deployment |
| description | Secure and deploy Cloudflare Workers applications with secrets, least-privilege bindings, authz, tenant isolation, input validation, CORS, preview/prod separation, migrations, rollout, and rollback practices. Use before shipping Cloudflare code.
|
| compatibility | Cloudflare Workers TypeScript projects using Wrangler; verify current Cloudflare APIs, limits, and pricing before production use. |
| metadata | {"source":"Architecting on Cloudflare plus official Cloudflare Developer Platform docs","generated":"2026-04-28"} |
Security and Deployment
Use this skill before shipping a Cloudflare Worker or modifying production bindings.
Security stance
- Bindings are capabilities. Give each Worker only the bindings it needs.
- Keep secrets out of source control and
wrangler.jsonc.
- Authenticate at the Worker boundary; authorize inside every data/tool operation.
- Validate all request input, queue messages, workflow parameters, WebSocket messages, and AI tool calls.
- Include tenant ID in every multi-tenant data access path.
- Avoid arbitrary user-controlled outbound fetches unless SSRF risk is explicitly addressed.
Secrets and config
- Use
vars only for non-secret values.
- Use
wrangler secret put NAME or a secret binding for credentials.
- Rotate secrets through deployment runbooks.
- Do not echo secrets into logs, error responses, AI prompts, or queue messages.
Authz helper pattern
type Principal = { userId: string; tenantId: string; roles: string[] };
function requireTenant(principal: Principal, tenantId: string) {
if (principal.tenantId !== tenantId) {
throw new Response("Forbidden", { status: 403 });
}
}
CORS rules
- Do not use
* for credentialed APIs.
- Keep an allowlist of origins per environment.
- Return CORS headers consistently for preflight and actual responses.
- Validate auth even when CORS permits the origin.
Deployment checklist
Migration/deployment ordering
For schema changes:
- Expand: deploy additive schema.
- Deploy code that can read/write old and new shape.
- Backfill or migrate asynchronously.
- Switch reads to new shape.
- Contract: remove old columns/tables only after verification.
AI/tool security
- Treat model output as untrusted.
- Validate tool arguments generated by the model.
- Enforce authorization in tools, not prompts.
- Do not include secrets or unrelated tenant data in prompts.
- Require confirmation for destructive/expensive actions.
Anti-patterns
- One Worker has every binding because it is convenient.
- Preview environment points at production D1/R2/KV by accident.
- Authorization enforced only in the frontend.
- Queue consumers trust messages without schema validation.
- Raw internal errors are returned to users.