Reverse-Proxy & IAP Hardening
Reverse-Proxy & IAP Hardening
Section titled “Reverse-Proxy & IAP Hardening”An identity-aware proxy (IAP) — Pomerium, Authentik Outpost, oauth2-proxy, or a plain reverse proxy with forward-auth — puts SSO in front of apps that don’t speak OIDC. It concentrates trust in two places: the proxy is the only gate, and every upstream trusts a forwarded identity signal whose provenance it usually cannot verify. Almost every real bypass is a provenance failure: something trusts a header or token because it is present, not because it provably came from trusted infrastructure.
This guide is the hardening checklist. The attack taxonomy it defends against: forwarded-header spoofing → OAuth entry points → token forgery → DNS redirection → lateral movement. (See Authentik Hardening for the IdP side.)
1. Forwarded-header spoofing (the #1 real-world bypass)
Section titled “1. Forwarded-header spoofing (the #1 real-world bypass)”A backend that authorizes on header presence is trivially bypassed. The classic:
CVE-2024-47070 (Authentik, CVSS 9.0):
X-Forwarded-For: a(unparsable IP) skipped a policy stage → login to any known account. And in a 2026 assessment, a backend granted access onX-Goog-Authenticated-User-ID/X-Forwarded-Userpresence alone — a forged header exposed internal API docs.
Rules:
- Client IP comes from the proxy’s own socket peer or
CF-Connecting-IP(Cloudflare), neverX-Forwarded-For.XFFis a comma list the client appends to;XFF.split(',')[0]is the value the attacker sent. In a Cloudflare Worker,CF-Connecting-IPis set by the edge;XFFis passed through as the client sent it. Never useXFFfor auth, rate-limit keys, IP allow/deny, or geofencing. - The proxy must OVERWRITE, not append to,
X-Forwarded-For/X-Real-IP. - Strip client-supplied identity headers at the edge (
X-Forwarded-User,X-Goog-Authenticated-User-ID,X-Authenticated-User,X-Remote-User) before forwarding. TRUSTED_PROXY_CIDRS(every “trusted proxies” list) names only the real proxy — loopback + the tunnel, not a whole shared Docker range. Too broad = any container on that range can spoofXFFand defeat IP policies. (In the Authentik example, narrowing a/16to the Docker gateway/32removed 22 containers’ spoof ability while keeping the tunnel working.)- Authorize on a signed assertion, not a header.
X-Pomerium-Jwt-Assertionis signed and verifiable against JWKS (.well-known/pomerium/jwks.json);X-Pomerium-Claim-*,X-Authentik-*,X-Remote-Userare unsigned. Prefer the signed one and verify signature + issuer + audience. - The upstream must be reachable ONLY through the proxy. If it binds the Docker bridge, LAN,
or
*, an attacker reaching it directly can forge every unsigned identity header. Bind upstreams to127.0.0.1and prove it (docker run --rm alpine wget http://172.17.0.1:<port>/must fail). Verified example: SearXNG also bound172.17.0.1:8888and was reachable from the default bridge — dropping that bind made it genuinely proxy-only. - Host header: when the proxy forwards the client’s
Hostunchanged (preserve_host_header), the upstream must not build absolute URLs / redirects / federation endpoints from it (host-header poisoning, open redirect). Pin the upstream’s own hostname.
2. OAuth / OIDC entry points (RFC 6819, RFC 9700)
Section titled “2. OAuth / OIDC entry points (RFC 6819, RFC 9700)”Each OAuth client is an entry point. Harden the flow:
- Authorization Code + PKCE for every client (defeats code interception). Avoid implicit.
- Bind
stateto the browser (short-lived HttpOnly cookie compared at the callback) or a victim gets logged into an attacker’s account. - Exact
redirect_uriallow-list (STRICT). Validate redirects by resolving them, not prefix matching (/\evil.examplestarts with/and still leaves the site). - Validate
iss/aud/expon every token; short access-token TTLs; identity is(provider, sub), never email. - Watch the callback handler itself — real case n8n GHSA-vpgc-2f6g-7w7x (“Authorization Bypass in OAuth Callback”).
3. Token / session forgery
Section titled “3. Token / session forgery”Whoever holds the signing key can mint any identity (Storm-0558 cross-tenant forgery; a hardcoded JWT secret in GHSA-mqq6-462x-jxmm let anyone forge admin tokens).
- Protect the proxy’s cookie signing + encryption secrets and the IdP signing key like root
credentials. A leak of the cookie secrets = forging
_pomeriumcookies = walking through the IAP as any allowlisted identity. - Rotate any key that leaked — it is burned. Rotation and a git-history purge (see below).
- JWKS with key rotation; short token lifetimes; never commit keys.
4. DNS redirection / poisoning
Section titled “4. DNS redirection / poisoning”Poison or rebind the app/IdP name so OAuth redirect_uri or token delivery goes to the attacker
(the “reflection attack to redirect an admin token”).
- Use hardened/validating resolvers (Cloudflare, or a validating resolver); DNSSEC where available.
- Pin
redirect_uritohttps; don’t run recursive resolvers with loose zone-transplant features (e.g. PowerDNSZoneToCache, CVE-2026-33612) against untrusted authoritative servers.
5. Lateral movement
Section titled “5. Lateral movement”Past the proxy, a compromised app pivots toward admin / hypervisor / other services. “Private” IPs
(Tailscale 100.x, Docker 172.x/10.x, ULA fdab:) are reachable from their own networks and
are not security boundaries. Segment so a downstream app can’t reach the IdP/DB/host directly;
treat Docker/Tailscale networks as untrusted; MFA on admin.
Verification checklist (run against a live deployment)
Section titled “Verification checklist (run against a live deployment)”# trusted-proxy scope (must be loopback + tunnel ONLY, not a shared range)grep -E 'TRUSTED_PROXY_CIDRS|trustForwardHeader' <idp-config># does the proxy send UNSIGNED claim headers? (jwt_claims_headers present = risk)grep -nE 'pass_identity_headers|jwt_claims_headers|preserve_host_header' <proxy-config># is the upstream proxy-only? (must NOT also bind the Docker bridge)ss -tlnp | grep ':<upstream-port> ' # 127.0.0.1 = good; 172.17.0.1 or * = reachable without the proxydocker run --rm alpine wget -T4 http://172.17.0.1:<port>/ # must fail# DNS resolver class (no loose ZoneToCache)systemctl is-active pdns-recursor; docker ps | grep -iE 'pdns|powerdns'Leaked secret / sensitive data in git history
Section titled “Leaked secret / sensitive data in git history”Rotation is mandatory (the value is burned) but the data lives in every clone and mirror’s history.
Scrub it with git filter-repo (--replace-text for a secret, --blob-callback for a category
like internal IPs / paths / container names), cover every branch that descends from the bad
commit, force-push to every remote (GitLab and any GitHub mirror), purge dangling objects
(git gc --prune=now), and verify from the outside (anonymous curl the public raw URL).
Full procedure: ops-safety.md in the operator rules.
Related
Section titled “Related”- Identity-Aware Proxies — choosing & deploying an IAP
- Authentik Hardening — the IdP side
- Server Hardening · MFA & Passkeys