From dc664fc31812574c6ed524b216efa8b8d5bb0483 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Tue, 20 Dec 2022 22:19:42 +0100 Subject: [PATCH] content: exclude links to ip addresses There is no good reason to link to an ip directly. Excluding links that look like ipv4 or ipv6. --- src/domutil.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/domutil.js b/src/domutil.js index bbfe9e1..d42aa68 100644 --- a/src/domutil.js +++ b/src/domutil.js @@ -38,6 +38,12 @@ function isValidURL(url) { if (url.hostname.slice(lastDot) === '.local') { 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; }