feat(hub): email one-time-code sign-in

POST /v1/auth/email/start and /verify with HMAC-protected 8-digit codes
(10 min, 5 tries, atomic single use), browser-bound via a __Host- cookie,
same-origin checks, per-address/source/global rate limits and an injectable
sender. Enabled in /v1/info only when SMTP is configured. Email identities
use external_identities(provider='email') and never merge with GitHub.
This commit is contained in:
Loki 2026-10-24 17:42:49 +02:00
parent f1883e5001
commit cca084b0ae
Signed by: boba
GPG key ID: 253067914055423B
20 changed files with 1756 additions and 59 deletions

View file

@ -0,0 +1,26 @@
-- Passwordless email sign-in. Email identities reuse external_identities
-- (provider='email', subject=normalized address): the (provider, subject) key already
-- guarantees one account per address and never collides with 'github.com' subjects,
-- so the two methods can never be merged implicitly.
--
-- One pending code per browser. Only keyed MACs are stored: neither the code, nor the
-- address of a pending attempt, nor the requester's network address.
CREATE TABLE email_attempts (
attempt_id TEXT PRIMARY KEY,
browser_hash TEXT NOT NULL UNIQUE,
email_mac TEXT NOT NULL,
code_mac TEXT NOT NULL,
failures INTEGER NOT NULL DEFAULT 0,
expires_at INTEGER NOT NULL
);
CREATE INDEX email_attempt_expiry ON email_attempts(expires_at);
-- Sliding-window ledger for send rate limits, keyed by MAC of address / source.
CREATE TABLE email_send_log (
email_mac TEXT NOT NULL,
source_mac TEXT NOT NULL,
sent_at INTEGER NOT NULL
);
CREATE INDEX email_send_by_address ON email_send_log(email_mac, sent_at);
CREATE INDEX email_send_by_source ON email_send_log(source_mac, sent_at);
CREATE INDEX email_send_by_time ON email_send_log(sent_at);