Skip to content

Add embed youtube link for error_template_helper#5650

Open
Fijxu wants to merge 2 commits intoiv-org:masterfrom
Fijxu:embed-error-template
Open

Add embed youtube link for error_template_helper#5650
Fijxu wants to merge 2 commits intoiv-org:masterfrom
Fijxu:embed-error-template

Conversation

@Fijxu
Copy link
Member

@Fijxu Fijxu commented Feb 27, 2026

Closes #5649

It also checks if the endpoint is /watch and that the v query parameter isn't empty before generating the embed URL ^^

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

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.

if video_id.presence
params.delete("v")
if params.present?
embed_link = "https://youtube.com/embed/#{video_id}?#{params}"
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Add YouTube 'embed' link to error pages

3 participants