diff --git a/test/server.test.mjs b/test/server.test.mjs index e7f8859..8d5096b 100644 --- a/test/server.test.mjs +++ b/test/server.test.mjs @@ -45,3 +45,97 @@ 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,