From 368b0ff80eaf46545c7d4964c189580c2f49bcc8 Mon Sep 17 00:00:00 2001 From: Sciscito <118936755+Sciscito@users.noreply.github.com> Date: Sat, 7 Nov 2026 18:58:10 +0100 Subject: [PATCH 1/2] test: cover validateUrl against look-alike and malformed hosts (#18) Adds tests for look-alike hosts, userinfo URLs, non-http(s) schemes, IP-literal hosts, uppercase hosts, trailing dots, a valid subdomain, and a host added through FLUX_EXTRA_SOURCE_HOSTS. AI-assisted: written by free models in a Kickswarm private hive, reviewed by a person. --- test/server.test.mjs | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/test/server.test.mjs b/test/server.test.mjs index e7f8859..690e15d 100644 --- a/test/server.test.mjs +++ b/test/server.test.mjs @@ -45,3 +45,99 @@ test("rejects unsupported formats and arbitrary extractor arguments", () => { assert.throws(() => optionsFor(o)); assert.equal(optionsFor({ language: "en-US" }).language, "en-US"); }); + +test("validateUrl rejects look-alike hosts and userinfo", () => { + for (const u of [ + "https://youtube.com.evil.test/", + "https://evilyoutube.com/", + "https://notyoutube.com/", + "https://youtube.com@evil.test/", + "https://user:pass@youtube.com/", + "https://user@youtube.com/", + ]) { + assert.throws(() => validateUrl(u)); + } + assert.equal( + validateUrl("https://m.youtube.com/watch?v=abc"), + "https://m.youtube.com/watch?v=abc", + ); + assert.equal(validateUrl("https://youtu.be/abc"), "https://youtu.be/abc"); +}); + +test("validateUrl rejects non-http(s) schemes", () => { + for (const u of [ + "file:///etc/passwd", + "ftp://youtube.com/file", + "javascript:alert(1)", + "data:text/html,