Edge Platform
Secrets Store Demo
Read account-scoped secrets from Cloudflare Secrets Store in a Worker - centralized secrets without per-Worker vars
Read an account-scoped secret from Cloudflare Secrets Store without ever returning the full value - only status, length, a short preview, or a boolean match.
Features
GET /secret/status- whether configured, length, and 2-character previewGET /secret/verify?expected=- compare without logging or returning the secret
API Reference
GET /secret/status
Example Request
curl "https://your-worker.workers.dev/secret/status"Success Response (configured)
{
"configured": true,
"length": 12,
"preview": "ab***"
}Success Response (missing)
{
"configured": false
}GET /secret/verify
Compare a candidate value to the stored secret.
expected string (required)
Example Request
curl "https://your-worker.workers.dev/secret/verify?expected=my-secret-value"Success Response
{
"match": true
}Error Codes
400- Missing or emptyexpected(MISSING_PARAM)
Use Cases
- Learn Secrets Store Workers bindings safely
- Verify API keys without exposing secret values in responses
- Prototype account-scoped secret checks vs per-Worker secrets
- Teach secure secret handling patterns at the edge
Limitations
- Never returns the full secret value
- Requires a real Secrets Store
store_idand secret name - Bindings may need remote/dev account access locally
- Demo uses a single
API_KEYbinding only
Use in your project
Copy these files into an existing Worker. Prefer Deployment to try the full experiment first. Source: apps/experiments/secrets-store-demo.
DependenciesNoneBindingsSecrets StorePlatformWorkers runtime
import type { SecretsStoreSecret } from "../types/env";import type { SecretStatus } from "../types/secret";/** Never log or return the full secret. */export function previewSecret(value: string): string { if (value.length === 0) return "***"; if (value.length === 1) return `${value}***`; return `${value.slice(0, 2)}***`;}export async function readSecretStatus( binding: SecretsStoreSecret | undefined): Promise<SecretStatus> { if (!binding || typeof binding.get !== "function") { return { configured: false }; } try { const value = await binding.get(); if (typeof value !== "string") { return { configured: false }; } return { configured: true, length: value.length, preview: previewSecret(value), }; } catch { return { configured: false }; }}export async function verifySecret( binding: SecretsStoreSecret | undefined, expected: string): Promise<boolean> { if (!binding || typeof binding.get !== "function") { return false; } try { const value = await binding.get(); return value === expected; } catch { return false; }}Deployment
Configure Secrets Store
- Create a Secrets Store and a secret named
demo-api-key - Set
store_idinwrangler.jsonundersecrets_store_secretsfor bindingAPI_KEY
Test your deployment
curl "https://your-worker.workers.dev/secret/status"Local Development
cd apps/experiments/secrets-store-demo
npm install
npm run devcurl "http://localhost:8787/secret/status"Secrets Store bindings may require a remote/dev account; unit tests mock API_KEY.get.
Configuration
wrangler.json declares:
- Secrets Store secret binding
API_KEYwithstore_idandsecret_name: "demo-api-key"
Cloudflare Features Used
- Workers - Edge compute runtime
- Secrets Store - Account-scoped secrets