Strict link protocol validation (#577)

This commit is contained in:
Timothy Carambat 2024-01-11 12:29:00 -08:00 committed by GitHub
parent 7200a06ef0
commit 1563a1b20f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,9 @@
const VALID_PROTOCOLS = ["https:", "http:"];
function validURL(url) {
try {
new URL(url);
const destination = new URL(url);
if (!VALID_PROTOCOLS.includes(destination.protocol)) return false;
return true;
} catch {}
return false;