fix(selfhost): stop client-spoofed cf-connecting-ip from bypassing rate limits - #7392
Conversation
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7392 +/- ##
=======================================
Coverage 91.18% 91.18%
=======================================
Files 716 717 +1
Lines 72697 72754 +57
Branches 20423 20454 +31
=======================================
+ Hits 66288 66340 +52
- Misses 5367 5368 +1
- Partials 1042 1046 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Caution 🛑 LoopOver review result - reject/close recommendedReview updated: 2026-07-20 03:21:35 UTC
Review summary Nits — 5 non-blocking
Why this is blocked
📋 Copy for AI agents — paste into your coding agentDecision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionPartially addressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
|
LoopOver is closing this pull request on the maintainer's behalf (No linked issue detected). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed. |
|
CI is fully green (validate, codecov/patch, self-host smoke). Auto-closed for linked issue #477 being closed as not_planned — this PR uses the Node-edge trusted-client-ip approach (supersedes closed #6550) which is the correct fix for self-host without trusting XFF on Workers. Maintainer: please reopen #477 (or file a new gittensor:bug issue) so this can merge. Happy to update the PR body with the new issue number. |
Summary
Root cause: Self-host binds Redis
RATE_LIMITER, butclientIp()insrc/auth/rate-limit.tstrustscf-connecting-ip. On Node that header is client-controlled (Caddy only setsX-Real-IP/X-Forwarded-For). Attackers can rotate it to bypass strict pre-auth buckets (10/min on/v1/auth/*); honest clients without it collapse to a sharedunknown-ipbucket.Fix: At the Node
serve({ fetch })edge, overwritecf-connecting-ipviaapplySelfHostFetchTrustedClientIp(src/selfhost/trusted-client-ip.ts): delete any client-supplied value; behind a private/link-local peer (Caddy) preferX-Real-IP/ leftmostX-Forwarded-For; on a public peer use the TCP address. Cloudflare Workers path unchanged.Impact: Self-host auth/webhook rate limits bind to the real client again.
Fixes #477
Test plan
test/unit/trusted-client-ip.test.ts— spoof rejection, Caddy hop, peerRemoteAddress shape, IPv4-mapped peers, malformed IP rejectionRisk / tradeoffs