Repository navigation
fix(plugin-auth)!: admin create-user refuses a password outside the deployment's length range - #25927
Conversation
…swordLength/maxPasswordLength better-auth's own createUser checks only the maximum length, so the admin create-user door saved a 1-character password that set-user-password and change-password refuse. The length range now lives in resolvePassword, the one place both admin doors resolve a credential: an explicit password outside the deployment's range is refused with set-user-password's INVALID_REQUEST before any account exists, and a generated password is sized to the range. Claude-Session: https://claude.ai/code/session_01Berf7f8pR4mCUBQwMPXUbV Co-authored-by: Claude <noreply@anthropic.com>
…d length range Claude-Session: https://claude.ai/code/session_01Berf7f8pR4mCUBQwMPXUbV Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 21 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 8bc6ea0d22863c031aa637070414dd7849a48180 && git checkout 8bc6ea0d22863c031aa637070414dd7849a48180
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 2a728ba2acf52c13d1918c2afca7b79bf391e1f5 ab706f70612cd6e99a4ca9a4e88a51b9a9cc33bb && git checkout -B drift-repro 2a728ba2acf52c13d1918c2afca7b79bf391e1f5 && git merge --no-ff ab706f70612cd6e99a4ca9a4e88a51b9a9cc33bb
node scripts/docs-audit/affected-docs.mjs --json 2a728ba2acf52c13d1918c2afca7b79bf391e1f5
|
Contract reviewServed-tier: Face: ① Derived judgmentsEach accept-set or public-surface change the diff implies, with the cited code it was read against.
The new describe block (17 pins: per door, from one table, three refusals, two boundaries, one configured range and two generated sizes, plus create-user's unreadable-context pin) reads correctly against the mock's default range 8 / 128: 'Abcde1!' is 7, 'Abcdef1!' is 8, the maximum pins are 128 and 129 characters. The pre-existing "enforces better-auth min password length" pin on set-user-password is kept and, per the dev's ablation A, goes red when the shared check is deleted. ② Semver level
③ Boundary flagsDev's report (6408177252) and the PR's Acceptance notes, each answered:
Check-runs on Implemented-by: VERDICT: PASS Generated by Claude Code |
…in the BREAKING banner Claude-Session: https://claude.ai/code/session_01Berf7f8pR4mCUBQwMPXUbV Co-authored-by: Claude <noreply@anthropic.com>
席位核对ACCEPT ·
Generated by Claude Code |
Requested by Elon · project thread
Fixes #25824
Clause-②: no (narrowing) — admin create-user refuses one request shape it used to run: an explicit
passwordshorter than the deployment'sminPasswordLength(one longer thanmaxPasswordLengthwas already refused by better-auth, now with set-user-password's code). Nothing is widened.Metadata-protocol: none
Why
POST /api/v1/auth/admin/create-usersaved a 1-character password, and the user then signed in with it (the card's repro, measured on a stock showcase boot).set-user-passwordrefuses the same value with400 INVALID_REQUEST"Password must be at least 8 characters", and the user's own change-password refuses it with400 PASSWORD_TOO_SHORT. The cause is in better-auth 1.7.12 itself:admin/create-userrunsassertPasswordNotTooLongonly, whileadmin/set-user-passwordruns bothassertPasswordNotTooShortandassertPasswordNotTooLong(better-auth/dist/plugins/admin/routes.mjs, read in this worktree's install). OurrunAdminCreateUserpassed the password straight to thatcreateUser. OurresolvePasswordran only the complexity check, and the length check lived only in the set-user-password runner. ADR-0069 recordspassword_min_length/password_max_length→emailAndPassword.minPasswordLength/maxPasswordLengthas enforced, and on this door it was not.What changed (
packages/plugins/plugin-auth/src/admin-user-endpoints.ts)resolvePasswordnow takes the deployment's range (AuthContextLike['password']['config'], better-auth's resolvedminPasswordLength/maxPasswordLength). It refuses a password outside that range with set-user-password's existing refusal:400 INVALID_REQUEST, "Password must be at least N characters" / "Password must be at most N characters". There is no new error code. set-user-password's own copy of the check is deleted, so the two doors cannot drift apart again.getAuthContext()beforeresolvePassword, so a refusal comes before the multi-org join check, the permission-set grant,createUser, the must-change stamp and the audit row. If the context cannot be read, the request is refused throughmapAuthApiError(create-user failed) and no account is created. That is the same mapping set-user-password already used for the same read.min(max(16, minPasswordLength), maxPasswordLength)long, andgenerateTemporaryPasswordstill never goes below 12. Before, it was always 16. So with a minimum above 16, set-user-password refused the password it had just generated, and create-user saved it below the minimum. The range check runs on generated passwords too, so one that still cannot fit (a maximum below 12) is refused, never saved.userId, then complexity, then length. The one difference is that the context read moved ahead of password resolution, which is observable only when that read throws.Changeset:
.changeset/25824-admin-create-user-password-length.md(@objectstack/plugin-authpatch, BREAKING banner, ADR-0087not-required (no-migration-prescription), before / now / fix).Verification
Run at
5737e51e(code) andd151a987(code + changeset; the code blob is identical).New pins (
admin-user-endpoints.test.ts, describe "admin doors: one password length range"), run across both doors from one table:'a'(the repro), one short of the minimum, one past the maximum. Each answers400,INVALID_REQUESTand the exact message, and writes nothing (nocreateUser, no hash, no account write, no engine update, no audit insert).minPasswordLength: 12refuses a 10-character password.pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/admin-user-endpoints.test.ts src/durability-swallow-repair.test.ts: VERDICT command-exit 0, 2 files, 115/115.pnpm --filter @objectstack/plugin-auth testatd151a987: VERDICT command-exit 0, Test Files 193 passed (193), Tests 3698 passed | 10 skipped (3708).pnpm --filter @objectstack/plugin-auth build && pnpm --filter @objectstack/plugin-auth typecheck: VERDICT command-exit 0 (tsc+ examples +check:test-typecheckOK, ledger unchanged: 10 files / 88 errors / 23 pinned signatures).Ablations. Each was committed first, mutated through
scripts/ablation-replace.mjsorgit restore --source, and restored to the HEAD blobb89b9184withgit diff HEADempty:cb0a2fcf, tests kept): 9 failed / 84 passed. All three create-user refusal pins, create-user's configured-range pin, all four generated-password pins (both doors) and the unreadable-context pin went red. set-user-password's refusal pins stayed green, as expected: that door already refused.resolvePassword): 9 failed / 84 passed. All six refusal pins (both doors), both configured-range pins, and the pre-existing "enforces better-auth min password length" went red.<→<=on the minimum): 4 failed / 89 passed. Both exactly-the-minimum pins and both minimum-raised generated pins went red.Gates. All run at
d151a987, derived bynode scripts/pm/dispatch-gates.mjs --commands(70 families). Exit codes were captured before any pipe, and--ranreconciles 70 derived: 68 run, 2 NOT MEASURED, 0 unrun.check-plugin-teardown-shape --self-testfirst exited 3 (prerequisite: the shallow clone could not reach its pinned fixture commit). It exited 0 after fetching that one commit.pnpm check:dts-closurefirst exited 1, naming@objectstack/metadata-cored.ts as missing. That package was being rebuilt by my own concurrent dogfood-closure build at that moment. It exited 0 on a re-run once that build finished.pnpm check:dual-build-cjs-loadsneeds every package'sdist/(39 are not built in this tree), andpnpm check:type-check-debt's closure build never got the shared verify lock. CI'sLint & Repo Gatesruns both.pnpm lint(repo-wide,eslint . --no-inline-config): exit 0, no output.Full dogfood battery (owed for the
(narrowing)arm): running ond151a987under the verify lock. Its VERDICT line and counts go in the card'sos-dev-report.Claim race on the card
Two
Claim:comments landed 88 s apart: this seat's 6407745341 (03:45:06Z) anddomain:serverseat 1's 6407761859 (03:46:34Z, read against a stale "unassigned" card). Seat 1 withdrew in 6407776655, and the seat's arbitration is 6407784753. This PR is the 6407745341 claim's. Seat 1's thread made no edit and opens no PR.Acceptance notes
passwordPolicy: 'temporary',admin-import-users.tscallsgenerateTemporaryPassword()with no length, and its deps carry no auth context. On a deployment whoseminPasswordLengthis above 16, a temporary-password import would save 16-character credentials below the minimum, the same way create-user did, because better-auth'screateUserchecks only the maximum. This is the same defect class, but it is in another file outside this claim's surface. Dedupe words: import-users temporary password minPasswordLength, generateTemporaryPassword length import.INVALID_REQUEST(set-user-password's existing code, kept per the triage route "with the same code"), while better-auth's sign-up and change-password answerPASSWORD_TOO_SHORT/PASSWORD_TOO_LONG. Aligning them would change a wire answer, so it is out of scope here.Generated by Claude Code