API Gateway Security:
Rate Limiting Bypass and Auth Delegation Flaws

API gateways promise centralised enforcement of authentication, rate limiting, and routing. But misconfigured gateways become false security anchors — while the upstream services remain fully exploitable through the gaps attackers reliably find.

API Gateway Security

The False Security Anchor

Modern API gateways — Kong, AWS API Gateway, Apigee, Traefik, Envoy — sit at the edge of service architectures and promise centralised auth, rate limiting, request validation, and observability. Teams invest heavily in gateway configuration then deprioritise security in the upstream services because "the gateway handles it."

This creates a dangerous single-layer security model. When the gateway has a misconfiguration, bypass, or vulnerability, every upstream service is exposed with no defence in depth. And misconfigurations are the norm, not the exception.

Critical Assumption Failure

API gateway security is additive, not substitutive. Upstream services must authenticate and authorise requests independently, as if the gateway did not exist — because in a real attack, it often effectively doesn't.

Rate Limiting Bypass Techniques

Rate limiting protects against brute force, credential stuffing, scraping, and abuse. API gateway rate limits are frequently bypassable through straightforward techniques that attackers apply routinely.

IP-Based Rate Limiting Bypass

Most gateways default to IP-based rate limiting. Attackers bypass this by rotating through IP addresses (residential proxies, cloud egress IPs) or by manipulating IP identification headers that the gateway trusts.

# Many gateways trust X-Forwarded-For without validation
# If the gateway reads this header for rate limiting:
GET /api/auth/login HTTP/1.1
X-Forwarded-For: 1.2.3.4          # Rotated IP — bypass rate limit
X-Real-IP: 5.6.7.8
X-Originating-IP: 9.10.11.12

# Kong rate-limit-advanced plugin misconfiguration
# If "identifier" is set to "ip" and gateway trusts X-Forwarded-For:
# Attacker sends 1000 requests each with a unique spoofed IP header
Header Trust Warning

Never configure a gateway to use X-Forwarded-For or X-Real-IP as the rate limiting identifier unless the gateway is behind a trusted proxy that sets those headers — and the gateway is configured to only trust headers set by that specific upstream source.

Path Variation Bypass

Rate limit rules are often defined on specific paths. URL encoding, case differences, trailing slashes, or parameter injection can produce paths that match the upstream route handler but don't match the gateway's rate limit rule.

# Rate limit applies to: /api/auth/login
# These may bypass the rule:
GET /api/auth/login/
GET /api/auth/Login
GET /api/auth/%6Cogin
GET /api/auth/./login
GET /api/auth/login%20
GET /api/auth/login?_=1      # Query param not in rule path

Consumer-Based Rate Limit Bypass

When rate limits are tied to API keys or JWT consumers, attackers register multiple accounts to distribute requests across multiple consumer identities — each staying within their individual limit while collectively far exceeding the intended protection threshold.

Routing and Path Confusion

API gateway routing maps incoming paths to upstream services. Path confusion vulnerabilities arise when the gateway's path normalisation logic differs from the upstream service's path resolution logic — creating routes that the gateway doesn't protect but the backend serves.

Path Confusion Attack Flow

1

Gateway routes /api/admin/* to admin service, requiring role: admin JWT claim

↓
2

Attacker requests /api/admin/%2F../admin/users — double-encoded path traversal

↓
3

Gateway sees path that doesn't match /api/admin/* rule — skips auth check, forwards request

↓
4

Upstream service normalises path, resolves to /api/admin/users — responds with admin data

# AWS API Gateway path example
# Route defined: /admin/{proxy+} with authoriser
# Route NOT defined: /Admin/{proxy+}

# If gateway routing is case-sensitive but backend is case-insensitive:
GET /Admin/users    # No gateway auth check, but backend serves /admin/users

Auth Token Forwarding Flaws

API gateways that verify JWTs at the edge must decide what to forward to upstream services. A common pattern is to forward the original JWT and let upstream services re-verify or trust it implicitly. Both approaches have distinct failure modes.

Algorithm Confusion on Re-Verification

If the upstream service re-verifies the JWT but doesn't pin the expected algorithm, an attacker can craft a JWT using the alg: none or RS256-to-HS256 confusion attack — the gateway validates its original JWT, the upstream accepts the crafted one.

# Attacker flow:
# 1. Obtain valid JWT from gateway
# 2. Craft modified JWT with alg:none and elevated claims
# 3. Gateway may reject if it re-checks, but if it only checks at entry...
# 4. Inject crafted JWT into X-Auth-Token header that upstream trusts

# Example: Kong JWT plugin validates bearer token
# Upstream service reads X-Authenticated-Userid header set by Kong
# Attacker sets this header directly on requests that bypass Kong

Header Injection into Forwarded Claims

Some gateways extract claims from validated JWTs and forward them as HTTP headers to upstream services (e.g., X-User-Id, X-User-Role). If the gateway doesn't strip these headers from incoming requests before the auth plugin runs, an attacker can pre-set them and the upstream service will trust the attacker-provided values.

Critical Misconfiguration

Every security-sensitive header that the gateway sets for upstream consumption must be stripped from the inbound request before processing. If X-User-Role: admin arrives from an untrusted client and the gateway doesn't strip it, whatever the upstream service does with that header is attacker-controlled.

Direct Backend Access

The most devastating API gateway bypass is the simplest: reaching backend services directly, without going through the gateway at all. This is possible whenever backends are accessible from the internet or from network segments the attacker can reach.

Common Direct Access Vectors

  • Backend microservices deployed with public load balancers or IPs
  • Kubernetes services exposed via NodePort or LoadBalancer instead of ClusterIP
  • Cloud Run and Lambda services with public URLs not protected by VPC or IAM auth
  • Internal services discoverable via DNS enumeration from cloud metadata
  • Legacy endpoints not routed through the gateway that still accept traffic
# Discovery: find backend services that bypass the gateway
# Cloud provider metadata can expose internal service names
# DNS: internal.service.svc.cluster.local or *.internal.company.com

# Check if backend Lambda accepts unauthenticated requests:
curl https://abc123.lambda-url.us-east-1.on.aws/admin/users

# Check if Kubernetes service is directly routable:
curl http://api-service.default.svc.cluster.local/admin/users

Plugin and Extension Security

Kong, Tyk, and other extensible gateways support custom plugins in Lua, Go, or Python. These plugins run with the same privileges as the gateway process — a vulnerability in a plugin compromises the entire gateway, including all traffic flowing through it.

Plugin Security Review

Treat gateway plugins as security-critical code. Require code review for all plugin changes, enforce plugin sandboxing where the gateway supports it, and scan plugin dependencies for known vulnerabilities. A compromised gateway plugin can read and modify all request/response data.

Gateway Admin API Exposure

Kong, Traefik, and many other gateways expose an admin API on a separate port that allows full configuration control — adding routes, disabling plugins, modifying rate limits. This API is frequently left accessible on internal networks or, in severe cases, the public internet.

# Kong admin API default port 8001
# If accessible: complete gateway control
curl http://gateway-internal:8001/services     # List all services
curl http://gateway-internal:8001/plugins      # List/modify all plugins

# Disable JWT auth plugin for a specific route:
curl -X DELETE http://gateway-internal:8001/routes/{route-id}/plugins/{plugin-id}

# Traefik dashboard — read-only but leaks all route config:
curl http://gateway-internal:8080/api/http/routers

Hardening the Gateway Layer

API Gateway Security Controls

  • Rate limiting by authenticated identity: Rate limit on API key or verified user ID, never on IP alone. Validate and strip IP override headers.
  • Path normalisation: Ensure gateway and upstream normalise paths identically. Test edge cases: double encoding, trailing slashes, case variations.
  • Header stripping: Strip all forwarded claim headers from inbound requests. Gateway sets them only after successful auth.
  • Backend network isolation: Backend services must only accept traffic from the gateway (security group, VPC rule, mTLS). Never directly internet-accessible.
  • Upstream re-verification: Upstream services should independently verify JWTs, not trust gateway-forwarded claims as source of truth.
  • Admin API protection: Gateway admin API must be on an isolated network segment, protected by mTLS or VPN, never internet-accessible.
  • Plugin security review: All gateway plugins treated as security-critical code with mandatory review and dependency scanning.

"The API gateway is a control plane, not a security perimeter. Every service behind it must be able to defend itself — because the gateway will eventually have a gap."

API gateway security failures consistently rank among the most impactful API vulnerabilities because they affect every service behind the gateway simultaneously. A single rate limit bypass, routing confusion, or header injection affects the entire API surface at once.

AquilaX scans code, dependencies and secrets for security problems. The scanners you can use depend on your plan.