Advanced rate limiting bypass techniques in Claude MCP skills — SA-SKL-RATELIMIT3
Rate limiting in MCP skills is commonly implemented as a per-IP counter using express-rate-limit with an in-memory store. This architecture has four exploitable gaps: cloud-based attackers can cycle through large IP ranges; X-Forwarded-For header spoofing lets any attacker claim an arbitrary source IP; in-process counters are not shared across horizontally scaled pods; and sliding-window implementations allow burst doubling at window boundaries. SA-SKL-RATELIMIT3 covers all four with Redis-backed fixes.
Why IP-based rate limiting fails at cloud scale
IP-based rate limiting was designed for the dial-up era when IP addresses corresponded to individual humans and changing your IP required a physical reconnect. In 2026, an attacker with a $20/month cloud account has access to hundreds of IPs in a single /24 subnet and can cycle through a /16 (65,536 IPs) for a few dollars in compute costs. Cloud providers assign IPs dynamically, and many abuse-originated traffic patterns come from the same /16 blocks owned by major cloud vendors. Additionally, most cloud deployments sit behind a load balancer or reverse proxy that adds an X-Forwarded-For header — and the rate limiter must read the right IP from that header chain, or it rate-limits the proxy's IP rather than the client's, effectively disabling the limit for all users simultaneously.
SA-SKL-RATELIMIT3 in scope: RATELIMIT3-001 (cloud IP rotation bypass), RATELIMIT3-002 (X-Forwarded-For spoofing), RATELIMIT3-003 (distributed per-pod counter bypass), RATELIMIT3-004 (burst window gaming). Each pattern includes SkillAudit detection rules and correct fixes.
RATELIMIT3-001 — Cloud IP rotation bypasses per-IP limits
An attacker running from AWS, GCP, or Azure can cycle through the provider's IP space — often a /16 or larger allocation — to send far more requests than the per-IP limit allows. Each new IP starts with a fresh counter. For brute-force attacks against login, OTP, or password-reset endpoints, the attacker exhausts the per-IP limit on one IP, rotates to the next, and continues. The fix is to add an account-level rate limit key in addition to the IP key: even if the attacker rotates IPs, the target account accumulates a counter. For unauthenticated endpoints (like login itself), add a combined key of `${ip}:${targetAccount}` so that many IPs targeting the same account are collectively throttled.
// VULNERABLE — per-IP only; cloud IP rotation allows unlimited attempts per account
import rateLimit from 'express-rate-limit';
const loginLimiter = rateLimit({
windowMs: 60 * 1000,
max: 5, // 5 attempts per IP per minute
keyGenerator: (req) => req.ip, // Per-IP only — attacker rotates IP after 5 attempts
});
app.post('/api/login', loginLimiter, async (req, res) => {
// After 5 failed attempts, attacker rotates IP → fresh 5 attempts
// 100 IPs × 5 attempts = 500 brute-force attempts/minute against one account
const { email, password } = req.body;
const user = await db.getUserByEmail(email);
if (!user || !await bcrypt.compare(password, user.passwordHash)) {
return res.status(401).json({ error: 'Invalid credentials' });
}
res.json({ token: issueJwt(user) });
});
// FIXED — dual key: per-IP AND per-target-account; Redis store shared across pods
import rateLimit from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import { createClient } from 'redis';
const redisClient = createClient({ url: process.env.REDIS_URL });
await redisClient.connect();
// Per-IP limiter (defense against broad scanning)
const ipLimiter = rateLimit({
windowMs: 60 * 1000,
max: 20,
keyGenerator: (req) => `ip:${req.ip}`,
store: new RedisStore({ sendCommand: (...args) => redisClient.sendCommand(args) }),
});
// Per-account limiter (defense against IP rotation targeting one account)
const accountLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15-minute window per account
max: 10,
keyGenerator: (req) => `account:${req.body?.email?.toLowerCase() ?? 'unknown'}`,
store: new RedisStore({ sendCommand: (...args) => redisClient.sendCommand(args) }),
skipSuccessfulRequests: true, // Don't count successful logins against limit
});
app.post('/api/login', ipLimiter, accountLimiter, async (req, res) => {
// Attacker rotating IPs: IP counter resets each rotation, but account counter
// accumulates across all IPs and locks the account after 10 failed attempts in 15 min
const { email, password } = req.body;
const user = await db.getUserByEmail(email);
if (!user || !await bcrypt.compare(password, user.passwordHash)) {
return res.status(401).json({ error: 'Invalid credentials' });
}
res.json({ token: issueJwt(user) });
});
account:{email}) in addition to the IP key so that all IPs targeting the same account accumulate a shared counter. Detection: SkillAudit flags login, OTP verification, and password-reset endpoints where the rate limiter's keyGenerator returns only req.ip without incorporating any account identifier from the request body.RATELIMIT3-002 — X-Forwarded-For spoofing bypasses IP-based rate limit
When a skill is deployed behind a reverse proxy or load balancer, the client's true IP arrives in the X-Forwarded-For header. Many rate limiters read req.ip which, in Express with trust proxy enabled, reads the first IP from the XFF header chain. The first IP in XFF is supplied by the client — it is not validated by the proxy. An attacker can set X-Forwarded-For: 1.2.3.4 in every request to claim any source IP, resetting the rate limit counter with each new IP value. The fix is to read the IP from the last trusted proxy in the XFF chain — the IP added by your own load balancer, which the attacker cannot spoof.
// VULNERABLE — req.ip reads first XFF value, which attacker controls
import express from 'express';
import rateLimit from 'express-rate-limit';
const app = express();
app.set('trust proxy', true); // Trust all proxies — req.ip = first XFF IP (attacker-controlled)
const limiter = rateLimit({
windowMs: 60 * 1000,
max: 100,
keyGenerator: (req) => req.ip, // = first XFF value = attacker can set to any IP
});
// Attacker sets: X-Forwarded-For: 1.2.3.4 → 2.3.4.5 → 3.4.5.6 → ...
// Each request claims a fresh IP → rate limit never triggered
// FIXED — trust only N known proxy hops; use socket.remoteAddress as fallback
import express from 'express';
import rateLimit from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
const app = express();
// Trust exactly 1 proxy hop (your load balancer only)
// req.ip will be the IP added by the load balancer — not attacker-controlled
app.set('trust proxy', 1);
// If behind multiple known proxies, set the exact count:
// app.set('trust proxy', 2); // LB → CDN → skill
const limiter = rateLimit({
windowMs: 60 * 1000,
max: 100,
keyGenerator: (req) => {
// With trust proxy = 1: req.ip is the IP from the first trusted proxy
// With no proxy: req.ip = req.socket.remoteAddress
return req.ip ?? req.socket.remoteAddress ?? 'unknown';
},
store: new RedisStore({ sendCommand: (...args) => redisClient.sendCommand(args) }),
});
// Also validate that req.ip is a plausible IPv4/IPv6 address before using it as a key
// to prevent cache-key injection via crafted proxy headers
req.ip with trust proxy: true in Express read the client-controlled first value of the X-Forwarded-For header, allowing any attacker to spoof their source IP and bypass per-IP limits by cycling through arbitrary IP values in the header; fix by setting trust proxy to the exact number of known proxy hops so Express reads the IP added by your load balancer (which the attacker cannot spoof). Detection: SkillAudit flags skills where Express is configured with app.set('trust proxy', true) or app.set('trust proxy', 1) and the rate limiter's keyGenerator uses req.ip without documentation of the proxy count.RATELIMIT3-003 — Per-instance in-process counters not shared across pods
The default store for express-rate-limit is in-memory — counters are stored in a JavaScript Map in the process heap. In a horizontally scaled deployment with N pods behind a load balancer, each pod maintains its own independent counter for each IP. An attacker who distributes requests across N pods effectively gets N times the allowed rate: each pod's counter sees only 1/N of the total requests and never hits the limit. For a skill running 10 pods with a limit of 100 requests/minute per pod, the effective global limit is 1000 requests/minute — 10× the intended value. The fix is to use a shared external store (Redis) for all rate limit counters, ensuring that all pods increment the same counter for each IP or account key.
// VULNERABLE — in-memory store; N pods = N× effective rate limit
import rateLimit from 'express-rate-limit';
// Default MemoryStore: counters stored in this process's heap only
const limiter = rateLimit({
windowMs: 60 * 1000,
max: 100,
// No store: defaults to MemoryStore
// With 10 pods behind load balancer:
// - Pod 1 sees requests 1, 11, 21, 31, 41... → counter = 10 after 100 total requests
// - Pod 2 sees requests 2, 12, 22, 32, 42... → counter = 10 after 100 total requests
// - Each pod limit: 100 → effective global limit = 10 × 100 = 1000 requests/minute
});
// FIXED — Redis shared store; all pods increment the same counter
import rateLimit from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import { createClient } from 'redis';
const redisClient = createClient({
url: process.env.REDIS_URL,
// Use a dedicated rate-limit DB number to separate from app cache
database: 1,
});
await redisClient.connect();
const limiter = rateLimit({
windowMs: 60 * 1000,
max: 100,
store: new RedisStore({
// Atomic Redis increment via INCR — no race conditions across pods
sendCommand: (...args: string[]) => redisClient.sendCommand(args),
prefix: 'rl:', // Key prefix: rl:{ip}
}),
// standardHeaders: 'draft-7' sends RateLimit headers to clients
standardHeaders: 'draft-7',
legacyHeaders: false,
});
// Redis Lua script for atomic increment + TTL set (rate-limit-redis uses this internally):
// EVAL "local c = redis.call('INCR', KEYS[1]) if c == 1 then redis.call('EXPIRE', KEYS[1], ARGV[1]) end return c" 1 key ttl
// Atomic: no race between INCR and EXPIRE across concurrent pods
express-rate-limit usage without an explicit store option in skills whose deployment config (Kubernetes manifests, ECS task definitions, Dockerfile) indicates more than one replica.RATELIMIT3-004 — Burst window gaming at sliding window boundaries
A fixed-window rate limit (100 requests per 1-minute window) has a well-known boundary vulnerability: an attacker who sends 100 requests in the last second of window N and 100 more in the first second of window N+1 sends 200 requests in a 2-second span without triggering any limit — both windows see exactly 100 requests. This doubles the effective burst rate. Even sliding-window implementations that reset counters based on the timestamp of the first request in the window have a similar property if the resolution is seconds rather than milliseconds. A token bucket or leaky bucket algorithm avoids this by enforcing a constant refill rate rather than a window reset: 100 requests/minute = 1 token added every 600ms, and a burst of 100 tokens can only be consumed at that rate regardless of wall-clock window boundaries.
// VULNERABLE — fixed window; burst of 200 requests in 2 seconds at window boundary
import rateLimit from 'express-rate-limit';
const limiter = rateLimit({
windowMs: 60 * 1000, // 1-minute fixed window
max: 100, // 100 requests per window
// Window resets at :00 seconds of each minute
// Attacker: 100 requests at :59 + 100 requests at :00 = 200 requests in 2 seconds
// Both windows see 100 each → neither limit triggered
});
// FIXED — sliding log or token bucket enforces true request rate across boundaries
// Option A: Use rate-limit-redis with sliding window log algorithm
import { RateLimiterRedis } from 'rate-limiter-flexible';
const rateLimiter = new RateLimiterRedis({
storeClient: redisClient,
keyPrefix: 'rl_slide',
points: 100, // 100 requests allowed
duration: 60, // Per 60 seconds — sliding window, not fixed window
blockDuration: 60, // Block for 60 seconds after limit hit
// Sliding window: uses sorted set with request timestamps
// 100 requests at :59 + any request at :00 is immediately rate-limited
// because the sliding 60-second window still contains all 100 prior requests
});
app.use('/api/sensitive', async (req, res, next) => {
try {
await rateLimiter.consume(req.ip);
next();
} catch (rejRes) {
const retryAfter = Math.ceil(rejRes.msBeforeNext / 1000);
res.set('Retry-After', String(retryAfter));
res.status(429).json({ error: 'Too many requests', retryAfter });
}
});
// Option B: Token bucket via Redis INCR with per-token TTL
// Each token is a separate Redis key with a 600ms TTL (1 token per 600ms = 100/min)
// Bucket depth of 10 allows short bursts while enforcing the average rate
rate-limiter-flexible with Redis sorted set backend) or a token bucket algorithm that enforces a constant refill rate independent of clock boundaries. Detection: SkillAudit flags express-rate-limit usage without a sliding-window store on endpoints that protect sensitive operations (login, OTP, password reset, email sending).