Generated Caddyfile cannot pass the real client address when a CDN or proxy sits in front of Caddy
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
Research direction
Start with setup-scripts/debian13/06-caddy.sh and its existing bats tests, then read setup.env.example and the proxy guidance in setup-scripts/debian13/README.md. Check how the generated Caddyfile handles all three reverse_proxy blocks and how the installer validates Caddy before replacing the file. Done means the optional settings preserve the default output, validate trusted proxy configuration, and meet the listed tests and documentation criteria.
Written by the indexing model from the issue text.
Description
Problem
The anonymous passkey routes are rate-limited per client address, and sessions store the same address. The key is request.client.host (server/orcaster_server/auth/router.py:105, server/orcaster_server/auth/router.py:181, server/orcaster_server/auth/router.py:411). uvicorn rewrites it from X-Forwarded-For only for trusted peers, which by default is the loopback address (server/orcaster_server/auth/rate_limit.py:27-30). In the setup from setup-scripts/debian13, that peer is Caddy.
The generated Caddyfile has a plain reverse_proxy and no trusted_proxies or client_ip_headers (setup-scripts/debian13/06-caddy.sh:79-116). By default Caddy ignores forwarded headers from peers it does not trust, which stops spoofing. When Caddy faces the internet directly, this is correct.
The docs describe putting a CDN, WAF or another proxy in front of the server (setup-scripts/debian13/README.md:362, setup-scripts/debian13/README.md:366-370, docs/user-manual.md:4283). In that layout, Caddy sees the edge address as the client and writes it into X-Forwarded-For. All visitors that reach the server through the same edge address then share one rate-limit bucket. One abusive client can cause 429 for all of them, and session records show edge addresses.
Proposed change
- Add two optional settings to
setup-scripts/debian13/setup.env.example, for exampleTRUSTED_PROXY_RANGES(space-separated CIDR list of the edge) andCLIENT_IP_HEADER(defaultX-Forwarded-For). - When
TRUSTED_PROXY_RANGESis set,06-caddy.shwrites the full chain, not only the trust list:- A global
serversblock withtrusted_proxies static <ranges>,client_ip_headers <header>andtrusted_proxies_strict. Without strict mode, Caddy takes the leftmostX-Forwarded-Forvalue, which the client controls. With strict mode, Caddy reads the header from right to left and takes the first address that is not a trusted proxy. header_up X-Forwarded-For {client_ip}in each of the threereverse_proxyblocks (setup-scripts/debian13/06-caddy.sh:101,:108,:114). By default, Caddy appends the edge address to the header it forwards, and uvicorn takes the rightmost untrusted address, so it would still see the edge. Withheader_up, uvicorn gets one value: the client address that Caddy resolved.- uvicorn keeps trusting only the loopback address (
server/orcaster_server/auth/rate_limit.py:27-30). Caddy is the only trusted peer of uvicorn, and the edge is trusted only by Caddy. - The settings need Caddy 2.8 or later (
client_ip_headers,trusted_proxies_strictand{client_ip}). The installer keeps an already installed Caddy (setup-scripts/debian13/06-caddy.sh:27), so the script checkscaddy versionand stops with a clear error on an older one, before the Caddyfile is replaced. - With a header other than
X-Forwarded-For, the edge must set that header itself and never pass a client value through. The docs say so.
- A global
- Document the settings in
setup-scripts/debian13/README.mdnext to the existing notes about a proxy in front. State that the operator must keep the ranges current, and that the limit needs these settings whenever Caddy does not face the internet directly.
Compatibility
- With the new settings unset, the generated Caddyfile is byte-identical to today. Existing deployments see no change.
- The settings are new and optional. No upgrade step is needed.
- A deployment that later enables them will see rate-limit keys and session addresses change from the edge address to the client address, as long as the edge adds the client address to the header and its ranges are current. A client that connects to Caddy directly from outside the ranges keeps its own address as the key.
Acceptance criteria
- With
TRUSTED_PROXY_RANGESunset, the generated Caddyfile is byte-identical to the current output (bats test). - With it set, the Caddyfile contains
trusted_proxies staticwith the given ranges,client_ip_headerswith the given header,trusted_proxies_strict, andheader_up X-Forwarded-For {client_ip}in all threereverse_proxyblocks, andcaddy validatepasses (bats test). - With it set and a Caddy older than 2.8, the script stops with a clear error and the current Caddyfile stays intact (bats test).
- Through a trusted edge that appends the client address,
request.client.hostequals the real client address (integration test or recorded manual check). - Through a trusted edge, a client-supplied leftmost
X-Forwarded-Forvalue does not change the rate-limit key (test). - An invalid range is rejected before the Caddyfile is replaced, and the current Caddyfile stays intact (bats test).
- Existing deployments keep working without config changes.
-
setup-scripts/debian13/README.mdandsetup.env.exampledocument both settings and when they are needed. - CHANGELOG entry under Unreleased.
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 10
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AInvirion/orcaster
-
enhancement P3 server
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
enhancement good first issue P3 server
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug P2 server
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
bug P3 server
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
enhancement P3 server
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
All issues in AInvirion/orcaster
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
daniel-ospina/tortoise#15308 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
difficulty:easy prio:low type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NatronGitHub/Natron#2405 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Jstar269/nakagawa-recomp#3746 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day