File size: 629 Bytes
e67ab0e 11e48d8 e67ab0e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// Shared server-side URL safety helper (exact behavior preserved)
export function isValidUrl(urlString: string): boolean {
try {
const url = new URL(urlString.trim());
// Only allow HTTPS protocol
if (url.protocol !== "https:") {
return false;
}
// Prevent localhost/private IPs (basic check)
const hostname = url.hostname.toLowerCase();
if (
hostname === "localhost" ||
hostname.startsWith("127.") ||
hostname.startsWith("192.168.") ||
hostname.startsWith("172.16.") ||
hostname === "[::1]" ||
hostname === "0.0.0.0"
) {
return false;
}
return true;
} catch {
return false;
}
}
|