From 75d95d84d602de576d122d15761f328011a69d5c Mon Sep 17 00:00:00 2001 From: martbost Date: Wed, 7 Oct 2026 16:27:17 -0500 Subject: [PATCH] Scanner and rotator accept bare domains (scheme added for them); clearer scanner error Co-Authored-By: Claude Fable 5.1 --- pages.js | 4 +++- rotator.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pages.js b/pages.js index 48a812c..f97fb0e 100644 --- a/pages.js +++ b/pages.js @@ -20,6 +20,8 @@ function init(opts) { DATA_DIR = opts.dataDir; ownHosts = opts.ownHosts || (() = const norm = e => String(e || '').trim().toLowerCase(); const TYPES = ['bridge', 'review', 'squeeze']; const cleanUrl = u => { const s = String(u || '').trim(); return /^https?:\/\/[^\s"'<>]+$/i.test(s) && s.length <= 700 ? s : ''; }; +// people type bare domains ("cryptoteambuild.com"): give them the scheme before judging the address (Marty 2026-10-07) +const withScheme = u => { const s = String(u || '').trim(); return s && !/^[a-z][a-z0-9+.-]*:\/\//i.test(s) && /^[^\s\/]+\.[^\s]+/.test(s) ? 'https://' + s : s; }; const slugify = t => (String(t || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 40) || 'page') + '-' + crypto.randomBytes(3).toString('hex'); const strs = (arr, n, len) => (Array.isArray(arr) ? arr : String(arr || '').split('\n')).map(x => String(x).trim()).filter(Boolean).slice(0, n).map(x => x.slice(0, len)); @@ -98,7 +100,7 @@ function fetchText(url, hops) { const meta = (h, name) => { const m = h.match(new RegExp(']+(?:property|name)=["\']' + name + '["\'][^>]*content=["\']([^"\']*)', 'i')) || h.match(new RegExp(']+content=["\']([^"\']*)["\'][^>]*(?:property|name)=["\']' + name + '["\']', 'i')); return m ? m[1].trim() : ''; }; const strip = s => String(s || '').replace(/<[^>]+>/g, ' ').replace(/ /g, ' ').replace(/&/g, '&').replace(/'|'/g, "'").replace(/"/g, '"').replace(/\s+/g, ' ').trim(); async function scan(url) { - url = cleanUrl(url); if (!url) return { error: 'Give the scanner a full https:// address.' }; + url = cleanUrl(withScheme(url)); if (!url) return { error: 'Give the scanner a website address, like example.com or https://example.com/page.' }; const host = new URL(url).hostname.toLowerCase(); if (!host.includes('.') || net.isIP(host)) return { error: 'Scan a public website address.' }; try { const rs = await dns.lookup(host, { all: true }); if (!rs.length || rs.some(r => isPrivateIp(r.address))) return { error: 'That host is not reachable from here.' }; } catch (e) { return { error: 'That host does not resolve.' }; } diff --git a/rotator.js b/rotator.js index f2b91d2..8045719 100644 --- a/rotator.js +++ b/rotator.js @@ -20,7 +20,7 @@ function init(opts) { DATA_DIR = opts.dataDir; geo = opts.geo || null; OWN_HOSTS const norm = e => String(e || '').trim().toLowerCase(); const newCode = () => { const a = 'abcdefghjkmnpqrstuvwxyz23456789'; let s = ''; for (let i = 0; i < 6; i++) s += a[crypto.randomInt(a.length)]; return s; }; const BOT = /bot|crawl|spider|slurp|facebookexternalhit|preview|telegrambot|whatsapp|curl|wget|python-requests|headless/i; -const cleanUrl = u => { const s = String(u || '').trim(); return /^https?:\/\/[^\s]+$/i.test(s) && s.length <= 500 ? s : null; }; +const cleanUrl = u => { let s = String(u || '').trim(); if (s && !/^[a-z][a-z0-9+.-]*:\/\//i.test(s) && /^[^\s\/]+\.[^\s]+/.test(s)) s = 'https://' + s; return /^https?:\/\/[^\s]+$/i.test(s) && s.length <= 500 ? s : null; }; function pub(r) { const hits = J.db.hits.filter(h => h.r === r.id);