RealComposer

Cloudflare Workers Safe & Unsafe Practices

Direct Answer

Cloudflare Workers should read credentials from secret bindings set with wrangler secret put, never from plaintext vars in wrangler config. Keep handlers stateless between requests, use the Web Crypto API, and use ctx.waitUntil for background work.

Credentials & Where They Belong

Server only
Secret bindings

Encrypted and set with wrangler secret put or the dashboard.

Client safe
vars in wrangler config

Plaintext in source control. Use only for non-sensitive settings.

Safe Practices

  • Use secret bindings for credentials

    Secrets are encrypted at rest and hidden in the dashboard after creation.

  • Keep request state out of module scope

    Isolates are reused across requests, so global mutable state can leak data between users.

  • Use .dev.vars locally and gitignore it

    Local secrets stay off the repository.

Unsafe Practices

  • Putting secrets in vars in wrangler.jsonc

    They are committed to git and visible to anyone with repo access.

  • Caching per-user data in global variables

    Another request on the same isolate can read it.

  • Logging headers or bodies that contain tokens

    Workers Logs and tail sessions would retain the secrets.

The RealComposer Pattern

RealComposer runs every pipeline on Workers, decrypting vault secrets in memory per request with AES-256-GCM and never persisting them in global state or logs.

START BUILDING FREE

Frequently Asked Questions

Q:What is the difference between vars and secrets in Workers?

Vars are plaintext configuration in your wrangler file. Secrets are encrypted bindings that never appear in source control.

Related Concepts