Skip to content

Commit 93153f0

Browse files
fix(plugin-hono-server): allow If-None-Match and expose ETag in the default CORS policy (#29092)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XSVi3D9xHiawX2ZeUzaNoQt)_ Fixes #28970 Clause-②: yes (widening) — two exported default lists each gain one value: `DEFAULT_CORS_ALLOW_HEADERS` gains `If-None-Match` and `DEFAULT_CORS_EXPOSE_HEADERS` gains `ETag`. A cross-origin client the policy already admits may now send one more request header and read one more response header. Allowed origins are unchanged. No `packages/spec/**` file is touched. Metadata-protocol: none — nothing a metadata author writes is read differently; this is the transport's CORS answer. ## 维护者速读 - 改了什么:默认 CORS 策略的两个列表各加一项:预检允许的请求头加 `If-None-Match`,对跨域 JS 暴露的响应头加 `ETag`。`@objectstack/plugin-hono-server` 和 `@objectstack/hono` 两处都读这两个常量,所以两处一起生效。允许的来源(origin)不变。 - 为什么改:服务器自己的门就在用这两个头:`/meta` 草稿保存认 `If-None-Match: *`(控制台首次存草稿发的就是它),元数据读返回 `ETag`、SDK 的缓存读会把它当 `If-None-Match` 发回来。原来的默认列表放行了 `If-Match` 却没放行 `If-None-Match`,也没暴露 `ETag`,所以前端和服务器不同源时,首次存草稿和缓存读在浏览器里直接报 `Failed to fetch`,请求根本到不了服务器。 - 风险与回滚:纯加法,两个列表各多一个值;未被允许的来源仍拿不到任何 `Access-Control-Allow-Origin`。自定义了 `allowHeaders` 的部署行为不变(仍是整体替换默认值)。回滚即 revert。 - 先看:`packages/plugins/plugin-hono-server/src/adapter.ts` 的两个常量及其注释;新测试 `packages/plugins/plugin-hono-server/src/cors-conditional-headers.test.ts`;`packages/adapters/hono/src/hono.test.ts` 里新增的两条 pin。 - 两分钟验证:`pnpm --filter @objectstack/plugin-hono-server exec vitest run src/cors-conditional-headers.test.ts`,预期 `Tests 5 passed (5)`。 - 需要你做的:无,席位落地。 ## What changes - **`packages/plugins/plugin-hono-server/src/adapter.ts`**: `DEFAULT_CORS_ALLOW_HEADERS` gains `'If-None-Match'` (right after `'If-Match'`), and `DEFAULT_CORS_EXPOSE_HEADERS` gains `'ETag'`. Each docblock gets a line saying which door needs the entry, in the style of the `If-Match` line: the `/meta` draft save's first-write pin and the cached metadata reads for `If-None-Match`, and the version the metadata reads answer for `ETag`. - **`content/docs/protocol/kernel/http-protocol.mdx`**: the documented default headers, the table of easy-to-overlook allowed headers (a new `If-None-Match` row) and the exposed-headers paragraph (now three, with `ETag`) match the new defaults. Leaving them would have made the published page false. - **`.changeset/28970-cors-conditional-headers.md`**: `@objectstack/plugin-hono-server` patch, with both declaration lines. `Metadata-protocol: none` grades it `patch`. It says what a deployment with its own `allowHeaders` has to add. ## Tests - New `packages/plugins/plugin-hono-server/src/cors-conditional-headers.test.ts` (5 cases), driven through the real `HonoServerPlugin.init()`, the real adapter and the real `hono/cors` middleware (`app.request`), not a captured config. A stand-in for the metadata item door is mounted behind the middleware: its read answers `ETag: "v1"`, and its draft save answers `200`. - A preflight from an admitted origin for `PUT …?mode=draft` asking `content-type,if-none-match,authorization` is answered `204` with `if-none-match` in `Access-Control-Allow-Headers`. - A cross-origin read of the item answers `Access-Control-Expose-Headers` including `etag`. - Controls: a disallowed origin gets no `Access-Control-Allow-Origin` on the preflight or the read; `If-Match` stays allowed, and `set-auth-token` and `x-objectstack-dropped-fields` stay exposed; a custom `allowHeaders` still replaces the default (exactly `content-type, authorization`, no `if-none-match`). - `packages/adapters/hono/src/hono.test.ts`, beside the existing expose-headers pins: `createHonoApp` exposes `etag` by default, and a preflight from a configured origin asking `if-match,if-none-match` is answered with both allowed. - **Red on base, green on head.** On `ab085a04` (base) the two new plugin cases and the two new adapter cases are red (`expected [ 'content-type', …(7) ] to include 'if-none-match'`, `expected [ 'set-auth-token', …(1) ] to include 'etag'`), and the three controls are green. On the head all are green. - **Ablation** (`scripts/ablation-replace.mjs`, both anchors hit once, on-disk count of each entry 0 afterwards): with the two entries removed, the plugin file reds 2 failed / 3 passed and the adapter group reds 2 failed / 4 passed, the same two failures each. Restore: the blob equals HEAD's (`69a105b3`), `git diff HEAD` is empty, and the plugin file is green again (5/5). Both suites read `adapter.ts` as source (the plugin test imports it relatively, and the hono adapter's `vitest.config.ts` aliases `@objectstack/plugin-hono-server` to `src/index.ts`), so no build sits on the path. ## Acceptance notes - **Every site that reads the two lists** (measured with `git grep`): `packages/plugins/plugin-hono-server/src/hono-plugin.ts` (the plugin's CORS block) and `packages/adapters/hono/src/index.ts` (`createHonoApp`). No other site builds its own allow or expose list, so there is no third spelling to fold. The `adapter.ts` docblock still says "three Hono-based CORS sites", and so does a comment in `hono.test.ts`, but only these two read the constants today. That count is stale wording, left untouched (outside this card's file surface). - **Server doors that read `If-None-Match` or answer `ETag`**: the `/meta` draft save (`@objectstack/rest` `meta-save-request.ts`, through `metaSaveRequestOptions`, which the runtime dispatcher's `/meta` door also reads); the metadata item read (`meta-item-read-routes.ts`, `ETag` and `304`); the metadata representation validator (`meta-representation-validator.ts`); the translations read (`packages/runtime/src/domains/i18n.ts`); plugin-hono-server's current-user endpoints (`current-user-endpoints.ts`); and cloud-connection's runtime config (`runtime-config-plugin.ts`). Producers on the client side: `@objectstack/client`'s `getCached` and `getAppBundle`, objectui's Studio first-draft saves and `DraftConflictDialog`, and `useETagCache`. - Allowed origins, methods, credentials and `maxAge` are unchanged, and no other header is added (order ruling). - No real cross-origin browser probe was run. The order lists it as optional, and the card's own Chromium measurement is the reach. ## Verification Local gates were run on tree `f103bad4`, which is the tree of head `ae2b0b73` (the head only rewords the commit message of `71cfe728`). - `pnpm --filter @objectstack/plugin-hono-server test`: Test Files 38 passed (38), Tests 472 passed (472). - `pnpm --filter @objectstack/hono test`: Test Files 14 passed (14), Tests 233 passed (233). - `pnpm --filter @objectstack/plugin-hono-server typecheck` (including `check:test-typecheck`) and `pnpm --filter @objectstack/hono typecheck`: exit 0. - `eslint --no-inline-config` on the three touched source files: exit 0. - `node scripts/pm/dispatch-gates.mjs --commands` derived 92 families. 91 exit 0. One, `pnpm check:dual-build-cjs-loads`, is NOT MEASURED, reason: it exits 3 (PREREQUISITE NOT MET) until every package in the repo is built (33 packages have no `dist/`), and a whole-repo build was out of the local budget. Its self-test passed (93 cases), and CI's run is the reading. `check:plugin-teardown-shape --self-test` and `spec check:skill-examples` first exited 3 on prerequisites (a shallow object, an unbuilt `client-react`) and both exited 0 once those were met. `dispatch-gates --ran` over the exit-coded record: `92 derived famil(ies) accounted for — 91 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)`. --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5nsjQhYdbu8MX5XyPn)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent bc02a77 commit 93153f0

5 files changed

Lines changed: 243 additions & 7 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/plugin-hono-server': patch
3+
---
4+
5+
fix(plugin-hono-server): the default CORS policy lets `If-None-Match` through and exposes `ETag`, so a cross-origin browser client can make the conditional requests the metadata doors speak
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
The `/meta` draft save reads `If-Match` and `If-None-Match: *` (the first-write pin the console's `DraftConflictDialog` and Studio's first-draft saves send), and the metadata reads answer an `ETag` that `@objectstack/client`'s cached reads send back as `If-None-Match`. The default CORS policy allowed `If-Match` but not `If-None-Match`, and exposed no `ETag`. From another origin, the first-draft save and every cached read failed in the browser with a bare `Failed to fetch` (the preflight refused them, so nothing reached the server), and cross-origin JS read the `ETag` as `null`.
11+
12+
- **`DEFAULT_CORS_ALLOW_HEADERS`** gains `If-None-Match`.
13+
- **`DEFAULT_CORS_EXPOSE_HEADERS`** gains `ETag`.
14+
15+
Both constants are applied by `@objectstack/plugin-hono-server` and by the `@objectstack/hono` adapter's `createHonoApp`. Allowed origins are unchanged: a request from an origin the policy does not admit still gets no `Access-Control-Allow-Origin`.
16+
17+
A deployment that passes its own `allowHeaders` replaces the default, as before: add `If-None-Match` to that list to let a cross-origin client send it. `exposeHeaders` still merges with the default, so `ETag` is exposed either way.

‎content/docs/protocol/kernel/http-protocol.mdx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,26 +1039,30 @@ ObjectStack sends CORS headers automatically:
10391039
```http
10401040
Access-Control-Allow-Origin: https://app.acme.com
10411041
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
1042-
Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With, X-Tenant-ID, X-Environment-Id, If-Match, X-Share-Password, X-Share-Password-Encoding
1043-
Access-Control-Expose-Headers: set-auth-token, x-objectstack-dropped-fields
1042+
Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With, X-Tenant-ID, X-Environment-Id, If-Match, If-None-Match, X-Share-Password, X-Share-Password-Encoding
1043+
Access-Control-Expose-Headers: set-auth-token, x-objectstack-dropped-fields, ETag
10441044
Access-Control-Max-Age: 86400
10451045
```
10461046

1047-
Five of the allowed request headers are easy to overlook, and each one disables
1047+
Six of the allowed request headers are easy to overlook, and each one disables
10481048
a feature if an intermediate proxy strips it:
10491049

10501050
| Header | Why it is allowed |
10511051
| --- | --- |
10521052
| `X-Tenant-ID` / `X-Environment-Id` | Route the request to its environment on a multi-tenant host. |
10531053
| `If-Match` | Carries the OCC token on record `PATCH`es. Without it, a cross-origin save fails in the browser with "Failed to fetch". |
1054+
| `If-None-Match` | Carries the `/meta` draft save's first-write pin (`If-None-Match: *`) and the `ETag` a cached metadata read sends back. Without it, the preflight refuses the request and the browser answers "Failed to fetch" before it reaches the server. |
10541055
| `X-Share-Password` | Carries a share-link password to the public `/share-links/:token/resolve` and `/messages` routes. It is the preferred form because a header stays out of URLs; without it, a cross-origin client can only send the password as a query parameter. |
10551056
| `X-Share-Password-Encoding` | Declares how `X-Share-Password` is encoded. Its one accepted value is `utf-8` (any case): the password header then carries the password's UTF-8 bytes percent-encoded, as `encodeURIComponent(password)` produces them. A browser cannot put a character above U+00FF in a header, and strips leading and trailing spaces, so this is how such a password is sent. Without this header, `X-Share-Password` is read raw, as it arrives. Any other value, or a password header that is not percent-encoded UTF-8 under `utf-8`, is refused with `400 VALIDATION_FAILED`. |
10561057

1057-
The two **exposed** response headers matter to browser clients specifically:
1058+
The three **exposed** response headers matter to browser clients specifically:
10581059
`set-auth-token` delivers a rotated session token (without it a cross-origin
1059-
session silently breaks even though every request succeeds), and
1060+
session silently breaks even though every request succeeds),
10601061
`x-objectstack-dropped-fields` warns that a write dropped undeclared keys — the
1061-
response body's `droppedFields` stays the primary channel for that.
1062+
response body's `droppedFields` stays the primary channel for that — and `ETag`
1063+
is the version a metadata read answers, which a client sends back as
1064+
`If-None-Match` or pins a save to as `If-Match` (without it cross-origin JS
1065+
reads it as `null`).
10621066

10631067
These are the defaults exported as `DEFAULT_CORS_ALLOW_HEADERS` and
10641068
`DEFAULT_CORS_EXPOSE_HEADERS` from `@objectstack/plugin-hono-server`. Supplying

‎packages/adapters/hono/src/hono.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,45 @@ describe('createHonoApp', () => {
10991099
expect(exposed).toContain('x-objectstack-dropped-fields');
11001100
});
11011101

1102+
// [#28970] The metadata reads answer an `ETag` that `@objectstack/client`'s
1103+
// cached reads send back; cross-origin JS reads it as `null` unless exposed.
1104+
it('always exposes ETag by default', async () => {
1105+
const app = createHonoApp({ kernel: mockKernel, prefix: '/api/v1' });
1106+
1107+
const res = await app.request('/api/v1/meta', {
1108+
method: 'GET',
1109+
headers: { Origin: 'https://app.example.com' },
1110+
});
1111+
const exposed = (res.headers.get('access-control-expose-headers') || '')
1112+
.split(',').map(s => s.trim().toLowerCase());
1113+
expect(exposed).toContain('etag');
1114+
});
1115+
1116+
// [#28970] The `/meta` first-draft save sends `If-None-Match: *`; a preflight
1117+
// that does not allow it fails the save in the browser before it is sent.
1118+
it('allows If-None-Match on a preflight by default, beside If-Match', async () => {
1119+
const app = createHonoApp({
1120+
kernel: mockKernel,
1121+
prefix: '/api/v1',
1122+
cors: { origin: 'https://app.example.com' },
1123+
});
1124+
1125+
const res = await app.request('/api/v1/meta/page/x?mode=draft', {
1126+
method: 'OPTIONS',
1127+
headers: {
1128+
Origin: 'https://app.example.com',
1129+
'Access-Control-Request-Method': 'PUT',
1130+
'Access-Control-Request-Headers': 'content-type,if-match,if-none-match',
1131+
},
1132+
});
1133+
expect(res.status).toBe(204);
1134+
expect(res.headers.get('access-control-allow-origin')).toBe('https://app.example.com');
1135+
const allowed = (res.headers.get('access-control-allow-headers') || '')
1136+
.split(',').map(s => s.trim().toLowerCase());
1137+
expect(allowed).toContain('if-none-match');
1138+
expect(allowed).toContain('if-match');
1139+
});
1140+
11021141
it('merges user-supplied exposeHeaders with set-auth-token (does not replace)', async () => {
11031142
const app = createHonoApp({
11041143
kernel: mockKernel,

‎packages/plugins/plugin-hono-server/src/adapter.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ import {
6767
* `If-Match` carries the OCC token on record PATCHes (objectui's inline edit,
6868
* REST `update` with `ifMatch`) — without it in the preflight allow-list every
6969
* cross-origin save fails in the browser with "Failed to fetch" (objectui#2572).
70+
* `If-None-Match` carries the `/meta` draft save's first-write pin (`*`, the
71+
* console's `DraftConflictDialog` and Studio's first-draft saves) and the
72+
* validator `@objectstack/client`'s cached metadata reads send back — without
73+
* it here the preflight refuses both and the browser answers a bare "Failed to
74+
* fetch" before the request reaches the door (#28970).
7075
* `X-Share-Password` carries a share-link password to the public
7176
* `/share-links/:token/resolve` and `/messages` routes — the preferred form,
7277
* since a header stays out of URLs (#21839); without it here a cross-origin
@@ -83,6 +88,7 @@ export const DEFAULT_CORS_ALLOW_HEADERS: readonly string[] = Object.freeze([
8388
'X-Tenant-ID',
8489
'X-Environment-Id',
8590
'If-Match',
91+
'If-None-Match',
8692
'X-Share-Password',
8793
'X-Share-Password-Encoding',
8894
]);
@@ -94,11 +100,15 @@ export const DEFAULT_CORS_ALLOW_HEADERS: readonly string[] = Object.freeze([
94100
* `set-auth-token` lets better-auth's `bearer()` plugin hand rotated session
95101
* tokens to cross-origin clients (see plugin-auth). `x-objectstack-dropped-fields`
96102
* (#3455) exposes the single-write drop warning (#3431); the body `droppedFields`
97-
* channel remains the primary, cross-origin-safe surface.
103+
* channel remains the primary, cross-origin-safe surface. `ETag` is the version
104+
* the metadata reads answer, which a cached read sends back as `If-None-Match`
105+
* and a save can pin as `If-Match` — without it here cross-origin JS reads it
106+
* as `null` (#28970).
98107
*/
99108
export const DEFAULT_CORS_EXPOSE_HEADERS: readonly string[] = Object.freeze([
100109
'set-auth-token',
101110
'x-objectstack-dropped-fields',
111+
'ETag',
102112
]);
103113

104114
/**
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The conditional-request headers the server's own doors speak must pass the
5+
* default CORS policy — driven through the real adapter and the real
6+
* `hono/cors` middleware (`app.request`), never a captured config.
7+
*
8+
* The doors: the `/meta` draft save reads `If-Match` and `If-None-Match: *`
9+
* (`@objectstack/rest`'s `metaSaveRequestOptions`), and the metadata reads
10+
* answer `ETag` and a bodiless `304` to an `If-None-Match` that names it
11+
* (`@objectstack/client`'s cached reads send it back). A cross-origin browser
12+
* client the policy admits must be able to send both conditional headers and
13+
* read the `ETag`: a preflight that does not allow `If-None-Match` fails the
14+
* request in the browser with a bare "Failed to fetch" before anything reaches
15+
* the server, and an `ETag` the policy does not expose reads as `null` in JS.
16+
*
17+
* The defaults are {@link DEFAULT_CORS_ALLOW_HEADERS} and
18+
* {@link DEFAULT_CORS_EXPOSE_HEADERS}; `@objectstack/hono`'s `createHonoApp`
19+
* applies the same two constants and carries its own pin.
20+
*/
21+
22+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
23+
import type { PluginContext } from '@objectstack/core';
24+
25+
import type { HonoCorsOptions } from './adapter';
26+
import { HonoServerPlugin } from './hono-plugin';
27+
28+
const ALLOWED = 'https://app.example.com';
29+
const FOREIGN = 'https://other.example';
30+
31+
/** Every variable the CORS block reads, canonical and legacy spellings. */
32+
const CORS_ENV = [
33+
'OS_CORS_ENABLED', 'CORS_ENABLED',
34+
'OS_CORS_ORIGIN', 'CORS_ORIGIN',
35+
'OS_CORS_CREDENTIALS', 'CORS_CREDENTIALS',
36+
'OS_CORS_MAX_AGE', 'CORS_MAX_AGE',
37+
'NODE_ENV',
38+
] as const;
39+
40+
let saved: Record<string, string | undefined> = {};
41+
42+
beforeEach(() => {
43+
saved = {};
44+
for (const name of CORS_ENV) {
45+
saved[name] = process.env[name];
46+
delete process.env[name];
47+
}
48+
process.env.NODE_ENV = 'production';
49+
});
50+
51+
afterEach(() => {
52+
for (const name of CORS_ENV) {
53+
if (saved[name] === undefined) delete process.env[name];
54+
else process.env[name] = saved[name];
55+
}
56+
});
57+
58+
function fakeCtx(): PluginContext {
59+
const services = new Map<string, unknown>();
60+
return {
61+
logger: { debug() {}, info() {}, warn() {}, error() {} },
62+
registerService: (name: string, svc: unknown) => services.set(name, svc),
63+
getService: (name: string) => services.get(name),
64+
hook: () => {},
65+
getKernel: () => ({}),
66+
} as unknown as PluginContext;
67+
}
68+
69+
interface ProbeContext {
70+
header(name: string, value: string): void;
71+
json(body: unknown): Response;
72+
}
73+
74+
interface RawApp {
75+
get(path: string, handler: (c: ProbeContext) => Response): unknown;
76+
put(path: string, handler: (c: ProbeContext) => Response): unknown;
77+
request(path: string, init?: RequestInit): Promise<Response>;
78+
}
79+
80+
const META_ITEM = '/api/v1/meta/page/zz_cors_probe';
81+
82+
/**
83+
* Run the real `init()` with one admitted origin, then mount a stand-in for
84+
* the metadata item door behind its middleware: the read answers an `ETag`,
85+
* the draft save answers `200`.
86+
*/
87+
async function boot(cors: HonoCorsOptions = {}): Promise<RawApp> {
88+
const plugin = new HonoServerPlugin({
89+
port: 0,
90+
serverTiming: false,
91+
cors: { origins: [ALLOWED], ...cors },
92+
});
93+
await plugin.init(fakeCtx());
94+
const rawApp = (plugin as unknown as { server: { getRawApp(): RawApp } }).server.getRawApp();
95+
rawApp.get(META_ITEM, (c) => {
96+
c.header('ETag', '"v1"');
97+
return c.json({ name: 'zz_cors_probe' });
98+
});
99+
rawApp.put(META_ITEM, (c) => c.json({ ok: true }));
100+
return rawApp;
101+
}
102+
103+
/** The browser's preflight ahead of the first-draft save `PUT …?mode=draft` + `If-None-Match: *`. */
104+
function draftPreflight(app: RawApp, origin: string, requested: string): Promise<Response> {
105+
return app.request(`${META_ITEM}?mode=draft`, {
106+
method: 'OPTIONS',
107+
headers: {
108+
Origin: origin,
109+
'Access-Control-Request-Method': 'PUT',
110+
'Access-Control-Request-Headers': requested,
111+
},
112+
});
113+
}
114+
115+
/** A comma-separated header value as a lower-cased list. */
116+
function listOf(res: Response, name: string): string[] {
117+
return (res.headers.get(name) ?? '')
118+
.split(',')
119+
.map((s) => s.trim().toLowerCase())
120+
.filter(Boolean);
121+
}
122+
123+
describe('the default CORS policy admits the conditional headers the metadata doors speak', () => {
124+
it('answers a preflight asking If-None-Match with it in Access-Control-Allow-Headers', async () => {
125+
const app = await boot();
126+
const res = await draftPreflight(app, ALLOWED, 'content-type,if-none-match,authorization');
127+
expect(res.status).toBe(204);
128+
expect(res.headers.get('access-control-allow-origin')).toBe(ALLOWED);
129+
expect(listOf(res, 'access-control-allow-headers')).toContain('if-none-match');
130+
});
131+
132+
it('exposes ETag on a cross-origin metadata read, so cross-origin JS can read the version', async () => {
133+
const app = await boot();
134+
const res = await app.request(META_ITEM, { headers: { Origin: ALLOWED } });
135+
expect(res.status).toBe(200);
136+
expect(res.headers.get('access-control-allow-origin')).toBe(ALLOWED);
137+
expect(res.headers.get('etag')).toBe('"v1"');
138+
expect(listOf(res, 'access-control-expose-headers')).toContain('etag');
139+
});
140+
});
141+
142+
describe('controls: what the two entries leave unchanged', () => {
143+
it('still answers a disallowed origin with no Access-Control-Allow-Origin, on the preflight and on the read', async () => {
144+
const app = await boot();
145+
const preflight = await draftPreflight(app, FOREIGN, 'content-type,if-none-match');
146+
expect(preflight.headers.get('access-control-allow-origin')).toBeNull();
147+
const read = await app.request(META_ITEM, { headers: { Origin: FOREIGN } });
148+
expect(read.headers.get('access-control-allow-origin')).toBeNull();
149+
});
150+
151+
it('keeps If-Match in the allow list and the existing exposed headers in the expose list', async () => {
152+
const app = await boot();
153+
const preflight = await draftPreflight(app, ALLOWED, 'content-type,if-match');
154+
expect(listOf(preflight, 'access-control-allow-headers')).toContain('if-match');
155+
const read = await app.request(META_ITEM, { headers: { Origin: ALLOWED } });
156+
const exposed = listOf(read, 'access-control-expose-headers');
157+
expect(exposed).toContain('set-auth-token');
158+
expect(exposed).toContain('x-objectstack-dropped-fields');
159+
});
160+
161+
it('lets a custom allowHeaders still replace the default (If-None-Match then only if listed)', async () => {
162+
const app = await boot({ allowHeaders: ['Content-Type', 'Authorization'] });
163+
const res = await draftPreflight(app, ALLOWED, 'content-type,if-none-match');
164+
expect(listOf(res, 'access-control-allow-headers')).toEqual(['content-type', 'authorization']);
165+
});
166+
});

0 commit comments

Comments
 (0)