You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5f34d65
Browse filesBrowse the repository at this point in the historyBrowse files
fix(ui): plugin same-server reads and me/localization carry the stored bearer (#37489)
Fixes#37225
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 只用登录令牌、没有会话 Cookie 的用户(例如嵌入在别的网站里、浏览器拦了第三方 Cookie):分享链接、AI
助手列表、模型列表、待审批操作、对话内审批、字段选择器和界面语言,以前都被当成未登录,现在能正常加载。
- 属于“会话凭证统一携带”这条线:插件和控制台的早期请求之前漏带了令牌,这次补齐,并让守卫覆盖全部前端包。
-
若出错,影响的是上述几个面板仍显示为空或未登录;改动只在前端请求里多带一个请求头,可直接撤回。控制台与接口不同源的部署这次还没覆盖,已另立跟进卡。
- 无
## What changes
The renderer packages' same-server reads sent the bare global fetch with
the cookie only, so a session held by its bearer token alone was
answered as anonymous. Every site the card lists is now converted or
recorded with its reason:
- **components / ShareDialog** (3 calls: list, create, revoke) and
**plugin-chatbot** (useAgents, useAiModels, usePendingActions,
useHitlInChat) send through the host's `SchemaRendererContext.apiFetch`
(the console builds it as `createAuthenticatedFetch({ sameOriginOnly:
true })`), falling back to the global fetch with no host. `credentials:
'include'` stays, so cookie sessions are unchanged. No renderer package
gains a dependency on `@object-ui/auth` (layering per `ui/AGENTS.md`; no
cycle introduced).
- **app-shell / field selector widget** (`fetchFieldSelectorOptions`)
goes through `createAuthenticatedFetch()`; app-shell already depends on
auth.
- **console / me-localization**: the stored bearer rides all three legs,
the early `index.html` seed request, `languageSeed.fetchAndCacheSeed`,
and `LocalizationFetchProvider`. Both TS legs build the init through one
helper, `meLocalizationInit(preferred)`, so the in-flight share key
(`inflightGetKey`) still matches between the seed and the provider. The
helper reads the token through `TokenStorage.get()`, so a
storage-blocked embed still sends the token sign-in kept in memory;
`index.html` runs before the bundle and stays on `localStorage` (rework
round 1, S5).
- **field selector path**: the object name is now
`encodeURIComponent`-encoded into `/api/v1/objects/NAME/fields` (rework
round 1, N3; not separately pinned, since the helper is module-private).
- **Ratchet widened** (`sameServerFetch.bearer.ratchet.test.ts`): it now
scans every `ui/packages/*/src` plus the console, and names the nine
renderer packages explicitly so a dropped root fails loudly. A new arm
counts a global fetch on a written `/api/` literal with no init, or with
an inline init without `credentials`, as bare. The allow list stays
shrink-only: the LocalizationFetchProvider row is removed (now 0 found),
and two rows are added for sites read and recorded: `auth/LoginForm.tsx`
(SSO sign-in, before any session exists) and
`permissions/MePermissionsProvider.tsx` (the `fetcher ?? fetch`
fallback; the console passes the authenticated fetch).
Sites recorded but not converted, because they already ride the host's
authenticated fetch (`apiFetch ?? fetch`, with the reason in their
header docs): useRecordCrudVerdicts, useRowApprovalLocks,
useRecordEditable, stageChangeStarts, queueClaim, ObjectChart,
DatasetWidget, ReportDateRange. Injection only, with no bare fallback:
preferenceOptions, ShareableObjectRefField.
## Tests
<details><summary>New pins (bearer-only server double, each with a
cookie-only control)</summary>
- `app-shell/src/console/rendererFetch.bearerSession-37225.test.tsx`:
ShareDialog list, useAgents, useAiModels, usePendingActions (list +
approve) and useHitlInChat (decide), each mounted in a
`SchemaRendererProvider` that carries the console's composition. With a
stored token, the request carries `Authorization: Bearer TOKEN` beside
`credentials: 'include'`. CONTROL, with no token: cookie-only, the 401
is refused, and it reaches the session-ended event.
- `FieldSelectorWidget.loadFailure.test.tsx`: a new describe for the
bearer-only session, plus a cookie-only control.
- `console/src/__tests__/sessionCheckBootDedup.test.tsx`: a cold load
sends one me/localization request carrying the bearer; the share key of
the slot equals `meLocalizationInit('zh-CN')` and contains the
authorization header; on a later boot with a cached seed, the provider
alone sends the bearer. CONTROL, no token: two requests, neither
carrying Authorization. CONTROL, a token stored after parse: the second
request carries it.
- Doubles in three neighbouring field-selector suites gained `headers`
(the authenticated fetch reads `set-auth-token` off every response), and
two gained the module-top collection imports `check:test-source-alias`
asks for.
</details>
<details><summary>Readings (head f66978d)</summary>
- Ratchet: 4/4 passed.
- Pins at the merged head: 5 files / 82 tests passed.
- Rework round 1 (head b0a4db6): the localization and field-selector
pins plus the boot-dedup and App boot suites: 11 files / 139 tests
passed.
- Narrowed affected suites (app-shell metadata-admin, components share,
plugin-chatbot, console subset): 168 files / 1722 tests passed; console
subset 26 files / 371 tests passed.
- Type-check (turbo, the 4 touched packages and their deps): 83/83 tasks
successful.
- `pnpm --dir ui exec vitest run scripts/`: 172 passed, 2 skipped.
</details>
<details><summary>Ablations (restored through ablation-replace; blob
equals HEAD; git diff HEAD empty)</summary>
- ShareDialog list read reverted to the bare fetch: the ratchet goes red
(unlisted site), and both ShareDialog pins go red, including the
control's session-end half. 3 failed / 8 passed.
- The Authorization line deleted from `meLocalizationInit`: the 4 bearer
cases go red and the cookie control stays green. 4 failed / 49 passed.
- Rework round 1: `storedToken()` reverted from `TokenStorage.get()` to
the direct `localStorage` read: only the new memory-fallback pin goes
red. 1 failed / 53 passed.
</details>
## Acceptance notes
- **Deviation from the card's Expected, ruled A by the seat.** The
card's Expected names a per-call `createAuthenticatedFetch`. The
renderer packages instead send through the host's `apiFetch`. In the
console that host fetch *is* `createAuthenticatedFetch({ sameOriginOnly:
true })`, so `sameOriginOnly` and the settle signal are applied once, at
the host, and the renderer packages stay free of an auth dependency. The
cost: a host that mounts no provider stays cookie-only.
- Changesets name the scope this PR covers: same-origin requests.
Split-origin layouts still go out without the token (see #37509). They
also note that a stored token now takes precedence over an
`Authorization` a caller passes, and that the host's tenant and language
headers ride these calls (N1).
- The field selector reads `/api/v1/objects/NAME/fields`. No server
route registers that path, and no form in either tree declares the
widget, so it is dormant. Read only, not filed.
- A cross-origin `VITE_AI_BASE_URL` / server URL goes bare through the
`sameOriginOnly` host fetch, as the card allows.
- Out-of-card bare sites, read and not converted: auth/LoginForm (1),
auth/createAuthClient (3, fenced to the auth lane),
data-objectstack/index (2, via an injected fetchImpl),
data-objectstack/metadata-client (1), react/useElementApiDataSource (1,
host fallback), react/useDatasetDimensionLabels (1, host fallback).
## Follow-up cards (rework round 1)
- S1 + S2 + S3b, ratchet completeness (aliased fallback, concatenated or
const URLs, spread inits, `same-origin`) and the `react` host fallbacks:
#37505
- S3a, `data-objectstack` uploads and `metadata-client` bypassing the
injected fetch: #37506
- S3c, the three same-server requests in `createAuthClient` (auth lane):
#37507
- S3d, the field-selector route that no server registers: register it or
retire the widget: #37508
- S4, split-origin deployments, where the seven converted calls still go
without the token: #37509
## Verification
Two minutes: `pnpm --dir ui exec vitest run --maxWorkers=2
packages/app-shell/src/console/rendererFetch.bearerSession-37225.test.tsx`.
Expect 7 passed: each bearer case carries `Bearer stored-session-token`,
and each control goes out cookie-only.
Read first, by risk:
1. `ui/apps/console/src/languageSeed.ts`: `meLocalizationInit`. The
share key between the seed and the provider depends on both legs
building the same headers.
2. `ui/packages/app-shell/src/sameServerFetch.bearer.ratchet.test.ts`:
the widened roots and the new bare-literal arm.
3. `ui/apps/console/index.html`: the early seed script reads the token
in a try block.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6Ca6EBDpTBZk8v46Jjv -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(plugin-chatbot): the agent list, the model picker, the pending-approvals inbox and in-chat approvals send through the host's authenticated fetch, so a session held by its sign-in token alone sees its agents and can approve
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
`useAgents`, `useAiModels`, `usePendingActions` and `useHitlInChat` asked the AI service with the session cookie only. A session held by its sign-in (bearer) token alone on the console's own origin (for example, a session cookie the browser blocked as third-party) was refused there: no agents, no models, an empty approvals inbox, and an in-chat approval that failed. They now send through the host's authenticated fetch, the `apiFetch` a host hands `SchemaRendererProvider` (the console's sends the stored token), as the renderers' own reads already do. The session cookie is still sent, a cookie session behaves exactly as before, and in the console a refused request now reaches its session-ended check. A host that mounts no provider keeps the plain `fetch`, as before. Where a host points these requests at another origin (an AI service or server URL configured off the page's origin), the host's fetch still sends them without the token; that layout is not fixed here. The hooks' options are unchanged in shape; in the console, a stored token now takes precedence over an `Authorization` passed in `headers`, and the host's tenant and language headers ride these requests too.
fix(app-shell): the metadata form's field picker reads an object's fields with the stored sign-in token, so a session held by its token alone can pick fields
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
The `field-selector` picker in the metadata forms read an object's field catalog with the session cookie only, so a session held by its sign-in (bearer) token alone was refused and the picker showed a load failure. It now sends the stored token as well, as the other same-server console requests do. The session cookie is still sent, a cookie session behaves exactly as before, and a refused request now reaches the console's session-ended check.
fix(console): the boot read of the signed-in user's language, currency and time zone sends the stored sign-in token, so a session held by its token alone boots in the user's own language and formats
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
`GET /api/v1/auth/me/localization` was read with the session cookie only, on all three of its legs: the request `index.html` sends during parse, the language seed before the app mounts, and the regional-defaults provider. A session held by its sign-in (bearer) token alone was answered as signed out, so the console booted in the browser's language and formatted numbers, currencies and dates without the user's own settings. All three now state the stored token. The seed and the provider read it where the other console requests read it, including a token kept in memory when the browser blocks storage; the parse-time request reads storage only. They still share one request: the three send the same request, and its identity includes the token. With no token stored the request is exactly as before. Nothing changes in what the server accepts.
fix(components): the share dialog lists, creates and revokes share links through the host's authenticated fetch, so a session held by its sign-in token alone sees its links
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
`ShareDialog` asked this server for a record's share links (and created and revoked them) with the session cookie only. A session held by its sign-in (bearer) token alone on the console's own origin (for example, a session cookie the browser blocked as third-party) was refused there: the dialog showed an error and no links. It now sends through the host's authenticated fetch, the `apiFetch` a host hands `SchemaRendererProvider` (the console's sends the stored token), as the renderers' own reads already do. The session cookie is still sent, a cookie session behaves exactly as before, and in the console a refused request now reaches its session-ended check. A host that mounts no provider keeps the plain `fetch`, as before. Where a host points these requests at another origin (an AI service or server URL configured off the page's origin), the host's fetch still sends them without the token; that layout is not fixed here. The `fetchHeaders` prop is unchanged in shape; in the console, a stored token now takes precedence over an `Authorization` passed in it, and the host's tenant and language headers ride these requests too.
@@ -898,3 +898,145 @@ describe("the language seed's me/localization starts at parse time beside discov
898
898
expect(localizationCalls()).toHaveLength(1);
899
899
});
900
900
});
901
+
902
+
describe('a bearer-only session: the stored Bearer rides me/localization on all three legs, and they still share one request (objectstack#37225)',()=>{
0 commit comments