/hardening:rate-limit-auditfrom hardening
Pre-launch gate that inventories every endpoint calling a paid API (LLM, email, SMS) and every auth endpoint, verifies a rate limiter exists, and actually tests it with scripted burst requests to confirm 429s fire. Use before launching a new product/feature, after adding an LLM-calling or auth route, or when asked to check rate limiting.
Ships in hardening. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A rate limiter that's configured but never tested is a rate limiter that might not actually work — wrong key extraction, wrong window, or a middleware ordering bug can all silently no-op it. This skill's job is proving the limit fires, not just confirming code that looks like a limiter exists. Required pre-launch on any endpoint that calls a paid API (Anthropic/Vercel AI SDK, email, SMS) and on all auth endpoints (login, password reset, OTP, signup) — per the house security rules.
Inventory every endpoint in scope — grep the App Router for candidates:
# Paid-API-calling routes
grep -rl "anthropic\|generateText\|streamText\|@ai-sdk" app/api
grep -rl "sendEmail\|resend\|sendgrid\|nodemailer" app/api
grep -rl "twilio\|sendSms" app/api
# Auth-adjacent routes
grep -rl "signIn\|signUp\|reset-password\|verify-otp\|magic-link" app/api
Also search files marked 'use server' — server actions call paid APIs and run auth flows too, and they're reachable by a direct POST, so they need the same limiter as the route handlers. Build a table: route path or server action, category (LLM / email / SMS / auth), current limiter (none / found), limiter library used.
Recommend defaults per endpoint class (starting points — tune to actual cost/abuse profile):
| Class | Suggested limit | Key |
|---|---|---|
| LLM chat/completion endpoint | 20 req / 10 min per user | user id (fallback IP if anonymous) |
| LLM endpoint, anonymous/free tier | 5 req / 10 min | IP |
| Email send (transactional) | 10 / hour per recipient | recipient email + IP |
| Email send (bulk/invite) | 5 / hour per sender | user id |
| SMS/OTP send | 3 / 10 min, 10 / day | phone number |
| Login attempt | 5 / 15 min | IP + email combo (lock the pair, not just the IP) |
| Password reset request | 3 / hour | email (return same response regardless of match) |
| Signup | 10 / hour | IP |
Verify implementation — for Next.js on Render (no built-in edge rate-limit infra like Vercel's), the common pattern is a Postgres- or Redis-backed limiter. The check and the increment must be one atomic statement — a count-then-insert lets concurrent requests all read the same count and all pass:
// lib/rate-limit.ts — fixed window over Postgres, one atomic upsert, no extra infra needed
// table: rate_limit(key text, window_start bigint, count int, primary key (key, window_start))
export async function checkRateLimit(key: string, limit: number, windowSeconds: number) {
const now = Math.floor(Date.now() / 1000);
const windowStart = now - (now % windowSeconds);
const [{ count }] = await prisma.$queryRaw<{ count: number }[]>`
INSERT INTO rate_limit (key, window_start, count) VALUES (${key}, ${windowStart}, 1)
ON CONFLICT (key, window_start) DO UPDATE SET count = rate_limit.count + 1
RETURNING count`;
return { allowed: count <= limit, retryAfter: windowStart + windowSeconds - now };
}
INSERT ... ON CONFLICT DO UPDATE guarantees an atomic insert-or-update outcome (PostgreSQL: INSERT). Delete expired windows on a schedule.
In the route handler:
const { allowed, retryAfter } = await checkRateLimit(`llm:${userId}`, 20, 600);
if (!allowed) {
return new Response('Too many requests', { status: 429, headers: { 'Retry-After': String(retryAfter) } });
}
A fixed window can admit up to 2x the limit at a boundary: limit requests at the end of one window plus limit at the start of the next. Upstash lists this as the fixed window's main weakness (Upstash Ratelimit: algorithms); use a sliding window where that matters. If Redis (Upstash) is already in the stack for a given project, prefer it over the Postgres table for lower latency (@upstash/ratelimit with Ratelimit.slidingWindow(limit, "10 m")) — but don't add a new Redis dependency solely for rate limiting on a low-traffic route.
Key extraction for IP-keyed limits — take the client IP from a header your own trusted proxy or host sets, as your host documents it, never the leftmost X-Forwarded-For value. The client can send its own X-Forwarded-For, and proxies append to it, so the leftmost entry is attacker-controlled; rotating it gives a fresh bucket on every request. MDN: security uses such as rate limiting "must only use IP addresses added by a trusted proxy" (MDN: X-Forwarded-For).
Actually test it with burst requests, sequential and concurrent — this is the non-negotiable step. Run it in bash, not zsh: export -f is a bash feature.
#!/usr/bin/env bash
URL=https://staging.example.com/api/chat
send() { curl -s -o /dev/null -w "%{http_code}\n" -X POST "$URL" \
-H "Authorization: Bearer $TEST_TOKEN" -H "Content-Type: application/json" -d '{"message":"test"}'; }
export -f send; export URL TEST_TOKEN
# Sequential: 25 requests in quick succession against a limit of 20/10min
for i in $(seq 1 25); do send; done | sort | uniq -c
# Concurrent: 25 at once, after the window resets — catches count-then-insert races
seq 1 25 | xargs -P 25 -I{} bash -c send | sort | uniq -c
Expected output for each run: 20 lines of 200, 5 lines of 429. More than 40 200s (2x the limit) means the limiter is not working — investigate before shipping, don't assume the code is correct because it compiles. Between 21 and 40 200s, rerun and check whether the run crossed a window boundary: a fixed window can admit up to 2x the limit there (see above). If a run that stays inside one window still lets more than 20 through, the limiter is broken. A sequential run alone can pass while the concurrent run shows the race.
Test the auth-lockout case specifically — brute-force a login endpoint with a wrong password 6+ times, confirm the 6th+ attempt returns 429 (or an account-lock message) rather than a normal "wrong password" 401 indistinguishable from the first attempt.
Document the limits in a short reference (README section or docs/rate-limits.md) so future endpoints get added consistently rather than each developer picking arbitrary numbers.
X-Forwarded-ForRetry-After header present on 429 responsesShow the user the inventory table (route / class / limiter present / tested), and the raw burst-test output (uniq -c counts of status codes, sequential and concurrent) for at least the two highest-risk routes. A limiter claimed without a burst-test result attached should be treated as unverified.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub stylusnexus/agent-plugins --plugin hardening12 skills in this plugin
/agent-tooling-reviewUse when connecting, auditing, or widening the permissions of tooling an AI agent can call: MCP servers, plugins, skills, database or GitHub connections, API tokens issued to an agent, or an agent that will run unattended (scheduled, looped, event-triggered, background, CI). Triggers: a new MCP or plugin is about to be added, an agent needs write access it did not have, a connection points at production, an unattended job is being set up, or a tool's description changed after approval./auth-hardeningNextAuth v5 security audit and hardening checklist — session/cookie config, CSRF, OAuth scopes, per-route role checks, password-reset/OTP rate limits, secret rotation, session invalidation on privilege change. Use when adding auth to a new product, auditing an existing NextAuth v5 app, or reviewing any PR that touches session/role/permission code./exposure-scanScan installed packages against bumblebee threat-intelligence exposure catalogs to detect known-compromised dependency releases from supply-chain campaigns. Use when checking for compromised packages, running a supply-chain or dependency security scan, auditing the machine after a reported npm/PyPI/Go/gem/extension compromise, or refreshing threat-intel catalogs./legal-docsDraft or review the customer-facing legal documents of a small SaaS - Terms of Service, Privacy Policy, refund policy, and acceptable use policy - in plain English, with placeholders instead of invented facts, a check that every claim matches what the product actually does, and a not-legal-advice notice on every draft. Use when asked to "write terms", "draft a privacy policy", "update our ToS", "write a refund policy", or before launching a product or feature that changes what data is collected or how billing works./llm-app-securityUse when a product feature sends untrusted content to a language model or lets a model call tools, write data, send messages, or render output to other users. Triggers: a new chat, RAG, summarization, agent, or tool-calling feature; a model that reads web pages, documents, emails, tickets, or other users' text; a 'can prompt injection reach this' question; a pre-launch review of anything with an LLM in the request path; or an incident where a model did something nobody asked for./privacy-auditData inventory and privacy audit for a product — enumerate exactly what user data is collected and where it lands (Neon/Supabase tables, logs, PostHog, Stripe, email provider, Better Stack/Sentry), check alignment with the privacy policy, verify GDPR export/delete paths exist, and grep for PII leaking into logs or API responses. Use when asked to "audit privacy," "check what data we collect," before a launch, or after adding a new data-collecting feature (signup field, analytics event, webhook).Other plugins' skills for the same job