Files
instantadpay/spamscan.js
T
martbost 337d4f9e8f Link-farm hardening (2026-10-30 incident: 106 free accounts used casino bios and website links as backlinks; Google indexed the text through /wall pages)
Public walls: profile fields (bio, avatar, socials, intro video) render only for a paying member (memberId > 0 or a registered position), on /api/wall and in the OG image; a free account's wall shows the name, the line's ads and the join call. The meta/og description is a fixed site sentence with the handle, never the bio. Outbound profile links are rel="sponsored ugc noopener" target="_blank". A deleted or unknown name is a real 404 with X-Robots-Tag noindex (was a bare "Banner wall" page at 200, a soft 404 that stayed indexed).

Policy (prohibited.js, byte-for-byte copy on LinkSpin): bios may not carry a URL or a domain token ("Links go in the social fields, not the bio"); gambling, adult, pharma, weapons and link-selling terms (Unicode aware, Vietnamese and Portuguese terms included) are refused in bios, social URLs, line banner targets, wall offers and every campaign field, with the refusal logged. lssync applies it on the way out and lsinbound on ingest.

Quarantine rule: a brand-new free account (no wallet, no sponsor, under 24 h) whose first profile save plants a link is saved with profileQuarantined (JSON + MySQL column), never rendered publicly, and told "Your profile links will appear after your first ad package"; the admin member card shows the flag.

Daily link-farm scan (spamscan.js, same copy on LinkSpin): in-app job at 06:30 Central, claimOnce per day, lists memberId-0 walletless accounts with a link plus a farm signal (prohibited term, sign-in over within 15 min, no sponsor), skips the spamScanAllow setting (seeded), writes DATA_DIR/wall-spam-scan.json and sends one Telegram to the private admin chat only when there are candidates. Admin > Members > Link-farm list: rows with "also on LinkSpin", Delete selected (existing DELETE /api/admin/member, on-chain refused, no cascade) and Allow.

Terms section 8 "Prohibited content", bio hint in the profile editor, chatbot canned answer "What content is not allowed?", KNOWLEDGE_DATE 2026-10-30. Test: qa/profile-policy.test.cjs (unit + local copy; runs in qa/run.sh member and policy).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-30 07:29:11 -05:00

134 lines
9.4 KiB
JavaScript

// Link-farm scan (Marty, 2026-10-30). BYTE-FOR-BYTE COPY in both repos (InstantAdPay site/ and LinkSpin site/): the two
// sites must flag the same accounts by the same rule; qa/profile-policy.test.cjs on each side hashes this file and
// prohibited.js against the sibling checkout when it is present. Edit one, copy to the other, never fork.
//
// Why: an SEO backlink farm opened 106 free accounts with casino and local-business bios plus a website link, and the public
// walls put that text in front of Google. The accounts are gone; this job finds the next batch before the crawler does.
// What: an in-app daily job (checked every few minutes, claimOnce per Central day, runs at 06:30 Central; replaces a server
// cron) lists accounts with memberId 0 and no wallet that carry a link (URL in the bio, or any social set) AND at least
// one farm signal: a prohibited term in the bio or socials, a sign-in that stopped within 15 minutes of the sign-up, or
// no sponsor at all. Emails on the site's spamScanAllow setting are skipped. The result lands in DATA_DIR/wall-spam-scan.json
// and, only when there are candidates, ONE Telegram goes to the private admin chat. The admin pane "Link-farm list"
// (Admin > Members) shows the rows with delete (the existing DELETE /api/admin/member, which refuses on-chain members) and
// allow (adds the email to spamScanAllow). Nothing is deleted automatically, and nothing cascades to the other site.
'use strict';
const fs = require('fs');
const path = require('path');
const P = require('./prohibited');
const TZ = 'America/Chicago';
const dayOf = ts => new Date(ts).toLocaleDateString('en-CA', { timeZone: TZ });
const minuteOf = ts => { const [h, m] = new Date(ts).toLocaleTimeString('en-GB', { timeZone: TZ, hour: '2-digit', minute: '2-digit', hour12: false }).split(':').map(Number); return h * 60 + m; };
const RUN_AT = 6 * 60 + 30; // 06:30 Central
const QUICK_MS = 15 * 60 * 1000;
const DEFAULT_ALLOW = ['cryptogoat76@gmail.com', 'csicsokaren@gmail.com', 'osamedefe2026@gmail.com'];
const SOCIAL_KEYS = ['facebook', 'twitter', 'youtube', 'instagram', 'tiktok', 'telegram', 'linkedin', 'website', 'video'];
const LINK_KEYS = ['website', 'twitter', 'youtube']; // the fields a farm comes for (quarantine rule at profile save)
let X = null, FILE = null, S = null, running = false;
// opts: { dataDir, site, siteUrl, accounts, siteConfig(), saveSite(patch), notify(text) async, marks?, alsoOn?(email) async -> true|false|null, otherSite }
function init(opts) { X = opts; FILE = path.join(opts.dataDir, 'wall-spam-scan.json'); S = load(); }
function load() { try { return JSON.parse(fs.readFileSync(FILE, 'utf8')); } catch (e) { return { day: null, at: 0, candidates: [], scanned: 0, skipped: 0 }; } }
function save() { try { fs.writeFileSync(FILE, JSON.stringify(S, null, 2)); } catch (e) {} }
async function claimOnce(key) { try { return X.marks ? await X.marks.claim(key) : true; } catch (e) { return true; } }
const norm = e => String(e || '').trim().toLowerCase();
function parseSocials(v) { if (!v) return null; if (typeof v === 'object') return v; try { const o = JSON.parse(v); return o && typeof o === 'object' ? o : null; } catch (e) { return null; } }
// every link a profile carries, socials first, then URLs picked out of the bio
function linksOf(a) {
const out = []; const soc = parseSocials(a.socials) || {};
for (const k of SOCIAL_KEYS) { const v = String(soc[k] || '').trim(); if (v) out.push(v); }
const m = String(a.bio || '').match(/https?:\/\/[^\s<>"']+|(?:www\.)?[a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z]{2,24}(?:\/[^\s<>"']*)?/gi);
if (m) for (const u of m) if (!out.includes(u)) out.push(u);
return out;
}
// Allowlist: the site setting (array or comma/space separated string) plus the seeded three.
function allowlist() {
const c = (X && X.siteConfig && X.siteConfig()) || {};
const raw = c.spamScanAllow == null ? DEFAULT_ALLOW : c.spamScanAllow;
const arr = Array.isArray(raw) ? raw : String(raw).split(/[\s,;]+/);
return [...new Set(arr.map(norm).filter(Boolean))];
}
function setAllow(email, on) {
const list = allowlist(); const e = norm(email); if (!e) return list;
const next = on ? [...new Set(list.concat(e))] : list.filter(x => x !== e);
if (X.saveSite) X.saveSite({ spamScanAllow: next.join(', ') });
return next;
}
// The detector. Pure: account in, verdict out. `allow` is a Set of lower-cased emails (defaults to the site allowlist).
function classify(a, allow, now) {
now = now || Date.now();
const r = { email: a.email, candidate: false, reasons: [], links: [] };
if (!a || !a.email) return r;
if (Number(a.memberId) > 0) return r; // a buyer is a member, never a candidate
if (a.address) return r; // a wallet means they came to earn, not to plant a link
const bioUrl = P.hasUrl(a.bio);
const soc = parseSocials(a.socials); const socialsPresent = !!(soc && SOCIAL_KEYS.some(k => String(soc[k] || '').trim()));
if (!bioUrl && !socialsPresent && !a.profileQuarantined) return r;
r.links = linksOf(a);
const term = P.match(a.bio) || (soc ? SOCIAL_KEYS.map(k => P.match(soc[k])).find(Boolean) : null);
if (term) r.reasons.push('prohibited:' + term);
const seen = Number(a.lastSeen) || Number(a.created) || now;
if (Number(a.created) && seen - Number(a.created) < QUICK_MS) r.reasons.push('quick');
if (!a.sponsorRef) r.reasons.push('no-sponsor');
if (a.profileQuarantined) r.reasons.push('quarantined');
if (!r.reasons.length) return r;
if ((allow || new Set(allowlist())).has(norm(a.email))) { r.allowlisted = true; return r; }
r.candidate = true;
return r;
}
// Quarantine rule at profile save (Marty): a brand-new account (memberId 0, no wallet, no sponsor, younger than 24 h)
// whose FIRST profile save carries a URL in the bio or a website / X / YouTube social is saved with profileQuarantined.
function shouldQuarantine(acct, bio, socials, now) {
now = now || Date.now();
if (!acct || Number(acct.memberId) > 0 || acct.address || acct.sponsorRef) return false;
if (!(Number(acct.created) > 0) || now - Number(acct.created) >= 24 * 3600 * 1000) return false;
if (acct.bio || parseSocials(acct.socials)) return false; // not the first save
const soc = parseSocials(socials) || {};
return P.hasUrl(bio) || LINK_KEYS.some(k => String(soc[k] || '').trim());
}
const QUARANTINE_NOTICE = 'Your profile links will appear after your first ad package.';
// One pass over every account. Writes the result file; sends the Telegram when there is anything to review.
async function run(opts) {
if (running) return S; running = true;
try {
const now = Date.now(); const allow = new Set(allowlist());
const all = await X.accounts.listAll(50000, { shells: true });
const names = new Map(); for (const a of all) { if (a.username) names.set(norm(a.username), a); if (a.code) names.set(norm(a.code), a); }
const out = []; let skipped = 0;
for (const a of all) {
const c = classify(a, allow, now);
if (c.allowlisted) { skipped++; continue; }
if (!c.candidate) continue;
const sp = a.sponsorRef ? names.get(norm(a.sponsorRef)) : null;
let alsoOn = null; try { alsoOn = X.alsoOn ? await X.alsoOn(a.email, a) : null; } catch (e) { alsoOn = null; }
out.push({ email: a.email, username: a.username || null, created: Number(a.created) || 0, lastSeen: Number(a.lastSeen) || 0, sponsorRef: a.sponsorRef || '',
sponsorName: sp ? (sp.username ? '@' + sp.username : sp.email) : (a.sponsorRef || null), firstLink: c.links[0] || null, links: c.links.slice(0, 6), reasons: c.reasons,
bio: String(a.bio || '').slice(0, 160), quarantined: !!a.profileQuarantined, alsoOn });
}
out.sort((x, y) => y.created - x.created);
S = { day: dayOf(now), at: now, candidates: out, scanned: all.length, skipped, manual: !!(opts && opts.manual) }; save();
if (out.length && !(opts && opts.quiet)) { try { await X.notify(telegramText(out, now)); S.notified = now; save(); } catch (e) { console.error('spamscan notify', e.message); } }
console.log('spamscan', X.site, 'scanned', all.length, 'candidates', out.length, 'allowlisted', skipped);
return S;
} finally { running = false; }
}
function telegramText(out, now) {
const lines = [X.site + ' link-farm scan: ' + out.length + ' candidate account' + (out.length === 1 ? '' : 's') + ' (' + dayOf(now) + ', ' + X.siteUrl.replace(/^https?:\/\//, '') + ')'];
for (const c of out.slice(0, 15)) lines.push((c.username ? '@' + c.username : c.email) + ' | joined ' + dayOf(c.created || now) + ' | sponsor ' + (c.sponsorName || 'none') + ' | ' + (c.firstLink || 'no link') + (c.alsoOn === true ? ' | also on ' + X.otherSite : ''));
if (out.length > 15) lines.push('... and ' + (out.length - 15) + ' more');
lines.push('Review in Admin > Members > Link-farm list');
return lines.join('\n');
}
// checked every few minutes from server.js: once per Central day, from 06:30 on
async function tick(now) {
now = now || Date.now(); const day = dayOf(now);
if (minuteOf(now) < RUN_AT || S.day === day) return { skipped: true };
if (!await claimOnce('spamscan:' + day)) { S.day = day; save(); return { skipped: true, claimedElsewhere: true }; }
return run();
}
function view() { return { site: X ? X.site : null, otherSite: X ? X.otherSite : null, last: S, allow: allowlist(), running }; }
module.exports = { init, classify, shouldQuarantine, linksOf, allowlist, setAllow, run, tick, view, telegramText, QUARANTINE_NOTICE, DEFAULT_ALLOW, RUN_AT, QUICK_MS, dayOf, minuteOf };