The gateway is where every API request passes first, so it is where
authentication, rate limiting, input validation, and logging either
hold or fail together. A gateway that forwards everything and trusts
the backend to sort it out is not a control, it is a router. This
skill covers testing and hardening the edge on systems you are
authorized to assess: prove each control with live traffic, then
check the config that is supposed to enforce it.
Quick Workflow
- Map the gateway: identify the product, the routes, and which
paths are public, authenticated, or admin only.
- Test authentication at the edge: no token, expired token, and a
token for the wrong audience on every route class.
- Test rate limiting: burst a single endpoint and a single
credential, then check whether limits are per IP, per key, or
absent.
- Test schema validation: oversized bodies, wrong types, unknown
fields, and malformed JSON against a validated route.
- Test WAF behaviour: classic injection strings and path traversal
against protected routes, and note what is blocked versus logged.
- Test logging: trigger a blocked request and a failed auth, then
confirm both appear in gateway logs with client, route, and
decision.
- Review the config: compare the live behaviour with the declared
routes, plugins, and policies, and report drift.
- Re-test after fixes: the same requests, in the same order, to
prove each control now holds.
1. Authentication at the edge
# Route classes first: which paths demand auth at the gateway
for p in /api/v1/public/health /api/v1/users/me /api/v1/admin/users; do
echo "== $p without token"
curl -s -o /dev/null -w '%{http_code}\n' "https://target.example$p"
echo "== $p with a garbage token"
curl -s -o /dev/null -w '%{http_code}\n' \
-H 'Authorization: Bearer garbage-token-value' "https://target.example$p"
done
echo "a public route returning 200 and an admin route returning 200"
echo "without a token are both findings, in different severity bands"
# Token confusion at the edge: gateway trusts a token the backend
# would reject, or vice versa. Test both layers and compare.
curl -s "https://target.example/api/v1/users/me" \
-H 'Authorization: Bearer expired-or-wrong-audience-token' | jq .
echo "gateway 200 plus backend 401 means the edge is not validating"
echo "gateway 401 plus backend 200 (direct) means defence in depth"
echo "is missing at the service layer, note it as a hardening gap"
2. Rate limiting
# Burst test: 60 requests in a loop, count the status codes
for i in $(seq 1 60); do
curl -s -o /dev/null -w '%{http_code}\n' \
-H 'Authorization: Bearer user-token-value' \
"https://target.example/api/v1/users/me"
done | sort | uniq -c
echo "all 200s means no effective limit for this credential"
echo "a 429 that arrives late means the window is generous, record"
echo "the threshold and the window, not just the presence of a 429"
#!/usr/bin/env python3
"""Rate limit probe across dimensions: same IP, same key, same user.
Run against an authorized target only. Reports which dimension the
limit (if any) is keyed on, which decides how an attacker evades it.
"""
import subprocess
TARGET = "https://target.example/api/v1/users/me"
def burst(headers, label):
codes = []
for _ in range(40):
out = subprocess.run(
["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}",
TARGET] + headers,
capture_output=True, text=True, check=False).stdout.strip()
codes.append(out)
limited = codes.count("429")
print(f"{label}: 429s in 40 requests = {limited}")
burst(["-H", "Authorization: Bearer user-token-value"], "same key")
burst([], "no token")
print("limit keyed on IP only means rotating keys does not help")
print("limit keyed on key only means rotating IPs does not help")
print("no limit on either dimension is the credential stuffing risk")
3. Schema validation and WAF behaviour
# Schema validation: oversized body, wrong type, unknown field
python3 - << 'PY'
import json, subprocess
base = ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}",
"https://target.example/api/v1/users",
"-H", "Authorization: Bearer user-token-value",
"-H", "Content-Type: application/json"]
cases = {
"oversized name (100k chars)": {"name": "A" * 100000},
"wrong type for age": {"name": "test", "age": "not-a-number"},
"unknown admin field": {"name": "test", "is_admin": True},
}
for label, body in cases.items():
out = subprocess.run(base + ["-d", json.dumps(body)],
capture_output=True, text=True).stdout.strip()
print(f"{label}: HTTP {out} (want 400 for the first two)")
PY
# WAF probe: one injection string per class, record block vs pass
for payload in "' OR '1'='1" "../../etc/passwd" "<script>alert(1)</script>"; do
code=$(curl -s -o /dev/null -w '%{http_code}' -G \
--data-urlencode "q=$payload" "https://target.example/api/v1/search")
echo "payload [$payload] -> HTTP $code"
done
echo "a 403 is a block, a 200 with the payload reflected is a gap,"
echo "a 200 that is only logged is a detection gap, not a block"
4. Gateway logging check
# Trigger one of each event class, then ask for the log lines
curl -s -o /dev/null "https://target.example/api/v1/admin/users"
curl -s -o /dev/null -H 'Authorization: Bearer garbage-token-value' \
"https://target.example/api/v1/users/me"
echo "each request above must appear in gateway logs with client IP,"
echo "route, auth decision, and status. Missing auth failures in"
echo "logs means brute force at the edge is invisible to defenders."
Edge cases
- The gateway passes auth through to the backend without validating
it. Then edge tests look clean while direct-to-service traffic
bypasses everything; test the service directly where authorized.
- Rate limits exist but are per IP behind a shared NAT or CDN. Then
one abusive tenant can throttle everyone else; check for a
per-credential limit as the second layer.
- The WAF runs in log-only mode. Findings must say detection only,
not protection, and the report should show the logged payloads.
- Schema validation rejects valid clients after a spec change. That
is a breaking change risk, so strict validation belongs in a
report-and-enforce rollout, not a silent switch-on.
- Multiple gateways or versions serve the same API. Test each; the
old gateway usually carries the old, weaker policy.
Key references
- OWASP API Security Top 10, especially unrestricted resource
consumption and broken authentication.
- OWASP Web Application Firewall guidance and the gateway vendor
documentation for the product in front of the target.
- Related skills: api-security-testing, openapi-security-review,
api-key-management, api-webhook-security, and the sub-skills
api-authentication-matrix and openapi-ci-gates.
1---2name: api-gateway-security3description: Use when securing an API gateway on an authorized engagement4 or review. Covers rate limiting, authentication at the edge, WAF5 rules, request schema validation, and gateway logging. Use when an6 API sits behind a gateway or reverse proxy, when edge controls are7 the first line of defence, when testing OWASP API Security Top 108 issues at the gateway layer, or when reviewing gateway config with9 Burp Suite traffic as evidence.10version: 1.0.011domain: api12lifecycle: stable13last_verified: "2026-10-27"14requires: [api-security-testing]15extends: []16relates: [openapi-security-review, grpc-security, api-key-management, api-webhook-security]17tools:18 - name: curl19 version: "8.5"20 - name: Python21 version: "3.12"22 - name: Burp Suite23 version: "2026.2"24 - name: jq25 version: "1.7"26metadata:27 source: https://skillmd.com/skills/mizazhaider-ceh/api-gateway-security28---2930The gateway is where every API request passes first, so it is where31authentication, rate limiting, input validation, and logging either32hold or fail together. A gateway that forwards everything and trusts33the backend to sort it out is not a control, it is a router. This34skill covers testing and hardening the edge on systems you are35authorized to assess: prove each control with live traffic, then36check the config that is supposed to enforce it.3738## Quick Workflow39401. Map the gateway: identify the product, the routes, and which41 paths are public, authenticated, or admin only.422. Test authentication at the edge: no token, expired token, and a43 token for the wrong audience on every route class.443. Test rate limiting: burst a single endpoint and a single45 credential, then check whether limits are per IP, per key, or46 absent.474. Test schema validation: oversized bodies, wrong types, unknown48 fields, and malformed JSON against a validated route.495. Test WAF behaviour: classic injection strings and path traversal50 against protected routes, and note what is blocked versus logged.516. Test logging: trigger a blocked request and a failed auth, then52 confirm both appear in gateway logs with client, route, and53 decision.547. Review the config: compare the live behaviour with the declared55 routes, plugins, and policies, and report drift.568. Re-test after fixes: the same requests, in the same order, to57 prove each control now holds.5859## 1. Authentication at the edge6061```bash62# Route classes first: which paths demand auth at the gateway63for p in /api/v1/public/health /api/v1/users/me /api/v1/admin/users; do64 echo "== $p without token"65 curl -s -o /dev/null -w '%{http_code}\n' "https://target.example$p"66 echo "== $p with a garbage token"67 curl -s -o /dev/null -w '%{http_code}\n' \68 -H 'Authorization: Bearer garbage-token-value' "https://target.example$p"69done70echo "a public route returning 200 and an admin route returning 200"71echo "without a token are both findings, in different severity bands"72```7374```bash75# Token confusion at the edge: gateway trusts a token the backend76# would reject, or vice versa. Test both layers and compare.77curl -s "https://target.example/api/v1/users/me" \78 -H 'Authorization: Bearer expired-or-wrong-audience-token' | jq .79echo "gateway 200 plus backend 401 means the edge is not validating"80echo "gateway 401 plus backend 200 (direct) means defence in depth"81echo "is missing at the service layer, note it as a hardening gap"82```8384## 2. Rate limiting8586```bash87# Burst test: 60 requests in a loop, count the status codes88for i in $(seq 1 60); do89 curl -s -o /dev/null -w '%{http_code}\n' \90 -H 'Authorization: Bearer user-token-value' \91 "https://target.example/api/v1/users/me"92done | sort | uniq -c93echo "all 200s means no effective limit for this credential"94echo "a 429 that arrives late means the window is generous, record"95echo "the threshold and the window, not just the presence of a 429"96```9798```python99#!/usr/bin/env python3100"""Rate limit probe across dimensions: same IP, same key, same user.101102Run against an authorized target only. Reports which dimension the103limit (if any) is keyed on, which decides how an attacker evades it.104"""105import subprocess106107TARGET = "https://target.example/api/v1/users/me"108109110def burst(headers, label):111 codes = []112 for _ in range(40):113 out = subprocess.run(114 ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}",115 TARGET] + headers,116 capture_output=True, text=True, check=False).stdout.strip()117 codes.append(out)118 limited = codes.count("429")119 print(f"{label}: 429s in 40 requests = {limited}")120121122burst(["-H", "Authorization: Bearer user-token-value"], "same key")123burst([], "no token")124print("limit keyed on IP only means rotating keys does not help")125print("limit keyed on key only means rotating IPs does not help")126print("no limit on either dimension is the credential stuffing risk")127```128129## 3. Schema validation and WAF behaviour130131```bash132# Schema validation: oversized body, wrong type, unknown field133python3 - << 'PY'134import json, subprocess135base = ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}",136 "https://target.example/api/v1/users",137 "-H", "Authorization: Bearer user-token-value",138 "-H", "Content-Type: application/json"]139cases = {140 "oversized name (100k chars)": {"name": "A" * 100000},141 "wrong type for age": {"name": "test", "age": "not-a-number"},142 "unknown admin field": {"name": "test", "is_admin": True},143}144for label, body in cases.items():145 out = subprocess.run(base + ["-d", json.dumps(body)],146 capture_output=True, text=True).stdout.strip()147 print(f"{label}: HTTP {out} (want 400 for the first two)")148PY149```150151```bash152# WAF probe: one injection string per class, record block vs pass153for payload in "' OR '1'='1" "../../etc/passwd" "<script>alert(1)</script>"; do154 code=$(curl -s -o /dev/null -w '%{http_code}' -G \155 --data-urlencode "q=$payload" "https://target.example/api/v1/search")156 echo "payload [$payload] -> HTTP $code"157done158echo "a 403 is a block, a 200 with the payload reflected is a gap,"159echo "a 200 that is only logged is a detection gap, not a block"160```161162## 4. Gateway logging check163164```bash165# Trigger one of each event class, then ask for the log lines166curl -s -o /dev/null "https://target.example/api/v1/admin/users"167curl -s -o /dev/null -H 'Authorization: Bearer garbage-token-value' \168 "https://target.example/api/v1/users/me"169echo "each request above must appear in gateway logs with client IP,"170echo "route, auth decision, and status. Missing auth failures in"171echo "logs means brute force at the edge is invisible to defenders."172```173174## Edge cases175176- The gateway passes auth through to the backend without validating177 it. Then edge tests look clean while direct-to-service traffic178 bypasses everything; test the service directly where authorized.179- Rate limits exist but are per IP behind a shared NAT or CDN. Then180 one abusive tenant can throttle everyone else; check for a181 per-credential limit as the second layer.182- The WAF runs in log-only mode. Findings must say detection only,183 not protection, and the report should show the logged payloads.184- Schema validation rejects valid clients after a spec change. That185 is a breaking change risk, so strict validation belongs in a186 report-and-enforce rollout, not a silent switch-on.187- Multiple gateways or versions serve the same API. Test each; the188 old gateway usually carries the old, weaker policy.189190## Key references191192- OWASP API Security Top 10, especially unrestricted resource193 consumption and broken authentication.194- OWASP Web Application Firewall guidance and the gateway vendor195 documentation for the product in front of the target.196- Related skills: api-security-testing, openapi-security-review,197 api-key-management, api-webhook-security, and the sub-skills198 api-authentication-matrix and openapi-ci-gates.