Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/36981-setup-doors-bearer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
'@object-ui/console': patch
---

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

Clause-②: no
Metadata-protocol: none

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".

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.

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.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({
}));

vi.mock('@object-ui/auth', async (importOriginal) => {
const authFetch = async () => new Response('{}', { status: 200 });
// A case that stubs the wire (the audit log's ledger read, which goes through
// the authenticated fetch) is answered by its stub; every other read gets `{}`.
const authFetch = async (input: RequestInfo | URL, init?: RequestInit) =>
vi.isMockFunction(globalThis.fetch) ? globalThis.fetch(input, init) : new Response('{}', { status: 200 });
return {
...(await importOriginal<Record<string, unknown>>()),
useAuth: () => AUTH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ let extraManifests: unknown[] = [];
let aiPayload: Record<string, unknown> | null = null;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ afterEach(() => {
});

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

function withI18n(ui: ReactElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function serveManifests(manifests: unknown[]) {
ok: true,
status: 200,
statusText: 'OK',
headers: new Headers(),
json: async () => ({ success: true, data: { manifests } }),
})),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ beforeEach(() => {
ok: true,
status: 200,
statusText: 'OK',
headers: new Headers(),
json: async () => ({ success: true, data: { manifests: MANIFESTS } }),
})),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ afterEach(() => {
});

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const REREAD_IP_RANGES = pinned('', 'OS_AUTH_ALLOWED_IP_RANGES', [
const fetchMock = vi.fn();

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

/** GET answers the page; a PUT answers `putValues` and the next GET reads `rereadValues`. */
Expand Down Expand Up @@ -256,6 +256,7 @@ describe('clear the value saved beneath an env pin (objectstack#30665)', () => {
ok: false,
status: 409,
statusText: 'Conflict',
headers: new Headers(),
json: async () => ({
success: false,
error: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ const LOCALIZATION = {
};

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

const refused = (status: number, code: string) =>
({
ok: false,
status,
statusText: status === 401 ? 'Unauthorized' : 'Forbidden',
headers: new Headers(),
json: async () => ({ success: false, error: { code, message: 'Platform admin required.' } }),
}) as unknown as Response;

Expand Down Expand Up @@ -192,6 +193,7 @@ describe('SettingsView — Allowed IP ranges shows the address the server judges
ok: false,
status: 400,
statusText: 'Bad Request',
headers: new Headers(),
json: async () => ({
success: false,
error: {
Expand Down Expand Up @@ -319,6 +321,7 @@ describe('SettingsView — Access policy shows the address the server judges (ob
ok: false,
status: 404,
statusText: 'Not Found',
headers: new Headers(),
json: async () => ({ success: false, error: { code: 'NOT_FOUND', message: 'Not found.' } }),
}) as unknown as Response,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function payloadOf(passwordOn: boolean, extra: Partial<Spec> = {}) {
const fetchMock = vi.fn();

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

/** GET answers the page; PUT answers the values it was sent. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ afterEach(() => {
});

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

function renderView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ beforeEach(() => {
ok: true,
status: 200,
statusText: 'OK',
headers: new Headers(),
json: async () => ({ success: true, data: PAYLOAD }),
} as unknown as Response);
});
Expand Down Expand Up @@ -241,6 +242,7 @@ describe('SettingsView refusal toasts interpolate through the bundle (objectui#4
ok: false,
status: 409,
statusText: 'Conflict',
headers: new Headers(),
json: async () => ({
success: false,
error: { code: 'SETTINGS_LOCKED', message: 'locked', details: { key: 'timezone' } },
Expand All @@ -267,6 +269,7 @@ describe('SettingsView refusal toasts interpolate through the bundle (objectui#4
ok: false,
status: 503,
statusText: 'Service Unavailable',
headers: new Headers(),
json: async () => ({
success: false,
error: {
Expand Down Expand Up @@ -302,6 +305,7 @@ async function saveRefusedWith(status: number, error: Record<string, unknown>, s
ok: false,
status,
statusText: 'Refused',
headers: new Headers(),
json: async () => ({ success: false, error }),
} as unknown as Response);
fireEvent.click(await screen.findByText(saveLabel));
Expand All @@ -316,6 +320,7 @@ function serveNamespace(payload: unknown) {
ok: true,
status: 200,
statusText: 'OK',
headers: new Headers(),
json: async () => ({ success: true, data: payload }),
} as unknown as Response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const PAYLOADS: Record<string, unknown> = {
const fetchMock = vi.fn();

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

/**
Expand Down Expand Up @@ -254,6 +254,7 @@ describe('the load-failure card (objectui#13254: translated at render, not in th
ok: false,
status: 403,
statusText: 'Forbidden',
headers: new Headers(),
json: async () => ({ success: false, error: { code: 'FORBIDDEN', message: 'Not allowed to read localization' } }),
}));
renderPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const PAYLOADS: Record<string, unknown> = {
const fetchMock = vi.fn();

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

/** GET answers the namespace named in the URL; PUT answers the values it was sent. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ beforeEach(() => {
ok: true,
status: 200,
statusText: 'OK',
headers: new Headers(),
json: async () => ({ success: true, data: payload }),
})),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function refusal(namespace: string, fields: Refused[]) {
ok: false,
status: 400,
statusText: 'Bad Request',
headers: new Headers(),
json: async () => ({
success: false,
error: {
Expand All @@ -112,6 +113,7 @@ function serve(payload: unknown) {
ok: true,
status: 200,
statusText: 'OK',
headers: new Headers(),
json: async () => ({ success: true, data: payload }),
} as unknown as Response);
}
Expand Down Expand Up @@ -292,6 +294,7 @@ describe('a refusal with no field errors keeps its message (objectui#13146)', ()
ok: false,
status: 500,
statusText: 'Internal Server Error',
headers: new Headers(),
json: async () => ({
success: false,
error: { code: 'INTERNAL_ERROR', message: 'Failed to write namespace' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function mailPayload(bannerText: string, host: string) {
const fetchMock = vi.fn();

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

/** The `sms` GET payload: a second namespace to move to. */
Expand Down Expand Up @@ -120,6 +120,7 @@ function serve() {
ok: false,
status: 503,
statusText: 'Service Unavailable',
headers: new Headers(),
json: async () => ({ success: false, error: { code: 'UNAVAILABLE', message: 'Settings unavailable' } }),
} as unknown as Response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const LOCALIZATION = {
const fetchMock = vi.fn();

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

/** GET answers the namespace; PUT answers the values it was sent. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const PAYLOAD = {
const fetchMock = vi.fn();

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

/**
Expand Down
96 changes: 96 additions & 0 deletions ui/apps/console/src/pages/settings/api.bearer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* Every `/api/settings` call — and the judged-address read the auth and
* access-policy namespaces make — goes out through the console's authenticated
* fetch (`createAuthenticatedFetch` in `@object-ui/auth`), so it carries the
* session's bearer token as every other console request does, beside the
* session cookie.
*
* The state this protects: a session held by its bearer token alone (the
* cookie was replaced by a second runtime on the same host, blocked as a
* third-party cookie, or cleared). The rest of the console works there; a
* cookie-only call answers `401`.
*
* The control: with no token stored, the same calls go out exactly as a
* cookie session needs them — `credentials: 'include'`, no `Authorization`.
*/

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { TokenStorage } from '@object-ui/auth';
import {
getJudgedClientAddress,
getSettingsNamespace,
listSettingsManifests,
runSettingsAction,
saveSettingsNamespace,
} from './api';

const TOKEN = 'stored-session-token';

const reply = (body: unknown, status = 200) =>
new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });

/** One fake per route: the body each call reads as success. */
function answer(url: string, method: string): Response {
const path = new URL(url, 'http://console.test').pathname;
if (path.startsWith('/api/v1/auth/')) return reply({ clientAddress: '203.0.113.7', trustProxy: false });
if (path === '/api/settings') return reply({ success: true, data: { manifests: [] } });
if (method === 'PUT') return reply({ success: true, data: { values: {} } });
if (method === 'POST') return reply({ success: true, data: { ok: true } });
return reply({ success: true, data: { manifest: { namespace: 'company' }, values: {} } });
}

type Sent = { url: string; method: string; credentials: RequestCredentials | undefined; authorization: string | null };
let sent: Sent[] = [];

beforeEach(() => {
sent = [];
vi.stubGlobal(
'fetch',
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);
const method = (init?.method ?? 'GET').toUpperCase();
sent.push({
url,
method,
credentials: init?.credentials,
authorization: new Headers(init?.headers).get('Authorization'),
});
return answer(url, method);
}),
);
});

afterEach(() => {
vi.unstubAllGlobals();
TokenStorage.clear();
});

/** Every call this module makes, each driven once. */
const CALLS: Array<[string, () => Promise<unknown>]> = [
['GET /api/settings', () => listSettingsManifests()],
['GET /api/settings/:namespace', () => getSettingsNamespace('company')],
['PUT /api/settings/:namespace', () => saveSettingsNamespace('company', { name: 'Acme' })],
['POST /api/settings/:namespace/:action', () => runSettingsAction('mail', 'send_test')],
['GET /api/v1/auth/admin/client-address', () => getJudgedClientAddress('/admin/client-address')],
['GET /api/v1/auth/client-address', () => getJudgedClientAddress('/client-address')],
];

describe('the settings client sends the stored bearer token', () => {
it.each(CALLS)('%s carries `Authorization: Bearer <token>` and the cookie', async (_name, call) => {
TokenStorage.set(TOKEN);
await call();
expect(sent).toHaveLength(1);
expect(sent[0].authorization).toBe(`Bearer ${TOKEN}`);
expect(sent[0].credentials).toBe('include');
});

it.each(CALLS)('%s with no token stored goes out cookie-only, as before', async (_name, call) => {
TokenStorage.clear();
await call();
expect(sent).toHaveLength(1);
expect(sent[0].authorization).toBeNull();
expect(sent[0].credentials).toBe('include');
});
});
Loading
Loading