Commit 5b0af2b
fix(plugin-auth): admit ObjectStack platform admins on /admin/impersonate-user (better-auth plugin endpoint, not a raw mount) (#10352)
* fix(plugin-auth): admit ObjectStack platform admins on /admin/impersonate-user
better-auth's admin plugin authorizes on the legacy `user.role === 'admin'`
scalar that ADR-0068 D2 stopped synthesizing, so a platform admin and a plain
member received byte-identical 403 YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS and
the sys_user "Impersonate User" button was dead everywhere.
Re-authorize the route as a better-auth PLUGIN ENDPOINT, replacing the vendor
endpoint in place on the admin plugin's own `endpoints` record, rebuilt from the
vendor's own options object so only the authorization predicate changes. A raw
Hono mount is forbidden: it means hand-rolled signed cookies against the
`admin_session` contract with /admin/stop-impersonating, and it would silently
detach the path-keyed #8243 rotation hook.
Measured on better-auth 1.7.1: `checkEndpointConflicts` only logs, so a second
plugin would boot and serve but print an endpoint-conflict error on every start;
replacing in place keeps exactly one plugin on the path.
The vendor's admin-TARGET guard read the same dead scalar and was inert; it is
re-asked through the ADR-0068 predicate so it means something again.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PnJHU45vPJj5UQrxe946Bx
* test(plugin-auth): record why the impersonation suite reuses the sibling engine double
Importing a sibling `.test.ts` re-registers its suites here. That cost is real
and is now written down alongside the three worse alternatives, so the next
reader does not "fix" it into a new engine double, a ledger-invisible helper, or
a suite-free fixture file this package's bare `vitest run` cannot load.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PnJHU45vPJj5UQrxe946Bx
* chore(devx): declare the ruled vendorWire entry for admin-impersonate-endpoint.ts
The 2026-08-21 maintainer ruling (#10554, option A) added a fourth state to
check-route-envelope's surface-3 grammar for a body this repo BUILDS whose
shape is a vendor's wire format. The machinery landed on `main` in 6abc4df
with no entries, deliberately: an entry for a file the walk cannot find is an
error, so the entry lands with the file, here.
The one counted body is the success return of POST /admin/impersonate-user,
`ctx.json({ session, user })`. The four refusals are `throw APIError.from(…)`,
which no counter on this surface reads, so `unenveloped: 1` is the whole
visible departure.
The body is byte-identical to better-auth 1.7.1's own handler return, and this
endpoint republishes the vendor's OpenAPI metadata untouched — a schema
declaring exactly `{ session, user }` — so enveloping it would contradict the
schema the same endpoint serves. The note names the three machine-checked
parties the ruling mandates: vendor, reader and partner.
The const-hoist evasion the ruling named is not used: the body literal stays
at the call site, visible to every counter.
node scripts/check-route-envelope.mjs --self-test
✓ check-route-envelope self-test passed
node scripts/check-route-envelope.mjs
✓ Plugin-mounted Hono routes — 12 module(s) audited, 166 hand-built
body/bodies (count reported, NOT pinned): 8 conformant, 0 ratcheted,
3 exempt, 1 vendor-wire
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PnJHU45vPJj5UQrxe946Bx
* chore(runtime): classify the four better-auth impersonation codes as foreign-vocabulary
`check-dispatcher-error-vocabulary` reported four unclassified-site findings
in the new `admin-impersonate-endpoint.ts`: FAILED_TO_CREATE_USER,
USER_NOT_FOUND, YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS and
YOU_CANNOT_IMPERSONATE_ADMINS. All four are better-auth 1.7.1's OWN constants
-- verified in the installed vendor at `dist/plugins/admin/error-codes` and
BASE_ERROR_CODES -- and three are read at runtime off `plugin.$ERROR_CODES`.
They became visible to this scan only because #9968 reimplements the vendor's
handler in-repo, so codes that used to be relayed from node_modules are now
stamped by a literal this repo builds.
The verdict is `foreign-vocabulary`, door `none`, which is the limb this table
already uses twice for better-auth codes in this same package
(IMPERSONATION_ROTATION_FAILED, YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_MEMBER).
Re-verified rather than inherited: the refusals are `APIError` thrown inside a
better-auth endpoint, better-auth answers its own failures with a `Response`,
`AuthManager.handleRequest` returns it untouched (logging only >= 500) and
`domains/auth.ts` passes it on as `{ handled: true, result: response }`, so
`errorFromThrown` is never reached; anything the auth service does throw is
answered `deps.error(INTERNAL_ERROR_MESSAGE, 500)` with a status-derived code
(#5085). The 2026-08-21 ruling (#10554) already recorded this same file's
bodies as the vendor's wire via `check-route-envelope`'s `vendorWire` entry.
`pending-registration` was considered and rejected as FALSE: it asserts the
code belongs in #8846's ObjectStack ledger batch. These are the vendor's
strings; registering them would promote a vendor spelling into the platform
vocabulary and leave a ledger member outliving its producer on the next bump.
The rows add zero to PENDING_LEDGER_REGISTRATION, which still holds only
`owd_widening_forbidden`.
No evasion: no rename, no indirection, no hoist -- every literal stays at its
call site, visible to the scanner.
node scripts/check-dispatcher-error-vocabulary.mjs
check-dispatcher-error-vocabulary: OK -- 21 unregistered code-stamping
site(s), all classified; 1 awaiting a ledger entry (#8846).
node scripts/check-dispatcher-error-vocabulary.mjs --self-test
check-dispatcher-error-vocabulary --self-test: 8 shapes + 102 assertions
OK (vocabulary + #9098 door typing)
node scripts/check-nul-bytes.mjs
check-nul-bytes: OK (scanned 6193 text file(s) ... no raw ASCII control bytes).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PnJHU45vPJj5UQrxe946Bx
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 76deca2 commit 5b0af2b
7 files changed
Lines changed: 860 additions & 11 deletions
File tree
- .changeset
- packages
- plugins/plugin-auth/src
- runtime/src
- scripts
| 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 | + | |
Lines changed: 377 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 262 additions & 0 deletions
| 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 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
| |||
2589 | 2592 | | |
2590 | 2593 | | |
2591 | 2594 | | |
2592 | | - | |
| 2595 | + | |
2593 | 2596 | | |
2594 | 2597 | | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
2595 | 2627 | | |
2596 | 2628 | | |
2597 | 2629 | | |
| |||
4319 | 4351 | | |
4320 | 4352 | | |
4321 | 4353 | | |
| 4354 | + | |
| 4355 | + | |
| 4356 | + | |
| 4357 | + | |
| 4358 | + | |
| 4359 | + | |
| 4360 | + | |
| 4361 | + | |
| 4362 | + | |
| 4363 | + | |
| 4364 | + | |
| 4365 | + | |
| 4366 | + | |
| 4367 | + | |
| 4368 | + | |
| 4369 | + | |
| 4370 | + | |
| 4371 | + | |
| 4372 | + | |
| 4373 | + | |
| 4374 | + | |
| 4375 | + | |
| 4376 | + | |
| 4377 | + | |
| 4378 | + | |
| 4379 | + | |
| 4380 | + | |
| 4381 | + | |
| 4382 | + | |
| 4383 | + | |
| 4384 | + | |
| 4385 | + | |
| 4386 | + | |
| 4387 | + | |
| 4388 | + | |
| 4389 | + | |
| 4390 | + | |
| 4391 | + | |
| 4392 | + | |
| 4393 | + | |
| 4394 | + | |
4322 | 4395 | | |
4323 | 4396 | | |
4324 | 4397 | | |
| |||
0 commit comments