-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add embed youtube link for error_template_helper #5650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's a |
||
| 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>)" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
@@ -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 | ||
|
|
||
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but when watching videos in a playlist, it actually contains two parameters,
listandindexinvidious/src/invidious/views/watch.ecr
Lines 121 to 122 in 21d0d10
I'll whitelist them so we only pass those to youtube links
There was a problem hiding this comment.
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