Nothing a customer can see. The schema change and the configuration land on their own so the widest-reaching edit in the project can be reviewed for what it is rather than buried inside a feature. The password hash becomes nullable. That is one line and it is not the work; the work is that every read of the column is now a question rather than a fact. Three places compared against it with bcrypt, and all three now ask first through one shared function. That function exists because the alternative is worse than a wrong answer. bcrypt.compare throws on a null hash rather than returning false, so any call site that forgot the check would answer a sign-in attempt with a 500 instead of a refusal. On the login route that is also an oracle, because it would happen for exactly the accounts that have no password. One function rather than a null check repeated three times means the question is asked identically everywhere and a fourth site cannot forget to ask it. Nothing writes a null yet. The first accounts without a password arrive with the sign-up path, which is why this is landed ahead of them. The identities table is a table rather than columns on customers, because one customer may eventually hold more than one. Columns would make a second provider a migration and a third an embarrassment. Its important column is the provider subject, and the comment on it is the whole security posture of the feature in one place: never the email. An email is a display value its owner can change and a provider may reassign; a subject is opaque and stable for the life of the account. Matching on the email would strand a customer who changed theirs and, far worse, hand their account to whoever inherited the old address. Unique across the provider and subject together, not the subject alone. The down migration drops the table and deliberately does not restore the NOT NULL. Re-adding it fails outright once a passwordless customer exists, and a down migration that destroys accounts to satisfy a constraint is far worse than a column that is merely more permissive than it needs to be. The redirect URI is derived from PUBLIC_URL, the same single source the WebAuthn Relying Party ID uses and for the same reason: Google compares it as an exact string and answers a mismatch with a message that says nothing about which half is wrong. Deriving it means the value is correct by construction anywhere the email links already are. The tests are mostly about what must not end up in it, since a trailing slash on PUBLIC_URL is an easy way to produce a URI that is one character from the registered one. The config also reports whether it is enabled at all, so a developer without credentials gets a storefront that works and simply does not offer the button, rather than one that offers it and fails. Absent rather than disabled, the same choice made for a browser without WebAuthn. Environment validation refuses to boot on one credential without the other, matching how the SMTP pair is handled. Half-configured is the case worth catching because the failure otherwise arrives at the moment a customer presses the button. The QA compose file sets both to empty, and the comment there says why at length rather than leaving it to look like an oversight. Google refuses a redirect URI whose host is not under a domain whose ownership has been proved by DNS, and nobody can prove ownership of anything under bermudalamb.synology.me because Synology owns the registrable domain above it. That is the same wall #285 hit with Cloudflare. So QA cannot run this at all until #313 moves it to a subdomain of the real domain, at which point it is two stack variables and one console entry, with no code change either way. Also corrects the record in #332, which lists account deletion as confirming with a password. It does not; the route takes none and the confirmation is a modal in the account page. Deletion needed no change here. Verified: backend tsc clean for src and tests, 550 unit tests pass including new coverage of the config derivation, the null-hash comparison and the environment rules; lint clean apart from warnings that predate this branch. The integration suite needs a database this machine has no Docker for. Closes #340 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
78 lines
3.6 KiB
JavaScript
78 lines
3.6 KiB
JavaScript
exports.up = (pgm) => {
|
|
pgm.sql(`
|
|
-- A sign-in that belongs to somebody else's identity provider (#340).
|
|
--
|
|
-- A table rather than columns on customers, because one customer may hold
|
|
-- more than one: Google today, and Apple if #332 ever decides in its
|
|
-- favour. Columns would mean a second provider is a migration and a third
|
|
-- is an embarrassment.
|
|
--
|
|
-- Same shape as customer_credentials, and for the same reason: a row that
|
|
-- links this account to something a third party can vouch for, deleted with
|
|
-- the customer because an identity that outlived its owner could
|
|
-- authenticate as a customer who no longer exists.
|
|
CREATE TABLE IF NOT EXISTS customer_identities (
|
|
id SERIAL PRIMARY KEY,
|
|
customer_id INTEGER NOT NULL REFERENCES customers(id) ON DELETE CASCADE,
|
|
|
|
-- 'google' today. Not a CHECK constraint: the values come from this
|
|
-- codebase rather than from a request, and the project has no enum types
|
|
-- elsewhere.
|
|
provider TEXT NOT NULL,
|
|
|
|
-- The provider's subject claim, and **never the email**.
|
|
--
|
|
-- This is the whole security posture of the table in one column. An email
|
|
-- is a display value that its owner can change and that a provider may
|
|
-- reassign; a subject is opaque, stable for the life of the account, and
|
|
-- means nothing outside the provider that issued it. Matching on the
|
|
-- email would strand a customer who changed theirs and, far worse, hand
|
|
-- their account to whoever inherited the old address.
|
|
provider_sub TEXT NOT NULL,
|
|
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
|
|
-- Null until first used, exactly as on a passkey. It is what tells two
|
|
-- entries apart on an account page where the names are similar.
|
|
last_used_at TIMESTAMPTZ,
|
|
|
|
-- Unique across the pair, not on the subject alone. Two providers could
|
|
-- in principle issue the same opaque string and it would mean nothing —
|
|
-- but the same provider issuing one subject to two accounts here means
|
|
-- something has gone wrong rather than that two people share an identity.
|
|
UNIQUE (provider, provider_sub)
|
|
);
|
|
|
|
-- Listing what an account is linked to is the common read, and it is always
|
|
-- scoped by owner.
|
|
CREATE INDEX IF NOT EXISTS customer_identities_customer_id_idx
|
|
ON customer_identities (customer_id);
|
|
|
|
-- The change with the widest blast radius in the whole project (#332).
|
|
--
|
|
-- A customer who signed up through Google has no password and never will
|
|
-- unless they ask for one, so the column has to admit that. Making it
|
|
-- nullable is one line; what it costs is that every read of it is now a
|
|
-- question rather than a fact, and the three that compare against it with
|
|
-- bcrypt have been made to ask first.
|
|
--
|
|
-- Nothing writes a NULL yet. The first accounts without a password arrive
|
|
-- with the sign-up path, and this is deliberately landed before them so the
|
|
-- schema change can be reviewed on its own.
|
|
ALTER TABLE customers ALTER COLUMN password_hash DROP NOT NULL;
|
|
`);
|
|
};
|
|
|
|
exports.down = (pgm) => {
|
|
pgm.sql(`
|
|
DROP TABLE IF EXISTS customer_identities;
|
|
|
|
-- Deliberately not restored. Re-adding NOT NULL fails outright if any
|
|
-- passwordless customer exists by then, and a down migration that destroys
|
|
-- accounts to satisfy a constraint would be far worse than a column that is
|
|
-- merely more permissive than it needs to be. Reversing this properly means
|
|
-- deciding what happens to those customers, which is not a schema decision.
|
|
SELECT 1;
|
|
`);
|
|
};
|