cloudflare-workers-security

cloudflare-workers-security is a skill for Claude Code, Codex from secondsky/claude-skills. It costs 45 tokens per session (1,785 once invoked), scanned A, original, MIT.

A guide to securing Cloudflare Workers and their APIs with authentication, input validation, CORS, rate limiting, and security headers. CORS controls which websites may call an API, while rate limiting restricts excessive requests.

In plain words
What is it for?
Use it to protect APIs, verify JWTs or API keys, validate request data, configure CORS, limit traffic, and store secrets safely.
Why use it?
It helps prevent unauthorized access, abusive traffic, unsafe input, and common browser-based attacks.

Skill for Claude CodeCodex

Part of the cloudflare-workers plugin — 10 skills, 5 commands, 3 agents shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/secondsky/claude-skills/cloudflare-workers-security
Any agent
npx skills add secondsky/claude-skills --skill cloudflare-workers-security
Clone the repo
git clone --depth 1 https://github.com/secondsky/claude-skills

Made for: Claude Code, Codex.

Or install cloudflare-workers, the plugin that ships this one along with the rest of its 10 skills, 5 commands, 3 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cloudflare-workers-security

README.md
[![agentmods](https://agentmods.dev/badge/skills/secondsky/claude-skills/cloudflare-workers-security.svg)](https://agentmods.dev/skills/secondsky/claude-skills/cloudflare-workers-security)
Your own site
<a href="https://agentmods.dev/skills/secondsky/claude-skills/cloudflare-workers-security"><img src="https://agentmods.dev/badge/skills/secondsky/claude-skills/cloudflare-workers-security.svg" alt="Measured on agentmods" height="20"></a>
Per session 45 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,785 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00045 $0.01785
Opus 5 $0.00023 $0.00892
Sonnet 5 $0.00009 $0.00357
Haiku 4.5 $0.00005 $0.00178

Measured 2d ago against content hash 500f73b5d2ec, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

cloudflare-workers-security scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

The scan reads SKILL.md. This mod also ships 5 executable files (scripts/security-audit.sh, templates/auth-middleware.ts, templates/cors-handler.ts, …), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/cloudflare-workers/skills/cloudflare-workers-security/SKILL.md · 232 lines

How it starts

The opening of the file, as written. The whole thing — 232 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Cloudflare Workers Security

Comprehensive security patterns for protecting Workers and APIs.

Quick Security Checklist

// 1. Validate all input
const validated = schema.parse(await request.json());

// 2. Authenticate requests
const user = await verifyToken(request.headers.get('Authorization'));
if (!user) return new Response('Unauthorized', { status: 401 });

// 3. Rate limit
const limited = await rateLimiter.check(clientIP);
if (!limited.allowed) return new Response('Too Many Requests', { status: 429 });

// 4. Add security headers
response.headers.set('X-Content-Type-Options', 'nosniff');
response.headers.set('X-Frame-Options', 'DENY');

// 5. Use HTTPS-only cookies
headers.set('Set-Cookie', 'session=xxx; Secure; HttpOnly; SameSite=Strict');

Critical Rules

  1. Never trust client input - Validate and sanitize everything
  2. Use secure secrets - Store in Wrangler secrets, never in code
  3. Implement rate limiting - Protect against abuse
  4. Set security headers - Prevent common attacks
  5. Use CORS properly - Don't use * in production

Top 10 Security Errors

Vulnerability Symptom Prevention
Missing auth Unauthorized access Verify tokens on every request
SQL injection Data breach Use parameterized queries with D1
XSS Script injection Sanitize output, set CSP
CORS misconfiguration Blocked requests or open access Configure specific origins
Secrets in code Exposed credentials Use wrangler secret
Missing rate limits DoS vulnerability Implement per-IP limits
Weak tokens Session hijacking Use crypto.subtle for signing
Missing HTTPS Data interception Enforce HTTPS redirects
Insecure headers Clickjacking, MIME attacks Set security headers
Excessive permissions Blast radius Principle of least privilege

Authentication Patterns

JWT Verification

async function verifyJWT(token: string, secret: string): Promise<{ valid: boolean; payload?: unknown }> {
  try {
    const [headerB64, payloadB64, signatureB64] = token.split('.');

    // Verify signature
    const key = await crypto.subtle.importKey(
      'raw',
      new TextEncoder().encode(secret),
      { name: 'HMAC', hash: 'SHA-256' },
      false,
      ['verify']
    );

    const signature = Uint8Array.from(atob(signatureB64.replace(/-/g, '+').replace(/_/g, '/')), c => c.charCodeAt(0));
    const data = new TextEncoder().encode(`${headerB64}.${payloadB64}`);

    const valid = await crypto.subtle.verify('HMAC', key, signature, data);
    if (!valid) return { valid: false };

    // Decode payload
    const payload = JSON.parse(atob(payloadB64.replace(/-/g, '+').replace(/_/g, '/')));

    // Check expiration
    if (payload.exp && Date.now() / 1000 > payload.exp) {
      return { valid: false };
    }

    return { valid: true, payload };
  } catch {
    return { valid: false };
  }
}

Read the full file on GitHub · 232 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 232 lines · 45 tokens per session scan A 500f73b5d2ec

Subscribe to this mod's changes

cloudflare-workers-security is a skill published in the GitHub repository secondsky/claude-skills (214 stars, last pushed 2d ago), licensed MIT. It adds 45 tokens to every session and 1,785 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.