Commit 3a20c62
fix(auth): address SSO/SCIM review feedback
Follow-up to #2924. Implements the actionable review feedback from that PR:
SCIM (apps/api/src/routes/scim.ts)
- Scope GET/PUT/PATCH/DELETE /Users/:id and group membership to the token's
org so a token can't read or mutate users outside its tenant.
- Honor `active: false` on user create (staged/suspended assignments no longer
get org membership).
- Recompute roles when a user is reactivated via PUT/PATCH and when a group is
renamed, so mapped admin/owner members aren't left as developer.
- Guard against removing the org's last owner during deprovisioning.
- Link the SSO provider account for pre-existing users, not just new ones.
- Enforce displayName uniqueness on group rename (PUT/PATCH).
- Push /Users and /Groups filtering + pagination into the database.
SSO management (apps/api/src/routes/sso.ts)
- Block plugin bypass: the raw Better Auth /auth/sso management endpoints are
now rejected at the HTTP handler (they only require a session).
- Prevent admins (non-owners) from creating owner role mappings.
- Recompute affected members when a role mapping is added or removed.
- Guard against a missing provider row after registration and clean up orphans.
- Clear SCIM tokens' stale provider link when a connection is deleted.
- Derive the SCIM token's provider link from the org's connection.
- Audit SCIM revoke against the token id, not the org id.
Auth enforcement (apps/api/src/auth/config.ts)
- Gate SSO enforcement on SSO_ENABLED and on an active, enterprise org.
- On a blocked non-SSO login, delete only that session, not all of the user's.
UI (apps/ui)
- Preserve the ?redirect= target and surface thrown errors on SSO sign-in.
- Confirm before destructive SSO/SCIM actions; only toast on successful copy;
show a loading state until the org plan resolves.
Shared role-recompute logic extracted to apps/api/src/lib/sso-roles.ts.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 7faa91c commit 3a20c62
7 files changed
Lines changed: 637 additions & 209 deletions
File tree
- apps
- api/src
- auth
- lib
- routes
- ui/src
- app/login
- components/sso
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
42 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
43 | 71 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 72 | + | |
| 73 | + | |
49 | 74 | | |
50 | 75 | | |
51 | 76 | | |
| |||
1060 | 1085 | | |
1061 | 1086 | | |
1062 | 1087 | | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
1063 | 1091 | | |
1064 | 1092 | | |
1065 | | - | |
| 1093 | + | |
1066 | 1094 | | |
1067 | 1095 | | |
1068 | 1096 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
10 | 29 | | |
11 | 30 | | |
12 | 31 | | |
| |||
22 | 41 | | |
23 | 42 | | |
24 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
25 | 47 | | |
26 | 48 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
0 commit comments