Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for private instances #4259

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ https_only: false
# Users and accounts
# -----------------------------

##
## Allow/Forbid the usage of the Invidious Instance without an account.
## Only /login and /privacy are accessible on such instances for unregistered
## users on the web interface. Moreover, certain API endpoints are accessible,
## to allow third-party clients to add the instance and login to an existing
## account.
##
## To avoid any data leakage it is recommended to set popular_enabled and
## statistics_enabled to 'false'. Furthermore, registration_enabled should be
## set to 'false' to only allow existing users to access the instance.
##
## Accepted values: true, false
## Default: false
##
#private_instance: false

##
## Allow/Forbid Invidious (local) account creation. Invidious
## accounts allow users to subscribe to channels and to create
Expand Down Expand Up @@ -777,7 +793,7 @@ default_user_preferences:
##
## Default dash video quality.
##
## Note: this setting only takes effet if the
## Note: this setting only takes effect if the
## 'quality' parameter is set to "dash".
##
## Accepted values:
Expand Down Expand Up @@ -812,7 +828,7 @@ default_user_preferences:
## Default: true
##
#vr_mode: true

##
## Save the playback position
## Allow to continue watching at the previous position when
Expand Down
2 changes: 2 additions & 0 deletions src/invidious/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class Config
property use_pubsub_feeds : Bool | Int32 = false
property popular_enabled : Bool = true
property captcha_enabled : Bool = true
# Only allow usage of the Invidious instance with an existing account
property private_instance : Bool = false
property login_enabled : Bool = true
property registration_enabled : Bool = true
property statistics_enabled : Bool = false
Expand Down
44 changes: 32 additions & 12 deletions src/invidious/routes/before_all.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ module Invidious::Routes::BeforeAll
env.response.headers["Strict-Transport-Security"] = "max-age=31536000; includeSubDomains; preload"
end

return if {
"/sb/",
"/vi/",
"/s_p/",
"/yts/",
"/ggpht/",
"/api/manifest/",
"/videoplayback",
"/latest_version",
"/download",
}.any? { |r| env.request.resource.starts_with? r }

if env.request.cookies.has_key? "SID"
sid = env.request.cookies["SID"].value

Expand Down Expand Up @@ -100,6 +88,38 @@ module Invidious::Routes::BeforeAll
end
end

# TODO: popular and trending are whitelisted for clients that require these endpoints to be accessible e.g. Clipious
# can be removed as soon as those clients can handele these request on private instances
unregistered_path_whitelist = {
"/login",
"/privacy",
"/api/v1/stats",
"/api/v1/popular",
"/api/v1/trending",
"/feed/webhook/v1:",
"/api/v1/videos/dQw4w9WgXcQ",
stonerl marked this conversation as resolved.
Show resolved Hide resolved
"/api/v1/comments/jNQXAC9IVRw",
}

if CONFIG.private_instance && !env.get?("user") && !unregistered_path_whitelist.any? { |r| env.request.path.starts_with? r }
env.response.headers["Location"] = "/login"
haltf env, status_code: 302
end

return if {
"/sb/",
"/vi/",
"/s_p/",
"/yts/",
"/ggpht/",
"/download",
"/licenses",
"/api/manifest/",
"/videoplayback",
"/latest_version",
"/opensearch.xml",
}.any? { |r| env.request.resource.starts_with? r }

dark_mode = convert_theme(env.params.query["dark_mode"]?) || preferences.dark_mode.to_s
thin_mode = env.params.query["thin_mode"]? || preferences.thin_mode.to_s
thin_mode = thin_mode == "true"
Expand Down
Loading