From bf6b9a0b86176199c897d459581fda28fc041331 Mon Sep 17 00:00:00 2001 From: syeopite Date: Tue, 29 Jun 2021 09:00:59 -0700 Subject: [PATCH] Don't send invidious URL params in brand_redirect --- src/invidious/routes/channels.cr | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr index 73b32d6e..5104f477 100644 --- a/src/invidious/routes/channels.cr +++ b/src/invidious/routes/channels.cr @@ -105,8 +105,17 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute def brand_redirect(env) locale = LOCALES[env.get("preferences").as(Preferences).locale]? + # /profile endpoint uses the `user` parameter + # /attribution_link endpoint needs both the `a` and `u` parameter + # and in order to avoid detection from YouTube we should only send the required ones + # without any of the additional url parameters that only Invidious uses. + yt_url_params = URI::Params.encode(env.params.query.to_h.select(["a", "u", "user"])) + + # Retrieves URL params that only Invidious uses + invidious_url_params = URI::Params.encode(env.params.query.to_h.select!(["a", "u", "user"])) + begin - resolved_url = YoutubeAPI.resolve_url("https://youtube.com#{env.request.path}#{env.params.query.size > 0 ? "?#{env.params.query}" : ""}") + resolved_url = YoutubeAPI.resolve_url("https://youtube.com#{env.request.path}#{yt_url_params.size > 0 ? "?#{yt_url_params}" : ""}") rescue ex : InfoException raise InfoException.new("This channel does not exist.") end