← Blog

Claude skill rate limit implementation security — SA-SKL-RATELIMIT2

Rate limiting implementation in MCP skills produces failure modes that go beyond simply missing a limit entirely. SkillAudit finds four implementation-level gaps that cause correctly-intended rate limits to fail in production: keying on the IP address alone blocks all users sharing a NAT gateway when one abuser hits the limit, in-memory counters reset to zero on every process restart giving attackers a burst window after every crash or deploy, rate limit response headers inadvertently expose internal AI call counts enabling competitive intelligence, and fixed-window counters allow the full quota to be exhausted in the first second of each window. SA-SKL-RATELIMIT2-001 through RATELIMIT2-004 cover each with the failure mode and Redis-backed fix.

By SkillAudit  |  5 Nov 2026

Rate limit implementation gaps vs. missing limits

SA-SKL-RATELIMIT covers the most common case: rate limiting not applied at all to AI-backed endpoints, allowing loop attacks that exhaust Claude API credits in minutes. SA-SKL-RATELIMIT2 covers a different failure class: rate limits that exist in code and appear to work during development but fail under production conditions or under deliberate adversarial pressure. The four patterns here are operational vulnerabilities — they require understanding of NAT gateway behavior, Node.js process model, CDN header forwarding, and window algorithm theory. They are more subtle than a missing middleware call and more common in skills that have already added basic rate limiting.

SA-SKL-RATELIMIT2 in scope: RATELIMIT2-001 (IP-only key blocks NAT users), RATELIMIT2-002 (in-memory counter lost on restart), RATELIMIT2-003 (rate limit header leaks AI call count), RATELIMIT2-004 (fixed-window burst in first second). These complement SA-SKL-RATELIMIT which covers missing limits, X-Forwarded-For header bypass, and timing-based account enumeration.

RATELIMIT2-001 — Rate limit key on IP only blocks NAT users

IP-based rate limiting is a reasonable starting point, but keying on the IP address alone creates a denial-of-service vulnerability against users sharing a NAT gateway. A corporate office, university campus, or cloud provider egress point may route thousands of users through a single public IP address. When one user (or an attacker targeting co-located users) hits the rate limit, all other users on the same NAT are blocked. For authenticated endpoints, the rate limit key should be (userId, endpoint) — the user is identified by their session, not their network address. For unauthenticated endpoints where IP is the only available identifier, the limit should be generous enough to tolerate NAT collisions, with anomaly detection used for abuse rather than a hard per-IP limit.

// VULNERABLE: rate limit key on IP address alone
const rateLimit = require('express-rate-limit');

const auditRateLimit = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 10, // 10 requests per 15 minutes per IP
  keyGenerator: (req) => req.ip, // ← IP-only: blocks all 1000 users on a corporate NAT
  message: { error: 'Too many audit requests' },
});

app.post('/api/audits', requireAuth, auditRateLimit, async (req, res) => {
  // One user at company.com exhausting 10 audits blocks all colleagues for 15 min
});
// FIXED: rate limit key includes userId for authenticated endpoints
const rateLimit = require('express-rate-limit');
const RedisStore = require('rate-limit-redis');
const redis = require('./lib/redis');

const auditRateLimit = rateLimit({
  windowMs: 15 * 60 * 1000,
  max: 10,
  // FIXED: key on userId for authenticated endpoints — NAT sharing doesn't block others
  keyGenerator: (req) => {
    // For authenticated routes: key on user ID
    if (req.session?.userId) return `audit:user:${req.session.userId}`;
    // For unauthenticated routes: key on IP with generous limit
    return `audit:ip:${req.ip}`;
  },
  store: new RedisStore({ sendCommand: (...args) => redis.sendCommand(args) }),
  standardHeaders: true,
  legacyHeaders: false,
});

// Plan-based rate limits for different tiers
const planLimits = { free: 3, pro: 100, team: 500 }; // Per month
app.post('/api/audits', requireAuth, async (req, res, next) => {
  const monthlyCount = await db.audits.countThisMonth(req.session.userId);
  const limit = planLimits[req.user.plan] || planLimits.free;
  if (monthlyCount >= limit) {
    return res.status(429).json({ error: 'Monthly audit limit reached', limit, used: monthlyCount });
  }
  next();
});
HIGH
SA-SKL-RATELIMIT2-001 — MCP skill rate limit middleware uses req.ip as the sole rate limit key on authenticated endpoints; a single abuser or attacker on a shared NAT gateway (corporate network, cloud egress) exhaust the per-IP limit and block all other users sharing the same public IP address, creating an inadvertent denial of service. Fix: use req.session.userId as the rate limit key for authenticated endpoints; use a Redis-backed store to persist limits across process restarts (see RATELIMIT2-002). Detection: SkillAudit flags keyGenerator functions in express-rate-limit that return only req.ip in handlers that also call requireAuth or similar authentication middleware.

RATELIMIT2-002 — In-memory rate limit counter lost on process restart

The default express-rate-limit store is an in-process Map. When the Node.js process restarts — due to a crash, a deploy, an OOM kill, or a PM2/Docker restart — all rate limit counters reset to zero. An attacker who wants to bypass a rate limit can deliberately trigger a process restart (via a crash-inducing request, an OOM attack, or if they have deploy access) and immediately send their burst of requests before the counter repopulates. In production, rate limit state must be stored in Redis with a TTL matching the rate limit window, so counters survive process restarts and are shared across multiple Node.js worker processes.

// VULNERABLE: default in-memory store — counters reset on process restart
const rateLimit = require('express-rate-limit');

const scanLimit = rateLimit({
  windowMs: 60 * 60 * 1000, // 1 hour window
  max: 5, // 5 scans per hour per user
  // No 'store' option — uses MemoryStore by default
  // MemoryStore resets on every process restart, deploy, or crash
  keyGenerator: (req) => req.session?.userId || req.ip,
});
// FIXED: Redis store persists counters across restarts and worker processes
const rateLimit = require('express-rate-limit');
const { RedisStore } = require('rate-limit-redis');
const { createClient } = require('redis');

const redis = createClient({ url: process.env.REDIS_URL });
redis.connect(); // Connect once, reuse across requests

const scanLimit = rateLimit({
  windowMs: 60 * 60 * 1000,
  max: 5,
  keyGenerator: (req) => `scan:${req.session?.userId || req.ip}`,
  store: new RedisStore({
    // FIXED: Redis store — counters persist across process restarts
    sendCommand: (...args) => redis.sendCommand(args),
    prefix: 'rl:', // Namespace in Redis
    // TTL is set automatically to windowMs/1000 seconds by rate-limit-redis
  }),
  standardHeaders: true,
  legacyHeaders: false,
  handler: (req, res) => {
    res.status(429).json({
      error: 'Rate limit exceeded',
      retryAfter: Math.ceil(req.rateLimit.resetTime / 1000),
    });
  },
});
HIGH
SA-SKL-RATELIMIT2-002 — MCP skill rate limit middleware uses the default MemoryStore (in-process Map); rate limit counters reset to zero on every Node.js process restart, deploy, or OOM kill, creating a burst window after each restart during which an attacker can submit the full quota immediately; in multi-worker configurations, each worker has its own counter, multiplying the effective limit by the worker count. Fix: use rate-limit-redis with a shared Redis instance; set prefix and ensure the Redis TTL matches windowMs; test with redis-cli keys rl:* to verify counters persist across restarts. Detection: SkillAudit flags express-rate-limit configurations that do not include a store option on endpoints that call an external AI or paid API.

RATELIMIT2-003 — Rate limit headers expose internal AI call count

The X-RateLimit-Remaining response header reports how many requests remain in the current rate limit window. For most endpoints this is benign, but for AI-backed audit endpoints where each user request triggers multiple internal Anthropic API calls, the remaining count reveals internal implementation details. If the free plan allows 3 audits per month and X-RateLimit-Remaining: 2 is returned after the first audit, a competitor or attacker learns that the endpoint rate limits at 3 — but if the remaining count decrements by a different amount on a "deep audit" endpoint (X-RateLimit-Remaining: 7 drops to X-RateLimit-Remaining: 2 after one request, revealing 5 internal Anthropic calls per deep audit), the headers expose billing rates and implementation complexity. Rate limit headers should return generic tier limits, not per-call internal counts.

// VULNERABLE: X-RateLimit-Remaining reflects exact internal AI call count
const rateLimit = require('express-rate-limit');

// Deep audit costs 5 Anthropic API calls; standard audit costs 1
// The rate limit window is 50 Anthropic calls per hour per user
const claudeApiRateLimit = rateLimit({
  windowMs: 60 * 60 * 1000,
  max: 50, // 50 Anthropic API calls per hour (internal resource limit)
  keyGenerator: (req) => `claude:${req.session.userId}`,
  standardHeaders: true, // Sends X-RateLimit-Remaining: N
  // ← Competitor observes: standard audit decrements by 1, deep audit by 5
  //   Reveals internal AI call count per audit type
});
// FIXED: rate limit on user-visible quota (audits/month), not internal API calls
// Internal API call budgets managed separately without header exposure

// User-facing rate limit: audits per plan tier (this is what users see)
const userAuditLimit = rateLimit({
  windowMs: 30 * 24 * 60 * 60 * 1000, // 30 days
  max: (req) => {
    const planLimits = { free: 3, pro: 1000, team: 5000 };
    return planLimits[req.user?.plan] ?? planLimits.free;
  },
  keyGenerator: (req) => `audit_monthly:${req.session.userId}`,
  store: redisStore,
  standardHeaders: true, // X-RateLimit-Remaining reflects audits remaining — no internal detail
  legacyHeaders: false,
});

// Internal API budget: tracked separately, never exposed in headers
async function checkApiCallBudget(userId, estimatedCalls) {
  const hourlyUsed = await redis.incrby(`api_budget:${userId}:${hour()}`, estimatedCalls);
  await redis.expire(`api_budget:${userId}:${hour()}`, 3600);
  if (hourlyUsed > HOURLY_API_CALL_LIMIT) throw new Error('API budget exceeded');
  // This internal counter is never sent in response headers
}
MEDIUM
SA-SKL-RATELIMIT2-003 — MCP skill rate limit middleware applies limits on internal Anthropic API call counts and exposes the counter via X-RateLimit-Remaining headers; different request types that trigger different numbers of internal AI calls cause the remaining count to decrement by varying amounts, revealing how many AI calls each endpoint type consumes to competitors and enumeration attacks. Fix: expose rate limits only on user-visible units (audits per month, scans per day); manage internal API call budgets in a separate Redis counter without header exposure; use a fixed max that reflects the user's plan tier, not the internal API call cost. Detection: SkillAudit flags rate limit configurations where the max option is set to a value that scales with internal AI or external API call counts rather than user-plan tier units.

RATELIMIT2-004 — Fixed-window burst in first second of window

Fixed-window rate limiting resets the counter at a fixed interval boundary — midnight UTC, the top of each hour, the start of each minute. An attacker who wants to maximize throughput sends all their requests in the last second before the boundary resets, then all their requests again in the first second after the reset, achieving double the stated rate limit in a two-second interval. With a 10-requests-per-minute limit, this enables 20 requests in 2 seconds — 10x the per-second rate. For AI-backed endpoints, this double-burst can trigger significant cost spikes. The fix is a sliding window algorithm (or token bucket) that considers the full window duration at any point in time, not a resetting counter.

// VULNERABLE: fixed-window counter — allows double-burst at window boundary
const rateLimit = require('express-rate-limit');

const scanLimit = rateLimit({
  windowMs: 60 * 1000, // 1-minute fixed window
  max: 10,             // 10 requests per window
  // Fixed window: counter resets at :00 seconds every minute
  // Attacker sends 10 requests at :59 and 10 requests at :00 → 20 requests in 2 seconds
  keyGenerator: (req) => `scan:${req.session.userId}`,
  store: redisStore,
});
// FIXED: sliding window via rate-limit-redis with 'sliding' window type
const rateLimit = require('express-rate-limit');
const { RedisStore } = require('rate-limit-redis');

const scanLimit = rateLimit({
  windowMs: 60 * 1000,
  max: 10,
  keyGenerator: (req) => `scan:${req.session.userId}`,
  store: new RedisStore({
    sendCommand: (...args) => redis.sendCommand(args),
    prefix: 'rl_slide:',
    // rate-limit-redis uses a sliding window by default via sorted sets:
    // ZADD rl_slide:userId timestamp timestamp
    // ZREMRANGEBYSCORE rl_slide:userId 0 (now - windowMs)
    // ZCARD rl_slide:userId → current count in rolling window
    // This prevents boundary double-bursts entirely
  }),
  standardHeaders: true,
  legacyHeaders: false,
});

// Alternative: token bucket for smooth rate enforcement
// npm install @upstash/ratelimit
// const { Ratelimit } = require('@upstash/ratelimit');
// const limiter = new Ratelimit({ redis: upstash, limiter: Ratelimit.tokenBucket(10, '1 m', 2) });
// tokenBucket(10, '1 m', 2): 10 req/min max, refills 2/min, burst capacity 2
MEDIUM
SA-SKL-RATELIMIT2-004 — MCP skill uses a fixed-window rate limit counter; an attacker sending the full quota at the end of one window and the full quota at the start of the next window achieves double the stated rate in a two-second interval; for AI-backed endpoints with per-request cost, this doubles the unprotected cost spike. Fix: use a sliding-window algorithm via rate-limit-redis sorted-set implementation or a token bucket via @upstash/ratelimit; a sliding window evaluates the count across the full window duration at any point in time, eliminating boundary double-bursts. Detection: SkillAudit flags express-rate-limit configurations on AI-backed endpoints that use the default fixed-window store without a sliding-window option.

SkillAudit detection summary — SA-SKL-RATELIMIT2

Pattern IDSeverityWhat SkillAudit flagsFix
RATELIMIT2-001HIGHkeyGenerator returning only req.ip in handlers that also call authentication middlewareKey on req.session.userId for authenticated endpoints
RATELIMIT2-002HIGHexpress-rate-limit without a store option on AI/paid-API endpointsrate-limit-redis store with shared Redis; verify persistence across restarts
RATELIMIT2-003MEDIUMmax option that scales with internal API call counts rather than user-plan tier unitsExpose rate limits in user-visible units; manage internal API budgets without header exposure
RATELIMIT2-004MEDIUMDefault fixed-window store on AI-backed endpoints without sliding-window optionSliding window via rate-limit-redis sorted sets or token bucket via @upstash/ratelimit

Related patterns: For missing rate limits entirely, X-Forwarded-For header bypass, and timing-based account enumeration via rate limit errors, see SA-SKL-RATELIMIT. For credential brute force on login endpoints that also require rate limiting, see SA-SKL-BRUTEFORCE.