Inline YouTube Music embeds with one shared embed spec

YouTube Music has no player of its own and music.youtube.com sends
X-Frame-Options SAMEORIGIN, so music links render YouTube's own player
with an Open in YouTube Music caption. Tracks, playlists and OLAK5uy
albums embed; browse, channel, search and library stay plain links.

- embeds.py is the single URL spec (exact host allowlists, query-order
  independent, validated ids only); embed-spec.js is generated from it by
  the embeds-sync CLI command and drift is tested
- rendering.py and ContentRenderer.js both follow it; the old duplicate
  YouTube regexes are removed
- max 3 music embeds per content item, overflow stays a plain link
- fixes evilyoutube.com matching and watch?feature=share&v=ID links
- fixes the invalid unicode CSS escape that printed u2197 after every
  external link in rendered content
- docs, privacy third-party row, parser table tests, server/client parity

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-01 11:53:55 +01:00
co-authored by Claude Sonnet 5.5
parent 762c06886c
commit f705099928
21 changed files with 698 additions and 44 deletions
+21
View File
@@ -1,5 +1,6 @@
# retoor <retoor@molodetz.nl>
import re
from html.parser import HTMLParser
from devplacepy.rendering import (
@@ -321,6 +322,26 @@ def test_xss_legitimate_youtube_embed_survives_audit():
assert_no_executable_html(out)
def test_xss_legitimate_music_embed_survives_audit():
out = str(render_content("hear https://music.youtube.com/watch?v=4D7u5KF7SP8 now"))
assert "youtube.com/embed/4D7u5KF7SP8" in out
assert "embed-music-caption" in out
assert_no_executable_html(out)
def test_xss_hostile_music_urls_never_reach_an_iframe():
hostile = (
"https://music.youtube.com/watch?v=4D7u5KF7SP8&list=x\"onload=alert(1)",
"https://music.youtube.com/playlist?list=\"><script>alert(1)</script>",
"https://music.youtube.com/watch?v=\"onload=alert(1)//",
)
for url in hostile:
out = str(render_content(url))
for src in re.findall(r'<iframe src="([^"]*)"', out):
assert re.fullmatch(r"https://www\.youtube\.com/embed/[A-Za-z0-9_\-/?=&;a-z]+", src), src
assert_no_executable_html(out)
def test_xss_legitimate_image_embed_survives_audit():
out = str(render_content("pic https://example.com/a.png end"))
assert "<img" in out