Skip to content

fix(ratelimit): stop forwarded clients from dodging sign-in rate limits - #2364

Merged
Quick104 merged 1 commit into
mainfrom
fix/auth-limit-peer-budget
Oct 12, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/auth-limit-peer-budget

Conversation

@Quick104

@Quick104 Quick104 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1216
Validation tasks: none (the only passed case these budgets reach, #1196 C2, accepts one invitation, far below the new cap; #1217 C1, not run yet, covers rate throttling)

Sign-in rate limits could be dodged by sending a different X-Forwarded-For on every request. The login, setup, signup, invitation, device sign-in and other auth budgets count per client IP, and the client IP comes from forwarding headers whenever the connection arrives from a trusted proxy. Every private range and loopback is trusted by default, so a LAN host, or any client whose connection reaches Silo through a container bridge, could name a new client on each request and start a fresh budget each time. The same limiter serves /api/v1, /api/v2 and the Jellyfin listener, so all three were open to unlimited password guessing this way. On an unfixed server, 150 wrong-password sign-ins sent that way across the three surfaces were all answered 401, with no 429.

Approach

When a request's client IP came from forwarding headers, it now also spends a second budget keyed on the connection's own address, which a client cannot forge. That budget is ten times the per-client one (for login: 200 a minute, burst 100) and is shared by every client behind that proxy. A client that rotates the header stops there, and the users behind one real reverse proxy each keep their own per-client budget until together they reach ten times one client's allowance. The extra budget is checked after the per-client one, so a single client already over its own limit does not use up the budget the others behind its proxy share.

Direct connections spend exactly what they did before, and so do requests through a network access provider such as the Tailscale plugin: its ingress token is checked first, and the plugin writes X-Forwarded-For itself, so the client cannot rotate it.

This is a v1 change made during the bridge window as a critical fix, recorded in docs/architecture/v1-scope.md. v2 and the Jellyfin listener change with it because they share the limiter. docs/auth-api.md gains a short Sign-in rate limits section, and the Jellyfin and autoscan webhook docs point to it. Clients need no change: these routes already answered 429 with Retry-After.

This touches only AuthEndpointHandlerWithRejectBody, not the generic limiter that #2353 reorders. The two branches merge without conflicts.

Validation

  • Unit tests send login requests through the real client IP middleware with the default trusted proxy list, on both the in-memory and the Redis limiter. With the header rotated on every request from one private address, the unfixed code allowed 300 of 300 on both backends, and the fixed code allows 100 of 600. Nine clients behind one proxy each get their full login burst. Other tests check which budgets direct, forwarded, overlay and unparseable-peer requests spend, and that a rejection does not spend the wider budgets.
  • On a disposable server (Docker, so requests from its host arrive from the bridge gateway), the same rotation across v1, v2 and Jellyfin sign-in: unfixed, 150 of 150 answered 401. Fixed with the memory limiter, 128 of 150 got through before 429. With the Redis limiter, 114 of 450. A client sending no forwarding header got 429 after its burst of 10 on both builds.
  • go build, gofmt, go vet, make lint-changed (0 issues), and the route inventory, local path and case collision checks pass. In make test-go, internal/ratelimit and internal/clientip pass. The other failures on the macOS test machine (TestAdminResourceCapabilitiesAndScope, two Jellyfin playback-info tests, three NFO lookup tests) fail the same way on main.
  • Web gate not run: no web files changed.

Evidence: https://evidence.siloserver.org/r/silo-server/auth-limit-peer-budget/

Evidence

No user-visible change. The steps, builds and trimmed results are on the evidence page linked under Validation.

Risks

  • Everyone behind one reverse proxy now shares a sign-in ceiling of ten times one client's budget. Many sign-ins at once behind a large ingress, or an attacker sending from ten or more real addresses through the same proxy, can use it up and get every user behind that proxy 429 until it refills (about a minute). Raising the endpoint budget raises both. Before this change, a client could only exhaust its own budget.
  • The Redis limiter counts in fixed minute windows, so across a minute boundary the shared budget can admit up to two windows' worth (400 for login). Per-client budgets already behave this way on Redis.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Codex (gpt-6.1-sol) reviewed 81f4f69ff for remaining ways to get fresh budgets, legitimate users locked out behind proxies, memory/Redis parity, doc accuracy and test quality; no findings. An earlier multi-agent review of the diff led to keeping network access ingress off the shared budget, skipping peers that are not IP addresses, and doc corrections.

🤖 Generated with Claude Code

The auth-endpoint limiter keyed its per-client budgets on the address
resolved from X-Forwarded-For or X-Real-IP. Every private range and
loopback is a trusted proxy by default, so a client connecting from such
an address could name a new client on each request and get a fresh
login, setup, signup, invitation or device sign-in budget every time, on
v1, v2 and the Jellyfin listener alike.

A request whose client IP came from forwarding headers now also spends a
budget keyed on the connection's own address, ten times the per-client
one and shared by every client behind that proxy. Direct connections and
network access ingress, whose plugin writes the header itself, spend the
same budgets as before. clientip.PeerIP gives the peer in the same form
as the resolved client IP so the two compare equal for a direct
connection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 18416398-52d7-4e1e-89c4-4221551bc945

📥 Commits

Reviewing files that changed from the base of the PR and between 984295b and 81f4f69.


📒 Files selected for processing (8)
  • docs/architecture/v1-scope.md
  • docs/auth-api.md
  • docs/autoscan-delivery-api.md
  • docs/jellycompat-api.md
  • internal/clientip/middleware.go
  • internal/clientip/peer_test.go
  • internal/ratelimit/auth_peer_test.go
  • internal/ratelimit/middleware.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.



📝 Walkthrough
📝 Walkthrough

Walkthrough

Eligible auth requests with a forwarded client IP now also consume a connection-peer budget. The peer budget is scaled from the endpoint limit and applies to the default network-access path. Tests and API documentation cover the limits, exclusions, and rate-limit responses.

Changes

Forwarded-client rate limits

Layer / File(s) Summary
Resolve connection peer IP
internal/clientip/middleware.go, internal/clientip/peer_test.go
Adds PeerIP to parse and normalize the transport peer IP. Tests cover IPv4, IPv6, mapped IPv6, and inputs that return an empty result.
Enforce and document peer budgets
internal/ratelimit/middleware.go, internal/ratelimit/auth_peer_test.go, docs/auth-api.md, docs/autoscan-delivery-api.md, docs/jellycompat-api.md, docs/architecture/v1-scope.md
Eligible requests spend a shared peer budget scaled to ten times the endpoint limits, subject to limiter bounds. Tests cover limiter backends, request cases, and rejection behavior. The documentation describes shared budgets, exclusions, and 429 responses with Retry-After.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: rhainland


Merge Risk: ⚪ Minimal · up to 81f4f

The additional shared budget has no established merge-blocking defect. The documented possibility of temporary 429 responses for clients behind a busy proxy remains an expected tradeoff.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description clearly explains the rate-limit bypass, the connection-address budget fix, affected endpoints, validation, risks, and documentation changes.
Title check Passed The title clearly and concisely identifies the main change: preventing forwarded clients from bypassing sign-in rate limits.

Full details: Docstring Coverage

Explanation

Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (4 skipped: 4 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added bug Something isn't working documentation Improvements or additions to documentation go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage triaged High-confidence review completed; does not mean fixed, validated, or accepted for release. labels Oct 12, 2026
@Quick104
Quick104 merged commit bdc79e7 into main Oct 12, 2026
16 checks passed
@Quick104
Quick104 deleted the fix/auth-limit-peer-budget branch October 12, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage triaged High-confidence review completed; does not mean fixed, validated, or accepted for release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant