diff --git a/tests/radio-source-plan.test.mjs b/tests/radio-source-plan.test.mjs index 16b96798..50306600 100644 --- a/tests/radio-source-plan.test.mjs +++ b/tests/radio-source-plan.test.mjs @@ -216,3 +216,19 @@ test("does not re-proxy an already proxied URL with canonical-equivalent host ca [otherStream, "https://cors.example/https://radio.example/live.mp3"], ); }); + +test("rejects proxy URLs with empty query or fragment delimiters", () => { + const source = [{ src: "https://radio.example/live.mp3" }]; + for (const proxy of [ + "https://proxy.example/?", + "https://proxy.example/#", + "https://proxy.example/path?", + "https://proxy.example/path#", + ]) { + assert.deepEqual( + buildPlaybackSources(source, proxy).map(item => item.src), + [source[0].src], + proxy, + ); + } +}); diff --git a/utils/radio-source-plan.mjs b/utils/radio-source-plan.mjs index 69493611..8631b81c 100644 --- a/utils/radio-source-plan.mjs +++ b/utils/radio-source-plan.mjs @@ -7,7 +7,7 @@ const normalizeProxyBase = (value) => { // an unusable playback candidate (or exposing credentials in its URL). try { const url = new URL(base); - if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) return ""; + if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || base.includes("?") || base.includes("#")) return ""; return base.endsWith("/") ? base : `${base}/`; } catch { return ""; } };