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
25 changes: 24 additions & 1 deletion src/invidious/helpers/errors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,35 @@ 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 = I18n.translate(locale, "next_steps_error_message")
refresh = I18n.translate(locale, "next_steps_error_message_refresh")
go_to_youtube = I18n.translate(locale, "next_steps_error_message_go_to_youtube")
go_to_youtube_embed = I18n.translate(locale, "videoinfo_youTube_embed_link")
switch_instance = I18n.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
if params.present?
new_params = URI::Params.new
list = params["list"]?.presence
index = params["index"]?.presence
if list && index
new_params.add("list", list)
new_params.add("index", index)
embed_link = HTML.escape("https://youtube.com/embed/#{video_id}?#{new_params}")
end
else
embed_link = HTML.escape("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
Copy Markdown
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 +224,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
Loading