Repository navigation
fix(plugin-auth)!: invite-member refuses a blank role 400 ROLE_NOT_FOUND and writes no invitation - #29296
Conversation
…UND and writes no invitation
better-auth's role check drops empty entries, so a blank role ("", whitespace,
[] or an empty entry like "member,") named no unknown role and was stored as
the invitation's role; under a walled group its acceptance wrote a membership
with no organization role. beforeCreateInvitation now refuses it first, with
the code the door already answers for an unknown role, and never defaults it.
Claude-Session: https://claude.ai/code/session_01ADHkmPVewfGaEY1hNx6XpK
Co-authored-by: Claude <noreply@anthropic.com>
…ization; pin a whitespace-only role too Claude-Session: https://claude.ai/code/session_01ADHkmPVewfGaEY1hNx6XpK Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmPVewfGaEY1hNx6XpK Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check6 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 22 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 b4d952cb8f42b03d73afbfc1b9c53e641b67e7be && git checkout b4d952cb8f42b03d73afbfc1b9c53e641b67e7be
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin c347d22d2bcce32b414e693f2ec5ca5f564db53a 214ca68802758ad6eca5333b2135bec5753ee666 && git checkout -B drift-repro c347d22d2bcce32b414e693f2ec5ca5f564db53a && git merge --no-ff 214ca68802758ad6eca5333b2135bec5753ee666
node scripts/docs-audit/affected-docs.mjs --json c347d22d2bcce32b414e693f2ec5ca5f564db53a |
|
domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY Contract-review-claim: The lane seat runs this PR's review at |
|
domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY Contract reviewServed-tier: Reviewed at 2026-11-02T11:29Z. Inputs: card #29158 (body and every comment), PR #29296 (body, file list, net diff against ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
No must-fix. One should-fix (② changeset prose). Check-runs on the head at post time: 49 total, all complete — 36 success, 13 skipped (UI, docs, opt-in and sharded-matrix placeholders), 0 failure, 0 in progress. Among the green: Check Changeset, Governed Surface Queue Guard, PR-body guards, Spec property liveness, Lint · ESLint, Type Check · workspace, Test Core 1–8/8, Build Core, Dogfood Regression Gate. These conclusions are the gate verdicts this record relies on; nothing was run locally. Implemented-by: VERDICT: PASS |
…ALIDATION_FAILED on the composed stack; name the code change for it Claude-Session: https://claude.ai/code/session_01ADHkmPVewfGaEY1hNx6XpK Co-authored-by: Claude <noreply@anthropic.com>
|
domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY Regen-provenance: contract review 6576041111 (PASS, head 席位核对 · ACCEPT ·
|
| item | reading |
|---|---|
| Shape | Base main, Fixes #29158. 6 files: the blank-role guard in beforeCreateInvitation (auth-manager-organization-plugin.ts), invitation-role-cap.ts, invite-role-not-found-code.ts, a unit test and a dogfood test, a @objectstack/plugin-auth patch changeset with BREAKING banner and ADR-0087 not-required (no-migration-prescription). Metadata-protocol: none. No packages/spec/**, no new code (ROLE_NOT_FOUND is ledgered for this door). Not governed. |
| Rule | A blank invitation role ("", whitespace, [], or a blank entry in a role list) is refused 400 ROLE_NOT_FOUND before the role cap and before any row is written, and is never defaulted. Every named role is judged as before. |
| Security | Access boundary (org invitations). The review probed every door that writes an invitation or membership role (invite, resend, re-issue, update-member-role, add-member, admin import) and found no blank that still gets through. Legacy role: '' rows stay accepted into a role-less membership, which is less privilege, not more. Noted, not owed here. |
| Open question | "member," moves from 400 VALIDATION_FAILED to 400 ROLE_NOT_FOUND: keep it, as the review rules. The changeset now names the code move. |
| Evidence | Base 104cd1a5: "" → 200 with a role '' row in both postures. Head: plugin-auth 208 files / 3618 tests, typecheck 0, eslint 0, full dogfood VERDICT 0, ablation red then restored, gates 65/65. CI on 8d01f7cf: 49 runs, 36 green, 13 skipped, none red. Auto-merge waits on every required check on the new head. |
| Landing | 「按照 pm-dispatch 规则复核过的都授权」 (Leehom, 2026-10-25T11:35Z): ready and auto-merge through the relay. |
Requested by Steve · project thread
Fixes #29158
Clause-②: no (narrowing) — measured: on base
104cd1a5a blank role ("", whitespace only) onPOST /api/v1/auth/organization/invite-memberanswered 200 and stored the invitation, in single and walledgroup; on this head it is refused 400ROLE_NOT_FOUNDand no row is written. Nothing is widened.Metadata-protocol: none — measured: no schema key, accepted metadata value or metadata type moves; the diff touches no
packages/spec/**.Skills-docs: none — the narrowing is an HTTP door's accept set, not anything a metadata author writes; no skill names a blank invitation role.
维护者速读
packages/plugins/plugin-auth/src/auth-manager-organization-plugin.ts(beforeCreateInvitation 新增的拒绝分支),invite-role-not-found-code.ts(判空与文案)。pnpm --filter @objectstack/plugin-auth exec vitest run src/accept-invitation-adopt-membership.test.ts,预期 17 个全部通过,其中 7 个是新的空角色用例。What changes
beforeCreateInvitation(auth-manager-organization-plugin.ts) refuses a blank role first, after the cloud-managed refusal and before the invitation role cap and the placement gate:APIError('BAD_REQUEST', { code: 'ROLE_NOT_FOUND', message }). The hook runs beforeadapter.createInvitation, so nosys_invitationrow is written.invite-role-not-found-code.tsgainshasBlankInvitationRoleEntryandblankInvitationRoleRefusal. Blank means the whole value is empty or whitespace (""," ",[]) or one entry of a role list is ("member,",",admin",["member", ""]). The message keeps the vendor'sROLE_NOT_FOUND:prefix and says the invitation role is empty.invitation-role-cap.ts: comment only. Its "not a reachable invitation shape" note on an empty role was false; it now points at the blank refusal that runs first.ROLE_NOT_FOUND), nopackages/spec/**edit, no change to which non-blank roles are accepted, no default tomember, no better-auth or overrides change.Tests
packages/plugins/plugin-auth/src/accept-invitation-adopt-membership.test.ts: new#29158block on the realAuthManagerand better-auth route. Six blank shapes are refused 400ROLE_NOT_FOUNDwith the empty-role sentence and zero rows; a delegated admin's blank role answersROLE_NOT_FOUND(not the cap's 403); control: the owner invitingadminis still 200 with the role stored.packages/qa/dogfood/test/invitation-blank-role-refusal.dogfood.test.ts(new): the composed CRM stack insingleand walledgroup(multiTenant: 'posture-only', the issuer owns a second organization).""," "and"member,"are refused 400ROLE_NOT_FOUNDwith no row; controlmemberis 200 with one pending row; a guard asserts the posture.Acceptance notes
"member,"(and",admin") was ALREADY refused on base, by thesys_invitation.roleselect validator: 400VALIDATION_FAILED(invalid_option), no row. On this head the same request answers 400ROLE_NOT_FOUNDinstead. Same status, same zero rows, a different code; only""and whitespace-only were accepted on base. Named in the report's open questions.sys_invitation.role: none found.admin-import-userswrites the admin plugin's user role, never an invitation, and drops a blank one. The data API servessys_invitationasget/listonly. A resend (resend: true) of an already pending invitation renews its expiry and keeps the stored role, before this hook, so it writes no role; a resend with no pending row creates a new invitation and meets this refusal.Verification
Premise on base 104cd1a (both postures, composed stack)
The three gate files restored to base, plugin-auth rebuilt, a throwaway probe (not committed) on the CRM stack:
""→ 200, rowrole: ''pending; the invitee signs up and accepts → 200,sys_member.rolemember(the sign-up's row is kept), invitation['', 'accepted']." "→ 200, rowrole: ' '."member,"→ 400VALIDATION_FAILED."superuser"→ 400ROLE_NOT_FOUND.""→ 200, rowrole: ''; accept → 200,sys_member.role'', invitation['', 'accepted']." "→ 200."member,"→ 400VALIDATION_FAILED."superuser"→ 400ROLE_NOT_FOUND.Ablation of the negative pins
node scripts/ablation-replace.mjs --anchor "if (blankRole) {" --replacement "if (blankRole && process.env.ABLATION_29158_GUARD === 'on') {", plugin-auth rebuilt,ablation-dist-preflight.mjssaw the marker in 2 dist files. Unit: 7 failed / 10 passed (expected 200 to be 400, body"role":""). Dogfood: 6 failed / 4 passed, every blank case in both postures. Restored withgit checkout HEAD -- …:git status --porcelainempty,git diff HEAD0 bytes, blob hash equal to HEAD, rebuilt, preflight--absent: marker absent from all 20 built files. A first attempt used a comment marker that the bundler strips; its preflight failed, so that reading was discarded and the run was redone with the string marker.Suites, gates, lint (head 8d01f7c, after merging main)
pnpm --filter @objectstack/plugin-auth typecheck: exit 0.pnpm --filter @objectstack/plugin-auth exec vitest run: Test Files 208 passed (208), Tests 3618 passed, 10 skipped.--no-inline-config) overpackages/plugins/plugin-authand the new dogfood file: exit 0.dispatch-gates --commands: 65 derived, 65 run with exit 0, reconciled with--ran: "65 run, 0 NOT-MEASURED, 0 UNRUN (a DERIVED zero)". Two stopped at a prerequisite on the first pass and were rerun green:check-plugin-teardown-shape --self-test(shallow clone, pinned fixture commit fetched) andcheck:dual-build-cjs-loads(7 packages outside the closure built first).pnpm --filter @objectstack/dogfood test): lock VERDICT command-exit 0; Test Files 390 passed, 3 skipped (393); Tests 3225 passed, 28 skipped (3253).Generated by Claude Code