mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
Post-merge fixes from pr-review-v5.md (CR-17, CR-5, CR-8, CR-10):
- CR-17 profiles: enforce the per-plan profile cap with a conditional INSERT
(INSERT ... SELECT WHERE (SELECT COUNT(*) ...) < limit) instead of a non-atomic
COUNT-then-INSERT, so two concurrent creates can't both slip past the cap.
- CR-5 reminders: the "biweekly" spending-report cron "0 10 1-7,15-21 * 4" over-fired —
cron day-of-month and day-of-week are OR'd, so it fired on every day in those ranges AND
every Thursday. Now fires twice monthly ("0 10 1,15 * *"), and both scheduled emails claim a
one-time per-period slot (new reminder_dedup table, migration 0007) so a cron re-fire can't
email the same report twice.
- CR-8 auth/login: always run password verification — against a fixed dummy PBKDF2 hash when the
account or its hash is absent — so the response time doesn't reveal whether an email is
registered (user-enumeration timing oracle).
- CR-10 auth/login: add a per-account login throttle (login-email:<email>) on top of the per-IP
limit, to blunt distributed brute-force against a single account.
Worker typecheck clean. NB: the deploy must run d1:migrate:dev for the new reminder_dedup table.
CR-9 (registration discloses an existing email) is deferred — a proper fix needs an
email-verification-on-signup flow; the rate limit + the upcoming Turnstile gate mitigate the
automated-probing vector in the meantime.
13 lines
622 B
SQL
13 lines
622 B
SQL
-- Idempotency for scheduled reminder emails (migration 0007).
|
|
--
|
|
-- Cloudflare cron can re-fire a trigger, and a schedule can match more days than intended (the
|
|
-- day-of-month and day-of-week fields are OR'd). This table makes each scheduled send claim a
|
|
-- one-time slot per (user, period) so a re-fire never emails the same report twice.
|
|
-- dedup_key examples: 'report:2026-06-H1' (1st-half spending report), 'budget:2026-06-15'.
|
|
CREATE TABLE IF NOT EXISTS reminder_dedup (
|
|
user_id INTEGER NOT NULL,
|
|
dedup_key TEXT NOT NULL,
|
|
sent_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
PRIMARY KEY (user_id, dedup_key)
|
|
);
|