Skip to content
Open
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
19 changes: 18 additions & 1 deletion src/invidious/helpers/errors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,29 @@ def error_redirect_helper(env : HTTP::Server::Context)

locale = env.get("preferences").as(Preferences).locale

if request_path.starts_with?("/search") || request_path.starts_with?("/watch") ||
if request_path.starts_with?("/search") || (is_watch = request_path.starts_with?("/watch")) ||
request_path.starts_with?("/channel") || request_path.starts_with?("/playlist?list=PL")
next_steps_text = translate(locale, "next_steps_error_message")
refresh = translate(locale, "next_steps_error_message_refresh")
go_to_youtube = translate(locale, "next_steps_error_message_go_to_youtube")
go_to_youtube_embed = translate(locale, "videoinfo_youTube_embed_link")
switch_instance = translate(locale, "Switch Invidious Instance")

if is_watch
params = URI.parse(env.request.resource).query_params
video_id = params.fetch("v", nil)

if video_id.presence
params.delete("v")
if params.present?
embed_link = "https://youtube.com/embed/#{video_id}?#{params}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out when passing URL parameters directly to youtube. They might contain tracking identifiers! That's why the other youtube link does not pass any.

Copy link
Member Author

@Fijxu Fijxu Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They might contain tracking identifiers! That's why the other youtube link does not pass any.

Right, but when watching videos in a playlist, it actually contains two parameters, list and index

if !plid.nil? && !continuation.nil?
link_yt_param = URI::Params{"list" => [plid], "index" => [continuation.to_s]}

I'll whitelist them so we only pass those to youtube links

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use (and expand) src/invidious/yt_backend/url_sanitizer.cr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a t parameter, it would need to become start #5658

else
embed_link = "https://youtube.com/embed/#{video_id}"
end
embed_html_element = "(<a rel=\"noopener\" referrerpolicy=\"origin-when-cross-origin\" href=\"#{embed_link}\">#{go_to_youtube_embed}</a>)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ever pass URL parameters, make sure to HTML escape them, otherwise that creates an XSS vulnerability.

end
end

return <<-END_HTML
<p style="margin-bottom: 4px;">#{next_steps_text}</p>
<ul>
Expand All @@ -202,6 +218,7 @@ def error_redirect_helper(env : HTTP::Server::Context)
</li>
<li>
<a rel="noreferrer noopener" href="https://youtube.com#{env.request.resource}">#{go_to_youtube}</a>
#{embed_html_element}
</li>
</ul>
END_HTML
Expand Down