From 28f678fea4e392f12f058cc50961a547bf262d42 Mon Sep 17 00:00:00 2001 From: wachtelhund Date: Wed, 18 Nov 2026 12:51:45 +0100 Subject: [PATCH] Revert "Let the Sourceful app sign a user up again after they left the list. (#4)" This reverts commit b9d7c1c11501b97b754889babc70fc15ca9d1244. --- docs/signup.md | 1 - src/contacts.ts | 7 ------- test/signup.test.ts | 3 --- test/subscribe.test.ts | 19 +------------------ 4 files changed, 1 insertion(+), 29 deletions(-) diff --git a/docs/signup.md b/docs/signup.md index 7b8b849..c370fa6 100644 --- a/docs/signup.md +++ b/docs/signup.md @@ -15,7 +15,6 @@ Pick the first that fits. A browser form is the weakest: browsers send a true `O - The address goes on the list with the consent id, the time and the form's name as its source (`subscriptions.source`). - An address that is suppressed, for this list (someone who left) or for every list (a hard bounce, a spam complaint, or cleaned in Mailchimp), stays out; the sign-up is dropped. Without double opt-in a form cannot tell the person from someone typing their address, so someone who left and wants back writes to you until double opt-in exists. -- Exception: the Sourceful app form (`sourceful-app`) signs the owner of the address in first. For that form only, a list-scoped `unsubscribe` is lifted and the address is signed up again. Bounce, complaint, Mailchimp-cleaned, and suppressions on every list (`*`) are never lifted. - The answer is the same in every case, so a form cannot be used to find out who is on a list. - A known reader keeps their first name and country, and an existing subscription keeps its consent id, time and source. Without double opt-in, anyone can type someone else's address into a form, and must not be able to change what that person agreed to. diff --git a/src/contacts.ts b/src/contacts.ts index eaefe6b..6a24969 100644 --- a/src/contacts.ts +++ b/src/contacts.ts @@ -137,14 +137,7 @@ export async function subscribe(env: Env, s: Signup, now = new Date()): Promise< // One batch whatever the address, with the suppression checked in each insert: a suppressed // address takes as long as a new one, so the time of the answer tells nothing either. const free = `NOT EXISTS (SELECT 1 FROM suppressions WHERE email_hash = ?2 AND scope IN (?3, '*'))`; - // The Sourceful app has already signed the owner in, so they may turn this list back on - // after leaving. Website forms must not: they cannot tell the person from someone typing - // their address. Bounce, complaint, and Mailchimp-cleaned stays in force. - const statements = source === 'sourceful-app' - ? [env.DB.prepare(`DELETE FROM suppressions WHERE email_hash = ?1 AND scope = ?2 AND reason = 'unsubscribe'`).bind(hash, list)] - : []; await env.DB.batch([ - ...statements, joinedStatement(env.DB, list, email, hash, iso(now).slice(0, 10)), env.DB.prepare(`INSERT INTO contacts (email, email_hash, first_name, country) SELECT ?1, ?2, ?4, ?5 WHERE ${free} ON CONFLICT DO NOTHING`) .bind(email, hash, list, firstName(s.firstName), country), diff --git a/test/signup.test.ts b/test/signup.test.ts index c587940..e258249 100644 --- a/test/signup.test.ts +++ b/test/signup.test.ts @@ -287,9 +287,6 @@ test('Sourceful\'s config: the app\'s accounts go to a list of their own, apart assert.deepEqual((await stored(e)).map(r => [r.list, r.consent, r.source]), [['app-users', 'app-account-2026-11', 'sourceful-app']]); assert.equal((await handle(unsubscribe({ email: body.email, list: 'app-users' }, { key: app }), e)).status, 200); assert.deepEqual(await stored(e), []); - // The app has signed the user in, so they may opt in again after leaving. - assert.equal((await handle(post(body, { origin: null, key: app }), e)).status, 200); - assert.deepEqual((await stored(e)).map(r => [r.list, r.source]), [['app-users', 'sourceful-app']]); }); test('the rate limit counts an IPv6 client per /64 and an IPv4 client per address', async () => { diff --git a/test/subscribe.test.ts b/test/subscribe.test.ts index 22a3e44..14b2f16 100644 --- a/test/subscribe.test.ts +++ b/test/subscribe.test.ts @@ -1,7 +1,7 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; import { handle } from '../src/app.ts'; -import { firstName, forget, subscribe } from '../src/contacts.ts'; +import { firstName, subscribe } from '../src/contacts.ts'; import { normalizeEmail } from '../src/util.ts'; import { admin, rows, testEnv } from './helpers.ts'; @@ -36,23 +36,6 @@ test('signing up again after leaving does not lift the suppression', async () => assert.deepEqual(await rows(env, 'SELECT list FROM subscriptions'), [{ list: 'ftw-box' }]); }); -test('the Sourceful app can sign the same user up again after they left that list', async () => { - const env = testEnv(); - const appSignup = { ...signup, source: 'sourceful-app' }; - await subscribe(env, appSignup); - await forget(env, appSignup.email, 'ftw-news', 'unsubscribe'); - assert.equal((await rows(env, 'SELECT COUNT(*) AS n FROM subscriptions')).at(0)!.n, 0); - assert.deepEqual(await subscribe(env, appSignup), { ok: true }); - assert.deepEqual(await rows(env, 'SELECT list, source FROM subscriptions'), [{ list: 'ftw-news', source: 'sourceful-app' }]); - assert.deepEqual(await rows(env, 'SELECT * FROM suppressions'), []); - // Bounce and complaint still block the app form. - const { hash } = (await rows<{ hash: string }>(env, 'SELECT email_hash AS hash FROM contacts'))[0]; - await env.DB.prepare('DELETE FROM subscriptions').run(); - await env.DB.prepare(`INSERT INTO suppressions (email_hash, scope, reason) VALUES (?, '*', 'bounce')`).bind(hash).run(); - assert.deepEqual(await subscribe(env, appSignup), { ok: true }); - assert.deepEqual(await rows(env, 'SELECT * FROM subscriptions'), []); -}); - test('a bounced or complaining address is not signed up again', async () => { const env = testEnv(); await subscribe(env, signup);