Spamhaus DBL cleanup (2026-11-17): close the ad-click redirector, mail links on the share domain

- /api/ads/click/<id> only redirects off-site for an active campaign (or its owner). Ended, paused,
  archived and flagged campaigns (488 of them, e.g. #164 -> shrt1.xyz) kept forwarding forever, a
  standing instantadpay.com redirector. They now land on the home page, uncounted.
- mailer.js rewrites every instantadpay.com URL in subject/text/html and List-Unsubscribe to
  MAIL_BASE (default https://instantadpay.link; '' = off). Email addresses and subdomains untouched.
- Share hosts answer /unsubscribe (GET + RFC 8058 POST) and /banners/* in place; leaderboard, blog,
  presentation, partners, launch, plays, bixpay, wall are pages, not usernames (none taken).
- NAS syndicated ad click URLs go out on instantadpay.link (NAS_CLICK_BASE) for new pushes.
- toolkit.js member links (AI writer, handout QR, split-test, partner promo) use shareDomain.
- my.js: banner "copy URL" on the share domain; bridge link (Wednesday/Friday) now builds from the
  share-form invite line (it silently fell back to the plain invite). my.js?v=20261117dbl.
iap-qa member: 0 bugs; networksso-partner e2e all passed on rerun.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-17 09:29:11 -06:00
parent f1c8ba33c8
commit 8c9d72a768
6 changed files with 39 additions and 15 deletions
+14 -2
View File
@@ -1,4 +1,4 @@
// Outbound mail via SendGrid v3 (domain-authenticated instantadpay.com).
// Outbound mail via SendGrid v3 (domain-authenticated instantadpay.com; links in bodies go out on the share domain, see mailLinks).
// Key sources: SENDGRID_KEY env, else DATA_DIR/sendgrid.key in the volume.
// No key = email sign-in stays feature-flagged off in production.
const fs = require('fs');
@@ -19,6 +19,17 @@ function hasKey() { return !!key(); }
// codes and mail to the admin is skipped for anyone who unsubscribed, carries
// the signed unsubscribe link (appended unless the body already has one) and
// RFC 8058 one-click List-Unsubscribe headers. New senders inherit this.
// Links in mail go on the share domain (2026-11-17, Spamhaus DBL): instantadpay.com is on the DBL, so every URL to it in a body
// (and the List-Unsubscribe header) counts against each email. One rewrite here covers every sender; the share host passes
// /my, /ledger, /join/<tok>, ... through to the same page and answers /unsubscribe and /banners/* itself. The From address
// and any name@instantadpay.com in the text stay as they are. MAIL_BASE='' turns it off.
const MAIL_BASE = String(process.env.MAIL_BASE == null ? 'https://instantadpay.link' : process.env.MAIL_BASE).trim().replace(/\/+$/, '');
const IAP_LINK_RE = /(?<![@\w.-])(?:https?:\/\/)?(?:www\.)?instantadpay\.com(?![\w-])/gi;
function mailLinks(s) {
if (!MAIL_BASE || s == null) return s;
const bare = MAIL_BASE.replace(/^https?:\/\//, '');
return String(s).replace(IAP_LINK_RE, m => /^https?:/i.test(m) ? MAIL_BASE : bare);
}
function isAdmin(to) { const a = String(process.env.ADMIN_EMAIL || '').trim().toLowerCase(); return !!a && String(to).trim().toLowerCase() === a; }
async function send(to, subject, text, html, opts) { // html optional (2026-10-01): sent alongside the plain text, never instead of it
@@ -29,6 +40,7 @@ async function send(to, subject, text, html, opts) { // html optional (2026-10-0
try { if (await drip.isUnsubscribed(to)) return false; } catch (e) { console.error('mailer opt-out check', e.message); }
try { unsub = drip.unsubUrl(to); } catch (e) { console.error('mailer unsub link', e.message); }
}
unsub = mailLinks(unsub); text = mailLinks(text); if (html) html = mailLinks(html); subject = mailLinks(subject);
if (unsub && !String(text).includes('/unsubscribe?')) text = text + '\n\n--\nStop these emails: ' + unsub;
if (unsub && html && !String(html).includes('/unsubscribe?')) {
const foot = '<p style="font-size:12px;color:#888;margin-top:24px">Stop these emails: <a href="' + unsub + '" style="color:#888">unsubscribe</a></p>';
@@ -68,4 +80,4 @@ function sendCode(to, code) {
+ 'InstantAdPay\nAdvertise and earn instantly. Locked in code, not promises.\nhttps://instantadpay.com', null, { transactional: true });
}
module.exports = { init, hasKey, send, sendCode };
module.exports = { init, hasKey, send, sendCode, mailLinks };
+2 -2
View File
@@ -76,7 +76,7 @@ async function pushCampaign(c, opts = {}) {
Name, Email, PaymentDetails, EDate, sp, width, height, BannerURL, pid, ref_by, catid)
VALUES (?,?,?,?,?,?,0,1,?,?,?,?,?,?,'',?,?,?,?,0,?)`,
// clicks route through our redirect so they count and carry the network site as the referrer
[token, c.title || null, c.type === 'text' ? (c.body || null) : null, 'https://instantadpay.com/api/ads/click/' + c.id,
[token, c.title || null, c.type === 'text' ? (c.body || null) : null, (process.env.NAS_CLICK_BASE || 'https://instantadpay.link') + '/api/ads/click/' + c.id,
assigned, assigned, now, kind.adtype,
opts.name || 'InstantAdPay member', opts.email || 'ads@instantadpay.com',
'InstantAdPay campaign #' + c.id, edate,
@@ -122,7 +122,7 @@ async function deactivate(nasAdId) {
// point an existing NAS ad at our click redirect (migration for rows pushed before 2026-09-10)
async function setClickUrl(nasAdId, campaignId) {
if (!enabled()) return { skipped: 'flag-off' };
await q('UPDATE sponsorads SET WebsiteURL=? WHERE ID=?', ['https://instantadpay.com/api/ads/click/' + Number(campaignId), Number(nasAdId)]);
await q('UPDATE sponsorads SET WebsiteURL=? WHERE ID=?', [(process.env.NAS_CLICK_BASE || 'https://instantadpay.link') + '/api/ads/click/' + Number(campaignId), Number(nasAdId)]);
return { ok: true };
}
async function topUp(nasAdId, addImpressions, days) {
+4 -2
View File
@@ -3059,7 +3059,9 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
if (bridge) {
// the bridge page with this member's referral: any public page + ?ref sets the sponsor cookie
const inv = (document.getElementById('inviteLine') || {}).textContent || '';
const fl = inv.replace(/\/join\/([^/?#]+).*$/, '/' + bridge.page + '?ref=$1');
// the invite line is the share link (https://<share>/<user>) or the old /join/<user> form (2026-11-17: the share form never matched, so the bridge link was the plain invite)
const im = /\/(?:join\/)?([A-Za-z0-9_]{1,40})\/?(?:[?#].*)?$/.exec(inv.trim());
const fl = im ? (SHARE_DOMAIN ? 'https://' + SHARE_DOMAIN : location.origin) + '/' + bridge.page + '?ref=' + im[1] : inv;
const note = document.createElement('div');
note.className = 'pb-note';
note.innerHTML = '<span>Post any of these with your ' + esc(bridge.name) + ' link: <b class="mono"></b></span>';
@@ -3070,7 +3072,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
grid.before(note);
}
for (const b of g.items) {
const url = location.origin + '/banners/' + b.file;
const url = (SHARE_DOMAIN ? 'https://' + SHARE_DOMAIN : location.origin) + '/banners/' + b.file; // share hosts serve /banners/* in place (2026-11-17, instantadpay.com is on Spamhaus DBL)
const d = document.createElement('div');
d.className = 'pb-item';
d.innerHTML = '<img src="/banners/' + b.file + '?v=4" alt="InstantAdPay banner ' + b.size + '" loading="lazy">'
+1 -1
View File
@@ -1313,7 +1313,7 @@
<script src="/assets/promo.js?v=20261103gp"></script>
<script src="/assets/support.js?v=20261116sg"></script>
<script src="/assets/netkits.js?v=20261117vas"></script>
<script src="/assets/my.js?v=20261117aiw"></script>
<script src="/assets/my.js?v=20261117dbl"></script>
<script src="/assets/fuel.js?v=20261113sso"></script><script src="/assets/tankfeed.js?v=20261115tb"></script>
<script src="/assets/engine-room.js?v=20261113sso"></script>
<script src="/assets/netsso.js?v=20261113sso"></script>
+10 -3
View File
@@ -2405,9 +2405,12 @@ const server = http.createServer(async (req, res) => {
// share-link domains (instantadpay.link active since 2026-11-04; ctbgo.com and mylinehq.com still answer): /<ref> goes to that member's join page, anything else to the same path
// here. 302 (not 301) so links never get pinned in caches; the query (?v= angle, ?promo=) rides along.
{ const sh = String(req.headers.host || '').toLowerCase().replace(/:\d+$/, '').replace(/^www\./, '');
if (SHARE_HOSTS.includes(sh)) {
// a public page name is that page, not a username (2026-11-17: the Network Weekend email links instantadpay.link/weekend)
const ref = /^\/(weekend|friday|wednesday|ledger|refuel|facts|games|support|my|join)\/?$/.test(p) ? null : /^\/([A-Za-z0-9_]{1,40})\/?$/.exec(p);
// answered in place on a share host, never redirected (2026-11-17, mail links moved to the share domain): the
// unsubscribe link (RFC 8058 one-click is a POST, which a 302 would break) and the banner images mail and promo tools embed
if (SHARE_HOSTS.includes(sh) && !(p === '/unsubscribe' || ((req.method === 'GET' || req.method === 'HEAD') && /^\/banners\/[\w.-]+$/.test(p)))) {
// a public page name is that page, not a username (2026-11-17: the Network Weekend email links instantadpay.link/weekend;
// leaderboard/blog/presentation added the same day when every email's links moved here; no member holds those names)
const ref = /^\/(weekend|friday|wednesday|ledger|refuel|facts|games|support|my|join|leaderboard|blog|presentation|partners|launch|plays|bixpay|wall)\/?$/.test(p) ? null : /^\/([A-Za-z0-9_]{1,40})\/?$/.exec(p);
const to = 'https://instantadpay.com' + (p === '/' ? '/' : ref ? '/join/' + ref[1] : p) + (u.search || '');
res.writeHead(302, { Location: to, 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex' }); return res.end();
} }
@@ -5644,6 +5647,10 @@ const server = http.createServer(async (req, res) => {
let own = false, cm = null;
try { cm = await ads.campaignById(m[1]); } catch (e) {}
try { const s = cm && await auth.fromRequest(req); if (s && s.email) own = !!(cm.owner && String(cm.owner).toLowerCase() === String(s.email).toLowerCase()); } catch (e) {}
// only a running campaign redirects off-site (2026-11-17, Spamhaus DBL): an ended, paused, archived or flagged campaign's
// click link used to keep forwarding to its target forever (e.g. #164 -> a URL shortener), a ready-made instantadpay.com
// redirector for anyone. Those now land on the home page, uncounted. The owner can still open their own link.
if (!own && (!cm || cm.status !== 'active')) { res.writeHead(302, baseHeaders({ Location: '/', 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex' })); return res.end(); }
const target = own ? await ads.targetOf(m[1]) : await ads.click(m[1]);
if (!target) { res.writeHead(404, baseHeaders()); return res.end(); }
if (!own) coach.recordClick(m[1], req.headers.referer); // where the click happened
+8 -5
View File
@@ -92,7 +92,7 @@ async function status(email) {
const u = usage()[email] || {}; const used = (u.months || {})[monthKey()] || 0;
const allowance = allowanceFor(tier, sc); const cost = Number(sc.aiCreditsPerGen) || 10;
let available = 0; try { const st = await R.ads.viewStatus(email); available = st.earnedAvailable != null ? st.earnedAvailable : (st.earned || 0); } catch (e) {}
const link = 'https://instantadpay.com/join/' + (acct.username || acct.code);
const link = SHARE() + '/join/' + (acct.username || acct.code);
const partner = tier === 'nexus' ? await partnerStatus(email) : null;
const handoutUrl = rank[tier] >= rank.spark && acct.username ? 'https://instantadpay.com/handout/' + acct.username : null;
return { tier, badges, username: acct.username || null, partner, handoutUrl, videoMaker: !!(R.videomaker && R.videomaker.available()), unlocked: ['surge', 'circuit', 'nexus'].includes(tier), engine: !!key(), allowance, used, freeLeft: Math.max(0, allowance - used), cost, available, link,
@@ -129,6 +129,9 @@ async function adminUsage() {
// ---- the rest of the ladder (Marty, 2026-09-14): Spark templates + handout, Circuit split tester + Video
// Maker, Nexus Leader Ops + team grants + a member-funded partner code ----
const KIT = 'https://instantadpay.com';
// member links that get pasted elsewhere go out on the share domain (2026-11-17, Spamhaus DBL: instantadpay.com is listed);
// <share>/join/<user> passes through to the join page. shareDomain '' (admin settings) = the old instantadpay.com links.
const SHARE = () => { const d = String((R && R.siteConfig && R.siteConfig().shareDomain) || '').trim().toLowerCase(); return /^[a-z0-9.-]+\.[a-z]{2,}$/.test(d) ? 'https://' + d : KIT; };
async function tierOf(email) { return tierFor(await R.ads.milestonesOf(email)); }
const rank = { free: 0, spark: 1, surge: 2, circuit: 3, nexus: 4 };
const atLeast = (tier, need) => rank[tier] >= rank[need];
@@ -154,7 +157,7 @@ async function template(email, memberId, ids, kind, budget) {
async function handout(username) {
const a = await R.accounts.byUsername(username); if (!a) return null;
if (!atLeast(await tierOf(a.email), 'spark')) return null;
const link = KIT + '/join/' + username; const qr = '/api/qr?d=' + encodeURIComponent(link);
const link = SHARE() + '/join/' + username; const qr = '/api/qr?d=' + encodeURIComponent(link);
const esc = t => String(t || '').replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
return '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>InstantAdPay handout for @' + esc(username) + '</title><meta name="robots" content="noindex">'
+ '<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&display=swap">'
@@ -168,7 +171,7 @@ async function handout(username) {
async function split(email) {
const tier = await tierOf(email);
const st = await R.coach.linkStats(email);
const acct = await R.accounts.byEmail(email); const base = KIT + '/join/' + (acct.username || acct.code);
const acct = await R.accounts.byEmail(email); const base = SHARE() + '/join/' + (acct.username || acct.code);
const rows = (st.angles || []).map(a => ({ angle: a.angle, link: base + (a.angle && a.angle !== 'plain' ? '?v=' + a.angle : ''), views: a.views || 0, views30: a.views30 || 0, joins: a.joins || 0, buyers: a.buyers || 0, rate: a.views ? Math.round(1000 * (a.joins || 0) / a.views) / 10 : 0 }));
const withData = rows.filter(r => r.views >= 10); const best = withData.length ? withData.slice().sort((x, y) => y.rate - x.rate || y.joins - x.joins)[0] : null;
return { unlocked: atLeast(tier, 'circuit'), rows, best: best ? best.angle : null, sources: st.sources || [] };
@@ -219,12 +222,12 @@ async function partnerCode(email, code, credits) {
const r = await R.promos.create({ code, credits: n, funder: email, partner: 'member: ' + email, note: 'member-funded partner code', maxUses: 0, expires: null, active: true });
if (r.error) return r;
const acct = await R.accounts.byEmail(email);
return { ok: true, code: r.code.code, credits: n, link: KIT + '/join/' + (acct.username || acct.code) + '?promo=' + r.code.code, kit: KIT + '/partners?ref=' + (acct.username || acct.code) + '&promo=' + r.code.code };
return { ok: true, code: r.code.code, credits: n, link: SHARE() + '/join/' + (acct.username || acct.code) + '?promo=' + r.code.code, kit: SHARE() + '/partners?ref=' + (acct.username || acct.code) + '&promo=' + r.code.code };
}
async function partnerStatus(email) {
const mine = await R.promos.byFunder(email); const acct = await R.accounts.byEmail(email);
if (!mine.length) return null; const c = mine[0];
return { code: c.code, credits: c.credits, uses: (await R.promos.adminView()).codes.find(x => x.code === c.code)?.uses || 0, link: KIT + '/join/' + (acct.username || acct.code) + '?promo=' + c.code, kit: KIT + '/partners?ref=' + (acct.username || acct.code) + '&promo=' + c.code };
return { code: c.code, credits: c.credits, uses: (await R.promos.adminView()).codes.find(x => x.code === c.code)?.uses || 0, link: SHARE() + '/join/' + (acct.username || acct.code) + '?promo=' + c.code, kit: SHARE() + '/partners?ref=' + (acct.username || acct.code) + '&promo=' + c.code };
}
module.exports = { init, status, generate, adminUsage, TIERS, KINDS, template, handout, split, videos, makeVideo, team, nudge, grant, partnerCode, partnerStatus };