Skip to content

docs(security): rate limiting must count in a shared store across instances - #536

Merged
addyosmani merged 1 commit into
addyosmani:mainfrom
CahidArda:docs/security-shared-store-rate-limiting
Sep 3, 2026
Merged

addyosmani merged 1 commit into
addyosmani:mainfrom
CahidArda:docs/security-shared-store-rate-limiting

Conversation

@CahidArda

Copy link
Copy Markdown

What

## Rate Limiting in security-and-hardening is a single express-rate-limit snippet with no prose. express-rate-limit counts in process memory by default, so the snippet as written enforces max × instances behind a load balancer and effectively nothing on serverless/edge, where each invocation can start from zero. The auth limiter (10 attempts / 15 min) is exactly the control that brute-force attackers spread across instances.

This adds one paragraph naming the failure mode and the fix (a shared store — Redis via rate-limit-redis — or an HTTP-based limiter for runtimes without a long-lived TCP connection), a short @upstash/ratelimit example for the auth endpoint, and matching one-line updates to the existing Red Flags and Verification entries.

Why here, and why not a new skill

  • The skill already owns rate limiting: STRIDE row "Denial of service → Rate limiting", the "Modifying rate limiting or throttling" Ask-First rule, checklist item "Login has rate limiting", Red Flag "No rate limiting on authentication endpoints", Verification "Rate limiting active on auth endpoints". None of them say the counter has to be shared, so an agent following the skill can add a limiter that passes every checkbox and does not work in production.
  • references/security-checklist.md L41 has the same gap ("Rate limiting on login endpoint (≤10 attempts per 15 minutes)").
  • Focused edit per CONTRIBUTING "Modifying Existing Skills"; no new directory, no frontmatter change, no routing surface added.

Disclosure

I work at Upstash, which makes @upstash/ratelimit. The paragraph leads with the vendor-neutral fix (store + rate-limit-redis) and the example is there because an HTTP-based limiter is the only option on edge runtimes; if you would rather keep the file free of a named product, I'm happy to drop the second code block and keep the prose, or swap the example for rate-limit-redis.

Pre-flight (per CONTRIBUTING)

Scope and size

One file. Frontmatter description unchanged. The file was at 499 lines and this takes it to 513 (or 508 if the second express block is folded into the shared-store example, which I can do on request). The 500-line note in skill-anatomy.md is a guideline rather than a CI rule, but flagging it so you can decide.

Verification

  • node scripts/validate-skills.js → 25 skills checked, 0 errors, 0 warnings
  • node scripts/run-evals.js --min-rank1 80 → 136 checks passed, rank-1 86% (72/84) — unchanged from main (description untouched)
  • node scripts/validate-reference-links.js → 25 skills checked, 0 errors
  • git diff --check → clean
  • Snippet checked against @upstash/ratelimit 2.0.8 / @upstash/redis 1.38.3 (Redis.fromEnv(), Ratelimit.slidingWindow(10, '15 m'), limit() → { success }).

@addyosmani addyosmani left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct and worth stating. A per-instance rate-limit counter silently fails the moment you run more than one instance, so 'count in a shared store for distributed setups' is the right addition. Small, verified clean. Approving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants