Skip to content

Commit adb3aef

Browse files
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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
fix(console): Settings, Packages, Audit Log and the connector pages send the stored bearer token, so a session the rest of the console accepts works there too
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
These Setup surfaces called their endpoints with the session cookie only (`credentials: 'include'`), while the rest of the console sends the stored bearer token through its authenticated fetch. A session held by its bearer token alone (a second local runtime on the same host replaced the cookie, the cookie was blocked as a third-party cookie, or the cookie jar was cleared) therefore worked everywhere except here, where each page printed the server's `401` instead: "Authentication is required to access this endpoint.", a bare `UNAUTHENTICATED`, or, on the Audit Log, the raw response body followed by "No audit entries".
12+
13+
They now go through `createAuthenticatedFetch` from `@object-ui/auth`, the path every other console request takes: every `/api/settings` call and the judged client-address read of the Authentication and Access policy pages, the Audit Log read, the connector credential and connection doors, the Packages list (the Installed Apps address included), and this runtime's own install ledger (`/api/v1/marketplace/install-local*`) and cloud-connection reads (`installed`, `org-packages`). The session cookie still rides along (`credentials: 'include'` is unchanged), so a cookie session behaves exactly as before, and a `401` now reaches the console's session-ended check as it does on every other page. Nothing changes in what the server accepts.
14+
15+
A failed Audit Log read no longer draws the "No audit entries" empty state, and its alert shows the refusal's own sentence when the response envelope carries one, or "Failed to load audit log" otherwise, never the raw response body.

‎ui/apps/console/src/pages/consoleFaces.displayLocale-9909.test.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({
101101
}));
102102

103103
vi.mock('@object-ui/auth', async (importOriginal) => {
104-
const authFetch = async () => new Response('{}', { status: 200 });
104+
// A case that stubs the wire (the audit log's ledger read, which goes through
105+
// the authenticated fetch) is answered by its stub; every other read gets `{}`.
106+
const authFetch = async (input: RequestInfo | URL, init?: RequestInit) =>
107+
vi.isMockFunction(globalThis.fetch) ? globalThis.fetch(input, init) : new Response('{}', { status: 200 });
105108
return {
106109
...(await importOriginal<Record<string, unknown>>()),
107110
useAuth: () => AUTH,

‎ui/apps/console/src/pages/settings/__tests__/FirstRunChecklist.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ let extraManifests: unknown[] = [];
158158
let aiPayload: Record<string, unknown> | null = null;
159159

160160
function ok(data: unknown) {
161-
return { ok: true, status: 200, statusText: 'OK', json: async () => ({ success: true, data }) } as unknown as Response;
161+
return { ok: true, status: 200, statusText: 'OK', headers: new Headers(), json: async () => ({ success: true, data }) } as unknown as Response;
162162
}
163163

164164
const fetchMock = vi.fn();
@@ -177,14 +177,14 @@ function routeFetch() {
177177
}
178178
if (url === '/api/settings/localization' && method === 'PUT') {
179179
if (putRefusal) {
180-
return { ok: false, status: 400, statusText: 'Bad Request', json: async () => putRefusal } as unknown as Response;
180+
return { ok: false, status: 400, statusText: 'Bad Request', headers: new Headers(), json: async () => putRefusal } as unknown as Response;
181181
}
182182
const body = JSON.parse(String(init?.body)) as Record<string, unknown>;
183183
const written = Object.fromEntries(Object.entries(body).map(([k, v]) => [k, resolved(v, 'tenant')]));
184184
localizationValues = { ...localizationValues, ...written };
185185
return ok({ values: written });
186186
}
187-
return { ok: false, status: 404, statusText: 'Not Found', json: async () => ({}) } as unknown as Response;
187+
return { ok: false, status: 404, statusText: 'Not Found', headers: new Headers(), json: async () => ({}) } as unknown as Response;
188188
});
189189
}
190190

‎ui/apps/console/src/pages/settings/__tests__/SettingsField.actionRowOneLabel-12610.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ afterEach(() => {
5252
});
5353

5454
function ok(body: unknown): Response {
55-
return { ok: true, status: 200, statusText: 'OK', json: async () => body } as unknown as Response;
55+
return { ok: true, status: 200, statusText: 'OK', headers: new Headers(), json: async () => body } as unknown as Response;
5656
}
5757

5858
function withI18n(ui: ReactElement) {

‎ui/apps/console/src/pages/settings/__tests__/SettingsHub.adminManaged-29085.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function serveManifests(manifests: unknown[]) {
4848
ok: true,
4949
status: 200,
5050
statusText: 'OK',
51+
headers: new Headers(),
5152
json: async () => ({ success: true, data: { manifests } }),
5253
})),
5354
);

‎ui/apps/console/src/pages/settings/__tests__/SettingsHub.pageHeader-12553.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ beforeEach(() => {
4242
ok: true,
4343
status: 200,
4444
statusText: 'OK',
45+
headers: new Headers(),
4546
json: async () => ({ success: true, data: { manifests: MANIFESTS } }),
4647
})),
4748
);

‎ui/apps/console/src/pages/settings/__tests__/SettingsIcons.knownName-11679.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ afterEach(() => {
6262
});
6363

6464
function ok(body: unknown): Response {
65-
return { ok: true, status: 200, statusText: 'OK', json: async () => body } as unknown as Response;
65+
return { ok: true, status: 200, statusText: 'OK', headers: new Headers(), json: async () => body } as unknown as Response;
6666
}
6767

6868
/**

‎ui/apps/console/src/pages/settings/__tests__/SettingsView.clearBeneathPin-30665.test.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const REREAD_IP_RANGES = pinned('', 'OS_AUTH_ALLOWED_IP_RANGES', [
105105
const fetchMock = vi.fn();
106106

107107
function ok(body: unknown): Response {
108-
return { ok: true, status: 200, statusText: 'OK', json: async () => body } as unknown as Response;
108+
return { ok: true, status: 200, statusText: 'OK', headers: new Headers(), json: async () => body } as unknown as Response;
109109
}
110110

111111
/** GET answers the page; a PUT answers `putValues` and the next GET reads `rereadValues`. */
@@ -256,6 +256,7 @@ describe('clear the value saved beneath an env pin (objectstack#30665)', () => {
256256
ok: false,
257257
status: 409,
258258
statusText: 'Conflict',
259+
headers: new Headers(),
259260
json: async () => ({
260261
success: false,
261262
error: {

‎ui/apps/console/src/pages/settings/__tests__/SettingsView.clientAddress-30313.test.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ const LOCALIZATION = {
6969
};
7070

7171
const ok = (data: unknown) =>
72-
({ ok: true, status: 200, statusText: 'OK', json: async () => ({ success: true, data }) }) as unknown as Response;
72+
({ ok: true, status: 200, statusText: 'OK', headers: new Headers(), json: async () => ({ success: true, data }) }) as unknown as Response;
7373

7474
const refused = (status: number, code: string) =>
7575
({
7676
ok: false,
7777
status,
7878
statusText: status === 401 ? 'Unauthorized' : 'Forbidden',
79+
headers: new Headers(),
7980
json: async () => ({ success: false, error: { code, message: 'Platform admin required.' } }),
8081
}) as unknown as Response;
8182

@@ -192,6 +193,7 @@ describe('SettingsView — Allowed IP ranges shows the address the server judges
192193
ok: false,
193194
status: 400,
194195
statusText: 'Bad Request',
196+
headers: new Headers(),
195197
json: async () => ({
196198
success: false,
197199
error: {
@@ -319,6 +321,7 @@ describe('SettingsView — Access policy shows the address the server judges (ob
319321
ok: false,
320322
status: 404,
321323
statusText: 'Not Found',
324+
headers: new Headers(),
322325
json: async () => ({ success: false, error: { code: 'NOT_FOUND', message: 'Not found.' } }),
323326
}) as unknown as Response,
324327
],

‎ui/apps/console/src/pages/settings/__tests__/SettingsView.confirmOff-30500.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function payloadOf(passwordOn: boolean, extra: Partial<Spec> = {}) {
7979
const fetchMock = vi.fn();
8080

8181
function ok(body: unknown): Response {
82-
return { ok: true, status: 200, statusText: 'OK', json: async () => body } as unknown as Response;
82+
return { ok: true, status: 200, statusText: 'OK', headers: new Headers(), json: async () => body } as unknown as Response;
8383
}
8484

8585
/** GET answers the page; PUT answers the values it was sent. */

0 commit comments

Comments
 (0)