Introducing a new way to review your PRs.

Read the announcement

iv-org / invidious

Invidious is an alternative front-end to YouTube

View on GitHub

19 documents · Updated Oct 12, 2026

docs / configuration-and-runtime-security

Configuration and runtime security

Invidious uses one validated configuration to shape how the service starts, connects to its database and upstream services, exposes its network interface, and protects browser and API actions. The same settings also control privacy choices, proxy boundaries, account access, and the limits applied to public instances.

Configuration lifecycle

The configuration lifecycle turns YAML or environment input into the runtime settings used by the server. It loads a file by default, accepts a complete YAML value through INVIDIOUS_CONFIG, then applies top-level INVIDIOUS_ environment overrides before startup continues.

The loader stops startup when a value cannot be parsed or when a required security or service setting is missing. It also turns the separate db form into a PostgreSQL URI, so deployment can choose either a structured database block or one database_url.

When the service starts, the validated settings become shared runtime state. Startup then opens PostgreSQL, builds outbound connection pools, starts enabled jobs, and selects either a TCP listener or a UNIX socket. Command-line options can override selected values such as logging and worker counts. The broader startup order is described in Application bootstrap and request routing.

flowchart LR
    A[Config file or INVIDIOUS_CONFIG] --> B[Parse YAML]
    C[INVIDIOUS_* overrides] --> D[Apply top-level values]
    B --> D
    D --> E[Validate required values and paths]
    E -->|valid| F[Build runtime services]
    E -->|invalid| G[Stop startup]
    F --> H[Serve web and API requests]

The main service requirements are:

  • A database connection through database_url or db.
  • A non-empty hmac_key for signed request protection.
  • A valid socket path and octal permission value when socket binding is enabled.
  • A 16-character invidious_companion_key when one or more companion services are configured.

References: src/…/config.cr• L83-175 src/…/config.cr• L223-346 src/invidious.cr• L60-69 src/invidious.cr• L248-261

Deployment-facing network settings

The listener settings define where the service accepts traffic and how it describes itself to clients. host_binding and port select a TCP listener unless socket_binding selects a UNIX socket instead; domain, external_port, and https_only let generated absolute URLs match the public reverse-proxy address.

Reverse-proxy deployments must keep the public scheme, host, and port aligned with these settings. alternative_domains extends cookie placement for approved public names detected through X-Forwarded-Host; it does not make arbitrary forwarded hosts trusted.

SettingOperational role
host_binding and portBind the direct TCP listener.
socket_bindingReplace TCP listening with a named UNIX socket and its file permissions.
domainSupply the public host for absolute links.
external_portSupply the public port when it differs from the listener port.
https_onlyMark the public service as HTTPS even when TLS ends at a proxy.
alternative_domainsPermit session and preference cookies for listed alternate hosts.

The container setup exposes the development service only on loopback and passes its configuration as INVIDIOUS_CONFIG. Production operators should treat that compose file as a local example and place the service behind the intended network and TLS boundary. The full image and service model is described in Container, database, and service deployment.

References: src/…/config.cr• L124-170 src/…/utils.cr• L217-241 src/…/before_all.cr• L35-36 src/…/login.cr• L27-35 src/…/login.cr• L61-65 src/…/preferences.cr• L234-239 docker-compose.yml• L1-39

Browser privacy and response controls

The request pre-processing layer applies browser controls before feature routes run. It reads the PREFS cookie or the language header to establish user display settings, then adds headers that reduce script, frame, content-type, referrer, and interest-cohort risks.

The content security policy allows local site resources and only the configured public companion origins for media and network access. Embedded pages are the only pages that permit framing. If video proxying is not forced by configuration and the user does not request local playback, the policy also permits direct Google media hosts.

https_only and the server's TLS mode determine whether cookies use the Secure flag and whether the service emits HSTS. Session cookies remain HttpOnly and use SameSite=Lax; preference cookies are readable by the browser because the interface stores display choices in them. I2P hosts are treated as a special case because they do not use HTTPS in the same way.

The user-level search_privacy preference changes the search form from a query-string request to a POST request. This keeps the search text out of the URL and therefore reduces its exposure through copied links, browser history, and referrer data.

References: src/…/before_all.cr• L14-68 src/…/before_all.cr• L120-146 src/…/cookies.cr• L7-50 src/…/preferences.cr• L1-60 src/…/search_box.ecr• L1-20

Outbound proxy and video access controls

Outbound proxy settings control how Invidious reaches upstream web services. The configured http_proxy can use HTTP CONNECT or SOCKS5; SOCKS5 sends host names to the proxy for remote DNS resolution and can use optional username and password authentication. The connection layer applies this proxy to normal upstream clients and keeps companion traffic on its private route without using the general outbound proxy.

This proxy is for Invidious's upstream requests. It does not replace the companion's own proxy used to load video streams from YouTube, so stream restriction or region controls belong in the companion deployment. The wider upstream request flow is described in YouTube backend integration.

The disable_proxy setting is a service-wide safety and resource control. It can disable all proxying or only selected paths:

  • dash blocks adaptive video playback.
  • livestreams blocks live segment proxying.
  • downloads blocks download-oriented playback requests.
  • local blocks local playback choices and keeps media behind the instance.

Playback routes also validate the requested upstream host before they proxy data. This prevents the playback endpoint from becoming a general-purpose open proxy.

References: src/…/config.cr• L68-80 src/…/config.cr• L152-174 src/…/config.cr• L208-221 src/…/connection_pool.cr• L107-136 src/…/connection_pool.cr• L148-179 src/…/socks_proxy.cr• L1-12 src/…/video_playback.cr• L18-28 src/…/video_playback.cr• L96-124

Account sessions and request tokens

Account sessions use a database-backed session identifier in the SID cookie. A logged-in request is mapped to a user before most page work begins, and the server creates a short-lived signed response token for state-changing browser actions such as account updates, subscriptions, playlists, sign-out, and token management.

The hmac_key signs both browser request tokens and API access tokens. Request validation checks the token's session, expiry, allowed method and path scope, and signature. Some flows also use a stored nonce so a short-lived authorization step cannot be replayed.

sequenceDiagram
    participant Browser
    participant Server
    participant Database
    Browser->>Server: Request with SID cookie
    Server->>Database: Resolve session to user
    Server-->>Browser: Page with scoped signed request token
    Browser->>Server: State-changing request with token
    Server->>Server: Check session, expiry, scope, signature, and nonce
    Server->>Database: Apply the authorized action

API clients can authenticate with a bearer access token instead of the session cookie. A user authorizes requested scopes through the web flow, and the service issues a signed token linked to a database session. The API handler rejects missing or invalid authentication with a 403 response, while scope checks limit the token to the requested API method and path. Users can list and revoke their issued sessions; a token with the token-management scope can revoke another token.

References: src/…/before_all.cr• L83-107 src/…/tokens.cr• L3-19 src/…/tokens.cr• L22-40 src/…/tokens.cr• L69-106 src/…/tokens.cr• L109-145 src/…/handlers.cr• L74-119 src/…/account.cr• L192-268 src/…/account.cr• L275-345 src/…/authorize_token.ecr• L29-76 src/…/token_manager.ecr• L19-35

Public-instance limits and administrator controls

Several configuration switches limit the features that create load, expose service data, or allow new accounts. Operators can disable registration, login, CAPTCHA, statistics, or selected API endpoints to match the risk and capacity of a public instance.

Administrator users can change a limited set of these settings from the preferences page. The changes are written to config/config.yml, while ordinary users only receive their own preference state through the database or the PREFS cookie.

ControlEffect
registration_enabledAllows or rejects creation of local accounts.
login_enabledAllows or rejects login attempts.
captcha_enabledAdds the built-in challenge to new-account login flow.
statistics_enabledExposes detailed instance statistics and enables its refresh job.
disable_abusable_apiRejects video, clip, and transcript API requests that can impose high upstream load.
playlist_length_limitCaps the number of videos in a user playlist.

These controls affect different layers. Login and registration checks protect account entry, the API handler rejects selected high-cost requests before route work, and feature routes enforce playback and playlist limits at the point of use.

References: src/…/config.cr• L133-145 src/…/config.cr• L189-193 src/…/login.cr• L13-15 src/…/login.cr• L33-35 src/…/login.cr• L77-96 src/…/handlers.cr• L136-153 src/…/preferences.cr• L192-232 src/…/misc.cr• L1-26 src/…/authenticated.cr• L307-309

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to hmac_key use must preserve the same signing key across browser tokens, bearer tokens, CAPTCHA tokens, and PubSub verification.
  • Changes to domain, external_port, https_only, or alternative_domains must be checked against absolute URLs, forwarded-host cookie selection, cookie security flags, HSTS, and reverse-proxy routes.
  • Changes to companion URLs must keep private service access, public media origins, the companion API key, and the content security policy aligned.
  • Changes to disable_proxy values must cover both the route that offers a playback choice and the route that serves the resulting stream.
  • Changes to token scope names must update both the authorization request and the validator's method/path matching rules.
  • Changes to INVIDIOUS_* environment handling must preserve YAML parsing for typed and converted values and must not bypass required-value checks.

Important failure modes

TriggerConsequenceGuard
Empty hmac_keyStartup stops because signed request protection cannot operate.Validate the key before the server starts.
Companion configured without a valid 16-character keyStartup stops before companion requests can be made.Validate companion configuration as one unit.
Reverse proxy publishes HTTPS but https_only is falseAbsolute links and cookie security can describe HTTP instead of the public HTTPS service.Set https_only and verify external_port and domain.
Unapproved forwarded host reaches login or preference handlingCookies may not be issued for the public host, or an unexpected host may be used for cookie selection.Keep alternative_domains limited to trusted names.
Invalid or missing request tokenState-changing browser action or authenticated API request is rejected.Generate a token for the exact action and validate its session, scope, expiry, and signature.
Playback request names an unapproved hostThe playback route refuses the request instead of proxying arbitrary traffic.Keep host validation in place before upstream access.
Public instance receives high-cost video API traffic with no abuse limitUpstream and local resources can be consumed by easy-to-spam endpoints.Enable disable_abusable_api when the deployment needs that limit.

Key files

FileWhy to read it
src/invidious/config.crDefines the shared configuration model, load sources, defaults, and startup validation.
config/config.example.ymlDescribes deployment-facing settings and the intended YAML contract.
src/invidious.crShows when configuration becomes runtime state and how it selects listeners, pools, jobs, and handlers.
src/invidious/routes/before_all.crShows request-wide browser headers, preference loading, CSP rules, and CSRF token setup.
src/invidious/user/cookies.crShows how HTTPS mode, domains, and cookie flags protect sessions and preferences.
src/invidious/yt_backend/connection_pool.crShows where outbound proxy settings affect upstream clients and where companion traffic is kept separate.
src/invidious/helpers/tokens.crDefines signed token creation, scope matching, expiry, nonce use, and validation.
src/invidious/helpers/handlers.crShows API authentication and the early rejection of disabled high-cost endpoints.
src/invidious/routes/video_playback.crShows host validation and the runtime checks for disabled playback modes.
docker-compose.ymlShows the development service boundary and environment-based configuration handoff.