Repository navigation
Commit 4c0cf65
feat(plugin-auth): the environment-access refusal carries the host's reason and sentence (#34265)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbSUQWB2j9eHYsRcrCiq1X1C)_
## 维护者速读
-
改了什么:云端拒绝某账号进入环境时,宿主可以说明原因(「不是该组织成员」「邀请尚未接受」)和一句给用户看的话;这个原因经环境自己的登录回调一路带到环境登录页,登录页按原因显示对应的本地化句子。应用把用户送来登录时,登录页显示「登录以继续前往
应用名」,而不再只显示对方的域名。
- 为什么改:cloud#4471 的托管登录需要告诉用户为什么进不去、该怎么做,也需要让用户知道自己正在登录哪个应用。
- 风险与回滚:宿主仍返回 true/false
时,三种拒绝回复与改动前逐字节一致(有测试钉住),谁能进入没有任何变化。新增一个无需登录的只读接口,只回答应用名,而且只回答已签名请求里点名的那个应用,其余情况一律同一个
404,并按来源地址限流(每 60 秒 10 次)。回滚即还原本 PR;云端只有在用上本版本 plugin-auth 之后才能返回原因对象。
-
先看:`packages/plugins/plugin-auth/src/oauth-client-name.ts`(新接口的放行条件)、`oauth-callback-refusal-reason.ts`(回调上带原因的条件)、`ui/apps/console/src/pages/auth/LoginPage.tsx`(登录页的两处读取)。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
--maxWorkers=2 src/oauth-authorize-refusal.test.ts`,预期 69 个测试全部通过。
- 需要你做的:无,席位落地。
Fixes #34168
Clause-②: yes (widening)
Metadata-protocol: none
## What changes
All four items of the card.
- **The seam may say why (item 1).**
`AuthManagerOptions.oidcAuthorizeGate` may answer
`OidcAuthorizeGateRefusal` (`{ allowed: false, reason, message }`) in
place of `false`. An object refuses only when it says `allowed: false`;
every other answer keeps the truthiness the gate was always read with,
so nothing changes who is admitted.
- **The refusal carries it (item 2)**, on each door
`oauth-authorize-refusal.ts` already chooses between:
- the `403` envelope keeps `code: ENV_ACCESS_DENIED`, gains `reason`,
and its `message` is the host's sentence;
- the redirect back to a registered `redirect_uri` keeps
`error=access_denied` (RFC 6749 §4.1.2.1), sends the host's sentence as
`error_description`, and adds `objectstack_error_reason`;
- the readable page shows the host's sentence, HTML-escaped, after the
signed-in account.
- **Nothing the host answers is trusted.** A reason outside
`[a-z_]{1,40}` is dropped and the refusal stands. A sentence with a
control character or an angle bracket, or longer than 300 characters, is
replaced by the fixed sentence. On the redirect only, a sentence outside
the character set RFC 6749 §4.1.2.1 allows for `error_description`
(printable ASCII without the double quote and the backslash) is also
replaced by the fixed sentence.
- **Why `objectstack_error_reason`.** RFC 6749 §8.2 asks an extension
parameter that is not registered to carry a vendor prefix, so it cannot
collide with a registered name. The card's example, `error_reason`, is
not free: some identity providers already send it with their own values.
- **The reason reaches the environment's sign-in page (item 3).** The
environment's OAuth callback (`GET /callback/:id`) rebuilds its error
redirect from `error` and `error_description` only. One after-hook,
`carryRefusalReasonOnCallback` (`oauth-callback-refusal-reason.ts`,
called from `auth-manager-after-hook.ts`), puts the reason back on that
redirect. It acts only when all of these hold: a `GET` of the platform
identity provider's callback; the request's own query says
`error=access_denied` and carries exactly one reason of the validated
shape; the callback answered a redirect whose query says
`error=access_denied` and carries no reason yet. The rest of the
location is kept byte for byte. The organization's name is not a field
anywhere: it travels only inside the host's sentence.
- **The Console's sentences (item 3).** `ssoCallbackRefusalMessage`
takes the reason: `not_member` and `invitation_pending` get their own
sentences, under `access_denied` only. An unknown reason, no reason, or
a reason beside another error code keeps today's sentence. Three keys
are added in all eleven packs (real translations; zh-Hant regenerated by
`gen:zh-hant`): `auth.login.errors.ssoAccessDeniedNotMember`,
`auth.login.errors.ssoAccessDeniedInvitationPending`,
`auth.login.ssoHandoffClient`.
- **The application's name on a hand-off (item 4).** The sign-in page
reads the client name only for the client its signed request names. New
route `GET
/api/v1/auth/oauth2/client-name?client_id=CLIENT_ID&oauth_query=SIGNED_QUERY`
(`oauth-client-name.ts`, mounted in `auth-plugin.ts`, ledgered in
`auth-route-ledger.ts` as `public`):
- `oauth_query` must carry a signature this server made and that has not
expired, checked by the provider's own `verifyOAuthQueryParams`; the
session is never read;
- the client is the single `client_id` inside the verified request, and
the URL's `client_id` must equal it;
- the answer is `{ client_name }` and nothing else of the client;
- a signature that does not verify or has expired, a mismatched
`client_id`, an unknown client, a disabled client and a client with no
name all answer the same `404`; a parameter outside the closed set, a
repeated one or a missing one answers `400`;
- it is rate-limited per client address (ADR-0121 D6), counted before
anything is read; over the limit it answers `429` `RATE_LIMIT_EXCEEDED`
with `Retry-After`.
`LoginPage` asks it once on a signed hand-off and shows "Sign in to
continue to NAME"; any other answer (refusal, network failure, another
body shape, no signed request on the URL) keeps "Continue to HOST".
- **The registered-`redirect_uri` rule is unchanged**: the redirect is
followed exactly when it was before.
## Tests
- `packages/plugins/plugin-auth/src/oauth-authorize-refusal.test.ts`,
over the file's real-`AuthManager` harness (real better-auth, the real
oauth-provider):
- items 1 and 2 as in round 1: the boolean CONTROL (envelope body,
redirect parameters in order, page SHA-256 equal to the merge base's),
reason and sentence pins on each door, the admitted set unchanged, the
resume pass;
- the client-name read: the matched client is served exactly `{ success:
true, data: { client_name } }`; a mismatched `client_id` is refused and
the other client's name never appears; an unknown client, a disabled
client, a signed request whose `client_id` was changed, and an expired
one each get the same refusal as a mismatch; three malformed requests
answer `400`; the window's reads from one address answer, the next is
refused with `429`, `RATE_LIMIT_EXCEEDED`, `Retry-After` and `no-store`,
and another address still answers;
- the callback carry: an environment `AuthManager` with the platform
identity provider and a second one, fed the provider's real refusal
parameters. The reason lands on `/_console/login` beside `error` and
`error_description`; CONTROL: a boolean refusal lands with no reason;
not carried for a reason of another shape, a reason beside another
error, a reason from the other identity provider, or two reasons.
- `auth-route-ledger.conformance.test.ts`: the new route in the
objectstack list.
- Console: `LoginPage.access-denied-32992.test.tsx` gains a describe for
the two reasons, an unknown reason and a reason beside another code. New
`LoginPage.handoff-client-name-34168.test.tsx`: the name is shown and
asked with the URL's client and the whole signed request; the host line
stays on a 404, a network failure and a body of another shape; CONTROL:
no signed request, nothing asked.
<details><summary>Ablations (each mutation landed on disk through
scripts/ablation-replace.mjs; every restore read blob == HEAD and git
diff HEAD empty; the subjects resolve from src, no build between
legs)</summary>
| Ablation (round 2, at `fb0d4b052`) | Result |
|:--|:--|
| client-name: URL `client_id` no longer has to equal the signed one | 1
failed (the mismatch pin) |
| client-name: disabled check removed | 1 failed (disabled) |
| client-name: signature verification removed | 1 failed (expired) |
| callback: platform-provider check removed | 1 failed (other identity
provider) |
| callback: reason shape check removed | 1 failed (reason of another
shape) |
| callback: exactly-one-reason check loosened | 1 failed (two reasons) |
| callback: both `access_denied` checks removed (request held, redirect
ablated) | 1 failed (reason beside another error) |
| Console: reason read under any error code | 1 failed (reason beside
another code) |
| Console: client-name body shape loosened | 1 failed (body of another
shape) |
| client-name: rate limit removed (round 3, at `749c7a2ca`) | 1 failed
(the rate-limit pin: expected 200 to be 429) |
Round 1 (items 1 and 2) ablations stand as reported there: reason
pattern 6 failed, sentence markup 2, sentence length 1, RFC charset 1,
object truthiness 1, page escape 1.
</details>
## Acceptance notes
- A host may return the refusal object only once it runs this
plugin-auth release or later: an older plugin-auth reads any object as
truthy, which admits. The changeset says so.
- The new route is rate-limited per client address: a fixed window of 10
reads per 60 seconds, counted before anything is read, in the kernel
`cache` service when one is registered, as the signed-out invitation
preview is (ADR-0121 D6). Over the limit it answers `429`
`RATE_LIMIT_EXCEEDED` with `Retry-After` and `Cache-Control: no-store`.
- The new route is an unauthenticated door, which ADR-0138 D2 asks to be
recorded in an ADR amendment; `docs/adr/**` is outside this card's file
surface, so that note is left to the seat.
- The callback carry covers the `GET` callback. A provider that answers
by `form_post` reaches `POST /callback/:id`, which the vendor re-issues
as a `GET` rebuilt from its own known fields, so the reason would not
survive that hop. The platform identity provider answers by query
redirect, so this path is not exercised today.
- The new types (`OidcAuthorizeGateRefusal` and the rest) are exported
from their modules, not re-exported from the package index.
- No `packages/spec/src/**` file is touched.
## Verification
Round 3 (`749c7a2ca`) adds the rate limit and touches plugin-auth only,
so the plugin-auth suite and typecheck were re-read there; the Console,
i18n and derived-gate readings below are from `fb0d4b052`, whose `ui/`
tree is unchanged at `749c7a2ca`.
<details><summary>plugin-auth suite and typecheck</summary>
- After `pnpm --filter '@objectstack/plugin-auth^...' build` and the
package's own build, under `os-verify-lock`: `pnpm --filter
@objectstack/plugin-auth test` exit 0, Test Files 278 passed (278),
Tests 5668 passed, 10 skipped.
- `pnpm --filter @objectstack/plugin-auth typecheck` exit 0: all three
legs (`tsc --noEmit`, `tsconfig.examples.json`, `check:test-typecheck`:
"OK — @objectstack/plugin-auth's test layer compiles").
- At `fb0d4b052` the full workspace build (119 tasks) and `pnpm
check:dual-build-cjs-loads` were green; round 3 adds no export and no
new file.
</details>
<details><summary>Console and i18n</summary>
From `ui/`: `pnpm exec vitest run` over `apps/console/src/pages/auth/`,
`all-locales-key-parity`, `untranslated-identity-4376`,
`en-zh-key-parity` and the product-neutral ratchet: Test Files 39 passed
(39), Tests 429 passed (429). `turbo run type-check
--filter=@object-ui/console`: exit 0, 75 tasks successful. `node
scripts/check-i18n-en-drift.mjs`: exit 0, "No en value changed in this
range."
</details>
<details><summary>Derived gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` at `fb0d4b052`: 83 families, each run with
stdin closed after the full build, reconciled with `--ran` (83 derived,
83 run). 82 exit 0, among them `pnpm check:auth-mount-ledger` and `pnpm
check:dual-build-cjs-loads` ("123 published require entry point(s)
across 72 package(s) load"). 1 NOT MEASURED: `pnpm
check:type-check-debt` exit 3 (PREREQUISITE NOT MET: its own closure
build did not get a turn on the shared verify lock), and two further
locked tries timed out in the queue (exit 99); read from CI. PR-body
gate: `check-closing-keyword-parity --body` on this body binds only
`Fixes #34168`.
</details>
<details><summary>Merge-tree (throwaway bare clone, no merge
driver)</summary>
`git merge-tree --write-tree` of `749c7a2ca` against `origin/main`
(`951eceeee`): exit 0, no conflicted path. #34257 has no pushed branch,
so there is nothing to probe against.
</details>
<details><summary>Clause-② re-measured</summary>
`yes (widening)` holds: the gate option's return type widens, the
envelope gains an optional `reason`, the redirects gain an optional
parameter, one public, rate-limited read route is added, and three i18n
keys are added. Nothing narrows: a boolean answer is byte-identical, and
every existing route answers as before.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
<!-- signed: domain:server#5 · zhuangjianguo ·
session_01QsR2jVPGBoi3MCGoKbW1Hv -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8436f67 commit 4c0cf65
27 files changed
Lines changed: 1357 additions & 29 deletions
File tree
- .changeset
- packages/plugins/plugin-auth/src
- ui
- apps/console/src/pages/auth
- __tests__
- packages/i18n/src/locales
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
233 | 238 | | |
234 | 239 | | |
235 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
604 | | - | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
605 | 607 | | |
606 | | - | |
607 | | - | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
608 | 613 | | |
609 | | - | |
| 614 | + | |
610 | 615 | | |
611 | | - | |
612 | | - | |
613 | | - | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
614 | 621 | | |
615 | 622 | | |
616 | 623 | | |
| 624 | + | |
617 | 625 | | |
618 | 626 | | |
619 | 627 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
| 327 | + | |
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
| |||
971 | 972 | | |
972 | 973 | | |
973 | 974 | | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
974 | 980 | | |
975 | | - | |
| 981 | + | |
976 | 982 | | |
977 | 983 | | |
978 | 984 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
726 | 726 | | |
727 | 727 | | |
728 | 728 | | |
| 729 | + | |
| 730 | + | |
729 | 731 | | |
730 | 732 | | |
731 | 733 | | |
| |||
901 | 903 | | |
902 | 904 | | |
903 | 905 | | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
904 | 916 | | |
905 | 917 | | |
906 | 918 | | |
| |||
5312 | 5324 | | |
5313 | 5325 | | |
5314 | 5326 | | |
| 5327 | + | |
| 5328 | + | |
| 5329 | + | |
| 5330 | + | |
| 5331 | + | |
| 5332 | + | |
| 5333 | + | |
| 5334 | + | |
| 5335 | + | |
| 5336 | + | |
| 5337 | + | |
| 5338 | + | |
| 5339 | + | |
| 5340 | + | |
| 5341 | + | |
| 5342 | + | |
| 5343 | + | |
| 5344 | + | |
| 5345 | + | |
| 5346 | + | |
| 5347 | + | |
| 5348 | + | |
| 5349 | + | |
| 5350 | + | |
| 5351 | + | |
| 5352 | + | |
| 5353 | + | |
| 5354 | + | |
| 5355 | + | |
| 5356 | + | |
| 5357 | + | |
| 5358 | + | |
| 5359 | + | |
| 5360 | + | |
| 5361 | + | |
| 5362 | + | |
| 5363 | + | |
| 5364 | + | |
| 5365 | + | |
5315 | 5366 | | |
5316 | 5367 | | |
5317 | 5368 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
251 | 257 | | |
252 | 258 | | |
253 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| 184 | + | |
| 185 | + | |
184 | 186 | | |
185 | 187 | | |
186 | 188 | | |
| |||
0 commit comments