Claude MCP skill IP spoofing via proxy header injection bypassing rate limits — SA-SKL-RATELIMIT10
Rate limiting that relies on IP addresses is only as trustworthy as the mechanism used to identify those addresses. When an MCP skill application trusts client-supplied headers like X-Forwarded-For or CF-Connecting-IP without verifying they were set by a trusted proxy, an attacker can inject any IP address per request and appear as a fresh client each time. Four SA-SKL-RATELIMIT10 patterns cover the most common proxy header injection paths in MCP skill deployments: unconfigured Express trust proxy, spoofed Cloudflare headers on direct-to-origin requests, nginx realip misconfiguration, and userId-only rate limit keys that fall to account rotation.
express-rate-limit reads req.ip; trust proxy not set in Express config; req.ip defaults to trusting X-Forwarded-For unconditionally; attacker sends a fresh X-Forwarded-For value per request and each appears as a different IP to the rate limiterCF-Connecting-IP header trusted as the real IP without first verifying the request arrived from a Cloudflare edge IP; direct-to-origin requests bypass Cloudflare entirely and inject any value into CF-Connecting-IPnginx realip_module reads X-Real-IP from the internal load balancer; the LB's internal IP is not listed in set_real_ip_from; nginx falls back to treating the LB IP as the real client, collapsing all traffic to one counteruserId from JWT only; free-tier users who register additional accounts can rotate identities and each account gets its own counter, multiplying the allowed rate by the number of throwaway accounts they createRATELIMIT10-001 — X-Forwarded-For injection with unconfigured trust proxy
Express sets req.ip using req.socket.remoteAddress by default. When app.set('trust proxy', N) is configured, Express instead reads the Nth entry from the right in the X-Forwarded-For header. Without any trust proxy setting, req.ip returns the socket-level IP — the IP of the last hop. However, express-rate-limit defaults to using req.ip for its key, and many deployments set trust proxy: true (trust all) rather than specifying a hop count. With trust proxy: true, Express trusts the leftmost value in X-Forwarded-For, which the client controls entirely. Each request with a unique spoofed IP bypasses the per-IP rate limit.
// VULNERABLE — RATELIMIT10-001 (HIGH)
// trust proxy not set, or set to 'true' (trust all hops).
// req.ip reads X-Forwarded-For leftmost value which the client controls.
import rateLimit from 'express-rate-limit';
app.set('trust proxy', true); // VULNERABLE: trusts all X-Forwarded-For values
const limiter = rateLimit({
windowMs: 60_000,
max: 100,
// keyGenerator defaults to req.ip — attacker rotates X-Forwarded-For per request
});
app.use('/api/', limiter);
// FIXED — RATELIMIT10-001
// Set trust proxy to the exact number of trusted reverse proxies in front of the app.
// 1 = one trusted proxy (e.g. Render, Railway, single Nginx).
// Use req.socket.remoteAddress as fallback key if behind no proxy.
app.set('trust proxy', 1); // FIX: trust only the immediate upstream proxy
const limiter = rateLimit({
windowMs: 60_000,
max: 100,
// With trust proxy: 1, req.ip is the second-to-last XFF entry (the proxy-set one)
// which cannot be spoofed by the client.
});
app.use('/api/', limiter);
RATELIMIT10-002 — CF-Connecting-IP spoofed on direct-to-origin requests
Cloudflare sets the CF-Connecting-IP header to the real client IP on every request it proxies. MCP skill backends that trust this header to get the real IP must also verify that the request actually came through Cloudflare. If the origin server is reachable directly (its IP is exposed via DNS history, Certificate Transparency logs, or a scan), an attacker can send a request directly to the origin with any value in CF-Connecting-IP and the backend will treat it as the real client IP. The fix is to validate the connecting socket address against Cloudflare's published IP ranges before trusting the header.
// VULNERABLE — RATELIMIT10-002 (HIGH)
// CF-Connecting-IP trusted unconditionally. Direct-to-origin requests bypass CF.
// Attacker sends: CF-Connecting-IP: 1.2.3.4 directly to origin port 443.
function getRealIP(req: express.Request): string {
// VULNERABLE: trusts header without verifying request came through Cloudflare
return req.headers['cf-connecting-ip'] as string || req.socket.remoteAddress || '';
}
const limiter = rateLimit({
windowMs: 60_000,
max: 100,
keyGenerator: (req) => getRealIP(req),
});
// FIXED — RATELIMIT10-002
// Validate that the socket-level remote address is a Cloudflare IP before
// trusting CF-Connecting-IP. If not from CF, fall back to socket address.
// Cloudflare IP ranges: https://www.cloudflare.com/ips/
import { isIPInRanges } from './ip-utils'; // CIDR membership check
const CF_IP_RANGES_V4 = [
'173.245.48.0/20', '103.21.244.0/22', '103.22.200.0/22',
'103.31.4.0/22', '141.101.64.0/18', '108.162.192.0/18',
'190.93.240.0/20', '188.114.96.0/20', '197.234.240.0/22',
'198.41.128.0/17', '162.158.0.0/15', '104.16.0.0/13',
'104.24.0.0/14', '172.64.0.0/13', '131.0.72.0/22',
];
function getRealIP(req: express.Request): string {
const socketIP = req.socket.remoteAddress || '';
const cfHeader = req.headers['cf-connecting-ip'] as string;
// FIX: only trust CF-Connecting-IP if the socket came from a CF IP
if (cfHeader && isIPInRanges(socketIP, CF_IP_RANGES_V4)) {
return cfHeader;
}
return socketIP;
}
RATELIMIT10-003 — nginx realip misconfiguration collapsing all traffic
The nginx ngx_http_realip_module replaces $remote_addr with the value from a trusted header (usually X-Real-IP or X-Forwarded-For) when the connecting IP is listed in set_real_ip_from. If the internal load balancer's IP is not in that list, nginx treats the LB IP as the real client. All traffic arriving through the LB shares one rate limit counter keyed on the LB IP, effectively disabling per-client rate limiting. Requests that exceed the shared counter lock out all users, while an attacker connecting directly to the app server bypasses it entirely.
# VULNERABLE — RATELIMIT10-003 (MEDIUM)
# nginx realip_module configured but LB IP not in set_real_ip_from.
# $remote_addr stays as the LB IP (10.0.0.5) for all requests.
# All traffic shares one rate limit bucket.
http {
limit_req_zone $remote_addr zone=api:10m rate=100r/m;
server {
# realip module loaded but set_real_ip_from does not include LB IP
real_ip_header X-Real-IP;
# MISSING: set_real_ip_from 10.0.0.5; <-- the LB's internal IP
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://app:3000;
}
}
}
# FIXED — RATELIMIT10-003
# Add the LB's IP (or CIDR) to set_real_ip_from. nginx will then replace
# $remote_addr with the value from X-Real-IP, restoring per-client keying.
http {
limit_req_zone $remote_addr zone=api:10m rate=100r/m;
server {
real_ip_header X-Real-IP;
# FIX: list the internal LB IP(s) so nginx trusts their X-Real-IP header
set_real_ip_from 10.0.0.0/8; # internal VPC range
set_real_ip_from 172.16.0.0/12; # Docker bridge networks
real_ip_recursive on; # unwrap multiple XFF hops
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://app:3000;
}
}
}
RATELIMIT10-004 — userId-only rate limit key bypassed by account rotation
Rate limiters keyed solely on the authenticated user ID protect against abuse from a single account but are trivially bypassed by creating multiple accounts. Free-tier plans that allow self-service signup without identity verification (no phone, no payment method) make account rotation trivially cheap. The fix is to apply rate limiting on both dimensions independently: per-IP for anonymous and unauthenticated requests, and per-userId for authenticated requests — with the IP counter being more aggressive, so that account farm IPs are throttled even before authentication.
// VULNERABLE — RATELIMIT10-004 (MEDIUM)
// Rate limiter key is userId only. Attacker creates 10 free accounts and
// rotates JWTs, getting 10x the allowed rate for each time window.
const authenticatedLimiter = rateLimit({
windowMs: 60_000,
max: 100,
keyGenerator: (req) => {
// VULNERABLE: attacker creates N accounts, each with its own counter
return req.user?.id || req.ip;
},
});
// FIXED — RATELIMIT10-004
// Apply two independent limiters: a strict per-IP limiter (catches account farms)
// and a per-userId limiter (catches single-account abuse).
// Using Redis store so limits are shared across horizontal app instances.
import RedisStore from 'rate-limit-redis';
const ipLimiter = rateLimit({
windowMs: 60_000,
max: 200, // per IP across all accounts from that IP
keyGenerator: (req) => req.ip,
store: new RedisStore({ client: redis, prefix: 'rl:ip:' }),
});
const userLimiter = rateLimit({
windowMs: 60_000,
max: 100, // per authenticated userId
keyGenerator: (req) => req.user?.id || req.ip,
store: new RedisStore({ client: redis, prefix: 'rl:user:' }),
skip: (req) => !req.user, // unauthenticated requests handled by ipLimiter only
});
// Apply both — IP limiter first, then user limiter
app.use('/api/', ipLimiter, authenticate, userLimiter);
SkillAudit detection: SA-SKL-RATELIMIT10 flags app.set('trust proxy', true) combined with IP-based rate limiters, CF-Connecting-IP header reads without Cloudflare IP range validation, nginx realip configs where set_real_ip_from does not cover the upstream LB or proxy IPs, and rate limiters with keyGenerator returning only req.user.id without a secondary IP-based limit. Run a free audit at skillaudit.dev.
| Pattern | CVSS | Impact | Fix |
|---|---|---|---|
| RATELIMIT10-001 XFF injection | 7.5 High | Unlimited requests via IP rotation through header | Set trust proxy to exact hop count; never trust all |
| RATELIMIT10-002 CF-Connecting-IP spoof | 7.5 High | Direct-to-origin requests bypass Cloudflare rate limit | Validate socket IP against CF IP ranges before trusting header |
| RATELIMIT10-003 nginx realip collapse | 5.3 Medium | All users share one counter; legitimate users locked out | Add LB IP to set_real_ip_from |
| RATELIMIT10-004 userId-only key | 5.3 Medium | Rate limit multiplied by number of throwaway accounts | Apply independent IP and userId limiters; IP counter is stricter |