The request lifecycle: why the order of ProxyAuth's gates is part of the contract
Was this useful?
0 unique visitors
Most gateway documentation lists features. What it rarely says is in which order they run, and that order matters more than any single feature: a check placed after the thing it is meant to protect protects nothing. ProxyAuth treats the order as part of its contract. This post walks through it gate by gate.
The chain
1. IP abuse blocklists → 403
2. ACME challenge path → served, always
3. route matching → 404
4. redirect_protect → maintenance response (503, target, or 303)
5. rate limit → 429
6. required_login → redirect to the login page
7. CSRF, access control,
request filters → 403 / login failure
8. forward to backend or serve from disk
9. response middleware → tags, hidden blocks, headers, compression
Response middleware only runs on routes that opted into it.
1 · Blocklists run before everything
ip_blocklists in config.json loads published abuse feeds — Spamhaus
DROP, FireHOL, an AbuseIPDB export, a local file — and checks the
resolved client IP against them before anything else happens. A blocked
address gets a flat 403 and never reaches route matching,
authentication or CSRF.
That placement is the point: nothing downstream — a permissive route, a misconfigured filter, a bug in a later stage — can be used to get around the block, because a blocked request never gets that far.
The one trap is the word resolved. Behind a load balancer the client
IP comes from X-Forwarded-For, but only when the TCP peer is listed in
trust_proxy_forward_for. Without that entry, ProxyAuth checks your
load balancer’s own address, and the blocklist silently protects
nothing. Details in the IP abuse blocklists
post.
2 · Certificate renewal is never gated
Requests for /.well-known/acme-challenge/{token} are answered right
after the blocklist and before routing. Nothing that comes later — a
maintenance gate, an allow_ips restriction, a required_login route
at / — can prevent Let’s Encrypt from validating a renewal.
This is what makes “put the vhost in maintenance for a week” a safe operation: the certificate keeps renewing throughout.
3 · Route matching
Matching runs in two passes over the requested host. The first
considers routes that name the host literally, plus catch-all routes
with no vhost; the second adds routes that match through a wildcard
pattern. Within a pass, regex routes are tried first in file order,
then prefix routes longest-first, with / always last.
Nothing matched means 404. Matching happens early because every later
gate is configured per vhost or per route: until the route is known,
there is no policy to apply. The
prefix vs regex and
wildcard vhosts
posts cover the algorithm.
4 · redirect_protect: who reaches the real content right now
Maintenance mode runs as early as a per-vhost gate can: after the blocklist and the ACME path, before authentication is even considered. It does not ask who is logged in but who reaches this route’s content at all at the moment.
A visitor outside allow_ip receives the maintenance page with a
503, a proxied response from target, or — for a failed paths
session check — a real 303 to redirect_url. It fails closed: an
undeterminable IP, a timed-out check, or nothing usable to serve all
end in a bare 503, never in the real content.
5 · Rate limiting
Two independent classes: ratelimit_auth for /auth, and
ratelimit_proxy for proxied traffic. A flood of bad passwords cannot
starve API traffic, and the reverse is also true. Anything over the
burst gets a clean 429, after block_delay milliseconds.
The counters are built once at startup and shared by every worker and
every num_instances server in the process, so the configured burst is
the burst enforced across the whole host.
/adm/* is deliberately outside both classes, so an operator or a
monitoring system is never throttled during an incident. Those endpoints
are protected by token_admin alone — treat it as a root credential.
6 · required_login
Only now does the session matter. A route with required_login: true
and no valid session sends a browser to the login page. Verifying a
token means decrypting it, checking its signature and its own expiry
(the cacheable part), then — on every request, cached or not — resolving
the user by index, checking expiry against the current
token_expiry_seconds, and checking the revocation set.
That is why a revoked token or a shortened expiry takes effect on the next request rather than when a cache entry ages out.
7 · CSRF, access control, filters
Three per-route checks for an already-authenticated request:
- CSRF applies when session cookies are on, CSRF resolves to
enabled for the vhost, and the route has
need_csrf(defaulttrue). - Access control —
username,groups,roles, combined as an OR. All three empty means any authenticated account. - Request filters — regex conditions on method, path, header,
query parameter or body, combined as an AND. The path is canonicalised
first, so
/a/../bis matched as/b.
8 · Forwarding
Ten hop-by-hop headers are stripped in both directions, client copies of
X-User* and forwarding headers are removed and replaced with
ProxyAuth-asserted values, and the body is re-serialised with its own
framing. The hop-by-hop headers
post explains why that last step is what closes request smuggling.
9 · Response middleware
Only on routes that asked for it: {{ }} tag substitution and
hidden_blocks (both require tag_proxyauth: true), CSRF injection
into forms, response headers merged from the vhost group and the route,
and compression. Anything that rewrites the body forces the route to
buffer, even with streaming: true — see the
streaming
post.
Reading a symptom backwards
The chain also works as a debugging tool:
| You see | The request stopped at |
|---|---|
a flat 403 for every path from one address | the blocklist |
404 | route matching — check the vhost and the prefix |
503 with your maintenance page | redirect_protect |
429 | rate limiting |
| a redirect to the login page | required_login |
403 on a logged-in request | access control or a filter |
502 on an mTLS route | a client certificate error with strict_mtls: true |
Blocklist first so nothing can route around it, ACME second so nothing can lock renewal out, maintenance before authentication, and everything identity-related only once the route and its policy are known. The order is the design.