Skip to content

fix(plugin-auth)!: a credential change ends access issued before it - #35664

Merged
os-zhuang merged 10 commits into
mainfrom
claude/credential-change-ends-prior-access
Nov 20, 2026
Merged

os-zhuang merged 10 commits into
mainfrom
claude/credential-change-ends-prior-access

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread

Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no skill under skills/ teaches these auth doors; the behaviour is documented in content/docs/permissions/authentication.mdx in this diff

维护者速读

  • 用户改密码或重置密码后,改密前发出的邮箱变更链接、改密前打开的二次验证,以及改密那一刻正在进行的登录,一律不再算数;用户重新申请链接或用新密码重新登录即可,其他用户无感。
  • 账户安全加固:替账户所有者保证"改了密码,改密前发放的访问就不再有效"。
  • 若判断有误,受影响的正常用户只会被要求重新申请链接或重新登录,不丢数据;改动只在登录认证插件内,可整块撤回。
  • 无

What changes

One rule in @objectstack/plugin-auth: a credential change ends access issued before it. One predicate (issuedBeforeCredentialChange) over one clock (readCredentialChangedAt: the last write over the account's local credential row, read through the vendor's own internalAdapter.findCredentialAccount, the same row its password check reads, so the rule needs no data engine; the row's creation is the first password, not a change). Once an account's password changes, these, issued for that account before the change, no longer grant access:

  • An email-change link (any link the email-change flow begun at POST /api/v1/auth/change-email mails, at either of its steps and to either address: the confirmation sent to the current address, and the link sent to the new one) minted before the change answers at GET /api/v1/auth/verify-email exactly what a never-issued link answers: 401 INVALID_TOKEN, or the error=INVALID_TOKEN redirect to its callback. The global before-hook hands the vendor's door a value no signer issued, so the vendor answers through its own path. Issue time is whole seconds, so a link minted in the same second as the change is refused too.
  • A second-factor challenge opened by a password sign-in before the change is ended at its verify door (its row and attempt counter deleted), which then answers what a never-opened challenge answers.
  • A door that ends the account's sessions when it sets the password ends them again once the password is written: both reset doors, POST /api/v1/auth/change-password with revokeOtherSessions: true (the session it installs is kept), and the one-step invitation acceptance (ahead of the session it opens).
  • A password sign-in during which the account's password changes is refused with what a wrong password answers at that door (email and phone), and its session is ended. The before-hook notes the credential the account holds before the vendor checks the password; the after-hook, first among the after-hooks, compares it with the credential held once the session is open.

Every door that overwrites the credential row counts, an administrator's POST /api/v1/auth/admin/set-user-password included. A check that cannot read its record refuses. Access issued after the change, and an account that never changed its local password, are untouched. No request, response or metadata shape changes.

This PR resumes a branch that was built earlier and never opened. On top of it, this round:

  • merged main once (one conflict: invitation-one-step-acceptance-34257.test.ts, where both sides appended a describe at the end of the file; both are kept, unchanged);
  • checked the doors main changed since the branch point: none of the touched doors moved. The operator's password reset that main added writes the credential row's updated_at and ends sessions after its write, so the same clock covers it with no change here;
  • declared the narrowing (fix(plugin-auth)!, Clause-②: no (narrowing), the ADR-0087 disposition and a BREAKING note in the changeset);
  • narrowed the claim in the changeset, the docs page and the rule module to the four things the rule covers, instead of "nothing issued before the change";
  • put the after-hook's own docblock back on globalAfterHook (the new helpers had been inserted between them), and moved the session re-end above the ADR-0069 D1 comment block it had split from its if.

Read first (by risk)

  1. packages/plugins/plugin-auth/src/credential-change-ends-prior-access.ts: readCredentialChangedAt (the clock over internalAdapter.findCredentialAccount, and the one-second first-credential window), issuedBeforeChangeOf (refuses when the adapter is missing or throws) and refuseSignInAcrossCredentialChange (ends the session it judged).
  2. packages/plugins/plugin-auth/src/auth-manager-after-hook.ts: the sign-in refusal at the top of globalAfterHook. It runs ahead of the impersonation and second-factor after-hooks, and its throw sits after the lockout settlement, so the attempt is counted as a wrong password.
  3. packages/plugins/plugin-auth/src/auth-manager-before-hook.ts: the /verify-email token replacement returns early from the global before-hook (the request can only be refused from there).

Two-minute check

After pnpm --filter '@objectstack/plugin-auth^...' build: pnpm --filter @objectstack/plugin-auth exec vitest run src/credential-change-ends-prior-access.test.ts. Expect Tests 17 passed (17).

Tests

  • credential-change-ends-prior-access.test.ts (new, 17 cases), driven through the real routes (a real AuthManager over a real ObjectQL engine on better-sqlite3, behind AuthPlugin.registerAuthRoutes on Hono):
    • an email-change link minted before a completed reset, a /change-password and an administrator's /admin/set-user-password answers what a never-issued link answers, with and without a callback; the address does not move and no session is opened. Control: a link minted after the reset verifies and moves the address;
    • a second-factor challenge opened before a reset answers what a never-opened challenge answers. Control: one opened after the reset completes;
    • a session that a sign-in opens between a door's revocation and its password write is ended: the emailed reset, the texted reset, and /change-password with revokeOtherSessions (the session it installs stands);
    • a password sign-in during which the password changes answers what a wrong password answers (email and phone doors) and leaves no session. Control: a sign-in with no change stands;
    • a check that cannot read its record refuses (3 cases through the real routes): an email-change link whose clock throws gets the never-issued answer and the address stays; a second-factor challenge whose clock throws gets the never-opened answer; a sign-in whose first reading throws gets the wrong-password answer, hands out no session and leaves the session set unchanged. Each has a control that passes once the reading works;
    • the clock and the sign-in readings need no data engine: on the vendor's in-memory adapter (no dataEngine), a link for an account that never changed its password verifies, a link minted before /change-password gets the never-issued answer, and both password doors sign in;
    • every refused sign-in and race case asserts that no session token is handed out (header or cookie), with positive controls at each door;
    • the predicate and the clock, as pure units (string and Date stamps).
  • invitation-one-step-acceptance-34257.test.ts: one new case. A session opened before the one-step door writes the password is ended, and the session the door opens stands.

Readings (local, final head b5cbc6ad19f)

All through scripts/pm/os-verify-lock.sh (VERDICT command-exit 0).

  • Closure build (turbo run build --filter='@objectstack/dogfood^...' --concurrency=2): 70/70 tasks successful.
  • pnpm --filter @objectstack/plugin-auth typecheck: exit 0 (check:test-typecheck OK).
  • pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2: Test Files 288 passed (288), Tests 6050 passed | 10 skipped (6060).
  • Full dogfood battery (pnpm --filter @objectstack/dogfood test, no shard, no path): Test Files 482 passed | 3 skipped (485), Tests 4092 passed | 68 skipped (4160), no failures.
  • Ablation, all legs inside one lock hold, each through scripts/ablation-replace.mjs (anchor hit once, mutation proven by blob hash, restore proven by blob == HEAD and an empty git diff HEAD); the test file imports from src:
    • A0 control, unmutated: Tests 17 passed (17).
    • A1, an unreadable clock admits instead of refusing: 2 failed | 15 passed (the link and challenge cases).
    • A2, a missing first reading lets the sign-in stand: 1 failed | 16 passed (the first-reading case).
    • A3, the phone door takes no first reading: 2 failed | 15 passed (the phone control and the in-memory phone leg).
    • A4, the clock and before-hook restored to 4cb593b8cc0: 4 failed | 13 passed (the in-memory case, the clock unit, both unreadable-clock cases).
    • A5, the refused sign-in no longer clears its session cookie: 3 failed | 14 passed (each on "hands out no session token").
    • Earlier round on 4cb593b8cc0: the predicate answering "not before" turned 6 of 13 red; the sign-in refusal never refusing turned 2 of 13 red.

Acceptance notes

  • An account's first password is not a change. The clock reads a credential row written over within one second of its creation as never written over: the row is created with its creation and update stamps taken separately.
  • Same-second issue. An email-change link carries its issue time in whole seconds, so one minted in the same second as a change, after it, is refused too. Its owner requests a new one.
  • Fails closed. A clock or record that cannot be read refuses what it was asked to admit: the link, the challenge or the sign-in.
  • No Fixes line. This PR implements a seat order with no card.

Verification

  • Derived gate families on b5cbc6ad19f (node scripts/pm/dispatch-gates.mjs --commands, 101 commands): 99 exit 0; 2 NOT MEASURED locally (exit 3, PREREQUISITE NOT MET: check:skill-examples, check:dual-build-cjs-loads), both answered by CI Lint & Repo Gates success. --ran reconciliation: 101 derived, 99 run, 2 NOT-MEASURED, 0 UNRUN.
  • check:type-check-debt OK; check:nul-bytes OK; check-adr-0087-registration: not-required (no-migration-prescription); check-empty-changeset clean.
  • CI on b5cbc6ad19f: 40 success, 15 skipped, 0 failure (Test Core 1–10/10, type checks, all lint lanes, Dogfood Regression Gate, Check Changeset, PR-body guards, Governed Surface Queue Guard).

Generated by Claude Code

🤖 Generated with Claude Code

…rule module and its tests

Claude-Session: https://claude.ai/code/session_012MmDsQg43GaB78K8X6U1sL
Co-authored-by: Claude <noreply@anthropic.com>
…cal password; changeset and docs

Claude-Session: https://claude.ai/code/session_012MmDsQg43GaB78K8X6U1sL
Co-authored-by: Claude <noreply@anthropic.com>
… own code; its race case

Claude-Session: https://claude.ai/code/session_012MmDsQg43GaB78K8X6U1sL
Co-authored-by: Claude <noreply@anthropic.com>
…nge-ends-prior-access

Claude-Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL
Co-authored-by: Claude <noreply@anthropic.com>
… the narrowing is declared and the claim is as wide as the rule

The changeset declares Clause-② no (narrowing) with its ADR-0087
disposition and BREAKING note; the changeset, the docs and the rule
module name what the rule covers instead of claiming everything issued
before the change; the after-hook's own docblock sits on the after-hook
again, and the session re-end sits above the ADR-0069 D1 block.

Claude-Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-auth, touching 32 documentable anchor(s).

7 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/deployment/environment-variables.mdx (via sys_session (literal, a string literal in endSessionsOnceThePasswordIsWritten))
  • content/docs/kernel/contracts/cache-service.mdx (via sys_session (literal, a string literal in endSessionsOnceThePasswordIsWritten))
  • content/docs/kernel/runtime-services/audit-service.mdx (via sys_session (literal, a string literal in endSessionsOnceThePasswordIsWritten))
  • content/docs/permissions/authentication.mdx (via phoneNumber (literal, a string literal on a changed line), sys_session (literal, a string literal in endSessionsOnceThePasswordIsWritten))
  • content/docs/permissions/authorization.mdx (via sys_session (literal, a string literal in endSessionsOnceThePasswordIsWritten))
  • content/docs/permissions/sharing-rules.mdx (via sys_session (literal, a string literal in endSessionsOnceThePasswordIsWritten))
  • content/docs/protocol/objectui/actions.mdx (via phoneNumber (literal, a string literal on a changed line))

⛔ 4 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v15.mdx (via phoneNumber (literal, a string literal on a changed line))
  • content/docs/releases/v17/17-2.mdx (via sys_session (literal, a string literal in endSessionsOnceThePasswordIsWritten))
  • content/docs/releases/v17/17-3.mdx (via sys_session (literal, a string literal in endSessionsOnceThePasswordIsWritten))
  • content/docs/releases/v17/17-4.mdx (via sys_session (literal, a string literal in endSessionsOnceThePasswordIsWritten))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 21 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json c03a8a342805186e04e05d9903f7f1913b43dabe → packageMentionDocs.

Which tree this was computed on

This run read content/docs from e3b79c3b21a0f453bbd8f4a44762342498a45fab — the merge of head b5cbc6ad19fe850a64cb98c4bf553cbbb3d5a128 into base c03a8a342805186e04e05d9903f7f1913b43dabe, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin e3b79c3b21a0f453bbd8f4a44762342498a45fab && git checkout e3b79c3b21a0f453bbd8f4a44762342498a45fab
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin c03a8a342805186e04e05d9903f7f1913b43dabe b5cbc6ad19fe850a64cb98c4bf553cbbb3d5a128 && git checkout -B drift-repro c03a8a342805186e04e05d9903f7f1913b43dabe && git merge --no-ff b5cbc6ad19fe850a64cb98c4bf553cbbb3d5a128

node scripts/docs-audit/affected-docs.mjs --json c03a8a342805186e04e05d9903f7f1913b43dabe

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs c03a8a342805186e04e05d9903f7f1913b43dabe → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract-review-claim: session_016WV4czt69hUUaG5XcgFNYL · head 4cb593b · 2026-11-19T23:08Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 4cb593b8cc030ec5f5e3acd319ef02a60f754f60
Local-runs: none
Scope: .changeset/credential-change-ends-prior-access.md (declaration lines), packages/plugins/plugin-auth/src/credential-change-ends-prior-access.ts, packages/plugins/plugin-auth/src/auth-manager-before-hook.ts, packages/plugins/plugin-auth/src/auth-manager-after-hook.ts, packages/plugins/plugin-auth/src/invitation-mailbox-proof.ts, packages/plugins/plugin-auth/src/credential-change-ends-prior-access.test.ts, packages/plugins/plugin-auth/src/invitation-one-step-acceptance-34257.test.ts + none in the diff beyond those; read, never reviewed: auth-manager-auth-instance.ts, auth-manager-sign-in-lockout.ts, auth-manager-database-secret.ts, admin-user-endpoints.ts, operator-password-reset.ts, driver-sql sql-driver-column-creation.ts, and better-auth 1.7.12 (api/dispatch, routes/email-verification, routes/update-user, utils/password, db/internal-adapter, plugins/two-factor) read from the published package source
Security-touching: yes

Review face: narrowing (Clause-②: no (narrowing) on the PR body and the changeset; no card, by rule). Inputs: the PR body, its eight-file list, the net diff against merge base eca20d22191, the check-runs on this head, the dev evidence on this head, and the security seat's private residual file. Nothing was built, run or re-run. content/docs/permissions/authentication.mdx is a prose face and is the seat's at ACCEPT.

Gate verdicts on this head (check-run conclusions): Test Core 1/10 to 10/10, TypeScript Type Check, Lint & Repo Gates, Check Changeset, PR-body guards, Governed Surface Queue Guard, Dogfood Regression Gate, Build Core, Build Docs, Spec property liveness: all success. No check-run concluded failure; the skipped ones are the UI, opt-in and queue legs. Dev evidence on this head: plugin-auth 288/288 files, 6046 passed, 10 skipped; dogfood battery command-exit 0, 482 files passed, 3 skipped, no failures; the predicate, the sign-in refusal and the session re-end each turn their cases red when removed.

① Derived judgments

The rule: a credential change ends access issued before it. One predicate (issuedBeforeCredentialChange, strict "before") over one clock (readCredentialChangedAt: updated_at of the account's sys_account row with provider credential; a row written within FIRST_CREDENTIAL_WINDOW_MS of its creation, and no row, read as never changed). Every accept-set change the diff implies:

  1. GET /verify-email, a token carrying updateTo whose iat falls before the clock: the before-hook replaces the token with a value no signer issued, so the vendor's own jwtVerify failure answers 401 INVALID_TOKEN or the error=INVALID_TOKEN redirect. Right. Read against routes/email-verification.mjs: the replacement lands before the handler reads ctx.query.token, and the hook's return shape is the context arm runBeforeHooks merges.
  2. The same door, both request types: the vendor's confirmation token and its verification token both carry updateTo, so both are judged. Right, and wider than the changeset's wording ("the one POST /change-email mails to the new address"), in the safe direction.
  3. The same door, a token that is both expired and older than the change now answers INVALID_TOKEN where it answered TOKEN_EXPIRED. Right (it is what a never-issued token answers); unstated in the changeset, and a refusal either way.
  4. The same door, same-second tokens: iat is whole seconds, so a token minted in the second of the change, after it, is refused. Right and declared.
  5. A token without updateTo, a token that does not decode, and a token naming no account are left to the vendor. Right: the rule's list names the email-change link only.
  6. The early return from the global before-hook on an ended link skips the rest of that hook for the request. Right: every later section of the hook is gated on a path other than /verify-email, so an ended link and a never-issued one reach the vendor through the same remaining path.
  7. /two-factor/verify-totp, /verify-otp, /verify-backup-code: a challenge whose createdAt is before the clock is deleted with its attempt counter, and the vendor answers what it answers for no challenge. Right, read against verify-two-factor.mjs (cookie name, identifier, value is the user id, 2fa-attempts- prefix).
  8. Both reset doors, on success: the account's sessions are ended again after the write, whatever the clock says. Right: revokeSessionsOnPasswordReset is fixed true in auth-manager-auth-instance.ts, so no deployment gains a revocation it had switched off.
  9. /change-password with revokeOtherSessions: true, on success: every session but the one the door installed is ended after the write. Right; without the flag nothing moves, as declared.
  10. One-step invitation acceptance for an existing account: sessions ended again after the write, ahead of the session the door opens. Right; the door already ended them before the write.
  11. /sign-in/email and /sign-in/phone-number: when the credential read after the session opened differs from the one read before the vendor's check, or either reading is missing, the session is deleted and the door answers its own wrong-password code (INVALID_EMAIL_OR_PASSWORD, or the phone plugin's INVALID_PHONE_NUMBER_OR_PASSWORD). Right. Derived and stated in the PR body: the attempt is settled as a refused credential, so it counts toward the lock and writes its login_failed row.
  12. Hook order: the refusal runs first in the global after-hook, which getHooks places ahead of every plugin after-hook, and it clears newSession, so the second-factor after-hook opens no challenge. Right, read against dispatch.mjs and two-factor/index.mjs.
  13. Public surface: no export, schema key, request or response shape moves. credential-change-ends-prior-access.ts is imported by three sibling modules and re-exported by none. Right.

② Semver level

@objectstack/plugin-auth: patch, title fix(plugin-auth)!, Clause-②: no (narrowing) and Metadata-protocol: none line-initial in both the PR body and the changeset body, a BREAKING paragraph, and one ADR-0087 marker (not-required (no-migration-prescription)). This matches what the diff publishes: a non-protocol breaking narrowing ships patch and keeps its banner and disposition (AGENTS.md, changeset rule). The narrowing takes away no declared capability at a consumer: each refused request gets a code the same door already answers. Check Changeset and PR-body guards conclude success on this head. Level and declaration lines are right.

③ Boundary flags

  • No card and no open_questions: nothing to answer from that side.
  • Dev flag, "no Fixes line": right for a seat order with no card.
  • Dev flag, three gate commands not measured locally (check:skill-examples, check:dual-build-cjs-loads, check:type-check-debt): answered by Lint & Repo Gates and Type Check · debt ledger, both success on this head.
  • Dev flag, the session re-end ablation leg: answered by the dev evidence on this head (the leg turns its cases red).
  • SQL push-down: no finding. The clock is one findOne on two equality predicates with a three-field projection. No in-app join is added. The one new id materialisation is endSessionsAfterCredentialWrite with keep (list the account's sessions, delete each but one); its reason is given in the docblock (each delete goes through the vendor's adapter so the session-delete hooks run), and the set is one account's live sessions.
  • Private residuals held by the security seat: R1, R2 — graded in the seat's private notes. Neither is graded must-fix for this PR.
  • Escalated to the seat, not a finding on this diff: the rule sentence in the changeset is bounded by "An account's first password is not a change"; what the clock is when a door creates the local credential is a ruling the seat holds with R1.

④ Design judgment

credential-change-ends-prior-access.ts: holds against the code it cites. The clock's row is the row every password door writes: internalAdapter.updatePassword and updateAccount (vendor reset, change and one-step doors), admin-user-endpoints.ts, and operator-password-reset.ts, which writes updated_at itself. Audit timestamps are millisecond or finer on every SQL dialect the driver creates (DATETIME(3), timestamptz), so the strict comparison against a millisecond challenge time and a whole-second iat behaves as the docblock says. Tried and not broken: an unsigned or repeated token parameter (left to the vendor, same answer), a token for an address with no account, a request carrying both a session and a challenge cookie, a change landing between the two sign-in readings, a first reading that fails (refused).

auth-manager-before-hook.ts: holds. The readings sit after the lock gate, the reset subject is the one the non-spending resolver already computed, and the email door's lookup lowercases as the vendor's does; the phone door reuses findPhoneSignInAccount.

auth-manager-after-hook.ts: holds. Setting returned to the refusal before the settlement and throwing after it is consistent with runAfterHooks, which turns a thrown APIError into the response and keeps running the later hooks against a cleared newSession.

invitation-mailbox-proof.ts: holds; five lines, after the write and before createSession.

Tests: thirteen cases through the real routes plus one on the one-step door; each of the four claims has a case and a control, and the staging moves the clock past the first-credential window before any change.

S1 (should-fix) — issuedBeforeChangeOf answers "before" whenever the manager has no data engine. On an AuthManager built without dataEngine (the in-memory arm createDatabaseConfig warns about) every email-change link and every second-factor challenge is refused, for accounts that never changed a password. The same row is readable through internalAdapter.findCredentialAccount, the seam the two sign-in readings already use. Read the clock there, or name this arm in the changeset.

S2 (should-fix) — the sign-in cases pin status and code only, and allow a set-auth-token header on the refused answer (if (raced.bearer) …). The changeset says the door answers "what a wrong password answers". Pin that the refused answer carries no session token in its headers, or state that it may carry one for a session already ended.

S3 (should-fix) — "a check that cannot read its record refuses" is pinned for the clock as a unit only. No case drives a link, a challenge or a sign-in with an unreadable clock or a missing first reading, and none of the three ablation legs covers the catch in issuedBeforeChangeOf or the missing-reading arm of refuseSignInAcrossCredentialChange.

N1 (nit) — in endEmailChangeTokenIssuedBeforeCredentialChange the import('jose') shares a try with the decode, so a failed import leaves the request as it came, while the docblock says each check fails closed. jose is a declared dependency, so the arm is not expected to run.

N2 (nit) — /two-factor/send-otp is not among TWO_FACTOR_VERIFY_PATHS: a challenge opened before the change can still ask for a code there, though no verify door will take it.

N3 (nit) — the changeset describes the refused link as the one mailed "to the new address"; the code judges every token carrying updateTo (derived judgment 2).

No must-fix.

Implemented-by: claude/credential-change-ends-prior-access
Reviewed-by: isolated sub-agent of session_016WV4czt69hUUaG5XcgFNYL

VERDICT: PASS

…pter; refusals that cannot read their record are pinned

The clock behind "a credential change ends access issued before it" reads
the account's credential row through better-auth's internal adapter, the
seam its own password check reads, so a manager with no data engine judges
links and challenges instead of refusing them all. New cases pin that a
refused sign-in hands out no session token in its headers, that a link, a
challenge and a sign-in whose record cannot be read are refused, and that
the clock works on the vendor's in-memory adapter. The changeset names
every email-change link the rule judges.

Claude-Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL
Co-authored-by: Claude <noreply@anthropic.com>
… through the vendor's adapter; the refusal cases pin what they claim

The first reading of `/sign-in/phone-number` named its account through the
data engine, so a manager without one took no reading and refused every
phone sign-in. It now names the account with the lookup the vendor's phone
door makes, through the vendor's adapter, as the email door already does.

The case for a sign-in whose first reading cannot be taken compares the
account's sessions before and after the refused sign-in (the session sign-up
opened stands throughout), and a control sign-in afterwards adds one.

The case for a manager without a data engine creates its account with the
administrator's create-user called in-process, since no sign-up door admits
an account without a data engine, and signs in at both password doors.

Claude-Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL
Co-authored-by: Claude <noreply@anthropic.com>
…le judges, at either step of the flow

An email-change link is judged whichever step of the flow mailed it: the
confirmation `POST /change-email` sends the current address, and the link to
the new address, whether `/change-email` mails it directly or the
confirmation step does. The changeset's parenthesis now says so. The
predicate module's docblock paragraph on the clock is re-wrapped; no code
moves.

Claude-Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract-review-claim: session_016WV4czt69hUUaG5XcgFNYL · head b5cbc6a · 2026-11-20T01:50Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: b5cbc6ad19fe850a64cb98c4bf553cbbb3d5a128
Local-runs: none
Scope: .changeset/credential-change-ends-prior-access.md (declaration lines and the reworded claim), packages/plugins/plugin-auth/src/credential-change-ends-prior-access.ts, packages/plugins/plugin-auth/src/auth-manager-before-hook.ts, packages/plugins/plugin-auth/src/auth-manager-after-hook.ts, packages/plugins/plugin-auth/src/invitation-mailbox-proof.ts, packages/plugins/plugin-auth/src/credential-change-ends-prior-access.test.ts, packages/plugins/plugin-auth/src/invitation-one-step-acceptance-34257.test.ts + none in the diff beyond those; read, never reviewed: auth-manager-sign-in-lockout.ts, auth-manager-database-secret.ts, operator-password-reset.ts, platform-objects sys-account.object.ts, and better-auth 1.7.12 (db/internal-adapter, routes/sign-in, plugins/phone-number/routes) read from the published package source
Security-touching: yes

This record replaces the one on 4cb593b8cc0 (record 7024920025: PASS, S1 to S3, N1 to N3). It is a delta review of the three commits over that head (04d44a601ea, b6285e3a27a, b5cbc6ad19f: four files, the changeset, the rule module, the before-hook and the rule's test file), read on top of the whole-PR judgment already rendered. The whole-PR diff against merge base eca20d22191 names the same eight files as before; the fix round added no file. Nothing was built, run or re-run. content/docs/permissions/authentication.mdx is unchanged in the delta and stays the seat's at ACCEPT.

Gate verdicts on this head (check-run conclusions, read once): 41 success, 17 skipped, none failure. Test Core, TypeScript Type Check, Lint & Repo Gates, Dogfood Regression Gate, Build Core, Build Docs, Governed Surface Queue Guard, PR-body guards and one Check Changeset run conclude success. A second Check Changeset run was still in_progress when read (the PR body was edited after the push); the seat reads its conclusion before ACCEPT. Dev evidence on this head: plugin-auth 288/288 files, 6050 passed, 10 skipped; the rule's test file 17/17; dogfood battery exit 0, 482 files passed, 3 skipped, 4092 tests passed, no failures; five ablation legs, each red (unreadable-clock catch 2, missing first reading 1, phone first reading 2, clock and before-hook at their 4cb593b8cc0 versions 4, no session-cookie deletion 3).

① Derived judgments

The thirteen judgments of the prior record stand on this head. What the delta moves:

  1. The clock's row. readCredentialChangedAt now reads internalAdapter.findCredentialAccount(userId): the row with the user's id, provider credential, and accountId equal to the user's id. The prior head read the row by user and provider alone. Right, and tighter: this is the row the vendor itself checks a password against at both password doors (routes/sign-in.mjs filters on accountId === user.id; the phone door calls findCredentialAccount), and the row updatePassword writes. A credential row whose accountId is another value opens no password sign-in, so the clock no longer follows a row no door admits. Several rows on the exact triple are written together by updatePassword, so whichever one findOne answers carries the same stamp.
  2. No data engine. The link and challenge checks no longer take the manager's engine. On a manager built without dataEngine they now judge by the same clock instead of refusing everything. Right; it removes a refusal the prior head gave to accounts that never changed a password.
  3. The phone door's first reading is ctx.context.adapter.findOne on model user, field phoneNumber, an equality match on the body's number. Right: it is the vendor's own lookup at /sign-in/phone-number, statement for statement.
  4. The changeset's first bullet now names both steps and both addresses of the email-change flow. Right: it matches the code, which judges every token carrying updateTo.
  5. Public surface: CredentialClockReader is a new exported interface of a module nothing re-exports; readCredentialChangedAt changes its first parameter inside the package. No published export, schema key, request or response shape moves. Right.

② Semver level

Unchanged and right: @objectstack/plugin-auth: patch, fix(plugin-auth)!, Clause-②: no (narrowing) and Metadata-protocol: none line-initial in the changeset and still present on the PR body, the BREAKING paragraph, one ADR-0087 marker. The delta rewords one bullet and publishes nothing the level would follow.

③ Boundary flags

  • Prior S1 to S3 and N1 to N3: answered in ④.
  • SQL push-down: no finding. The clock is still one single-row read on equality predicates. It now returns the whole credential row where the prior head projected three fields; the reason is given in the docblock (the vendor's seam, so the clock needs no data engine), and the vendor reads the same row the same way on every password check. The phone reading is one single-row equality read. No in-app join, no id materialisation.
  • Private residuals held by the security seat: R1, R2 — graded in the seat's private notes. Both are ruled and assigned to one follow-up change after this one lands; neither is graded must-fix for this PR.
  • For the seat: the second Check Changeset run named above.

④ Design judgment

credential-change-ends-prior-access.ts: holds against the code it cites. issuedBeforeChangeOf refuses when the request carries no adapter with findCredentialAccount, and when the read throws. Read against db/internal-adapter.mjs, the reader is the three-predicate lookup the docblock names. Tried and not broken: a row on another accountId (answers "no row", and that row admits no sign-in), duplicate rows on the triple (one stamp), Date and string stamps (both pinned in the unit), a manager on the vendor's in-memory adapter (pinned through the routes).

auth-manager-before-hook.ts: holds. Both first readings go through the vendor's adapter; a lookup that throws is caught in noteSignInCredential and leaves no reading, which the second reading refuses. The now-unused import is removed.

credential-change-ends-prior-access.test.ts: 17 cases. The four added cases are driven through the real routes, and each carries a positive control.

Prior findings on this head:

  • S1 — resolved. The clock and both first readings use the vendor's adapter; the clock and the sign-in readings need no data engine runs a manager with no dataEngine through a link that verifies, a link refused after a change, and both password doors.
  • S2 — resolved. handsOutSession (a set-auth-token header, or a session cookie set to a value) is asserted false on the refused sign-in at both doors, beside false for a wrong password and true for the controls. The conditional assertion is gone.
  • S3 — resolved. a check that cannot read its record refuses: a link, a challenge and a sign-in, each with the credential read failing, each compared with the never-issued, never-opened or wrong-password answer, each followed by its control. The ablation legs named above cover the catch and the missing-reading arm.
  • N3 — done (derived judgment 4).
  • N1 — kept as an accepted deviation; acceptable (jose is a declared dependency).
  • N2 — kept as an accepted deviation; acceptable (the send door grants no access).

Fail-closed, path by path: no adapter, refuses; clock read throws, refuses; account lookup for a link throws, refuses; issue time missing, refuses once a change exists; challenge with no readable user, ended; first sign-in reading missing or unreadable, refused; second reading throws, refused. One arm answers the other way:

N4 (nit) — a credential row that is read but carries no parseable updatedAt answers "never changed" in readCredentialChangedAt, while the docblock says a record that cannot be read refuses. Present at both heads. sys_account.updated_at defaults to now and every password write stamps it, so a blank stamp means no write has happened; the wording, not the behaviour, is what is off.

No must-fix, no should-fix.

Implemented-by: claude/credential-change-ends-prior-access
Reviewed-by: isolated sub-agent of session_016WV4czt69hUUaG5XcgFNYL

VERDICT: PASS

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 20, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-sales · session_01L6bhgUkbQqRUUFSiu2HGob

Recorded 2026-11-20T04:47Z. Pre-landing notice for this PR's owner. PR #35610 (card #35321, Tier H, awaiting approval) adds a narrowed leg at the merge queue. Once #35610 merges, a pull that declares a narrowing, as this one does, is refused at the queue unless two things are on its head: an authorized approval (or the authorized account's own enqueue), and a standing PASS contract review at CONTRACT_REVIEW_TIER. See the Landing impact section of #35610.

@os-zhuang
os-zhuang marked this pull request as ready for review November 20, 2026 06:15
@os-zhuang
os-zhuang enabled auto-merge November 20, 2026 06:15
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 20, 2026
@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 20, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: b5cbc6ad19fe850a64cb98c4bf553cbbb3d5a128
Local-runs: none
Scope: .changeset/credential-change-ends-prior-access.md (declaration lines and the reworded claim), packages/plugins/plugin-auth/src/credential-change-ends-prior-access.ts, packages/plugins/plugin-auth/src/auth-manager-before-hook.ts, packages/plugins/plugin-auth/src/auth-manager-after-hook.ts, packages/plugins/plugin-auth/src/invitation-mailbox-proof.ts, packages/plugins/plugin-auth/src/credential-change-ends-prior-access.test.ts, packages/plugins/plugin-auth/src/invitation-one-step-acceptance-34257.test.ts + none in the diff beyond those; read, never reviewed: auth-manager-sign-in-lockout.ts, auth-manager-database-secret.ts, operator-password-reset.ts, platform-objects sys-account.object.ts, and better-auth 1.7.12 (db/internal-adapter, routes/sign-in, plugins/phone-number/routes) read from the published package source
Security-touching: yes

This record replaces the one on 4cb593b8cc0 (record 7024920025: PASS, S1 to S3, N1 to N3). It is a delta review of the three commits over that head (04d44a601ea, b6285e3a27a, b5cbc6ad19f: four files, the changeset, the rule module, the before-hook and the rule's test file), read on top of the whole-PR judgment already rendered. The whole-PR diff against merge base eca20d22191 names the same eight files as before; the fix round added no file. Nothing was built, run or re-run. content/docs/permissions/authentication.mdx is unchanged in the delta and stays the seat's at ACCEPT.

Gate verdicts on this head (check-run conclusions, read once): 41 success, 17 skipped, none failure. Test Core, TypeScript Type Check, Lint & Repo Gates, Dogfood Regression Gate, Build Core, Build Docs, Governed Surface Queue Guard, PR-body guards and one Check Changeset run conclude success. A second Check Changeset run was still in_progress when read (the PR body was edited after the push); the seat reads its conclusion before ACCEPT. Dev evidence on this head: plugin-auth 288/288 files, 6050 passed, 10 skipped; the rule's test file 17/17; dogfood battery exit 0, 482 files passed, 3 skipped, 4092 tests passed, no failures; five ablation legs, each red (unreadable-clock catch 2, missing first reading 1, phone first reading 2, clock and before-hook at their 4cb593b8cc0 versions 4, no session-cookie deletion 3).

① Derived judgments

The thirteen judgments of the prior record stand on this head. What the delta moves:

  1. The clock's row. readCredentialChangedAt now reads internalAdapter.findCredentialAccount(userId): the row with the user's id, provider credential, and accountId equal to the user's id. The prior head read the row by user and provider alone. Right, and tighter: this is the row the vendor itself checks a password against at both password doors (routes/sign-in.mjs filters on accountId === user.id; the phone door calls findCredentialAccount), and the row updatePassword writes. A credential row whose accountId is another value opens no password sign-in, so the clock no longer follows a row no door admits. Several rows on the exact triple are written together by updatePassword, so whichever one findOne answers carries the same stamp.
  2. No data engine. The link and challenge checks no longer take the manager's engine. On a manager built without dataEngine they now judge by the same clock instead of refusing everything. Right; it removes a refusal the prior head gave to accounts that never changed a password.
  3. The phone door's first reading is ctx.context.adapter.findOne on model user, field phoneNumber, an equality match on the body's number. Right: it is the vendor's own lookup at /sign-in/phone-number, statement for statement.
  4. The changeset's first bullet now names both steps and both addresses of the email-change flow. Right: it matches the code, which judges every token carrying updateTo.
  5. Public surface: CredentialClockReader is a new exported interface of a module nothing re-exports; readCredentialChangedAt changes its first parameter inside the package. No published export, schema key, request or response shape moves. Right.

② Semver level

Unchanged and right: @objectstack/plugin-auth: patch, fix(plugin-auth)!, Clause-②: no (narrowing) and Metadata-protocol: none line-initial in the changeset and still present on the PR body, the BREAKING paragraph, one ADR-0087 marker. The delta rewords one bullet and publishes nothing the level would follow.

③ Boundary flags

  • Prior S1 to S3 and N1 to N3: answered in ④.
  • SQL push-down: no finding. The clock is still one single-row read on equality predicates. It now returns the whole credential row where the prior head projected three fields; the reason is given in the docblock (the vendor's seam, so the clock needs no data engine), and the vendor reads the same row the same way on every password check. The phone reading is one single-row equality read. No in-app join, no id materialisation.
  • Private residuals held by the security seat: R1, R2 — graded in the seat's private notes. Both are ruled and assigned to one follow-up change after this one lands; neither blocks this PR.
  • For the seat: the second Check Changeset run named above.

④ Design judgment

credential-change-ends-prior-access.ts: holds against the code it cites. issuedBeforeChangeOf refuses when the request carries no adapter with findCredentialAccount, and when the read throws. Read against db/internal-adapter.mjs, the reader is the three-predicate lookup the docblock names. Tried and not broken: a row on another accountId (answers "no row", and that row admits no sign-in), duplicate rows on the triple (one stamp), Date and string stamps (both pinned in the unit), a manager on the vendor's in-memory adapter (pinned through the routes).

auth-manager-before-hook.ts: holds. Both first readings go through the vendor's adapter; a lookup that throws is caught in noteSignInCredential and leaves no reading, which the second reading refuses. The now-unused import is removed.

credential-change-ends-prior-access.test.ts: 17 cases. The four added cases are driven through the real routes, and each carries a positive control.

Prior findings on this head:

  • S1: closed. The clock and both first readings use the vendor's adapter; the clock and the sign-in readings need no data engine runs a manager with no dataEngine through a link that verifies, a link refused after a change, and both password doors.
  • S2: closed. handsOutSession (a set-auth-token header, or a session cookie set to a value) is asserted false on the refused sign-in at both doors, beside false for a wrong password and true for the controls. The conditional assertion is gone.
  • S3: closed. a check that cannot read its record refuses: a link, a challenge and a sign-in, each with the credential read failing, each compared with the never-issued, never-opened or wrong-password answer, each followed by its control. The ablation legs named above cover the catch and the missing-reading arm.
  • N3 — done (derived judgment 4).
  • N1 — kept as an accepted deviation; acceptable (jose is a declared dependency).
  • N2 — kept as an accepted deviation; acceptable (the send door grants no access).

Fail-closed, path by path: no adapter, refuses; clock read throws, refuses; account lookup for a link throws, refuses; issue time missing, refuses once a change exists; challenge with no readable user, ended; first sign-in reading missing or unreadable, refused; second reading throws, refused. One arm answers the other way:

N4 (nit) — a credential row that is read but carries no parseable updatedAt answers "never changed" in readCredentialChangedAt, while the docblock says a record that cannot be read refuses. Present at both heads. sys_account.updated_at defaults to now and every password write stamps it, so a blank stamp means no write has happened; the wording, not the behaviour, is what is off.

No must-fix, no should-fix.

Implemented-by: claude/credential-change-ends-prior-access
Reviewed-by: isolated sub-agent of session_016WV4czt69hUUaG5XcgFNYL

VERDICT: PASS

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 20, 2026
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 20, 2026
@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 20, 2026
Merged via the queue into main with commit 92ab056 Nov 20, 2026
76 checks passed
@os-zhuang
os-zhuang deleted the claude/credential-change-ends-prior-access branch November 20, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants