← Blog

Claude skill rate limiting bypass via header spoofing and distributed sharding — SA-SKL-RATELIMIT6

Rate limiting is only as strong as the key it uses to identify callers. SA-SKL-RATELIMIT6 covers four patterns that make MCP skill rate limiters trivially bypassable: trusting the user-controlled X-Forwarded-For header to identify the caller IP; running isolated in-memory counters on each replica of a horizontally-scaled deployment; keying the limiter on the User-Agent header that attackers rotate freely; and applying HTTP-path limits to GraphQL endpoints without counting operations per request body, letting batch queries multiply effective throughput by 50×.

By SkillAudit  |  7 Nov 2026

Why rate limiting is harder than it looks

Rate limiting feels like a solved problem — add a middleware, choose a threshold, done. The reality is that every component in the deployment path introduces a new bypass surface. The proxy layer controls which headers carry the real client IP. The runtime topology determines whether counters are shared or siloed. The key selection determines how hard it is for an attacker to rotate to a fresh quota bucket. The API semantics determine whether the HTTP request unit maps to any meaningful unit of cost. Getting any one of these wrong means your rate limiter is a configuration fiction that blocks only the most naive callers.

MCP skill servers are especially exposed because they sit behind Caddy or nginx reverse proxies, may be deployed across multiple container replicas, and often handle API-style requests (GraphQL, JSON-RPC) where the relationship between HTTP requests and application-level operations is non-trivial. SkillAudit's SA-SKL-RATELIMIT6 check examines all four bypass dimensions in a single scan.

SA-SKL-RATELIMIT6 findings at a glance
HIGHRATELIMIT6-001 — X-Forwarded-For spoofing bypasses per-IP counter via req.headers['x-forwarded-for'] direct read
HIGHRATELIMIT6-002 — Distributed request sharding: 10 replicas × in-memory counter = 10× effective quota
HIGHRATELIMIT6-003 — User-Agent keyed rate limiter: free unlimited quota via per-request UA rotation
HIGHRATELIMIT6-004 — GraphQL operation count ignored: HTTP-path limit allows 50-operation batches at any throughput

RATELIMIT6-001 — X-Forwarded-For header spoofing bypasses per-IP counter

When an MCP skill server sits behind a reverse proxy, the client's real IP is not in req.socket.remoteAddress — it is in a forwarding header such as X-Forwarded-For or the standard Forwarded. Many developers correctly recognise that they need to read the forwarding header, but then read it directly from req.headers['x-forwarded-for'] without understanding that this header is fully attacker-controlled. Any HTTP client can send an arbitrary X-Forwarded-For: 1.2.3.4 header value. Because the header is a comma-separated list of IPs appended by each proxy hop, a direct read of the header value returns whatever the client put there — not the real client IP appended by the trusted proxy.

The correct approach is to configure Express with app.set('trust proxy', 1) (or the specific proxy CIDR if more than one hop), which tells Express to trust exactly one upstream proxy. Express then sets req.ip to the first IP in X-Forwarded-For that was not set by a trusted proxy — the real client IP. Rate limiters must use req.ip (the Express-resolved value), never the raw header string. The express-rate-limit package uses req.ip by default when you configure trust proxy correctly; custom limiters that read raw headers bypass this protection entirely.

// VULNERABLE — reads X-Forwarded-For header directly; attacker can send any IP
import rateLimit from 'express-rate-limit';
import express from 'express';

const app = express();
// No trust proxy setting — req.ip will be the socket address (reverse proxy IP)

const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  keyGenerator: (req) => {
    // VULNERABLE: reads header directly — attacker sends X-Forwarded-For: 1.2.3.4
    // Rate limiter counts against 1.2.3.4, not attacker's real IP
    // With enough spoofed IPs, quota is effectively infinite
    return req.headers['x-forwarded-for']?.split(',')[0].trim()
      || req.socket.remoteAddress;
  }
});

app.use('/api/audit', limiter, auditHandler);
// FIXED — configure trust proxy; use req.ip set by Express from trusted proxy chain
import rateLimit from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import { createClient } from 'redis';
import express from 'express';

const app = express();

// Trust exactly one upstream proxy (the load balancer / Caddy instance)
// Express will set req.ip to the first untrusted IP in X-Forwarded-For
// Adjust the number to match your actual proxy hop count
app.set('trust proxy', 1);

const redisClient = createClient({ url: process.env.REDIS_URL });
await redisClient.connect();

const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  standardHeaders: true,
  legacyHeaders: false,
  store: new RedisStore({ sendCommand: (...args) => redisClient.sendCommand(args) }),
  // keyGenerator defaults to req.ip — Express sets this correctly when trust proxy is set
  // No custom keyGenerator needed; req.ip is already the real client IP
});

app.use('/api/audit', limiter, auditHandler);

RATELIMIT6-002 — Distributed request sharding across replicas multiplies quota

An in-memory rate limiter — including the default store in express-rate-limit without a Redis backend — maintains its counter in the Node.js process heap. When a service is deployed as 10 replicas behind a load balancer, each replica has its own independent in-memory counter. An attacker who distributes requests across replicas (which a load balancer does automatically via round-robin) gets 10× the configured quota: each replica sees only 1/10 of the actual traffic, never reaching its local threshold.

The fix is a shared, atomic counter stored outside of any single process. Redis with the rate-limit-redis store (backed by an atomic INCR + EXPIRE operation) maintains a single counter per key across all replicas. The rate-limiter-flexible library's RateLimiterRedis class provides the same guarantee with more configuration options. Any deployment that uses horizontal scaling — Kubernetes pods, ECS tasks, PM2 cluster, Docker Swarm replicas — must use a shared store.

// VULNERABLE — in-memory store; each of 10 replicas has its own counter
import rateLimit from 'express-rate-limit';

// Default MemoryStore — counter lives in this Node.js process only
const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  // No store: option — defaults to MemoryStore
  // With 10 replicas: attacker sends 10 req/replica = 100 total, all within limit
  // Effective rate limit: 100 * 10 = 1,000 requests per minute per IP
});

app.use('/api', limiter, handler);
// FIXED — shared Redis counter; single atomic state across all replicas
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();

const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  standardHeaders: true,
  legacyHeaders: false,
  store: new RedisStore({
    // sendCommand uses the native Redis client's atomic INCR
    sendCommand: (...args) => redisClient.sendCommand(args),
    prefix: 'rl:api:',  // namespace to avoid key collisions with other limiters
  }),
  // All 10 replicas share the same Redis key; counter is globally consistent
  // A single INCR + EXPIRE pipeline is atomic — no double-count under concurrency
});

// Alternative: rate-limiter-flexible for more granular sliding window support
import { RateLimiterRedis } from 'rate-limiter-flexible';

const rateLimiterRedis = new RateLimiterRedis({
  storeClient: redisClient,
  keyPrefix: 'rl_api',
  points: 100,         // requests
  duration: 60,        // per second window
  blockDuration: 300,  // block for 5 min on exceed
});

app.use('/api', async (req, res, next) => {
  try {
    await rateLimiterRedis.consume(req.ip);
    next();
  } catch {
    res.status(429).json({ error: 'Too Many Requests' });
  }
}, handler);

RATELIMIT6-003 — User-Agent keyed rate limiter bypassed by header rotation

Using the User-Agent, Accept-Language, or other user-controlled request headers as a rate limit key is a security anti-pattern. These headers are freely settable by any HTTP client. An attacker who finds their IP blocked can simply rotate the User-Agent string on each request — using a different browser UA, a random string, or programmatically generating unique values — to get a fresh quota bucket per request. The same applies to any header the client can arbitrarily set: X-Request-ID, X-Client-Version, Accept, or custom application headers.

Rate limit keys must be based on values that the application controls or that cannot be freely rotated: the client's real IP (via trusted proxy chain), the authenticated user ID from a validated JWT or session token, or an API key that was issued by the application and stored in the database. For unauthenticated endpoints where IP is the only available key, accept that IP-based limits are weaker against distributed attackers and layer additional controls (CAPTCHA on threshold, temporary ban, Cloudflare DDoS protection) rather than inventing a weaker pseudo-identity from request headers.

// VULNERABLE — User-Agent as rate limit key; attacker rotates UA per request
import rateLimit from 'express-rate-limit';

const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  keyGenerator: (req) => {
    // VULNERABLE: User-Agent is user-controlled
    // Attacker sends a different UA string with each request:
    //   User-Agent: Mozilla/5.0 (custom-1)
    //   User-Agent: Mozilla/5.0 (custom-2)  ...etc.
    // Each gets its own counter; effective rate limit = unlimited
    return req.headers['user-agent'] || req.ip;
  }
});

// Also vulnerable: Accept-Language, X-Client-Version, X-Request-ID keyed limiters
const badLimiter = rateLimit({
  keyGenerator: (req) =>
    `${req.headers['accept-language']}-${req.headers['user-agent']}`,
  // Attacker controls both headers — this is marginally harder to rotate but still trivial
});
// FIXED — use req.ip (trusted) for anonymous callers; userId for authenticated callers
import rateLimit from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import { createClient } from 'redis';
import { verifyJwt } from './auth.js';

const redisClient = createClient({ url: process.env.REDIS_URL });
await redisClient.connect();

// Stricter limit for authenticated users (they have a real userId to key on)
const authLimiter = rateLimit({
  windowMs: 60 * 1000,
  max: 500,  // authenticated callers get more quota
  store: new RedisStore({ sendCommand: (...args) => redisClient.sendCommand(args) }),
  keyGenerator: (req) => {
    // Use the authenticated userId from verified JWT — not any request header
    // If this middleware runs after auth middleware, req.user.id is set
    return `user:${req.user?.id || req.ip}`;
  }
});

// IP-only limit for unauthenticated callers
const anonLimiter = rateLimit({
  windowMs: 60 * 1000,
  max: 20,   // tighter limit for anonymous callers
  store: new RedisStore({ sendCommand: (...args) => redisClient.sendCommand(args) }),
  // keyGenerator defaults to req.ip — correct when trust proxy is configured
});

// Routes use appropriate limiter based on auth state
app.use('/api/audit', verifyJwt, authLimiter, auditHandler);
app.use('/api/scan/public', anonLimiter, publicScanHandler);

RATELIMIT6-004 — GraphQL operation count ignored: HTTP-path rate limit allows batch abuse

GraphQL's design allows multiple operations to be batched in a single HTTP request body as a JSON array. A rate limiter applied at the HTTP path level — POST /graphql limited to 100 requests/minute — counts HTTP requests, not GraphQL operations. An attacker who sends 2 HTTP requests each containing an array of 50 operations executes 100 GraphQL operations while the rate limiter registers only 2 requests, well within the threshold. This is not a theoretical attack: batching is used by legitimate GraphQL clients (Apollo Client uses it by default for query deduplication) and by attackers to amplify query throughput.

The correct approach is to combine HTTP-request counting with per-operation limiting inside the GraphQL layer. At the HTTP layer, limit the number of operations per request body (reject arrays longer than a small maximum, e.g. 10). At the resolver layer, apply field-level rate limiting using a library such as graphql-rate-limit or graphql-shield with per-operation Redis counters. For public APIs, consider disabling batching entirely by rejecting array-shaped request bodies.

// VULNERABLE — HTTP-path rate limit on /graphql; ignores operation count per request
import rateLimit from 'express-rate-limit';

const graphqlLimiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  // Counts HTTP requests only — POST /graphql with 50-operation batch counts as 1
});

app.use('/graphql', graphqlLimiter, graphqlHandler);

// Attacker sends:
// POST /graphql  (count: 1 of 100)
// Body: [
//   {"query": "{ auditSkill(id:1) { ... } }"},
//   {"query": "{ auditSkill(id:2) { ... } }"},
//   ... 50 operations total ...
// ]
// Sends 2 such requests = 2 of 100 HTTP requests used, but 100 operations executed
// FIXED — reject batch arrays above limit + per-operation resolver rate limiting
import rateLimit from 'express-rate-limit';
import { createRateLimitRule } from 'graphql-rate-limit';
import { shield, and } from 'graphql-shield';
import { createClient } from 'redis';

const redisClient = createClient({ url: process.env.REDIS_URL });
await redisClient.connect();

// Step 1: reject batched requests with more than 5 operations
const batchSizeLimit = (req, res, next) => {
  if (Array.isArray(req.body)) {
    if (req.body.length > 5) {
      return res.status(400).json({
        error: 'Batch size limit exceeded',
        max: 5,
        received: req.body.length
      });
    }
  }
  next();
};

// Step 2: HTTP request rate limit (now meaningful since batch size is capped)
const httpLimiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  store: new RedisStore({ sendCommand: (...args) => redisClient.sendCommand(args) }),
});

// Step 3: per-operation resolver rate limit
const rateLimitRule = createRateLimitRule({
  identifyContext: (ctx) => ctx.user?.id || ctx.req.ip,
  formatError: () => 'Too many requests on this operation',
});

export const permissions = shield({
  Query: {
    auditSkill: rateLimitRule({ window: '1m', max: 20 }),
    searchSkills: rateLimitRule({ window: '1m', max: 50 }),
  },
  Mutation: {
    runFullAudit: rateLimitRule({ window: '1m', max: 5 }),
  },
});

// Apply all three layers in order
app.post('/graphql',
  express.json({ limit: '100kb' }),
  batchSizeLimit,
  httpLimiter,
  graphqlHandler   // permissions middleware applied inside graphqlHandler
);

Summary table — SA-SKL-RATELIMIT6 patterns

IDSeverityRoot causeFix
RATELIMIT6-001HIGHreq.headers['x-forwarded-for'] direct read — attacker controls IPapp.set('trust proxy', 1) + use req.ip
RATELIMIT6-002HIGHIn-memory counter per replica — 10 replicas = 10× quotaRedis shared store via rate-limit-redis or RateLimiterRedis
RATELIMIT6-003HIGHUser-Agent / Accept-Language key — freely rotated per requestKey on req.ip (anon) or userId from verified JWT (auth)
RATELIMIT6-004HIGHHTTP request count ignores GraphQL batch size — 2 req = 100 opsReject arrays > N + per-resolver graphql-rate-limit counters

SkillAudit scans for all four SA-SKL-RATELIMIT6 patterns in a single audit run. Run a free scan at skillaudit.dev or see related patterns: SA-SKL-RATELIMIT5, SA-SKL-CORS11.