Skip to content

fix(jellycompat): apply rate limits to the Jellyfin listener - #2305

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/1216-jellycompat-rate-limits
Oct 12, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/1216-jellycompat-rate-limits

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1216
Validation tasks: none (recorded passed cases unchanged).
Planned validation: #1217 C1 and #1246 C1, both Not run.

The Jellyfin-compatible listener ignores the server's rate limits, so POST /Users/AuthenticateByName accepts unlimited password guesses. Silo has no per-account lockout, and the native sign-in throttle only covers the native API. Anyone who can reach the Jellyfin port, which is often exposed for apps such as Infuse, can guess passwords as fast as the server answers. This change applies the same rate limits, with the same counters, to the Jellyfin listener.

Approach

  • The listener receives the native rate-limit middleware instance, so admin settings, hot reloads and counters (in memory or Redis) are shared with the native API.
  • AuthenticateByName spends the login budget: per IP, per IP for sign-in, then global. A sign-in attempt on either listener counts against the same budget.
  • Authenticated API and media routes run the global and per-IP limits after authentication, where the native API applies them. Anonymous images, avatars, web assets and public server reads stay unlimited, as their native equivalents are.
  • A rejected request gets a 429 in the listener's usual error shape ({"Error":"TooManyRequests",...}) with Retry-After. Native 429 responses do not change.
  • With rate limiting off, the listener behaves as before. API keys used on this listener get the global and per-IP limits but not a per-key tier, because the listener's API-key auth does not carry the native key details.

docs/jellycompat-api.md describes the limits.

Validation

  • Two API replicas with the Redis rate-limit backend and default budgets (sign-in 20 per minute, burst 10), 14 wrong-password sign-ins on one replica's Jellyfin listener:

    • Before: all 14 returned 401, and the correct password still worked straight away.
    • After: the 13th returned 429 with Retry-After. The correct password was then refused for that IP on the other replica's Jellyfin listener and on native sign-in on both replicas.
  • Unit tests cover the sign-in budget per IP, the shared counter with native sign-in, routes that stay unlimited, unauthenticated requests still answering 401, and the limiter being off.

  • go build, go vet, make lint-changed, make verify-route-inventory, make lint-router-recovery, make verify-local-paths and the internal/jellycompat and internal/ratelimit tests pass. The full CONTRIBUTING gate ran on a combined build of this branch with the other [v1] Server limits & audit logs #1216 branches. Every step passed except make test-go: its failures also occur on unmodified main on the macOS test machine (hardware-acceleration probes and TestAdminResourceCapabilitiesAndScope), apart from transcode timing tests that failed under heavy machine load and passed on rerun.

  • Not run: real Jellyfin clients (Infuse, Jellyfin Web, Findroid) against the limits. The default per-IP budget is 120 requests per second with images exempt; representative real-client traffic has not been measured against it.

  • Independent review at 7f80e3e2b: the complete rate-limit package, Jellyfin router rate-limit tests, and focused race tests pass. Two Dolby Vision playback tests fail on both this head and a clean base checkout on the review machine. The CI database-pin failure also occurs in main run 38185031866. No live sandbox or real-client verification was repeated by this review.

  • GitHub GraphQL rate limiting prevented a board refresh. REST validation-issue records were checked instead; no recorded passed case was found to regress. Server limits & audit logs — Server #1217 C1 and Compatibility layers (Jellyfin / Audiobookshelf) — Jellyfin compatibility #1246 C1 remain Not run.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2305/

Risks

Several Jellyfin clients behind one household IP now share the per-IP budget with native apps on that IP. Native apps already shared it with each other, and the defaults leave a wide margin.

Follow-ups

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 (implementation) and Codex (independent review), running in T3 Code
  • Tool(s): Claude Code, Codex review subagents, T3 Code delegated review, GitHub CLI, silo-evidence
  • Model(s): claude-opus-5-5 (implementation and cross-provider review); gpt-6.1-sol (independent review and validation check)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: an independent review checked credential-route coverage (path normalisation and /emby prefixes), client IP handling, native parity for media routes, and normal Jellyfin client load; no issues found
  • Independent review: Codex at xhigh, with six read-only review/verification subagents at high, and one Claude Opus 5.5 adversarial round at high, reviewed 7f80e3e2b. No introduced defect was confirmed. The documented API-key tier exception was retained; existing proxy-trust and generic-budget-order issues are tracked in [bug] A direct client in a trusted proxy range can bypass per-IP sign-in limits #2329 and [bug] Requests rejected by per-IP limits still consume the global request budget #2330.

The Jellyfin listener had no request rate limiting, so
POST /Users/AuthenticateByName allowed unlimited password guessing.

The listener now shares the native rate-limit middleware instance:
sign-in spends the per-IP login budget (the same counter as native
login), authenticated and media routes run the generic limiter after
auth, and anonymous artwork, avatars, web assets and public server
reads stay unlimited, matching the native surfaces. 429s use the
listener's error envelope with Retry-After. With rate limiting
disabled the listener behaves as before.
@silo-kody

silo-kody Bot commented Oct 11, 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 11, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fec6d86b-d5bd-4ab4-ba63-31936f3cfd71

📥 Commits

Reviewing files that changed from the base of the PR and between 7db3178 and 7f80e3e.


📒 Files selected for processing (7)
  • cmd/silo/main.go
  • docs/jellycompat-api.md
  • internal/jellycompat/ratelimit.go
  • internal/jellycompat/ratelimit_test.go
  • internal/jellycompat/router.go
  • internal/jellycompat/server.go
  • internal/ratelimit/middleware.go

  • 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T23:29:00.746649Z 7f80e3e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-triage silo-triage Bot added bug Something isn't working 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 labels Oct 11, 2026
@Rhainland

Copy link
Copy Markdown
Contributor Author

No evidence to submit: this change has no user-visible screen or UI change. The measured before and after results are in the Validation section.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f80e3e2b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +220 to +221
r.With(compatAuthEndpointRateLimit(deps.RateLimit, compatLoginRateLimitBucket)).
Post("/Users/AuthenticateByName", authHandler.HandleAuthenticateByName)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Throttle credential attempts by the immutable peer

When the caller's transport address falls inside clientip.trusted_proxies (the defaults include all RFC 1918 and loopback ranges), the caller can rotate X-Forwarded-For to bypass this wrapper: clientip.Middleware stores the header-derived address in clientip.FromContext, and AuthEndpointHandlerWithRejectBody uses it for both the ip: and authip: keys, so every forged address receives a fresh password-guess budget. internal/clientip/middleware.go explicitly reserves PeerFromContext for rate limiters and abuse controls (and the ABS login limiter already follows that contract), so this credential route needs an unforgeable transport-peer budget in addition to any resolved-client budget.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the trigger for a direct peer in a trusted range, but the same resolver and clientip.FromContext keying exist on the base branch and on native login. Before this PR, Jellyfin password sign-in had no request limiter. I filed #2329 for the inherited trust/abuse boundary.

Adding the existing login budget to the raw proxy peer would make every client behind that proxy share one 20-per-minute, burst-10 allowance, including across the native and Jellyfin listeners. That needs a separate correction which preserves legitimate proxy traffic. This PR keeps the native per-client behavior; no code change was made for this comment.

AI: Codex in T3 Code, gpt-6.1-sol; independently checked by claude-opus-5-5.

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 7f80e3e2b137f7b08f174fe49233fa3d3baadd13: no confirmed introduced defect after the multi-agent source review, focused tests, and one cross-provider adversarial round. The proxy-header concern is inherited from the native limiter and tracked in #2329; generic global-budget ordering is tracked in #2330. The summary comment records the remaining CI and live-client validation conditions.

AI: Codex in T3 Code, gpt-6.1-sol; read-only adversarial review by claude-opus-5-5. No code changes.

@Quick104

Copy link
Copy Markdown
Contributor

Reviewed head: 7f80e3e2b137f7b08f174fe49233fa3d3baadd13.

Fit: 9/10 · Readiness: 7/10 — conditional. Sharing the existing limiter closes the unlimited Jellyfin sign-in path without duplicating counters or changing native response contracts. No introduced defect was confirmed. Readiness remains conditional on green required CI and representative Jellyfin-client validation.

Review results

  • Source review: three finders, a validation checker, a sweep, and an inherited-defect verifier on gpt-6.1-sol at high, with the parent at xhigh. One cross-provider adversarial round used claude-opus-5-5 at high. Reviewed route aliases, authentication order, response parity, shared memory/Redis counters, reloads, and playback routes.
  • The bot's forwarded-address concern is real for direct peers inside the trusted ranges and already affects native login on the base branch. It is tracked in [bug] A direct client in a trusted proxy range can bypass per-IP sign-in limits #2329. Applying the existing login limit to the proxy peer would combine legitimate clients into one allowance, so that change was not made here.
  • The generic limiter's global-before-IP order also predates this PR and is tracked in [bug] Requests rejected by per-IP limits still consume the global request budget #2330. Both issues were confirmed from source on head and base; neither was reproduced on a live deployment during this review.
  • API-key tier limits remain a documented exception: compatibility authentication accepts unscoped admin keys and does not publish native API-key claims. This PR adds global/per-IP limits to those requests; it does not remove a previously enforced tier budget. Retained as the stated scope.
  • No source fixes, commits, or pushes were needed. The PR description now links the published evidence and identifies the existing issues, manual update, and unrun validation cases.

Verification and remaining checks

The rate-limit package and Jellyfin router rate-limit tests pass. Focused native/Jellyfin middleware tests also pass with -race -count=1. The full Jellyfin package has two local Dolby Vision failures, TestPlaybackInfoWithoutStripOrToneMapStillHasNoRoute and TestPlaybackInfoSkipsStripWhenRPUCannotBeStripped; both reproduce in a clean base checkout.

The PR's required database-pin check fails in TestLogPartitionsMatchPartmanOnNonUTCServer/America/New_York, with activity_log_default holds 1 rows inside the partitioned window. The same failure occurs on main run 38185031866. The Evidence check now passes. The required CI check still needs to be green on this head.

Real Jellyfin clients were not exercised by this review. #1217 C1 and #1246 C1 are both recorded as Not run. Validate shared limits and counter contention, then sign-in, browsing/library sync, and playback with representative Jellyfin clients; normal-load safety was assessed from source, not measured in those clients.

Validated features

The validation helper could not refresh the board because GitHub GraphQL is rate-limited. REST fallback read 214 Validation-labeled issues across Server, Apple, and Android and found 98 passed surface/case records. Board membership and status remain unverified. No regression was found in those records.

Recorded passed cases Validated build Classification
API keys: Server #1190 C1–C3, #1191 C1–C2 #1190 C1: 940 · 3838c3ac; others: 807 · d4e35ba9 No behavior change: native authorization and tier/429 behavior are preserved.
Impersonation: Server #1199 C1–C2, #1200 C1–C2 745 · cbc13de1 No behavior change: identity and start/end authorization are unchanged.
Calendar: Server #1136 C1–C6; Apple #303/#304 C1–C6; Android #313/#314 C1–C6 927 · 66f6a52a; Android TV #313 C1/C5 rechecked on 1116 · 1555e521 No behavior change in the recorded native flows.
People: Server #1143 C1/C2/C5, #1144 C1–C5; Apple #307 C1–C5/#308 C1–C6; Android #317 C1–C5/#318 C1–C6 941 · 82b5b39e No behavior change: catalog/profile/photo paths and native limiter semantics remain intact.
Branding reads: Server #1227 C1, #1229 C1 1144 · 74158b4a Unaffected: public branding/assets remain outside the generic limiter.
Branding administration: Server #1228 C1 1144 · 74158b4a No behavior change: native save/preview behavior is preserved.
User/access-group policies: Server #1196 C1–C2, #1197 C1–C2 Server 7cc2c1f2 (build unrecorded); Web admin 807 · d4e35ba9 No behavior change: policy inheritance, invitations and management permissions are unchanged.

Shared-path evidence: internal/api/router.go supplies the original limiter to v2; internal/apiv2/gates.go retains its gate order. The new wrappers in internal/ratelimit/middleware.go preserve the native response writer. Mixed native/Jellyfin traffic now shares allowances; the passed records do not validate that new contention.

Validation tasks: none among the retrieved passed cases. Planned, not yet run: #1217 C1 and #1246 C1.

Manual and clients

Silo-Server/siloserver.org#174 already covers the shared-limit explanation in configuration.md and optionally jellyfin-apps.md. No matching open docs PR was found. Apple and Android use native v2 sign-in and require no wire-compatibility changes; this PR brings Jellyfin into the existing native budgets.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2305/

AI: Codex in T3 Code, gpt-6.1-sol, with one read-only claude-opus-5-5 cross-provider round. No live sandbox, issue claim, code changes, or merge. Review-mode run; no ongoing babysit watch.

@Quick104
Quick104 merged commit 0b342b4 into Silo-Server:main Oct 12, 2026
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants