content: exclude links to ip addresses #53

Merged
offbyn merged 2 commits from content-exclude-iplinks into master 2 years ago

@ -31,6 +31,9 @@ function isValidURL(url) {
if (!['', '443', '80'].includes(url.port)) {
return false;
}
if (url.hostname === 'localhost') {
return false;
}
const lastDot = url.hostname.lastIndexOf('.');
if (lastDot < 1) {
return false;
@ -38,6 +41,12 @@ function isValidURL(url) {
if (url.hostname.slice(lastDot) === '.local') {
offbyn marked this conversation as resolved
x1ddos commented 2 years ago
Review

btw, also refuse localhost?

btw, also refuse localhost?
return false;
}
if (url.hostname.slice(lastDot + 1).match(/^[\d]+$/)) { // there should be no tld with numbers, possible ipv4
return false;
}
if (url.hostname.includes(':')) { // possibly an ipv6 addr; certainly an invalid hostname
return false;
}
return true;
}

Loading…
Cancel
Save