Skip to content

The agent that grows with you

fix(desktop): embed host answers malformed paths with 404 instead of throwing

teknium1e9d7a18dc551
diff --git a/apps/desktop/electron/embed-host.test.ts b/apps/desktop/electron/embed-host.test.ts
index 7d4a3b0006a..2f935bc17bb 100644
--- a/apps/desktop/electron/embed-host.test.ts
+++ b/apps/desktop/electron/embed-host.test.ts
@@ -32,7 +32,16 @@ test('wraps the player with an origin YouTube can match', () => {
})
test('serves nothing but a well-formed video id', () => {
- for (const path of ['/', '/youtube/', '/youtube/short', '/youtube/M7lc1UVf-VE/x', '/youtube/"><script>x', '/other']) {
+ for (const path of [
+ '/',
+ '/youtube/',
+ '/youtube/short',
+ '/youtube/M7lc1UVf-VE/x',
+ '/youtube/"><script>x',
+ '/other',
+ '//',
+ '//['
+ ]) {
assert.equal(youtubeWrapperFor(path, ORIGIN), null, path)
}
})
@@ -62,4 +71,5 @@ test('the live host serves the wrapper locked down, and only to its own Host', a
assert.equal((await get(host.origin, '/youtube/nope')).status, 404)
assert.equal((await get(host.origin, '/youtube/M7lc1UVf-VE', 'evil.test')).status, 404)
+ assert.equal((await get(host.origin, '//[')).status, 404)
})
diff --git a/apps/desktop/electron/embed-host.ts b/apps/desktop/electron/embed-host.ts
index 012a61b29ed..a1713d33e24 100644
--- a/apps/desktop/electron/embed-host.ts
+++ b/apps/desktop/electron/embed-host.ts
@@ -27,6 +27,12 @@ function wrapperHtml(playerUrl: string): string {
/** The wrapper document for a request path, or null for anything we don't serve. */
function youtubeWrapperFor(requestUrl: string, origin: string): null | string {
+ // `//` and similar targets don't parse; throwing here would escape the
+ // request handler as an uncaught main-process error and never answer.
+ if (!URL.canParse(requestUrl, origin)) {
+ return null
+ }
+
const url = new URL(requestUrl, origin)
const match = /^\/youtube\/([^/]+)$/.exec(url.pathname)