Skip to content

fix(historyimport): keep user-supplied server addresses off the server's network - #1492

Merged
Quick104 merged 4 commits into
mainfrom
fix/media-server-address-guard
Sep 26, 2026
Merged

Quick104 merged 4 commits into
mainfrom
fix/media-server-address-guard

Conversation

@Quick104

@Quick104 Quick104 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: changes #1240 C1–C3, #1241 C1–C3, #1242 C1–C3, #1243 C1–C2, #1237 C1–C2 (none run yet: a non-admin account that imports from or syncs with a server on Silo's own network now needs the new admin setting)

Any signed-in account could make Silo send requests to addresses on its own network. History import and Plex webhook sync fetch whatever server address the user supplies. That can be a typed Jellyfin or Plex URL, or a server address that Emby Connect or plex.tv lists for the user's account. The HTTP client followed redirects and checked nothing. So on a shared server, any account could point Silo at its database, cache, transcode nodes, the Kubernetes API, or a cloud metadata endpoint, and read the result of each attempt from the response status and timing. Error bodies could leak too:

  • Plex error responses (up to 2 KB) were stored in run warnings, and the v1 run endpoints and realtime history-import events returned them unfiltered.
  • Webhook sync stored raw error text as the connection's last error.

Reported privately by @hackchang.

With this change, server addresses from non-admin accounts must be on the public internet by default. An admin setting lets every account use local network servers. Metadata and other special addresses are refused for everyone.

Approach

  • A new internal/netguard package classifies addresses as public, private, or blocked.
    • Its HTTP transport checks the address on every connection it opens, which covers redirects and DNS answers that change after a URL was checked.
    • Trusted and untrusted requests use separate connection pools, so an untrusted request never reuses a connection opened to a LAN server.
    • Proxy environment variables are ignored.
    • The notification webhook guard now uses the same address list. It blocks everything it blocked before, plus IPv6 multicast, IPv6 site-local, local-use NAT64, and IPv4-compatible IPv6 literals.
  • History import and webhook sync decide trust per account. An enabled admin account may use local network addresses, and so may any account while media_servers.allow_private_destinations is on. Servers an admin configured as import sources are always allowed. A queued run reads the policy again when it starts, so turning the setting off also stops runs already accepted.
  • The setting defaults to off and sits on Security & Access > Network, with a warning shown while it is on. Imports keep working as before on a server where only admin accounts import.
  • A refused address returns 422 on v2 and 400 on v1, with a message that says what to change. It is never reported as an unreachable server.
  • v1 run responses and realtime events now carry the same safe summaries as the v2 run monitors.

Applying the webhook rule, which refuses every private address, would have been simpler. It would also break the main use: importing from a Plex, Jellyfin, or Emby server on the same LAN.

Validation

  • Go: make test-go passes, and go vet, gofmt, and make lint-changed are clean. With a migrated test database attached, the touched packages pass, except two v1 handler tests (TestAdminSubtitleListPageDB, TestCatalogTransferPersistsJobsAndSignedLink). Those two test code this PR does not change and fail the same way on current main.
  • Web: lint (no new warnings), format check, build, bundle budget, and make test-web pass.
  • Contracts and hygiene: every verify-* target in the gate and TestCommittedArtifactMatchesRouter pass.
  • Manual, against a local build with a fake Jellyfin server on loopback:
    • A non-admin account was refused for the metadata address and for loopback (including the IPv4-mapped form and 0.0.0.0), RFC 1918, and CGNAT addresses. This held on v1 and v2, for a Plex custom URL, and for webhook sync, and the fake server received no requests.
    • An admin account imported from the loopback server to completion. When that server redirected to the metadata address, the redirect was refused.
    • With the setting on, the non-admin account could import from loopback, and the metadata address was still refused. Turning the setting off took effect on the next request.
  • Not covered end to end: the check against the server's own public interface address has a unit test only, because the test host has no public address.

Risks

  • Behavior change: non-admin accounts that import from or sync with a server on Silo's network are refused until an admin turns on the new setting. Admin accounts and admin-configured sources are unaffected. The release notes should say this.
  • Proxy environment variables no longer apply to history import and webhook sync requests.
  • Admission resolves a user-supplied hostname once, for at most two seconds, before accepting a run.
  • Any account can still make Silo request public addresses, as notification webhooks already allow.
  • In a container with bridge networking, Silo cannot see the host's public address, so it does not treat that address as its own.
  • The Apple and Android apps do not call these endpoints, so they need no change. The Jellyfin compatibility layer does not include history import or webhook sync.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code subagents, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, directed by the maintainer; not yet human-reviewed
  • Adversarial review: A separate, read-only Claude Code review agent (feature-dev:code-reviewer, sonnet model alias) traced every path from a user- or admin-supplied address to an outbound request. It checked the trust decision on each path, connection-pool separation, address encodings, the notification webhook guard, the redaction surfaces, and whether the tests could pass vacuously. It found no bypass. It flagged IPv4-compatible IPv6 literals (::a.b.c.d) as classified public; they are now blocked. It also noted that the v1 admin run endpoints and the admin websocket snapshot still return unredacted diagnostics. These are left as they are because only admins receive them.

Note

Guard user-supplied history-import server addresses against private networks via netguard

  • Adds the internal/netguard package: a shared outbound address policy that blocks private, blocked (metadata, multicast, NAT64, etc.), and local-interface destinations, with a WithPrivateAccess context marker and guarded HTTP clients used by the Emby, Jellyfin, and Plex clients
  • Adds a LocalNetworkAccess policy in local_network.go: private destinations are allowed only when the media_servers.allow_private_destinations setting is on, or for enabled admin accounts. Personal-run admission, queued execution, and admin user discovery all apply it, with rechecks when queued runs start
  • Adds a PublicRun sanitizer in public_messages.go that replaces stored error, warning, and unmatched-sample diagnostics with an approved message set. v1, v2, and websocket history-import responses now use this projection
  • Webhook sync applies the same policy to Plex connection creation, account discovery, and webhook parsing; refused addresses return HTTP 400 with the address-policy message
  • Admins can toggle the setting in Security & Access; it defaults to false (see outbound-address-guard.md)
  • Risk: history-import and webhook-sync runs with private server addresses now fail until media_servers.allow_private_destinations is enabled or the user is an enabled admin; guarded transports disable proxy environment variables, and errors previously reported as unreachable upstream are now mapped to the new server-address messages

Macroscope summarized baf2944.

Quick104 and others added 2 commits September 26, 2026 03:43
…r's network

History import and Plex webhook sync fetched whatever server address a user
supplied with a plain HTTP client, so any signed-in account could make the
server send requests to its own LAN, cluster services, or cloud metadata.

Add internal/netguard: address classes shared with the notification webhook
guard, and a transport that checks every dialed address (redirects included)
with separate connection pools for trusted and untrusted requests. Server
addresses from non-admin accounts must be public unless an admin turns on
media_servers.allow_private_destinations; admin-configured sources stay
trusted, and metadata and other special addresses are refused for everyone.
Queued runs read the policy again when they start.

v1 run responses and realtime history-import events now carry the same safe
summaries as the v2 monitors instead of stored upstream error text.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
::a.b.c.d is deprecated and has no legitimate use; classify it as blocked
instead of relying on the network stack never routing it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: d595f7a5-25f6-4525-9bab-14d9b8e6f570

📥 Commits

Reviewing files that changed from the base of the PR and between 02a7d2e and 7626b6c.

📒 Files selected for processing (43)
  • docs/admin-api.md
  • docs/architecture/notifications.md
  • docs/architecture/outbound-address-guard.md
  • docs/settings-api.md
  • internal/api/handlers/events_ws.go
  • internal/api/handlers/history_import.go
  • internal/api/handlers/history_import_test.go
  • internal/api/handlers/webhook_sync.go
  • internal/api/handlers/webhook_sync_service.go
  • internal/api/handlers/webhook_sync_test.go
  • internal/api/router.go
  • internal/apiv2/history_imports.go
  • internal/apiv2/history_imports_test.go
  • internal/config/admin_settings.go
  • internal/events/publishers.go
  • internal/historyimport/emby_client.go
  • internal/historyimport/emby_provider_test.go
  • internal/historyimport/errors.go
  • internal/historyimport/jellyfin_client.go
  • internal/historyimport/jellyfin_client_test.go
  • internal/historyimport/jellyfin_provider_test.go
  • internal/historyimport/local_network.go
  • internal/historyimport/local_network_test.go
  • internal/historyimport/loopback_test.go
  • internal/historyimport/personal_runner_test.go
  • internal/historyimport/plex_admin_provider_test.go
  • internal/historyimport/plex_client.go
  • internal/historyimport/plex_metadata_test.go
  • internal/historyimport/plex_provider_test.go
  • internal/historyimport/plex_watchlist_test.go
  • internal/historyimport/public_messages.go
  • internal/historyimport/service.go
  • internal/historyimport/service_admin.go
  • internal/historyimport/service_personal_auth.go
  • internal/historyimport/service_personal_auth_test.go
  • internal/historyimport/service_queue.go
  • internal/netguard/netguard.go
  • internal/netguard/netguard_test.go
  • internal/notifications/webhook_guard.go
  • internal/webhooksync/local_network_test.go
  • internal/webhooksync/service.go
  • web/src/pages/admin-settings/SecurityAccessSettings.test.tsx
  • web/src/pages/admin-settings/SecurityAccessSettings.tsx

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


📝 Walkthrough

Walkthrough

This change adds shared outbound address checks and policy-controlled private-network access for media-server requests. It applies the policy to history imports and webhook sync, adds an administrator setting, and sanitizes public history-import run summaries.

Changes

Outbound address protection

Layer / File(s) Summary
Address classification and guarded transport
internal/netguard/*, docs/architecture/outbound-address-guard.md
Adds public, private, and blocked destination classifications, URL checks, and dial-time enforcement. Trusted and untrusted requests use separate connection pools.
Media-server access policy and configuration
internal/config/admin_settings.go, internal/historyimport/local_network.go, internal/historyimport/service*.go, internal/historyimport/service_queue.go, internal/api/router.go, web/src/pages/admin-settings/SecurityAccessSettings.tsx, web/src/pages/admin-settings/SecurityAccessSettings.test.tsx
Adds media_servers.allow_private_destinations, defaulting to false, and applies the shared policy to personal authentication and import provider construction. The admin settings page exposes the toggle and its warning.
Guarded media-server requests and import validation
internal/historyimport/*_client.go, internal/historyimport/*_test.go
Uses guarded HTTP clients for Emby, Jellyfin, and Plex. Tests cover refused private and blocked destinations, trusted requests, and policy rechecks when queued runs execute.
Webhook sync and destination policy
internal/webhooksync/service.go, internal/webhooksync/local_network_test.go, internal/notifications/webhook_guard.go, internal/api/handlers/webhook_sync*.go, internal/api/handlers/webhook_sync_test.go, docs/settings-api.md, docs/architecture/notifications.md
Applies the local-network policy to Plex connection creation and webhook-sync requests. Address refusals use the policy message. Notification webhook checks use shared address classification and accept only public destinations.
History-import errors and public run summaries
internal/historyimport/public_messages.go, internal/historyimport/errors.go, internal/api/handlers/history_import*.go, internal/api/handlers/events_ws.go, internal/apiv2/history_imports*.go, internal/events/publishers.go, docs/admin-api.md
Maps refused-address errors to API responses and transforms run errors, warnings, and unmatched reasons before history-import API and realtime serialization.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant LocalNetworkAccess
  participant netguard
  participant GuardedHTTPClient
  participant MediaServer
  User->>LocalNetworkAccess: Submit server URL
  LocalNetworkAccess->>netguard: CheckServerURL
  netguard-->>LocalNetworkAccess: Allow or address refusal
  LocalNetworkAccess->>GuardedHTTPClient: Pass policy context
  GuardedHTTPClient->>netguard: Check destination at dial time
  netguard-->>GuardedHTTPClient: Allow or refuse connection
  GuardedHTTPClient->>MediaServer: Send allowed request
Loading

Merge Risk: ⚪ Minimal · up to 7626b

No identified issue remains that should prevent merging after normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 7626b

The change substantially restricts previously unrestricted media-server requests, but the new administrator-controlled exception grants every account local-network access when enabled. That shared permission and its rollout merit architecture review; no introduced or worsened security vulnerability was confirmed.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — With the default policy, a signed-in non-admin account cannot use the examined guarded media clients to connect to private addresses. An administrator enabling the shared exception extends private-network reach to every account using those paths, but not to blocked addresses.

Security Findings and Attack Paths

  • inferred — No introduced or worsened attack path was established in the examined media-client chain. The dial-time control, blocked-address precedence, and pool separation counter the identified redirect, changing-DNS, and trusted-connection reuse routes; unrelated outbound clients were not assessed.

Trust Boundaries and Controls

  • observed — The policy binds private access to a live setting or enabled-admin check, and queued personal-run provider selection checks the policy again. The transport ignores proxies so its address check applies to the destination it dials.

Resilience and Maintainability Implications

  • inferred — Admission and execution checks limit the effect of disabling private access on queued work. Active-fetch revocation and protection of clients outside the guarded media-server paths remain distinct operational limits, not established PR regressions.

Hardening Proposals

  • proposed — Where rapid permission revocation or container-to-host isolation is required, consider cancelling active imports on policy changes and enforcing destination restrictions at the deployment network boundary as well.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.10% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 102 functions across 39 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.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing user-supplied history-import server addresses from reaching the server's local network.
Description check ✅ Passed The description directly explains the problem, security policy, implementation approach, validation, and behavior changes covered by the pull request.
Full details: Docstring Coverage

Explanation

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

  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

Comment thread internal/netguard/netguard.go Resolved
@macroscopeapp

macroscopeapp Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR introduces a new outbound network security boundary and admin-controlled trust policy across history import, webhook sync, and notification transports, changing existing server-originated behavior and API/event diagnostics. Its cross-component security impact warrants human review.

You can add or adjust custom eligibility rules. Learn more.

fec0::/10 is deprecated (RFC 3879) but can still be routed inside a site,
so an untrusted request to a site-local address must be refused like ULA.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread internal/netguard/netguard.go Resolved
A NAT64 gateway translates 64:ff9b::/96 to the IPv4 address in its last 32
bits, so 64:ff9b::a9fe:a9fe reached cloud metadata for trusted callers. Block
a well-known NAT64 address whose embedded IPv4 address is blocked, keep the
rest private, and block local-use NAT64 outright because its embedding varies
by network.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 merged commit d5df9f7 into main Sep 26, 2026
11 of 12 checks passed
@Quick104
Quick104 deleted the fix/media-server-address-guard branch September 26, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant