Link check: safeLookup answers in the shape Node 20's https agent asks for (opts.all -> an array; every address checked for private ranges). Answering with one address made every probe fail as 'could not reach', so no text ad / banner link could be saved (Marty 2026-11-15). The status note scrolls into view when it shows (it sits at the foot of the page, so a refused post looked like a dead button). Smoke all green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 14:15:06 -06:00
parent 484f4a0242
commit 4ea6e038e1
14 changed files with 20 additions and 16 deletions
+7 -3
View File
@@ -69,11 +69,15 @@ function privateIp(ip) {
if (s.startsWith('::ffff:')) return privateIp(s.slice(7));
return s === '::' || s === '::1' || s.startsWith('fc') || s.startsWith('fd') || s.startsWith('fe80') || s.startsWith('ff');
}
// Node 20's https agent asks for every address (opts.all, for happy eyeballs) and expects an array back; answering with one
// address broke every link check (2026-11-15: no text ad could be posted). Answer in the shape asked for, private ones refused.
function safeLookup(host, opts, cb) {
dns.lookup(host, Object.assign({}, opts, { all: false }), (err, addr, fam) => {
if (typeof opts === 'function') { cb = opts; opts = {}; }
dns.lookup(host, Object.assign({}, opts, { all: true }), (err, list) => {
if (err) return cb(err);
if (privateIp(addr)) return cb(new Error('private address'));
cb(null, addr, fam);
if (!list.length || list.some(a => privateIp(a.address))) return cb(new Error('private address'));
if (opts && opts.all) return cb(null, list);
cb(null, list[0].address, list[0].family);
});
}
// GET with a size cap, a timeout and no redirects followed (a redirect is reported so the caller can decide)