Skip to content

feat(api): report the request origin in system info - #3023

Merged
Quick104 merged 2 commits into
mainfrom
feat/roku-request-origin
Oct 25, 2026
Merged

Quick104 merged 2 commits into
mainfrom
feat/roku-request-origin

Conversation

@Quick104

@Quick104 Quick104 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

A native client can reach Silo through a different origin than the one the user configured. A reverse proxy might send it elsewhere, or a redirect might move it to another host or from HTTPS to HTTP, and the client can't tell. The Roku client follows redirects silently and re-sends the request body on a 307, so it could hand a password or token to an origin it never meant to trust. This change lets a client check which origin it actually reached before it sends credentials. It also stops authenticated /api/v2 routes from sending a client to another origin.

GET /api/v2/system/info gains request_origin, the scheme and host the server saw the request arrive on. A client compares it with its configured origin before signing in.

Approach

  • request_origin is derived the same way as the OAuth iss: the transport scheme and Host, replaced by X-Forwarded-Proto and X-Forwarded-Host only when the request comes from a configured trusted proxy. When the forwarded scheme is ambiguous, it names the transport's scheme, so a wrong guess shows up as a mismatch, never a false match. The derivation and its canonical serialization moved from the OAuth handler to clientip.RequestOrigin and clientip.SerializeOrigin, so iss and request_origin cannot drift apart. The OAuth behavior is unchanged.
  • Because the response now varies per request, system/info is served with Cache-Control: private, no-cache (it was no-cache). That is the capability documents' existing posture, and it keeps a shared cache from handing one origin's value to a client of another.
  • The v2 transcode manifest and segment routes answer a transcode node's 3xx with 502 instead of relaying it. A node's Location names the node or its front end, never this server. 304 is still relayed.
  • The v2 plugin-content mount answers a plugin redirect that leaves the request's origin, a scheme downgrade included, with 502. It also refuses a Location that Go reads as a path but browsers read as another host: one containing a backslash (/\host, which browsers read as //host) or starting with three or more slashes (///host, where browsers skip the extra slashes). A redirect that sends Location under more than one spelling is refused too, so the value checked is always the value sent. Relative and same-origin redirects pass through. Plugin response headers are now kept under their canonical names on both mounts; the response written is the same.
  • The frozen /api/v1 routes keep relaying both redirects unchanged.
  • docs/architecture/api-contract.md records the new member, the cache policy, and the remaining deliberate cross-origin redirects: the opt-in media-proxy 307s on -proxy downloads and the bandwidth probe, plus the browser OAuth and Discord-link handshakes. OpenAPI, the fixtures, and web/src/api/v2/schema.ts are regenerated.

The field is additive and optional. Apple and Android clients need no change; jellycompat is unaffected because Jellyfin clients use their own system info.

Validation

  • Go: make embed-stub, go build ./..., gofmt -l ., go vet ./..., make lint-changed, make lint-router-recovery, and make test-go pass.
  • Web: pnpm install --frozen-lockfile, lint, format:check, build, and budget:check pass. make test-web failed 3 of 6,730 tests on a heavily loaded host (GlobalSearch, WatchPage, and the PGS parser, including one 5 s timeout). All three files pass when rerun on their own, and this branch changes only one generated type in web/.
  • Contracts and hygiene: every target in the CONTRIBUTING list passes, along with TestCommittedArtifactMatchesRouter and verify-prometheus-rules. make verify-apiv2-contract reports one non-breaking change: the optional request_origin property was added. make verify-actionlint refused the local binary because it prints its version as v1.7.12; actionlint 1.7.12 run directly passes. make verify-shellcheck was not run because only ShellCheck 0.9.0 is installed, and the branch changes no shell files.
  • Tests cover origin derivation (combining scheme and host, and the fallback for an ambiguous scheme), canonical serialization, the transcode relay refusing a node redirect while passing a 304, and the plugin mount allowing relative and same-origin redirects while refusing another host, a scheme-relative URL, a downgrade, a backslash, three or more leading slashes, a control character (tab or newline), and a response with two spellings of Location. The contract fixtures pin request_origin and the new cache header.
  • Not tested: no test checks that router.go wraps the two v2 transcode routes in RefuseRelayRedirects; removing the wrapper fails nothing. The handler test covers the refusal itself. A route-level test would need a full transcode session with stream-token claims and a node, which no router test sets up today.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/roku-request-origin/

Risks

  • A plugin page in the web app that redirects the browser off-origin, for example to an external OAuth provider, now gets a 502 on the v2 mount. So does an absolute redirect built from the plugin proxy base URL (the server's public URL) when the user reached Silo on another address. No first-party plugin returns redirects from its HTTP routes; third-party plugins could.
  • A transcode node behind a front end that redirects, such as an HTTP-to-HTTPS upgrade, now fails v2 transcode playback with 502 instead of following the redirect.
  • system/info responses are no longer stored by shared caches.
  • The media proxy node's own relay (internal/proxy) is unchanged. Requests to it carry signed stream tokens, not account credentials; applying the same redirect refusal there is a possible follow-up.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated; the maintainer requested it and tested the Roku sign-in on a dev deployment, and has not yet reviewed the code
  • Adversarial review: a separate Claude Code agent (claude-opus-5-5) reviewed the full diff read-only with a security focus, and an automated commit security review also ran. Findings: a Location sent under two spellings and a backslash Location could pass the plugin redirect check (both fixed, with test rows); the router wiring has no test (recorded above). No other issues found.

🤖 Generated with Claude Code

Note

Add request_origin to system-info and refuse off-origin relay redirects

  • GET /api/v2/system/info now returns a request_origin field derived via clientip.RequestOrigin, and sets Cache-Control: private, no-cache so per-request origins are not served from shared caches (system.go, middleware.go)
  • Transcode manifest and segment routes are wrapped with RefuseRelayRedirects; relayed 3xx responses (except 304) from the transcode node now get the transcode-unavailable response instead of forwarding the redirect (relay_redirect.go, playback.go)
  • Plugin content pages now reject redirects whose Location leaves the request origin (cross-origin, downgrade, backslash, ambiguous duplicate Location headers) with a 502; the frozen /api/v1 HTTPProxy.ServeRoute keeps old behavior (http_proxy.go)
  • Origin helper logic moves from the auth package to shared clientip.RequestOrigin / clientip.SerializeOrigin (oauth_handler.go)
  • Behavioral Change: system-info Cache-Control changes from no-cache to private, no-cache; native API v2 transcode routes return 502 instead of relaying node redirects (304 still relayed); guarded plugin routes return 502 for off-origin or ambiguous redirects

Macroscope summarized 1abef83.

GET /api/v2/system/info gains request_origin, the scheme and host the
server saw the request arrive on, derived like the OAuth iss: the transport
scheme and Host, replaced by X-Forwarded-Proto and X-Forwarded-Host only
from a configured trusted proxy. A client that must send credentials only
to the origin it configured, such as the Roku client, compares the two
before signing in. The response is now Cache-Control: private, no-cache so
a shared cache never hands one origin's value to another.

The origin derivation and serialization move from the OAuth handler to
clientip (RequestOrigin, SerializeOrigin) so both callers share them.

Authenticated v2 routes also stop redirecting a client to another origin:
the v2 transcode manifest and segment relay answers a node's 3xx with 502,
and the v2 plugin-content mount answers a plugin redirect that leaves the
request's origin, a scheme downgrade included, with 502. It also
refuses a Location with a backslash, which browsers read as a slash,
and one sent under more than one spelling. Plugin
response headers are kept under their canonical names, so the Location
the guard checks is the one written. The frozen v1 routes keep relaying
both redirects unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 25, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T02:09:19.859613Z 1abef83 New commits
🔒 Security Review ✅ Completed 2026-10-25T02:11:50.237069Z 1abef83 New commits
ℹ️ 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-kody

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

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The API v2 system-info response now includes a normalized request origin and uses a private, no-cache policy. Native OAuth shares the origin helpers. Plugin routes and native v2 playback routes add redirect handling.

Changes: Request origins and redirect handling

Layer / File(s) Summary
Shared request-origin derivation
internal/clientip/middleware.go, internal/clientip/request_origin_test.go, internal/auth/oauth_handler.go, internal/auth/oauth_handler_test.go
The client IP package adds request-origin derivation and serialization helpers. Native OAuth uses these helpers instead of local implementations.
System-info request origin
internal/apiv2/system.go, internal/apiv2/router_test.go, internal/apiv2/fixtures_test.go, contracts/api/v2/openapi.json, contracts/api/v2/fixtures/*, web/src/api/v2/schema.ts, docs/architecture/api-contract.md
The system-info response adds request_origin and changes its cache policy to private, no-cache. Schemas, fixtures, tests, and documentation reflect the response contract.
Plugin-route redirect checks
internal/plugins/content.go, internal/plugins/http_proxy.go, internal/plugins/content_test.go
Plugin routes enable same-origin redirect checks. The response handling rejects ambiguous or off-origin redirects with 502. Tests cover redirect locations and conflicting Location headers.
Native v2 playback redirect refusal
internal/api/handlers/relay_redirect.go, internal/api/router.go, internal/api/handlers/playback.go, internal/api/handlers/playback_proxy_test.go
The v2 manifest and segment routes mark requests to refuse transcode-node redirects. The playback handler returns the unavailable response for redirects, while 304 responses remain relayed.

Priority: Normal

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant SystemInfoHandler
  participant clientipRequestOrigin
  Client->>SystemInfoHandler: Request system info
  SystemInfoHandler->>clientipRequestOrigin: Derive origin from request
  clientipRequestOrigin-->>SystemInfoHandler: Return normalized origin
  SystemInfoHandler-->>Client: Return system info with request_origin
Loading
sequenceDiagram
  participant Client
  participant APIV2Router
  participant RefuseRelayRedirects
  participant relayToTranscodeNode
  participant TranscodeNode
  Client->>APIV2Router: Request manifest or segment
  APIV2Router->>RefuseRelayRedirects: Wrap playback handler
  RefuseRelayRedirects->>relayToTranscodeNode: Set redirect-refusal context
  relayToTranscodeNode->>TranscodeNode: Request playback content
  TranscodeNode-->>relayToTranscodeNode: Return response
  relayToTranscodeNode-->>Client: Return 502 for redirect, or relay non-redirect response
Loading

Suggested labels: enhancement, go, javascript, api-v2, impact: usability, size/M

Suggested reviewers: rhainland

Merge Risk: Moderate · up to df92d

The new plugin redirect protection can be bypassed with a triple-slash Location value. A malicious or compromised plugin could then redirect clients off-origin despite the v2 contract. Reject such locations before merging; the actual impact depends on how the client handles the redirect.

Security architecture risk: Moderate · up to df92d

The change strengthens credential-origin protection, but an existing redirect escape remains reachable. It therefore provides a partial security improvement rather than a complete same-origin guarantee. The inspected changes do not establish an expansion of access or privileges.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The retained redirect condition requires influence over an installed plugin's route response and affects clients that access that route. Public descriptors can be reached without authentication; authenticated and admin descriptors retain their respective access gates. Sensitive-material disclosure additionally depends on the client's redirect and credential-forwarding behavior. The evidence does not establish arbitrary anonymous control over installed plugins or an increase in server or worker privileges.

Security Findings and Attack Paths

  • observed — The retained open-redirect finding survives the new v2 guard: a triple-slash Location can be interpreted as a same-origin path by Go but as an off-origin authority by a WHATWG client, after which the original Location is relayed. The guard rejects backslashes, parse errors, and duplicate Location spellings, but those controls do not address this parser discrepancy. The same route caller previously relayed plugin responses unconditionally, so the security condition and effective exposure predate this PR; the PR does not establish a complete fix.

Trust Boundaries and Controls

  • observed — Production v2 manifest and segment handlers receive the refusal wrapper and retain their authentication gates. The node request is signed, and a reconstruction token is forwarded only after verification against the requested session. Internal node clients do not follow redirects. For marked requests, the relay rejects every 3xx except 304 before copying node headers or body, preventing the client-facing Location from crossing that boundary.

Resilience and Maintainability Implications

  • observed — The new refusal policy is request-scoped rather than shared mutable state. Plugin rejection returns before copying plugin headers or body. Relay rejection returns before response forwarding and completion acknowledgment, while the deferred upstream-body close still runs. These terminal paths avoid emitting the rejected destination or acknowledging a redirected segment as delivered.

Hardening Proposals

  • proposed — Close the residual parser gap by rejecting browser-ambiguous authority forms or emitting a validated canonical destination instead of the unchecked original value. Add a triple-slash interoperability regression and a full-router test covering authenticated manifest and segment refusal, including preservation of 304 responses.
Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 77.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 14 files. (5 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "feat(api): report the request origin in system info" matches the main change: an optional request_origin field added to GET /api/v2/system/info, derived from the request scheme and host. It…
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 is detailed and directly related to the changeset. It explains the problem (clients reaching Silo through a different origin, Roku redirect handling), adds request_origin to `GET /ap…
Full details: Title check

Explanation

The title "feat(api): report the request origin in system info" matches the main change: an optional request_origin field added to GET /api/v2/system/info, derived from the request scheme and host. It omits the redirect-refusal changes on v2 routes, but it names the primary feature and is specific enough for a reviewer scanning history.

Full details: Description check

Explanation

The description is detailed and directly related to the changeset. It explains the problem (clients reaching Silo through a different origin, Roku redirect handling), adds request_origin to GET /api/v2/system/info, and describes the derivation via shared clientip helpers, the Cache-Control change, the transcode and plugin redirect refusals, the frozen v1 routes, and the docs/OpenAPI/fixture updates. It also lists validation, risks, and an AI disclosure. Every part of it maps to the file-level summaries.

Full details: Docstring Coverage

Explanation

Docstring coverage is 77.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 14 files. (5 skipped: 4 unsupported, 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

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

@silo-triage silo-triage Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase enhancement New feature or request go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P1 Core-path bug; painful workaround — next after P0 labels Oct 25, 2026

@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: df92d0f942

ℹ️ 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 thread internal/plugins/http_proxy.go Resolved
Comment thread internal/plugins/http_proxy.go Resolved
@coderabbitai coderabbitai Bot added impact: usability Core flow broken or severely blocked javascript Pull requests that update javascript code size/M 50–199 added + deleted lines (all files); change volume, not priority. labels Oct 25, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 41ad2a74-2aa4-4084-b3d6-29b82adbf85f
Commits

Reviewing files that changed from the base of the PR and between d2c12db and df92d0f.

Files selected for processing: 19
  • contracts/api/v2/fixtures/get_system_info_ok.json
  • contracts/api/v2/fixtures/index.json
  • contracts/api/v2/openapi.json
  • docs/architecture/api-contract.md
  • internal/api/handlers/playback.go
  • internal/api/handlers/playback_proxy_test.go
  • internal/api/handlers/relay_redirect.go
  • internal/api/router.go
  • internal/apiv2/fixtures_test.go
  • internal/apiv2/router_test.go
  • internal/apiv2/system.go
  • internal/auth/oauth_handler.go
  • internal/auth/oauth_handler_test.go
  • internal/clientip/middleware.go
  • internal/clientip/request_origin_test.go
  • internal/plugins/content.go
  • internal/plugins/content_test.go
  • internal/plugins/http_proxy.go
  • web/src/api/v2/schema.ts

Included review availability: This review used your included allowance. 5 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 8 reviews per hour.

Comment thread internal/plugins/http_proxy.go Resolved
Go's url.Parse reads `///host/x` as a path on the request host, but
WHATWG URL parsers skip any number of slashes and go to `host`. The
same-origin guard on the v2 plugin mount passed such a Location and
relayed it unchanged. Refuse it before resolution, as the guard already
does for a backslash, and add the three-slash, four-slash, scheme-plus-
three-slash, leading-space, and newline cases to the redirect tests.

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

silo-kody Bot commented Oct 25, 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 ❌

@Quick104
Quick104 merged commit 4146972 into main Oct 25, 2026
36 checks passed
@Quick104
Quick104 deleted the feat/roku-request-origin branch October 25, 2026 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase enhancement New feature or request go Pull requests that update go code impact: security Auth, privacy, or permission boundary impact: usability Core flow broken or severely blocked javascript Pull requests that update javascript code priority: P1 Core-path bug; painful workaround — next after P0 size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant