Skip to content

Add embed youtube link for error_template_helper - #5650

Open
Fijxu wants to merge 3 commits into
iv-org:masterfrom
Fijxu:embed-error-template
Open

Add embed youtube link for error_template_helper#5650
Fijxu wants to merge 3 commits into
iv-org:masterfrom
Fijxu:embed-error-template

Conversation

@Fijxu

@Fijxu Fijxu commented Feb 27, 2026

Copy link
Copy Markdown
Member

Closes #5649

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

Comment thread src/invidious/helpers/errors.cr Outdated
if video_id.presence
params.delete("v")
if params.present?
embed_link = "https://youtube.com/embed/#{video_id}?#{params}"

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.

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.

@Fijxu Fijxu Feb 28, 2026

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
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.

Comment thread src/invidious/helpers/errors.cr Outdated
@Fijxu
Fijxu force-pushed the embed-error-template branch from f00668e to d4d6fb2 Compare April 26, 2026 18:15
@Fijxu

Fijxu commented Apr 26, 2026

Copy link
Copy Markdown
Member Author

works fine, should be ready to merge

@NintendoManiac64

Copy link
Copy Markdown

It might be worth noting that the "Embed" youtube link seems to be broken again: #5706

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

5 participants