Spot edits: unlimited, full link check on every one, every one logged; admin takedown and restore (Marty 2026-11-16)
Edits (POST /api/my/spot/<id>, /api/my/default, uploads): still any number of times. Every change now gets the full check:
checkLink, then (LINK_PROBE on) the link must answer (safety.probeLink, up to 3 redirects each checked) and an image address must
download as a real 468x60 image of 150 KB or less (safety.probeImage; the address is kept, a Banner Spin image rotates). The
Banner Spin image + click link LinkSpin just handed the member are not fetched (that would count a LinkSpin click). safety.js gains
privateIp + safeLookup with the Node 20 fix VBB/ViralAdBlitz needed (honors opts.all, answers an array). Every real change is
logged on the spot (or the default): old and new link and image, time, via edit/upload; the owner sees the newest 10. 120 changes
an hour per connection (each one fetches the link).
Admin takedown (the Viral Banner Blitz way, 8e6d2f9): /admin (new page) finds a spot by #number, wallet or network username;
POST /api/admin/spots/<id>/takedown {reason (required, the owner sees it), credit}. Hidden everywhere at once: the board shows a
house tile in its place (nobody else moves), the gate gives its step to a house site, /go/<id> goes home, its Network Ad Space
banner is paused (approved = 0) and no new one is placed. No views or clicks count while down. My Spots shows "Taken down" with
the reason and no edit controls. Restore (POST .../restore) reverses it (NAS resumed). Admin ledger: GET /api/admin/actions (who,
when, reason, credit decision). The contract is never touched.
CREDIT BACK IS NOT BUILT: a spot is a $5 on-chain purchase and this site has no free replacement spot or post credit, so
credit: "back" is refused with a note until Marty decides what it means here; takedowns are "no credit".
Chatbot: CANNED takedown + banner answer (unlimited checked, logged edits) + FACTS EDITS/TAKEDOWN lines, KNOWLEDGE_DATE 2026-11-16.
line.css?v=9, my.js?v=z3.
Tests: smoke section 10 (the lookup shape, edit log, unlimited edits, refusals: unreachable, 404, private address, http redirect,
shortener, bad image size/404/unreachable; redirect followed; same link logs nothing; upload logged; default checked + logged;
takedown: token, reason, credit choice, credit back refused, held house tile, image nowhere, /go home, gate, no views, owner view,
no edits while down, ledger, restore, /admin) against a stand-in internet preloaded into the app (qa/out/probe-stub.cjs, nothing
leaves the machine), plus phone renders of My Spots taken down and /admin: 193/193 with UI. chatbot.test 181/181.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// Link + image checks for My Spots. https only, a real public hostname, no tricks; uploads must be a real
|
||||
// PNG/JPG/GIF at 468x60 (or 936x120 retina) and at most 150 KB.
|
||||
const net = require('net');
|
||||
const dns = require('dns');
|
||||
const https = require('https');
|
||||
|
||||
const MAX_UPLOAD = 150 * 1024;
|
||||
const BAD_HOST = /(^|\.)(localhost|local|internal|lan|home|corp|onion|test|invalid|example)$/i;
|
||||
@@ -54,4 +56,86 @@ function checkImage(buf) {
|
||||
return { ok: true, info };
|
||||
}
|
||||
|
||||
module.exports = { checkLink, checkImage, imageInfo, MAX_UPLOAD };
|
||||
// ---- the network part of the check (2026-11-16: every edit gets it, any number of edits) ----
|
||||
// Outbound requests only to public addresses: the DNS answer used for the connection is the one checked.
|
||||
function privateIp(ip) {
|
||||
if (net.isIPv4(ip)) {
|
||||
const [a, b] = ip.split('.').map(Number);
|
||||
return a === 0 || a === 10 || a === 127 || (a === 100 && b >= 64 && b <= 127) || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31)
|
||||
|| (a === 192 && b === 168) || (a === 192 && b === 0) || (a === 198 && (b === 18 || b === 19)) || a >= 224;
|
||||
}
|
||||
const s = String(ip).toLowerCase();
|
||||
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 on VBB and ViralAdBlitz (fixed there 2026-11-15). Answer in the shape asked for, private refused.
|
||||
function safeLookup(host, opts, cb) {
|
||||
if (typeof opts === 'function') { cb = opts; opts = {}; }
|
||||
dns.lookup(host, Object.assign({}, opts, { all: true }), (err, list) => {
|
||||
if (err) return cb(err);
|
||||
if (!list || !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)
|
||||
function get(url, maxBytes, timeoutMs) {
|
||||
return new Promise(resolve => {
|
||||
let done = false; const fin = v => { if (!done) { done = true; resolve(v); } };
|
||||
let req;
|
||||
try {
|
||||
req = https.get(url, { lookup: safeLookup, timeout: timeoutMs || 5000, headers: { 'User-Agent': 'Mozilla/5.0 (compatible; DLBCheck/1.0; +https://downlinebanners.com)', Accept: '*/*' } }, res => {
|
||||
const out = { status: res.statusCode, headers: res.headers, location: res.headers.location || null };
|
||||
if (!maxBytes) { res.destroy(); return fin(out); }
|
||||
const ch = []; let n = 0;
|
||||
res.on('data', c => { n += c.length; if (n > maxBytes) { res.destroy(); return fin(Object.assign(out, { tooBig: true })); } ch.push(c); });
|
||||
res.on('end', () => fin(Object.assign(out, { body: Buffer.concat(ch) })));
|
||||
res.on('error', () => fin(Object.assign(out, { error: 'read' })));
|
||||
});
|
||||
req.on('timeout', () => { req.destroy(); fin({ error: 'timeout' }); });
|
||||
req.on('error', e => fin({ error: /private address/.test(e.message) ? 'private' : 'unreachable' }));
|
||||
} catch (e) { fin({ error: 'unreachable' }); }
|
||||
});
|
||||
}
|
||||
// the target link must answer (up to 3 redirects, each one checked like the link itself). Unlike VBB, a site that refuses frames
|
||||
// is fine here: the gate opens it in a new tab instead (board.frameable).
|
||||
async function probeLink(url) {
|
||||
let cur = url;
|
||||
for (let hop = 0; hop < 4; hop++) {
|
||||
const r = await get(cur, 0, 6000);
|
||||
if (r.error === 'private') return { error: 'That link points to a private network address.' };
|
||||
if (r.error) return { error: 'We could not reach that link. Check it opens in your browser and try again.' };
|
||||
if (r.status >= 300 && r.status < 400 && r.location) {
|
||||
let next; try { next = new URL(r.location, cur).toString(); } catch (e) { return { error: 'That link redirects somewhere invalid.' }; }
|
||||
const c = checkLink(next, 'The page your link redirects to'); if (c.error) return c;
|
||||
cur = c.url; continue;
|
||||
}
|
||||
if (r.status >= 400) return { error: 'That link answered with an error (' + r.status + '). Use a page that loads.' };
|
||||
return { ok: true };
|
||||
}
|
||||
return { error: 'That link redirects too many times.' };
|
||||
}
|
||||
// an https image address: downloaded once and checked like an upload (468x60 or 936x120, 150 KB). The spot keeps the address
|
||||
// (a LinkSpin Banner Spin image rotates, so it is never copied). -> { ok, info } or { error }
|
||||
async function probeImage(url) {
|
||||
let cur = url, r = null;
|
||||
for (let hop = 0; hop < 4; hop++) { // up to 3 redirects, each one checked like the address itself
|
||||
r = await get(cur, MAX_UPLOAD, 6000);
|
||||
if (!r.error && r.status >= 300 && r.status < 400 && r.location) {
|
||||
let next; try { next = new URL(r.location, cur).toString(); } catch (e) { return { error: 'That image address redirects somewhere invalid.' }; }
|
||||
const c = checkLink(next, 'The address your image redirects to'); if (c.error) return c;
|
||||
cur = c.url; r = null; continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!r) return { error: 'That image address redirects too many times.' };
|
||||
if (r.error === 'private') return { error: 'That image address points to a private network address.' };
|
||||
if (r.error) return { error: 'We could not download that image. Check the address or upload the file instead.' };
|
||||
if (r.tooBig) return { error: 'That image is over 150 KB.' };
|
||||
if (r.status !== 200) return { error: 'The image address answered ' + r.status + '. Use a direct link to the image file, or upload it.' };
|
||||
const c = checkImage(r.body); if (c.error) return c;
|
||||
return { ok: true, info: c.info };
|
||||
}
|
||||
|
||||
module.exports = { checkLink, checkImage, imageInfo, privateIp, safeLookup, probeLink, probeImage, MAX_UPLOAD };
|
||||
|
||||
Reference in New Issue
Block a user