From 47de249a8b723d2d447ac9cc8130b47ed3d3427b Mon Sep 17 00:00:00 2001 From: martbost Date: Mon, 16 Nov 2026 11:36:29 -0600 Subject: [PATCH] Free check partly gated behind joining the network (Marty 2026-11-16) Not signed in: grade, verdict, first finding and the opinion line; the rest (scores, findings, chain facts, screenshot, evidence) stays on the server. Join or sign in by one-time email link (hub /v1/join with the wwi.ref sponsor when HUB_JOIN=1; staging reads only). 1 free check a day without an account, 3 for members. Red flags deduped (deterministic VERIFIED one kept), grade recomputed on read. Privacy: joining and emails. Co-Authored-By: Claude Opus 5.5 --- chatbot.js | 4 +- db.js | 6 +++ join.js | 94 +++++++++++++++++++++++++++++++++++++++++ public/404.html | 4 +- public/admin.html | 6 +-- public/assets/admin.js | 3 ++ public/assets/join.js | 19 +++++++++ public/assets/render.js | 30 ++++++++++++- public/disclaimer.html | 6 +-- public/index.html | 10 ++--- public/join.html | 29 +++++++++++++ public/my.html | 6 +-- public/privacy.html | 14 ++++-- public/report.html | 8 ++-- public/rubric.html | 6 +-- public/terms.html | 8 ++-- report.js | 13 +++++- server.js | 67 ++++++++++++++++++++++++----- tools/build-index.py | 10 ++--- tools/build-pages.py | 30 ++++++++++--- 20 files changed, 317 insertions(+), 56 deletions(-) create mode 100644 join.js create mode 100644 public/assets/join.js create mode 100644 public/join.html diff --git a/chatbot.js b/chatbot.js index 4f9f082..ee6aa3e 100644 --- a/chatbot.js +++ b/chatbot.js @@ -23,7 +23,7 @@ const CANNED = [ a: 'The findings are public facts, each tagged VERIFIED, INFERRED or UNKNOWN and linked to its source. The scores, grade and verdict are our opinion, formed by applying our published rubric to those facts. A report is information about code and on-chain records, not financial advice and not a judgment of any person.' }, { id: 'free', title: 'How many free checks do I get?', q: ['How many free checks?', 'Is it free?', 'Why can I not run another check?'], tags: ['free', 'limit'], re: /(how many (free )?checks|is (it|this) free|free check limit|no more (free )?checks)/i, - a: 'Every visitor gets 3 free checks a day. A free check is a short scorecard: a verdict, six category scores and the top findings, each tagged. The deep report is the full write-up.' }, + a: 'Without an account you get 1 free check a day and see its grade, verdict and first finding. Join free (one account across the network, no wallet needed) to get 3 free checks a day and the full free scorecard: six category scores, every top finding, the chain facts and the website screenshot. The deep report is the full write-up.' }, { id: 'price', title: 'What does a deep report cost?', q: ['How much is a deep report?', 'Prices', 'What is the 10 pack?'], tags: ['price', 'deep report', 'pack', 'watch'], re: /(how much|price|cost).*(report|pack|watch)|(deep report|10 ?pack|watch alerts?).*(cost|price|how much)/i, a: 'One deep report is $10. Ten deep reports are $79 ($7.90 a report). Watch alerts are $9 for 3 months on one contract, one payment that stops by itself. All are one-time payments on Polygon with SafePal or any other crypto wallet. No subscriptions.' + (STAGING ? ' On this staging site payments are not live yet: they arrive at launch.' : '') }, @@ -37,7 +37,7 @@ const FACTS = () => [ '- PUBLIC ONLY: every check uses only public information anyone could look up: public blockchain records, verified or decompiled public contract code, the project public website. No private data, no hacking, no signing in to or interacting with the project, no moving funds. Read-only. Never asks anyone to connect a wallet to run a check.', '- OPINION: findings are public facts tagged VERIFIED (on chain), INFERRED (code, simulation, website text) or UNKNOWN. Scores, grade and verdict are our opinion from the published rubric (six categories: control and upgradeability 25, custody and exit paths 25, economic design 20, insider flows 15, disclosure vs code 10, trajectory 5; a critical red flag forces High risk). Not financial advice, not a judgment of any person. Projects can reply in their public thread.', '- FACT GATE: every address, transaction and number in a written report must match the evidence, or the report is not shown and only the facts read straight from the chain are shown.', - '- LIMITS AND PRICES: 3 free checks a day per visitor. Deep report $10, 10 reports $79, watch alerts $9 for 3 months. One-time payments on Polygon, SafePal or any other crypto wallet.' + (STAGING ? ' Staging: payments arrive at launch.' : ''), + '- LIMITS AND PRICES: 1 free check a day without an account (grade, verdict and first finding shown; the rest after joining free), 3 a day for signed-in members. Deep report $10, 10 reports $79, watch alerts $9 for 3 months. One-time payments on Polygon, SafePal or any other crypto wallet.' + (STAGING ? ' Staging: payments arrive at launch.' : ''), '- SPONSORS: 20% to the direct sponsor, 5% on levels 2 to 5, company 60%; pass-up over people who never bought here; voucher redemptions pay nothing.', '- PAGES: Terms ' + URL_ + '/terms, Disclaimer ' + URL_ + '/disclaimer, Privacy ' + URL_ + '/privacy. Run by TrustClickz. SUPPORT: ' + SUPPORT ].join('\n'); diff --git a/db.js b/db.js index 440ed5e..e87d29b 100644 --- a/db.js +++ b/db.js @@ -26,6 +26,9 @@ const SCHEMA = [ line_json TEXT, split_json TEXT, note VARCHAR(300), real_money TINYINT NOT NULL DEFAULT 0, INDEX (at), INDEX (buyer), INDEX (buyer_username), INDEX (buyer_wallet)) ENGINE=InnoDB`, `CREATE TABLE IF NOT EXISTS members (email VARCHAR(190) PRIMARY KEY, hub_id VARCHAR(40), username VARCHAR(60), wallet CHAR(42), sponsor VARCHAR(60), created BIGINT, last_seen BIGINT, INDEX (username), INDEX (wallet)) ENGINE=InnoDB`, + `CREATE TABLE IF NOT EXISTS joins (token_hash CHAR(64) PRIMARY KEY, email VARCHAR(190) NOT NULL, username VARCHAR(40), ref VARCHAR(60), optin TINYINT NOT NULL DEFAULT 0, + to_path VARCHAR(200), created BIGINT NOT NULL, expires BIGINT NOT NULL, confirmed_at BIGINT, ip_hash CHAR(24), status VARCHAR(16) NOT NULL DEFAULT 'pending', + mailed TINYINT NOT NULL DEFAULT 0, hub_result VARCHAR(300), INDEX (email), INDEX (created)) ENGINE=InnoDB`, `CREATE TABLE IF NOT EXISTS sessions (id CHAR(48) PRIMARY KEY, email VARCHAR(190) NOT NULL, created BIGINT NOT NULL, expires BIGINT NOT NULL, INDEX (email)) ENGINE=InnoDB` ]; @@ -36,6 +39,9 @@ async function init(url) { try { await pool.query('SELECT 1'); break; } catch (e) { if (i === 29) throw e; await new Promise(r => setTimeout(r, 2000)); } } for (const s of SCHEMA) await pool.query(s); + for (const a of ['ALTER TABLE members ADD COLUMN optin TINYINT NOT NULL DEFAULT 0', "ALTER TABLE members ADD COLUMN via VARCHAR(20)"]) { + try { await pool.query(a); } catch (e) { if (!/Duplicate column/i.test(e.message)) throw e; } + } } const q = (sql, args) => pool.query(sql, args).then(r => r[0]); const one = async (sql, args) => (await q(sql, args))[0] || null; diff --git a/join.js b/join.js new file mode 100644 index 0000000..76b2595 --- /dev/null +++ b/join.js @@ -0,0 +1,94 @@ +// Join free / sign in by email (Marty 2026-11-16: the free check is partly gated behind joining the network). +// One form for both: a visitor enters their email and we send a one-time link (30 minutes). Opening it: +// - an existing network member (the hub knows the email): signs in here as that member +// - a new person: joins the network through the hub (POST /v1/join {email, ref, username}, sponsor = the wwi.ref referral cookie, +// so the member who shared the link gets the new member), then signs in. HUB_JOIN=1 writes the join; without it (staging) the +// hub is only read and nobody is created there: the session is local to this site. +// - a member the hub blocked: refused +// Then the browser lands back on the page they came from (to = a relative path only), so a report opens unlocked. +// Mail: MAIL_URL (a relay taking JSON {from, to, subject, text}, MAIL_KEY as bearer). Unset = no mail is sent (staging): the admin +// page lists pending links, and on staging only, addresses at the reserved test domains example.com/.org/.net get the link back in +// the answer (those domains cannot receive mail, so nobody real is involved). +// Emails: the sign-in link only, plus network news if the person ticked the opt-in box; every news email carries an unsubscribe link. +'use strict'; +const crypto = require('crypto'); + +const EMAIL_RE = /^[a-z0-9._%+-]{1,64}@[a-z0-9.-]{1,190}\.[a-z]{2,24}$/; +const NAME_RE = /^[A-Za-z0-9_.-]{3,30}$/; +const TEST_RE = /@example\.(com|org|net)$/; +const TTL = 30 * 60000; +let D = null; +const sha = s => crypto.createHash('sha256').update(String(s)).digest('hex'); +const safeTo = t => { t = String(t || '/my'); return /^\/(?!\/)[A-Za-z0-9/_.?=&%-]{0,190}$/.test(t) ? t : '/my'; }; + +async function mail(to, subject, text) { + const url = String(process.env.MAIL_URL || '').trim(); if (!url) return false; + const r = await fetch(url, { method: 'POST', signal: AbortSignal.timeout(10000), headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + String(process.env.MAIL_KEY || '') }, + body: JSON.stringify({ from: process.env.MAIL_FROM || 'WebWorthIt ', to, subject, text }) }); + return r.ok; +} + +async function hubJoin(email, ref, username) { + const raw = JSON.stringify({ email, ref: ref || undefined, username: username || undefined }); const ts = String(Date.now()); + const sig = crypto.createHmac('sha256', String(process.env.HUB_SECRET).trim()).update(ts + '\n' + raw).digest('hex'); + const r = await fetch(String(process.env.HUB_URL).trim().replace(/\/+$/, '') + '/v1/join', { method: 'POST', body: raw, signal: AbortSignal.timeout(8000), + headers: { 'Content-Type': 'application/json', 'X-Hub-Site': String(process.env.HUB_SITE || 'webworthit').trim(), 'X-Hub-Ts': ts, 'X-Hub-Sig': sig } }); + const j = await r.json().catch(() => ({})); + if (r.status !== 200) return { ok: false, status: r.status, error: j && j.error }; + return { ok: true, created: !!j.created, person: j.person || null }; +} + +async function start(req, res) { + const { db, json, readBody, cookies, unsign, ipHash, limited } = D; + if (limited(req, 'join', 5, 15 * 60000)) return json(res, 429, { error: 'Too many tries from this connection. Wait 15 minutes.' }); + const b = await readBody(req); + const email = String(b.email || '').trim().toLowerCase(); + if (!EMAIL_RE.test(email)) return json(res, 400, { error: 'That email address does not look right.' }); + const username = b.username && NAME_RE.test(String(b.username)) ? String(b.username) : null; + const recent = await db.one('SELECT COUNT(*) n FROM joins WHERE email = ? AND created > ?', [email, Date.now() - 3600000]); + if (Number(recent.n) >= 3) return json(res, 429, { error: 'We already sent links to that address in the last hour. Check your inbox and spam folder.' }); + const token = crypto.randomBytes(24).toString('base64url'); + const ref = unsign(cookies(req)['wwi.ref']); + const to = safeTo(b.to); + await db.q('INSERT INTO joins (token_hash, email, username, ref, optin, to_path, created, expires, ip_hash) VALUES (?,?,?,?,?,?,?,?,?)', + [sha(token), email, username, ref || null, b.optin ? 1 : 0, to, Date.now(), Date.now() + TTL, ipHash(req)]); + const link = 'https://' + D.SITE_HOST + '/join/confirm?t=' + token; + let mailed = false; + try { mailed = await mail(email, 'Your WebWorthIt sign-in link', 'Open this link within 30 minutes to sign in to WebWorthIt (one account across the network). New here? The same link creates your free account.\n\n' + link + '\n\nIf you did not ask for this, ignore this email: nothing happens without the link.'); } catch (e) { mailed = false; } + if (mailed) await db.q('UPDATE joins SET mailed = 1 WHERE token_hash = ?', [sha(token)]); + const out = { ok: true, mailed }; + if (!mailed && D.STAGING && TEST_RE.test(email)) out.testLink = link; // staging, reserved test domain only + if (!mailed && !out.testLink) out.note = D.STAGING ? 'Staging: email is not switched on yet, so no link was sent.' : 'We could not send the email. Try again in a few minutes.'; + return json(res, 200, out); +} + +async function confirm(req, res, u) { + const { db, hubpeople } = D; + const t = String(u.searchParams.get('t') || ''); + const bad = msg => { res.writeHead(302, { Location: '/join?err=' + encodeURIComponent(msg), 'Cache-Control': 'no-store' }); res.end(); }; + if (!/^[A-Za-z0-9_-]{20,60}$/.test(t)) return bad('That link is not valid.'); + const row = await db.one('SELECT * FROM joins WHERE token_hash = ?', [sha(t)]); + if (!row || row.status !== 'pending') return bad('That link was already used. Ask for a new one.'); + if (row.expires < Date.now()) return bad('That link has expired. Ask for a new one.'); + const r0 = await db.q("UPDATE joins SET status = 'used', confirmed_at = ? WHERE token_hash = ? AND status = 'pending'", [Date.now(), sha(t)]); + if (!r0.affectedRows) return bad('That link was already used. Ask for a new one.'); + const email = row.email; + let person = null, result = ''; + const look = await hubpeople.resolve({ email }).catch(() => ({ ok: false })); + if (look.ok && look.person && look.person.blocked) { await db.q('UPDATE joins SET hub_result = ? WHERE token_hash = ?', ['blocked on the hub', sha(t)]); return bad('This account cannot sign in. Contact network support.'); } + if (look.ok && look.person) { person = look.person; result = 'existing network member, signed in'; } + else if (String(process.env.HUB_JOIN || '') === '1' && hubpeople.on()) { + const j = await hubJoin(email, row.ref, row.username).catch(e => ({ ok: false, error: e.message })); + if (!j.ok) { await db.q('UPDATE joins SET hub_result = ? WHERE token_hash = ?', [('hub join failed ' + (j.status || '') + ' ' + (j.error || '')).slice(0, 300), sha(t)]); return bad('Joining the network did not work just now. Try again in a few minutes.'); } + person = j.person; result = (j.created ? 'joined the network' : 'already on the network') + (row.ref ? ', sponsor ref ' + row.ref : ''); + } else { + result = look.ok ? 'staging: HUB_JOIN is off, nobody was created on the hub; local session only' + (row.ref ? ' (ref ' + row.ref + ' would be the sponsor)' : '') : 'hub unreachable; local session only'; + } + await db.q('UPDATE joins SET hub_result = ? WHERE token_hash = ?', [result.slice(0, 300), sha(t)]); + const ck = await D.makeSession(email, { hubId: person && person.id, username: person && person.username, wallet: person && hubpeople.wallet(person), sponsor: person && person.sponsor ? person.sponsor.username : null, + optin: !!row.optin, via: person ? 'email-hub' : 'email-local' }); + res.writeHead(302, { Location: safeTo(row.to_path), 'Set-Cookie': ck, 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer' }); res.end(); +} + +function init(deps) { D = deps; return { start, confirm }; } +module.exports = { init, safeTo, TEST_RE }; diff --git a/public/404.html b/public/404.html index 911a3b6..822ed77 100644 --- a/public/404.html +++ b/public/404.html @@ -8,10 +8,10 @@ - +

Page not found

Back to WebWorthIt

- + diff --git a/public/admin.html b/public/admin.html index 85062d6..40c6dd6 100644 --- a/public/admin.html +++ b/public/admin.html @@ -8,7 +8,7 @@ - +
@@ -16,7 +16,7 @@
Admin token
- - + + diff --git a/public/assets/admin.js b/public/assets/admin.js index 821c39d..4b63c93 100644 --- a/public/assets/admin.js +++ b/public/assets/admin.js @@ -19,6 +19,9 @@ return '' + ct(c.created) + '' + esc(c.kind) + '' + esc(c.website || '') + ' ' + esc(WWI.short(c.address) || '') + ' ' + esc(c.chain || '') + '' + (c.error ? '
' + esc(c.error.slice(0, 160)) + '' : '') + '' + esc(c.status) + (c.status !== 'done' ? ' (' + esc(c.step || '') + ')' : '') + '' + esc(c.model || '') + '$' + Number(c.cost_usd || 0).toFixed(4) + '' + (tm ? Math.round(tm.total_s) + ' s' : '') + '' + ''; }).join('') + ''; + h += '
Join and sign-in links (no email is sent while MAIL_URL is unset)
' + (j.joins || []).map(function (x) { + return ''; + }).join('') + '
WhenEmailRefOpt-inBack toStatusHub
' + ct(x.created) + '' + esc(x.email) + '' + esc(x.ref || '') + '' + (x.optin ? 'yes' : 'no') + '' + esc(x.to_path || '') + '' + esc(x.status) + (x.mailed ? ', mailed' : '') + '' + esc(x.hub_result || '') + '
'; h += '
Test purchases and the sponsor line (nothing paid in staging)
' + j.purchases.map(function (p) { var s = p.split || {}; var l = p.line || {}; return '
WhenBuyerItemViaRefLine sourceWould payCompany
' + ct(p.at) + '' + esc(p.buyer_username ? '@' + p.buyer_username : p.buyer || 'visitor') + '' + esc(p.item) + ' $' + Number(p.usd).toFixed(2) + '' + esc(p.via) + '' + esc(p.ref || '') + '' + esc(l.source || '') + (l.ok === false ? ' (hub partial)' : '') + '
' + (l.line || []).map(function (x) { return (x.username ? '@' + esc(x.username) : esc(WWI.short(x.wallet) || '?')) + (x.qualified ? ' (bought)' : ' (passed over)'); }).join(' > ') + '
' diff --git a/public/assets/join.js b/public/assets/join.js new file mode 100644 index 0000000..383c18a --- /dev/null +++ b/public/assets/join.js @@ -0,0 +1,19 @@ +// /join: one email form for joining free and for signing in (a one-time link). Lands back on ?to= (the report that was locked). +(function () { + 'use strict'; + var $ = WWI.$, q = new URLSearchParams(location.search); + var to = q.get('to') || '/my'; if (!/^\/(?!\/)/.test(to)) to = '/my'; + if (q.get('err')) $('msg').textContent = q.get('err'); + $('hubBtn').href = '/sso/start?mode=go&to=' + encodeURIComponent(to); + fetch('/api/config').then(function (r) { return r.json(); }).then(function (c) { if (c.member) { $('form').classList.add('hide'); $('msg').innerHTML = 'You are signed in. Continue'; } }); + $('form').addEventListener('submit', function (e) { + e.preventDefault(); $('go').disabled = true; $('msg').textContent = ''; + WWI.post('/api/join', { email: $('email').value.trim(), optin: $('optin').checked, to: to }).then(function (j) { + $('go').disabled = false; + if (!j.ok) { $('msg').textContent = j.error || 'That did not work. Try again.'; return; } + if (j.mailed) $('msg').textContent = 'Check your inbox: we sent a link that signs you in (or creates your free account). It works for 30 minutes.'; + else if (j.testLink) $('msg').innerHTML = 'Staging test address: no email is sent. Open the sign-in link.'; + else $('msg').textContent = j.note || 'No link was sent.'; + }); + }); +})(); diff --git a/public/assets/render.js b/public/assets/render.js index 74215ac..caf31df 100644 --- a/public/assets/render.js +++ b/public/assets/render.js @@ -80,6 +80,34 @@ var Render = (function () { var deep = v.kind === 'deep' && v.report ? '
' + deepSections(v.report, ex) + '' + OPINION + '
' : ''; return head + '
' + main + '
' + side + '
' + deep; } - function draw(el, v) { el.innerHTML = v.status === 'done' ? done(v) : steps(v); } + // not signed in: the server sent only the grade, the verdict, the first finding and counts of what is locked + function gated(v) { + var ex = v.explorer, g = v.grade || {}, L = v.locked || {}; + var title = v.address ? WWI.short(v.address) : (v.website || 'Check'); + var head = '
Free check' + + '

' + esc(title) + (v.chainName ? ' on ' + esc(v.chainName) + '' : '') + '

' + + '' + (v.address && ex ? '' + esc(WWI.short(v.address)) + '' : '') + (v.readAt ? ' · read ' + esc(v.readAt.time) + ' · block ' + Number(v.readAt.block).toLocaleString('en-US') : '') + '
' + + (g.grade ? '
' + esc(g.grade) + '
' + (g.forced_by_flag ? 'One critical flag caps the grade at High, whatever the other scores. ' : '') + 'Our opinion, from the published rubric applied to the public facts.
' : '') + '
'; + var f = v.report && v.report.top_findings && v.report.top_findings[0]; + var first = f ? '
' + esc(f.tag) + '' + link(f.text, ex) + '
' + : v.firstFact ? '
' + esc(v.firstFact.tag) + '' + link(v.firstFact.text, ex) + (v.firstFact.source ? ' source' : '') + '
' : ''; + var items = []; + if (L.scores) items.push(L.scores + ' category scores'); + if (L.findings) items.push(L.findings + ' more finding' + (L.findings === 1 ? '' : 's')); + if (L.flags) items.push(L.flags + ' critical flag' + (L.flags === 1 ? '' : 's') + ' explained'); + if (L.facts) items.push(L.facts + ' facts read straight from the chain, with sources'); + if (L.screenshot) items.push('the website screenshot'); + if (L.siteVsCode) items.push('website claims vs code'); + var to = '/c/' + v.id; + var main = (v.report && v.report.verdict ? '
Our verdict (opinion): ' + link(v.report.verdict, ex) + '
' : '') + + (first ? '
First finding (public fact)' + first + '
' : '') + + '' + OPINION.replace('below', 'in this report') + ''; + var lock = '
Join free to see the full report: one account across the network' + + (items.length ? 'Still locked: ' + esc(items.join(', ')) + '.' : '') + + 'Joining is free and never asks you to connect a wallet. Members get 3 free checks a day.' + + '
'; + return head + '
' + main + '
' + lock + '
'; + } + function draw(el, v) { el.innerHTML = v.status === 'done' ? (v.gated ? gated(v) : done(v)) : steps(v); } return { draw: draw, OPINION: OPINION, link: link }; })(); diff --git a/public/disclaimer.html b/public/disclaimer.html index 4958659..506be2e 100644 --- a/public/disclaimer.html +++ b/public/disclaimer.html @@ -8,7 +8,7 @@ - + - - + + diff --git a/public/index.html b/public/index.html index c80995c..361f282 100644 --- a/public/index.html +++ b/public/index.html @@ -8,7 +8,7 @@ - +
@@ -30,7 +30,7 @@
-Fill in one or both. With both, we compare what the website promises against what the code does. 3 free checks a day. Read-only: a check never asks you to connect a wallet. +Fill in one or both. With both, we compare what the website promises against what the code does. 1 free check a day, 3 a day when you join free (one account across the network). Read-only: a check never asks you to connect a wallet. @@ -261,8 +261,8 @@ - - - + + + diff --git a/public/join.html b/public/join.html new file mode 100644 index 0000000..17cd347 --- /dev/null +++ b/public/join.html @@ -0,0 +1,29 @@ + + + + +Join free or sign in | WebWorthIt + + + + + + + + +
+

Join free, or sign in

+

One account across the network. Enter your email and we send you a one-time link: it signs you in if you are already a member, or creates your free account if you are new. Joining never asks you to connect a wallet.

+
+ + + + +
+

+

Signed in on InstantAdPay or LinkSpin already? Sign in with the network. See the Privacy Policy for how emails are used.

+
+ + + + diff --git a/public/my.html b/public/my.html index ef2eb85..f5646e4 100644 --- a/public/my.html +++ b/public/my.html @@ -8,14 +8,14 @@ - +

My checks

Loading...

- - + + diff --git a/public/privacy.html b/public/privacy.html index 61d9b99..122040d 100644 --- a/public/privacy.html +++ b/public/privacy.html @@ -8,7 +8,7 @@ - + - - + + diff --git a/public/report.html b/public/report.html index db6ab08..131133a 100644 --- a/public/report.html +++ b/public/report.html @@ -8,15 +8,15 @@ - +
Loading the check...

Run another check

- - - + + + diff --git a/public/rubric.html b/public/rubric.html index 0315221..cdedbc4 100644 --- a/public/rubric.html +++ b/public/rubric.html @@ -8,7 +8,7 @@ - + - - + + diff --git a/public/terms.html b/public/terms.html index 572ee53..499a2df 100644 --- a/public/terms.html +++ b/public/terms.html @@ -8,7 +8,7 @@ - + - - + + diff --git a/report.js b/report.js index 1c58723..96c3b85 100644 --- a/report.js +++ b/report.js @@ -157,7 +157,18 @@ function grade(report, E) { if (eoaUp.length) flags.push({ text: 'One personal wallet can replace the code in a single transaction (' + eoaUp.join(', ') + ').', tag: 'VERIFIED', source: 'rubric red flag 1' }); const v = (E && E.verification) || {}; if (E && E.proxy && E.proxy.upgradeable && !(v.implementation && v.implementation.match)) flags.push({ text: 'The implementation behind the upgradeable proxy has no verified source on Sourcify.', tag: 'VERIFIED', source: 'rubric red flag 2' }); - for (const f of report.critical_flags || []) if (typeof f === 'string' && f.trim()) flags.push({ text: f.trim(), tag: 'INFERRED', source: 'model, from the rubric list' }); + // the model often restates the deterministic red flags: keep one per issue, the deterministic VERIFIED one + const has1 = flags.some(f => f.source === 'rubric red flag 1'), has2 = flags.some(f => f.source === 'rubric red flag 2'); + const words = t => new Set(String(t).toLowerCase().match(/[a-z]{4,}/g) || []); + const similar = (a, b) => { const A = words(a), B = words(b); let n = 0; for (const w of A) if (B.has(w)) n++; return n / Math.max(1, Math.min(A.size, B.size)) >= 0.5; }; + for (const f of report.critical_flags || []) { + if (typeof f !== 'string' || !f.trim()) continue; + const t = f.trim(); + if (has1 && /(upgrad|replace (the )?code|single[- ](eoa|wallet|key)|one (personal )?wallet|\beoa\b|owner key)/i.test(t)) continue; + if (has2 && /(unverified|not verified|no verified|source)/i.test(t)) continue; + if (flags.some(x => similar(x.text, t))) continue; + flags.push({ text: t, tag: 'INFERRED', source: 'model, from the rubric list' }); + } let band = overall == null ? null : overall <= 25 ? 'Low risk' : overall <= 50 ? 'Moderate risk' : overall <= 75 ? 'Elevated risk' : 'High risk'; const forced = flags.length > 0 && band !== 'High risk'; if (flags.length) band = 'High risk'; diff --git a/server.js b/server.js index 3e3391e..69fe438 100644 --- a/server.js +++ b/server.js @@ -22,13 +22,16 @@ const hubpeople = require('./hubpeople'); const hubevents = require('./hubevents'); const netsites = require('./netsites'); const chatbot = require('./chatbot'); +const joinMod = require('./join'); +const reportMod = require('./report'); const PORT = Number(process.env.PORT || 3000); const STAGING = process.env.STAGING === '1'; const SITE_HOST = process.env.SITE_HOST || 'webworthit.com'; const IS_PROD = process.env.NODE_ENV === 'production'; const PUB = path.join(__dirname, 'public'); -const FREE_PER_DAY = 3; +const FREE_PER_DAY = 3; // a signed-in network member +const FREE_PER_DAY_GUEST = 1; // not signed in (Marty 2026-11-16: the free check is partly gated behind joining the network) const SECRET = (() => { if (process.env.SESSION_SECRET) return process.env.SESSION_SECRET; const f = path.join(DATA_DIR, '.secret'); try { return fs.readFileSync(f, 'utf8').trim(); } catch (e) {} @@ -80,7 +83,10 @@ async function member(req) { } function holderOf(req, m) { if (m) return 'm:' + m.email; const t = unsign(cookies(req)['wwi.t']); return t ? 't:' + t : null; } const unlocked = req => unsign(cookies(req)['wwi.unlock']) === 'test'; -async function freeLeft(req) { const r = await db.one('SELECT n FROM daily_free WHERE day = ? AND ip_hash = ?', [today(), ipHash(req)]); return Math.max(0, FREE_PER_DAY - (r ? r.n : 0)); } +// the daily free counter: per member when signed in (3 a day), per hashed IP when not (1 a day) +const freeKey = (req, m) => m ? hmac('m|' + m.email).slice(0, 24) : ipHash(req); +const freeCap = m => (m ? FREE_PER_DAY : FREE_PER_DAY_GUEST); +async function freeLeft(req, m) { const r = await db.one('SELECT n FROM daily_free WHERE day = ? AND ip_hash = ?', [today(), freeKey(req, m)]); return Math.max(0, freeCap(m) - (r ? r.n : 0)); } async function creditsOf(holder) { if (!holder) return { deep: 0, free_extra: 0 }; return (await db.one('SELECT deep, free_extra FROM credits WHERE holder = ?', [holder])) || { deep: 0, free_extra: 0 }; } // ---- network sign-in (hub provider; pairwise fallback is off unless NETWORK_SSO_SECRET is set AND the peer lists this site) ---- @@ -101,7 +107,7 @@ networksso.init({ self: 'webworthit', hubSite: 'webworthit', peer: 'iap', peerBa await db.q('INSERT INTO sessions (id, email, created, expires) VALUES (?,?,?,?)', [sid, email, Date.now(), Date.now() + 30 * 86400000]); return cookie('wwi.sid', sid, 30 * 86400, true); }, - landing: to => to, signinPath: to => '/my?signin=1&to=' + encodeURIComponent(to || '/my') }); + landing: to => to, signinPath: to => '/join?to=' + encodeURIComponent(to || '/my') }); hubevents.init({ dataDir: DATA_DIR, site: 'webworthit', end: async who => { const rows = await db.q('SELECT s.id, s.email, s.created, m.hub_id, m.wallet FROM sessions s LEFT JOIN members m ON m.email = s.email'); const ids = rows.filter(s => s.created < who.before && who.match({ email: s.email, hubId: s.hub_id, wallet: s.wallet, address: s.wallet })).map(s => s.id); @@ -109,17 +115,32 @@ hubevents.init({ dataDir: DATA_DIR, site: 'webworthit', end: async who => { return ids.length; } }); +const join = joinMod.init({ db, json, readBody, cookie, cookies, unsign, ipHash, limited, hubpeople, STAGING, SITE_HOST, + makeSession: async (email, extra) => { + await db.q('INSERT INTO members (email, hub_id, username, wallet, sponsor, created, last_seen, optin, via) VALUES (?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE hub_id = COALESCE(VALUES(hub_id), hub_id), username = COALESCE(VALUES(username), username), wallet = COALESCE(VALUES(wallet), wallet), sponsor = COALESCE(VALUES(sponsor), sponsor), last_seen = VALUES(last_seen), optin = GREATEST(optin, VALUES(optin))', + [email, extra.hubId || null, extra.username || null, extra.wallet || null, extra.sponsor || null, Date.now(), Date.now(), extra.optin ? 1 : 0, extra.via || 'email']); + const sid = crypto.randomBytes(24).toString('hex'); + await db.q('INSERT INTO sessions (id, email, created, expires) VALUES (?,?,?,?)', [sid, email, Date.now(), Date.now() + 30 * 86400000]); + return cookie('wwi.sid', sid, 30 * 86400, true); + } }); + // ---- views ---- const SHORT = a => a ? a.slice(0, 6) + '...' + a.slice(-4) : ''; +// The free check is partly gated (Marty 2026-11-16): a visitor who is not signed in sees the grade, the verdict, the FIRST finding +// and the opinion line; everything else stays on the server until they join the network or sign in. Never gated: deep reports +// (paid), public checks ("Network, checked", shared public links), admin-run checks, and the staging test code. +const isGated = (c, viewer) => c.kind === 'free' && !c.is_public && c.holder !== 'admin' && !viewer.member && !viewer.unlocked; function publicView(c, opts) { const steps = c.steps_json ? JSON.parse(c.steps_json) : {}; const rep = c.report_json ? JSON.parse(c.report_json) : null; const E = c.evidence_json ? JSON.parse(c.evidence_json) : null; const site = c.site_json ? JSON.parse(c.site_json) : null; + if (rep && rep.report && E) rep.grade = reportMod.grade(rep.report, E); // recomputed on read: rubric weights + deduped red flags const v = { id: c.id, kind: c.kind, status: c.status, created: c.created, website: c.website, chain: c.chain, chainName: (jobs.CHAINS[c.chain] || {}).name, address: c.address, pickedNote: c.picked_note, steps: jobs.STEPS.map(k => Object.assign({ key: k, name: jobs.STEP_NAMES[k] }, steps[k] || { state: 'waiting' })), queuePos: jobs.qpos(c.id), error: c.status === 'failed' ? c.error : null, label: c.public_label, isPublic: !!c.is_public }; if (c.status !== 'done') return v; + if (opts.gated) return gatedView(c, v, rep, E, site); v.timings = c.timings_json ? JSON.parse(c.timings_json) : null; v.cost = Number(c.cost_usd) || 0; v.model = c.model; v.facts = c.facts_json ? JSON.parse(c.facts_json) : []; @@ -135,6 +156,22 @@ function publicView(c, opts) { return v; } +function gatedView(c, v, rep, E, site) { + const facts = c.facts_json ? JSON.parse(c.facts_json) : []; + const r = rep && rep.report; + const finds = r && Array.isArray(r.top_findings) ? r.top_findings : []; + v.gated = true; + v.explorer = E ? E.explorer : null; + if (E && E.read_at) v.readAt = { block: E.read_at.block, time: E.read_at.time_ct }; + if (rep) v.grade = { grade: rep.grade.grade, overall: rep.grade.overall, forced_by_flag: rep.grade.forced_by_flag }; + v.report = r ? { verdict: r.verdict, top_findings: finds.slice(0, 1) } : null; + if (!r && facts.length) v.firstFact = facts[0]; + v.factcheck = c.factcheck_json ? { passed: !!JSON.parse(c.factcheck_json).passed } : null; + v.locked = { findings: Math.max(0, finds.length - 1), scores: r && r.scores ? Object.keys(r.scores).length : 0, flags: rep && rep.grade && rep.grade.flags ? rep.grade.flags.length : 0, + facts: facts.length, screenshot: !!(site && site.ok), siteVsCode: !!(r && r.site_vs_code) }; + return v; +} + async function startCheck(req, res, b, m) { const kind = b.kind === 'deep' ? 'deep' : 'free'; let site = b.website ? website.normalizeUrl(b.website) : null; @@ -149,13 +186,14 @@ async function startCheck(req, res, b, m) { let via = null; if (kind === 'free') { if (!unlocked(req)) { - const left = await freeLeft(req); + const left = await freeLeft(req, m); if (left <= 0) { const cr = await creditsOf(holder); - if (!(cr.free_extra > 0)) return json(res, 429, { error: 'You have used your 3 free checks for today. They come back tomorrow (Central time).', freeLeft: 0 }); + if (!(cr.free_extra > 0)) return json(res, 429, m ? { error: 'You have used your 3 free checks for today. They come back tomorrow (Central time).', freeLeft: 0 } + : { error: 'You have used your free check for today. Join free (one account across the network) for 3 checks a day.', freeLeft: 0, join: true }); await db.q('UPDATE credits SET free_extra = free_extra - 1, updated = ? WHERE holder = ? AND free_extra > 0', [Date.now(), holder]); via = 'voucher credit'; } else { - await db.q('INSERT INTO daily_free (day, ip_hash, n) VALUES (?,?,1) ON DUPLICATE KEY UPDATE n = n + 1', [today(), ih]); + await db.q('INSERT INTO daily_free (day, ip_hash, n) VALUES (?,?,1) ON DUPLICATE KEY UPDATE n = n + 1', [today(), freeKey(req, m)]); } } } else { @@ -177,7 +215,7 @@ async function startCheck(req, res, b, m) { return json(res, 200, { id, kind, via }); } -const PAGES = { '/': 'index.html', '/my': 'my.html', '/admin': 'admin.html', '/privacy': 'privacy.html', '/terms': 'terms.html', '/disclaimer': 'disclaimer.html', '/rubric': 'rubric.html' }; +const PAGES = { '/join': 'join.html', '/': 'index.html', '/my': 'my.html', '/admin': 'admin.html', '/privacy': 'privacy.html', '/terms': 'terms.html', '/disclaimer': 'disclaimer.html', '/rubric': 'rubric.html' }; const server = http.createServer(async (req, res) => { let u; try { u = new URL(req.url, 'http://x'); } catch (e) { res.writeHead(400); return res.end(); } @@ -208,7 +246,7 @@ const server = http.createServer(async (req, res) => { // api if (p === '/api/config' && req.method === 'GET') { const m = await member(req); const holder = holderOf(req, m); const cr = await creditsOf(holder); - return json(res, 200, { staging: STAGING, freeLeft: unlocked(req) ? null : await freeLeft(req), freePerDay: FREE_PER_DAY, unlocked: unlocked(req), credits: cr, + return json(res, 200, { staging: STAGING, freeLeft: unlocked(req) ? null : await freeLeft(req, m), freePerDay: freeCap(m), unlocked: unlocked(req), credits: cr, member: m ? { username: m.username, wallet: m.wallet ? SHORT(m.wallet) : null, sponsor: m.sponsor, refLink: m.username ? 'https://' + SITE_HOST + '/?ref=' + encodeURIComponent(m.username) : null } : null, sso: networksso.hubOn(), zones: ZONES, prices: sponsor.ITEMS, sponsorPct: { levels: sponsor.LEVEL_PCT, company: sponsor.COMPANY_PCT } }); } @@ -216,14 +254,18 @@ const server = http.createServer(async (req, res) => { let mm; if ((mm = /^\/api\/check\/([A-Za-z0-9]{12})$/.exec(p)) && req.method === 'GET') { const c = await db.one('SELECT * FROM checks WHERE id = ?', [mm[1]]); if (!c) return json(res, 404, { error: 'No check with that id.' }); - return json(res, 200, publicView(c, { full: true })); + const m = await member(req); + return json(res, 200, publicView(c, { full: true, gated: isGated(c, { member: m, unlocked: unlocked(req) }) })); } if ((mm = /^\/api\/check\/([A-Za-z0-9]{12})\/shot\.jpg$/.exec(p)) && req.method === 'GET') { + const c = await db.one('SELECT kind, is_public, holder FROM checks WHERE id = ?', [mm[1]]); + if (!c || isGated(c, { member: await member(req), unlocked: unlocked(req) })) { res.writeHead(c ? 403 : 404, headers()); return res.end(); } const s = await db.one('SELECT mime, bytes FROM screenshots WHERE check_id = ?', [mm[1]]); if (!s) { res.writeHead(404, headers()); return res.end(); } res.writeHead(200, headers({ 'Content-Type': s.mime, 'Cache-Control': 'public, max-age=86400' })); return res.end(s.bytes); } if ((mm = /^\/api\/check\/([A-Za-z0-9]{12})\/evidence$/.exec(p)) && req.method === 'GET') { - const c = await db.one('SELECT pack_md FROM checks WHERE id = ?', [mm[1]]); if (!c || !c.pack_md) return json(res, 404, { error: 'No evidence pack for this check.' }); + const c = await db.one('SELECT pack_md, kind, is_public, holder FROM checks WHERE id = ?', [mm[1]]); if (!c || !c.pack_md) return json(res, 404, { error: 'No evidence pack for this check.' }); + if (isGated(c, { member: await member(req), unlocked: unlocked(req) })) return json(res, 403, { error: 'Join free to see the full report.', join: true }); res.writeHead(200, headers({ 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-store' })); return res.end(c.pack_md); } if (p === '/api/network-checks' && req.method === 'GET') { @@ -263,6 +305,8 @@ const server = http.createServer(async (req, res) => { await db.q('INSERT INTO credits (holder, deep, updated) VALUES (?,?,?) ON DUPLICATE KEY UPDATE deep = deep + VALUES(deep), updated = VALUES(updated)', [holder, n, Date.now()]); return json(res, 200, { ok: true, credits: await creditsOf(holder), split: r.split }); } + if (p === '/api/join' && req.method === 'POST') return join.start(req, res); + if (p === '/join/confirm' && req.method === 'GET') return join.confirm(req, res, u); if (p === '/api/me' && req.method === 'GET') { const m = await member(req); if (!m) return json(res, 200, { member: null, sso: networksso.hubOn() }); const checks = await db.q('SELECT id, kind, website, chain, address, status, created FROM checks WHERE member = ? ORDER BY created DESC LIMIT 30', [m.email]); @@ -282,7 +326,8 @@ const server = http.createServer(async (req, res) => { const promos = await db.q('SELECT * FROM promo_codes ORDER BY created DESC'); const redemptions = await db.q('SELECT * FROM promo_redemptions ORDER BY at DESC LIMIT 300'); const cost = await db.one('SELECT COUNT(*) n, SUM(cost_usd) usd FROM checks'); - return json(res, 200, { checks, purchases: purchases.map(x => Object.assign(x, { line: JSON.parse(x.line_json || 'null'), split: JSON.parse(x.split_json || 'null') })), promos, redemptions, cost, staging: STAGING, zones: ZONES, sso: networksso.hubOn(), hub: hubpeople.view ? hubpeople.view() : null }); + const joins = await db.q('SELECT email, username, ref, optin, to_path, created, confirmed_at, status, mailed, hub_result FROM joins ORDER BY created DESC LIMIT 100'); + return json(res, 200, { joins, checks, purchases: purchases.map(x => Object.assign(x, { line: JSON.parse(x.line_json || 'null'), split: JSON.parse(x.split_json || 'null') })), promos, redemptions, cost, staging: STAGING, zones: ZONES, sso: networksso.hubOn(), hub: hubpeople.view ? hubpeople.view() : null }); } if (p === '/api/admin/promo' && req.method === 'POST') { const b = await readBody(req); diff --git a/tools/build-index.py b/tools/build-index.py index e5bd5fd..d94f505 100644 --- a/tools/build-index.py +++ b/tools/build-index.py @@ -21,7 +21,7 @@ rep(' '') rep(' + +

+

Signed in on InstantAdPay or LinkSpin already? Sign in with the network. See the Privacy Policy for how emails are used.

+''' + nf = '''

Page not found

Back to WebWorthIt

''' files = { @@ -127,6 +146,7 @@ files = { 'report.html': page('Check', 'A WebWorthIt check: public facts with sources, and our opinion from the published rubric.', report, ('common.js', 'render.js', 'report.js')), 'my.html': page('My checks', 'Your WebWorthIt checks and referral link.', my, ('common.js', 'my.js')), 'admin.html': page('Admin', 'WebWorthIt admin.', admin, ('common.js', 'admin.js')), + 'join.html': page('Join free or sign in', 'One account across the network. Join WebWorthIt free or sign in with a one-time email link.', joinp, ('common.js', 'join.js')), '404.html': page('Not found', 'Page not found.', nf), } for k, v in files.items():