Jump to…
snowfix: 500 error because of database is patchedyuzpxzopsouq1mo
Matt W1-- Session cookies carry a random token, not the row id.
Matt W2--
Matt W3-- The cookie used to be the `sessions.id` UUIDv7: a 48-bit millisecond
Matt W4-- timestamp plus a counter that is reseeded once per millisecond and then
Matt W5-- incremented. Sessions minted in the same millisecond therefore shared their
Matt W6-- leading bits, and other UUIDs from the same generator (comment ids, which are
Matt W7-- rendered into review pages) disclosed the counter state. A UUIDv7 is a good
Matt W8-- primary key and was never meant to be a bearer secret.
Matt W9--
Matt W10-- The cookie now carries 32 CSPRNG bytes and this table stores only their
Matt W11-- SHA-256, so a leaked snapshot of `sessions` no longer contains anything that
Matt W12-- can be presented to the server.
Matt W13--
Matt W14-- Existing rows cannot be migrated: their tokens never existed, and the id is
Matt W15-- deliberately no longer accepted. Everyone is signed out exactly once, which
Matt W16-- is the correct price for the change.
Matt W17DELETE FROM sessions;
Matt W18
Matt W19ALTER TABLE sessions ADD COLUMN token_hash text NOT NULL;
Matt W20
Matt W21-- Unique because it is the lookup key, and the index is what makes resolving a
Matt W22-- session one probe rather than a scan.
Matt W23CREATE UNIQUE INDEX sessions_token_hash_idx ON sessions (token_hash);

23 lines · SQL