Skip to main content
Be Bitwise

API Gateway & Microservice Exploitation

Advanced API Exploitation · API Security track

6 min read

In this module

The Gateway as the Security Boundary

Modern APIs rarely run as a single monolith. An API gateway sits at the edge, routing requests to a fleet of backend microservices. The gateway handles auth, rate limiting, logging, and routing. Microservices handle business logic.

The whole arrangement rests on one assumption: microservices trust the gateway to enforce security. Break that assumption — through bypass, routing manipulation, or SSRF — and the damage tends to be ugly, because internal services usually ship with no security controls of their own.

Gateway Bypass Techniques

Direct Backend Access

The cleanest bypass is no bypass at all: you just talk to the backend directly. Internal services get accidentally exposed on public IPs, or cloud security groups end up loose enough that anyone can reach them.

http
# Normal path through gateway
GET https://api.example.com/v1/users/1842
# Gateway enforces auth, rate limiting, logging
# Direct access to backend (if exposed)
GET http://10.0.3.45:8080/users/1842
# No auth, no rate limiting, no logging

To find these holes: scan the target's IP ranges, dig through DNS for internal subdomains, and read error messages closely — they leak backend hostnames more often than you'd expect.

Path Manipulation

API gateways route requests based on URL paths. Inconsistencies between how the gateway parses paths and how the backend interprets them create bypass opportunities.

http
# Gateway blocks /admin/* paths
GET /admin/users HTTP/1.1 # → 403 Forbidden
# Path variations the gateway may not match
GET /Admin/users HTTP/1.1 # Case sensitivity mismatch
GET /./admin/users HTTP/1.1 # Path normalisation difference
GET /%61dmin/users HTTP/1.1 # URL-encoded characters
GET /v1/../admin/users HTTP/1.1 # Path traversal
Parser Differential Attacks

Path-manipulation bypasses exploit parser differentials. The gateway reads one URL; the backend reads another. The gateway thinks it's forwarding something harmless. The backend resolves the same string to a restricted endpoint and serves it up without a second glance.

HTTP Method Override

Some gateways only police certain HTTP methods. Override headers let you smuggle one method past the gateway while the backend honours another:

http
POST /api/v1/users/1842 HTTP/1.1
X-HTTP-Method-Override: DELETE

Gateway: applies POST rules. Backend: honours the override header and runs a DELETE.

Internal API Exposure

Microservices chat with each other through internal APIs that the outside world is never supposed to touch. Misconfigure the gateway routing and those endpoints leak straight onto the internet.

Common indicators of internal API exposure include:

  • Endpoints with /internal/, /admin/, or /debug/ prefixes
  • Health check and metrics endpoints (/health, /metrics, /debug/pprof)
  • Service discovery endpoints that list registered microservices
  • Swagger or OpenAPI specifications for internal services

SSRF Through API Gateways

Server-Side Request Forgery hits hardest in gateway/microservice setups. The gateway can reach internal services you cannot, so any SSRF effectively borrows its network position.

SSRF usually shows up where an endpoint takes a URL as input and fetches it server-side:

http
POST /api/v1/webhooks HTTP/1.1
Content-Type: application/json
{
"callback_url": "http://169.254.169.254/latest/meta-data/iam/security-credentials/"
}

That URL points at the AWS metadata service — reachable only from inside the cloud environment, never from the public internet. A working SSRF here pulls out temporary credentials, service-account tokens, and configuration data. That works against the old IMDSv1, which answers any GET. IMDSv2 first requires a session token obtained with a PUT request carrying a special header, which a simple URL-fetching SSRF can't send, so check which version the instance enforces before you promise impact. Defences beyond that are the usual ones: an allowlist of destinations the feature may fetch, blocking link-local and private ranges after DNS resolution, and egress filtering so the service can't reach what it doesn't need.

SSRF Escalation in Microservices

Beyond cloud metadata, SSRF in a microservice environment can:

  • Access internal APIs: Reach services that are not exposed through the gateway
  • Scan the internal network: Map which services are running and on which ports
  • Bypass authentication: Internal services often trust requests from other internal services without requiring authentication tokens
  • Chain with other vulnerabilities: Use SSRF to reach an internal service vulnerable to injection or BOLA
http
POST /api/v1/preview HTTP/1.1
Content-Type: application/json
{
"url": "http://internal-payment-service:8080/admin/refund?order_id=10458&amount=99999"
}

If the preview service blindly fetches that URL and the payment service trusts internal callers without authentication, the SSRF turns into a wire transfer.

Service Mesh Security

A service mesh (Istio, Linkerd, take your pick) bolts a sidecar proxy onto every microservice. The sidecar handles mTLS, traffic shaping, and observability. Meshes do harden service-to-service traffic, but they bring new attack surface with them:

  • Sidecar bypass: If a service can be reached on its container port directly rather than through the sidecar proxy, all mesh security policies are bypassed.
  • Policy misconfiguration: Overly permissive mesh policies that allow all services to communicate with all other services negate the segmentation benefit.
  • Control plane attacks: Compromising the mesh control plane (the management component that distributes configuration to sidecars) allows an attacker to modify routing rules, disable mTLS, or redirect traffic.

Path Traversal in Routing

API gateways that route based on URL path prefixes can be vulnerable to path traversal attacks that escape the intended service boundary:

http
# Intended route: /api/v1/documents/* → Document Service
GET /api/v1/documents/../../../internal/config HTTP/1.1

If the gateway strips the /api/v1/documents/ prefix without normalising the rest, the traversal sneaks through and the request lands somewhere it shouldn't.

Some gateways also support wildcard routing that can be exploited:

http
# Route: /api/v1/{service}/* → forwards to {service}
GET /api/v1/internal-auth-service/tokens HTTP/1.1

If the routing accepts arbitrary service names, you can pick any internal service off the menu by name.

Testing Strategy

When testing API gateways and microservice architectures:

  1. Map the architecture: Identify the gateway technology, the routing rules, and the backend services through error messages, response headers, and documentation.
  2. Test path parsing: Try URL encoding, double encoding, path traversal, case variations, and path normalisation differences.
  3. Probe for internal endpoints: Fuzz for /internal/, /admin/, /debug/, /health, /metrics, and similar paths.
  4. Test SSRF vectors: Any endpoint that accepts URLs, hostnames, or IP addresses is a potential SSRF entry point. Target cloud metadata endpoints and internal service addresses.
  5. Check for method override: Test X-HTTP-Method-Override, X-Method-Override, and _method parameter support.

Gateway and microservice work sits at the seam between external API testing and proper internal network pentesting. The final lesson stitches the individual bugs from this module into full attack chains.