Repository navigation
STE-53: the API sees the visitor behind Cloudflare and Caddy, not the proxy - #53
Merged
Merged
Conversation
…t the proxy Found on production while recording the STE-52 transcript. Every public request reached the API from Caddy's container address (172.18.0.3 in the logs), so: - the "100 req/min per IP" limit was one bucket shared by every visitor; - URLs built from the request said http://, including the x402 resource.url in every 402 challenge and STE-48's challenge_url. Two halves, both required, both measured: - Caddyfile: trusted_proxies static private_ranges, so Caddy keeps the X-Forwarded-For / X-Forwarded-Proto that cloudflared sends instead of overwriting them. With the old Caddyfile the app-side fix alone still produced http:// and a shared bucket. - API: ProxyHeadersMiddleware as the outermost middleware, trusting only STERISH_TRUSTED_PROXIES (private ranges by default); uvicorn's own proxy handling is off (--no-proxy-headers) so the rule lives in one tested place. The rightmost untrusted X-Forwarded-For entry is the client, so a caller cannot pick its own bucket. Tests: API 178 passed. 8 new; the three that exercise the real app fail without the middleware and pass with it. E2E with caddy:2-alpine in front of this branch's API, rate limit 3/min: old Caddyfile -> resource.url http://, visitor B 429 after visitor A's 3 requests; new Caddyfile -> https://, visitor B 200, API log shows the real visitor addresses. caddy validate: valid.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear: STE-53 · ACC by Axel 2026-09-17 · reviewers @axelmatsama @fable
Problem (verified on production)
The API sits behind Cloudflare → cloudflared → Caddy but did not know it:
172.18.0.3). The "100 req/min per IP" limit was therefore one bucket shared by every visitor.http://, includingresource.urlin every x402 challenge and STE-48'schallenge_url.Fix (two halves, both required)
Caddyfile:trusted_proxies static private_ranges. Caddy keeps theX-Forwarded-For/X-Forwarded-Protothat cloudflared sends instead of overwriting them.ProxyHeadersMiddlewareis now the outermost middleware and trusts onlySTERISH_TRUSTED_PROXIES(private ranges by default). uvicorn's own proxy handling is switched off (--no-proxy-headers), so exactly one tested rule applies. The rightmost untrustedX-Forwarded-Forentry is the client, so a caller cannot choose its own bucket.Tests
API 178 passed. Of the 8 new tests, the 3 that exercise the real app fail without the fix.
E2E
Real
caddy:2-alpinein front of this branch's API, rate limit 3/min, forwarding headers as cloudflared sends them:resource.urlhttp://https://Evidence:
docs/evidence/ste-53-proxy-aware-2026-09-17.json.Deploy
Normal
ctredeploy. It also ships STE-48 (already merged). Axel accepted that on the ACC; Ancung will be told the same day.