Repository navigation
Commit adb3aef
fix(console): Settings, Packages, Audit Log and the connector pages send the stored bearer token (#37077)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBTDAJKyXUan6fJCKsZUf5Pv)_
Fixes #36981
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:管理员只靠浏览器里保存的登录令牌在线(会话 Cookie
被同机第二个本地运行时替换、被拦截或被清掉)时,设置、已安装应用、审计日志、连接器凭据和连接器连接这几页从报"需要登录"变为正常加载;只用
Cookie 登录的管理员看不到任何变化。
- 为什么做:控制台其它页面都会带上登录令牌,只有这几张设置页漏带,属于"控制台设置页"这一块的体验缺陷,替所有遇到这种登录状态的管理员解决。
- 出错会怎样:最坏情况是这几页重新读不到数据,与修复前一样显示加载失败;不改服务端接受什么、不改登录方式,可以直接撤回本次改动。
- 要你做什么:无。
## What changes
These Setup surfaces called their endpoints with the session cookie
only, so a session held by its bearer token alone (the case the card
measures) read a 401 there while the rest of the console worked. Each
now goes through `createAuthenticatedFetch` from `@object-ui/auth`, the
path every other console request already takes. `credentials: 'include'`
is still passed on every call, so the cookie rides along exactly as
before. A 401 now reaches the console's session-ended check, as it does
on every other page. Besides the bearer, the shared wrapper also stamps
`X-Tenant-ID` (the active organization) and `Accept-Language` (from the
html `lang` attribute, never overriding a header the caller set) on
these calls, and stores a rotated `set-auth-token` from the response,
exactly as it already does for every other console request (L1 N1).
Nothing changes in what the server accepts, how sessions are minted,
stored or refreshed, cookies, CORS or any policy.
| Surface (card row) | Calls routed through the authenticated fetch |
|---|---|
| All settings and every namespace page | the five `/api/settings` calls
in `pages/settings/api.ts` (list, read, save, action, and the judged
client-address read of the Authentication and Access policy pages) |
| Installed apps (Packages) | `PackagesPage`'s `apiJson` (every
`/api/v1/packages` call the page makes); in `marketplaceApi.ts`, the
runtime's own `/api/v1/cloud-connection/installed` and `org-packages`
reads and every `/api/v1/marketplace/install-local*` call |
| Audit log | the `/api/v1/data/sys_audit_log` read |
| Connector credentials | the three credential-ref calls in
`connectorCredentials.ts` |
| Connector connections | the one `call` helper in
`connectorConnections.ts` (declaration, registry, status, begin, revoke)
|
Each module builds the wrapper per call
(`createAuthenticatedFetch()(input, init)`, as `approvalsApi.ts` does).
A module-level instance would run at import, before a test file's
hoisted `@object-ui/auth` mock can supply it.
Audit log failure state: a failed read no longer draws the "No audit
entries" empty state, because the table card is not drawn under the
alert. The alert shows the refusal's own sentence when the response
carries the declared envelope (`readEnvelopeFailureText`). Otherwise it
shows the page's own "Failed to load audit log". It never shows the raw
response body or a bare machine code.
`marketplaceApi.ts`: the calls to the cloud control plane's own origin
(`getCloudBase()`) and the marketplace browse calls (`credentials:
'omit'`) are deliberately left alone. The cloud origin must never see
this runtime's bearer.
## Tests
New pins, each with a cookie-only control (no token stored: no
`Authorization` header, `credentials: 'include'`):
- `ui/apps/console/src/pages/settings/api.bearer.test.ts`: every
settings call sends `Authorization: Bearer TOKEN` when a token is
stored.
-
`ui/apps/console/src/pages/system/AuditLogPage.bearerAndFailure.test.tsx`:
the ledger lists against a server that answers only the bearer. A 401
(the REST seam's flat body) shows "Failed to load audit log", with no
`HTTP 401`, no JSON and no `UNAUTHENTICATED`, and does not show "No
audit entries". An enveloped 403 shows its sentence. An empty answer
still shows the empty state.
- `ui/packages/app-shell/src/views/setup/setupDoorsBearer.test.ts`:
every connector credential and connection call, and the org-packages,
cloud-installed and install-ledger reads.
-
`ui/packages/app-shell/src/views/metadata-admin/PackagesPage.bearerSession.test.tsx`:
the Installed Apps address lists a marketplace install against a server
that refuses any request without the bearer.
Fixture triage: the authenticated fetch reads `response.headers` (for a
rotated session token, which a real `Response` always carries). The
`Response` doubles of 29 existing settings, connector and Packages test
files carried only `ok`, `status` and `json`. Each gains `headers: new
Headers()`. The display-locale harness
(`consoleFaces.displayLocale-9909.test.tsx`) mocks
`createAuthenticatedFetch` with a fixed empty answer, so its mock now
hands a case that stubs the wire to that stub. No assertion changed.
## Acceptance notes
- Same defect family, not fixed here (reported for a family card):
`packages-io.ts`'s held package-list read (`GET /api/v1/packages`, read
by the shell's sidebar, header and Studio entries on every page) is
cookie-only too. In the browser it answered 401 on every Setup page with
a bearer-only session. Fixing it moves the `Response` doubles of roughly
a dozen unrelated shell test files, so it was left out of this card.
Many other `ui/` modules still call `fetch` with the cookie only.
- `actionErrorDetail` (`@object-ui/core`) reads a bare-string `error`
before `message`. Against the REST seam's flat 401 body (`{ error:
'UNAUTHENTICATED', code, message }`, a sanctioned envelope per
`anonymous-deny.ts`), it therefore answers the code. That is where the
connector connections page's bare `UNAUTHENTICATED` came from. With the
bearer attached these surfaces no longer meet that 401, and a real ended
session goes to the session-ended check. The shared reader is not
changed here.
- Browser cookie-only control: after sign-in, the console's session
check writes the token back into localStorage from the cookie session,
so a "cookie only, no token" state cannot be held in a real browser tab.
The cookie-only control is therefore pinned at unit level. In the
browser, the cookie session still loads every surface.
## Verification
<details><summary>Reproduced on main, then fixed (real boot: showcase
backend + Console dev server, signed in, session cookie removed, bearer
kept)</summary>
On `main` (305fe60), every surface answered 401 without the bearer:
```text
settings hub 401 GET /api/settings bearer=no "Authentication is required to access this endpoint."
settings/company 401 GET /api/settings/company bearer=no
access_policy 401 GET /api/settings/access_policy, 401 GET /api/v1/auth/client-address
installed apps 401 GET /api/v1/packages, 401 GET /api/v1/marketplace/install-local "... (UNAUTHENTICATED)"
audit log 401 GET /api/v1/data/sys_audit_log "HTTP 401: {"error":"UNAUTHENTICATED",...}" + "No audit entries"
connector creds 401 GET /api/v1/automation/connectors/credential-refs
connector conns 401 GET /api/v1/meta/connector "Could not load connector connections. UNAUTHENTICATED"
```
With the fix, in the same state, every request carried the bearer,
answered 200, and the pages rendered their content (settings manifests
and fields, the Packages list, audit rows, the connector empty states).
No page showed `HTTP 401`, `UNAUTHENTICATED` or "Authentication is
required".
</details>
<details><summary>Pins fail on main's source, pass on the fix;
ablation</summary>
Against main's source (the seven source files restored to `305fe60e6e`
on disk, each blob checked equal to the base blob, then restored to
`HEAD`, with `git diff HEAD` empty afterwards), the four new pin files
failed exactly the bearer pins and the audit failure-state pins. The
cookie-only controls and the empty-state control passed:
```text
Test Files 4 failed (4)
Tests 21 failed | 21 passed (42)
```
Ablations at `8d5bf768c5`, through `scripts/ablation-replace.mjs`. Each
mutation was proven on disk (anchor 1 to 0, blob moved). Each restore
was proven (blob equal to `HEAD`, `git diff HEAD` empty).
```text
settings api.ts createAuthenticatedFetch()(input, init) -> fetch(input, init) 6 failed | 6 passed (12) only the bearer cases
PackagesPage.tsx same mutation 1 failed | 1 passed (2) the bearer-only listing
AuditLogPage.tsx table-card guard -> always drawn 2 failed | 3 passed (5) both failure-state pins
```
An earlier ablation of `connectorConnections.ts` (module-level form)
turned exactly its five bearer cases red: `5 failed | 18 passed (23)`.
</details>
<details><summary>Suites, typecheck and gates</summary>
Run at `7d8601826f` (the final head): the eight edited or new test files
that changed last, `Test Files 8 passed (8)`, `Tests 74 passed (74)`.
`@object-ui/app-shell` `type-check` exit 0. At `8d5bf768c5`:
`@object-ui/console` `type-check` exit 0. Both typechecks ran after
building the dependency closure (`pnpm --filter '@object-ui/console^...'
build`, exit 0).
Full package suites were run at `f8533fabdd`. Only test files changed
after it.
- `@object-ui/console`: `Test Files 1 failed | 331 passed (332)`, `Tests
7 failed | 3560 passed (3567)`. All seven failures were in
`consoleFaces.displayLocale-9909.test.tsx`, whose auth mock answered
`{}` for the audit ledger. Its mock was fixed at `fc22fa2f7d`. The file
then passed alone: 15 of 15.
- `@object-ui/app-shell`: `Test Files 1 failed | 2416 passed | 1 skipped
(2418)`, `Tests 1 failed | 22867 passed | 9 skipped (22877)`. The one
failure (`RecordDetailView.recordPageTiers-26678`) is outside this
diff's reach and passed alone, 10 of 10, at `fc22fa2f7d`. The full run
took 6054 s on a shared box.
Derived gate families (`node scripts/pm/dispatch-gates.mjs --commands`):
all 39 ran at `8d5bf768c5`, each exit 0. That includes `pnpm
check:type-check-debt` under the lock and `pnpm --dir ui exec vitest run
scripts/` (`Test Files 172 passed | 2 skipped`). `--ran` printed: "39
derived famil(ies) accounted for — 39 run, 0 NOT-MEASURED (a DERIVED
zero …)". At that head `check:test-source-alias` was red on four edited
test files. The fix (module-top side-effect imports) landed as
`7d8601826f`. At `7d8601826f`, `check:test-source-alias`,
`check:undeclared-dep-imports` and `check:nul-bytes` each exited 0.
`node scripts/pm/overlap-check.mjs` ran before each push from the third
one on: `VERDICT clean exit 0`, and #36973 (which shares
`PackagesPage.tsx`) merges cleanly.
</details>
Read first:
1. `ui/apps/console/src/pages/system/AuditLogPage.tsx`: the failure and
empty-state hunk. The table card is now conditional.
2. `ui/packages/app-shell/src/console/marketplace/marketplaceApi.ts`:
confirm only same-server calls moved to `serverFetch`, and that no
`getCloudBase()` call did.
3. `ui/apps/console/src/pages/settings/api.ts`: the five call sites.
Two-minute check: sign in on the Console, delete the
`better-auth.session_token` cookie in devtools, and open Setup, then All
Settings. The settings cards load. On `main` the page reads
"Authentication is required to access this endpoint."
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufziG2t1d9cfRQJDrHkB)_
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufziG2t1d9cfRQJDrHkB -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ebb4713 commit adb3aef
41 files changed
Lines changed: 641 additions & 48 deletions
File tree
- .changeset
- ui
- apps/console/src/pages
- settings
- __tests__
- system
- packages/app-shell/src
- console/marketplace
- __tests__
- views
- metadata-admin
- setup
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
| 180 | + | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
| 187 | + | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| 259 | + | |
259 | 260 | | |
260 | 261 | | |
261 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| |||
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| 196 | + | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
| |||
319 | 321 | | |
320 | 322 | | |
321 | 323 | | |
| 324 | + | |
322 | 325 | | |
323 | 326 | | |
324 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
0 commit comments