diff --git a/tests/station-schedule.test.mjs b/tests/station-schedule.test.mjs index b770b263..826430e6 100644 --- a/tests/station-schedule.test.mjs +++ b/tests/station-schedule.test.mjs @@ -20,6 +20,10 @@ test("normalizes only real HTTP schedule URLs", () => { assert.equal(normalizeScheduleUrl(false), ""); assert.equal(normalizeScheduleUrl(""), ""); assert.equal(normalizeScheduleUrl("schedule-only"), ""); + assert.equal(normalizeScheduleUrl("https://"), ""); + assert.equal(normalizeScheduleUrl("https://example.com:bad/epg"), ""); + assert.equal(normalizeScheduleUrl("https://user:pass@example.com/epg"), ""); + assert.equal(normalizeScheduleUrl("https://example.com/epg"), "https://example.com/epg"); }); test("detects Zing schedule by provider endpoint instead of country", () => { diff --git a/utils/station-schedule.mjs b/utils/station-schedule.mjs index afb163a2..e76e9252 100644 --- a/utils/station-schedule.mjs +++ b/utils/station-schedule.mjs @@ -4,7 +4,14 @@ export const normalizeScheduleUrl = (value) => { const url = value.trim(); if (!/^https?:\/\//i.test(url)) return ""; - return url; + try { + const parsed = new URL(url); + // Reject malformed endpoints and embedded credentials before a schedule fetch. + if (!["http:", "https:"].includes(parsed.protocol) || !parsed.hostname || parsed.username || parsed.password) return ""; + return url; + } catch { + return ""; + } }; export const isZingScheduleUrl = (value) => {