Repository navigation
fix(abuse): key rate limits on route path, not request host - #14785
Conversation
|
Review complete. 🟠 1 high 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
The change introduces a shared
Reviewed commit: c7f04ba |
🟢 Tier S · Ready to mergeAbuse-limit keys now use the matched route path, and realtime connection limits use the fixed realtime path. Forwarded host and port headers are configurable in the HTTP package and trusted by Appwrite only for requests from configured proxies. Trusted forwarded host and port values now use the nearest proxy’s comma-separated entry, with regression coverage for host selection. Latest changes: The latest commit changes trusted forwarded host and port parsing to select the rightmost value and updates the host test to verify that a client-supplied leftmost value is ignored.
📂 Walkthrough · 9
Merged |
There was a problem hiding this comment.
This PR adds trusted-proxy handling for host/port headers and removes the client-controllable hostname from abuse-limit keys, but the new header-trust logic reads the spoofable leftmost X-Forwarded-Host value.
Key findings
- 🟠 Trusted host/port headers read the spoofable leftmost value — Request.php:169
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
|
On the tenki nitpick about dropping the hostname from |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
# Conflicts: # tests/e2e/General/AbuseTest.php
…14785) The {url} abuse-key component included the request hostname, so a client could reset any limit by changing the Host or X-Forwarded-Host header. It is now the matched route path, and the realtime connection limit keys on /v1/realtime instead of the raw URI. The forwarded host and port trust changes live in packages/http, which 1.9 does not have, and are not ported. (cherry picked from commit 5cb4be8)
…14785) The {url} abuse-key component included the request hostname, so a client could reset any limit by changing the Host or X-Forwarded-Host header. It is now the matched route path, and the realtime connection limit keys on /v1/realtime instead of the raw URI. The forwarded host and port trust changes live in packages/http, which 1.9 does not have, and are not ported. (cherry picked from commit 5cb4be8)
…14785) The {url} abuse-key component included the request hostname, so a client could reset any limit by changing the Host or X-Forwarded-Host header. It is now the matched route path, and the realtime connection limit keys on /v1/realtime instead of the raw URI. The forwarded host and port trust changes live in packages/http, which 1.9 does not have, and are not ported. (cherry picked from commit 5cb4be8)
…14785) The {url} abuse-key component included the request hostname, so a client could reset any limit by changing the Host or X-Forwarded-Host header. It is now the matched route path, and the realtime connection limit keys on /v1/realtime instead of the raw URI. The forwarded host and port trust changes live in packages/http, which 1.9 does not have, and are not ported. (cherry picked from commit 5cb4be8)
…14785) The {url} abuse-key component included the request hostname, so a client could reset any limit by changing the Host or X-Forwarded-Host header. It is now the matched route path, and the realtime connection limit keys on /v1/realtime instead of the raw URI. The forwarded host and port trust changes live in packages/http, which 1.9 does not have, and are not ported. (cherry picked from commit 5cb4be8)
fix(abuse): key rate limits on route path, not request host (cherry picked from commit 5cb4be8)
Summary
Rate-limit keys now depend only on server-side request facts, not on the hostname the request names.
app/controllers/shared/api.php: the{url}abuse-key component is the matched route path instead ofhostname + route path, in both the init check and the shutdown reset. Key shape is otherwise unchanged; labels still scope by project, IP, user, email, and so on.app/realtime.php: the realtime connection limit keys on the fixed/v1/realtimepath instead of the raw request URI.packages/http:TrustedHeadersgainshostandportlists, empty by default. The Swoole request readsx-forwarded-host/x-forwarded-portonly when they are named there, the same wayipandprotoalready work. Before this change it always believed them.Appwrite\Utopia\Requesttrustsx-forwarded-host/x-forwarded-portonly when the connection comes from an address in_APP_TRUSTED_PROXIES, matching howgetIP()treatsX-Forwarded-For. Deployments behind a CDN or a proxy on a private network (Traefik, Fastly into the cluster) keep their current hostname resolution.Existing buckets are keyed differently after deploy, so counters start fresh once.
Test plan
bin/monorepo check http,bin/monorepo test http(newSwooleRequestTestcases: forwarded host/port ignored by default, honoured when named, non-numeric port skipped)tests/unit/Utopia/RequestTest.php: forwarded host/port ignored from an untrusted client, honoured from a trusted proxycomposer refactor:checkAbuseTest::testAbuseLimitIgnoresHostexhausts thePOST /accountlimit, then expects 429 with a differentHostand with a differentX-Forwarded-HostRelated: appwrite-labs/cloud#6674