Skip to content

STE-53: the API sees the visitor behind Cloudflare and Caddy, not the proxy - #53

Merged
Lin1er merged 1 commit into
mainfrom
fix/53-proxy-aware-client-and-scheme
Sep 17, 2026
Merged

Lin1er merged 1 commit into
mainfrom
fix/53-proxy-aware-client-and-scheme

Conversation

@Lin1er

@Lin1er Lin1er commented Sep 17, 2026

Copy link
Copy Markdown
Owner

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:

  • Every public request reached it from Caddy's container address (172.18.0.3). The "100 req/min per IP" limit was therefore one bucket shared by every visitor.
  • URLs built from the request said http://, including resource.url in every x402 challenge and STE-48's challenge_url.

Fix (two halves, both required)

  • Caddyfile: trusted_proxies static private_ranges. Caddy keeps the X-Forwarded-For / X-Forwarded-Proto that cloudflared sends instead of overwriting them.
  • API: ProxyHeadersMiddleware is now the outermost middleware and trusts only STERISH_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 untrusted X-Forwarded-For entry 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-alpine in front of this branch's API, rate limit 3/min, forwarding headers as cloudflared sends them:

Caddyfile resource.url visitor A ×3 visitor B, first request
main http:// 200 200 200 429
this branch https:// 200 200 200 200

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.

…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.
@vercel

vercel Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sterish Ready Ready Preview Sep 17, 2026 11:54am UTC

@Lin1er
Lin1er merged commit 42d726c into main Sep 17, 2026
5 checks passed

This branch was successfully deployed

1 active deployment
Preview — a1c6a48e Deployed Sep 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant