VNOX-Server/hub/migrations/0003_email_auth.sql
loki5512344 cca084b0ae
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.
2026-10-24 17:42:52 +02:00

26 lines
1.1 KiB
SQL

-- 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);