@adea-ai/app-framework 0.33.0 → 0.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1316,6 +1316,9 @@ Host, Origin and browser fetch metadata before dispatch. These headers are not
1316
1316
  credentials: a local process can forge them. Route handlers must enforce their
1317
1317
  own authorization, input and request-size limits, and safe upstream behavior;
1318
1318
  use the authenticated service gateway for privileged native operations.
1319
+ Route responses render in the shell origin, so the host adds its
1320
+ content-security policy, `nosniff` and `no-referrer` to any route response that
1321
+ does not set those headers itself.
1319
1322
 
1320
1323
  The internal update tree identity scans a bounded tree and fingerprints file
1321
1324
  contents, names and permissions while rejecting changed files and, by default,
@@ -191,14 +191,7 @@ function toUiVariant(stored) {
191
191
  const projectionSources = {};
192
192
  for (const fallback of LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS) {
193
193
  if (Object.hasOwn(stored.flatTokens, fallback.token)) continue;
194
- let value = stored;
195
- for (const key of fallback.path) {
196
- if (!value || typeof value !== "object" || !Object.hasOwn(value, key)) {
197
- value = void 0;
198
- break;
199
- }
200
- value = value[key];
201
- }
194
+ const value = fallback.path.reduce((node, key) => node && typeof node === "object" && Object.hasOwn(node, key) ? node[key] : void 0, stored);
202
195
  if (typeof value === "string") projectionSources[fallback.token] = value;
203
196
  }
204
197
  return {
@@ -26,6 +26,27 @@ function contentSecurityPolicy(frameSources) {
26
26
  if (!Array.isArray(sources) || sources.length > 8 || sources.some((source) => typeof source !== "string" || !FRAME_SOURCE.test(source) || Number(/:([0-9]+)$/.exec(source)?.[1] ?? 443) > 65535)) throw new Error("Invalid desktop frame sources");
27
27
  return `frame-src ${sources.length ? [...new Set(sources)].join(" ") : "'none'"}; frame-ancestors 'none'; object-src 'none'; base-uri 'none'`;
28
28
  }
29
+ /**
30
+ * Route responses render in the privileged shell origin too: add the shell's
31
+ * CSP, nosniff and referrer policy unless the route set its own. A response
32
+ * with immutable headers (for example a proxied fetch) is copied first.
33
+ */
34
+ function withShellHeaders(response, csp) {
35
+ const defaults = [
36
+ ["content-security-policy", csp],
37
+ ["x-content-type-options", "nosniff"],
38
+ ["referrer-policy", "no-referrer"]
39
+ ];
40
+ if (defaults.every(([name]) => response.headers.has(name))) return response;
41
+ let result = response;
42
+ try {
43
+ for (const [name, value] of defaults) if (!result.headers.has(name)) result.headers.set(name, value);
44
+ } catch {
45
+ result = new Response(response.body, response);
46
+ for (const [name, value] of defaults) if (!result.headers.has(name)) result.headers.set(name, value);
47
+ }
48
+ return result;
49
+ }
29
50
  /** Run an app socket handler; a throw closes the socket instead of reaching the server. */
30
51
  function routeSocketCall(run, socket) {
31
52
  try {
@@ -142,7 +163,7 @@ function createDesktopHost(options, lifecycle) {
142
163
  try {
143
164
  const result = await route.handle(request, context);
144
165
  if (upgraded) return void 0;
145
- return result instanceof Response ? result : new Response(null, { status: 500 });
166
+ return result instanceof Response ? withShellHeaders(result, csp) : new Response(null, { status: 500 });
146
167
  } catch {
147
168
  return upgraded ? void 0 : new Response(null, { status: 500 });
148
169
  }
@@ -1 +1 @@
1
- {"version":"0.33.0","commit":"c0d47a5bed1a1d47838e66063839560804f3374d"}
1
+ {"version":"0.33.1","commit":"fdc518d937394cc69f360277a52a0ac578f401fe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/app-framework",
3
- "version": "0.33.0",
3
+ "version": "0.33.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -403,14 +403,14 @@ export function toUiVariant(stored: CustomThemeStored): UiThemeVariant {
403
403
  const projectionSources: Record<string, string> = {}
404
404
  for (const fallback of LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS) {
405
405
  if (Object.hasOwn(stored.flatTokens, fallback.token)) continue
406
- let value: unknown = stored
407
- for (const key of fallback.path) {
408
- if (!value || typeof value !== 'object' || !Object.hasOwn(value, key)) {
409
- value = undefined
410
- break
411
- }
412
- value = (value as Record<string, unknown>)[key]
413
- }
406
+ // Read-only walk over own properties of the stored record.
407
+ const value = fallback.path.reduce<unknown>(
408
+ (node, key) =>
409
+ node && typeof node === 'object' && Object.hasOwn(node, key)
410
+ ? (node as Record<string, unknown>)[key]
411
+ : undefined,
412
+ stored
413
+ )
414
414
  if (typeof value === 'string') projectionSources[fallback.token] = value
415
415
  }
416
416
  return { ...base, tokens: { ...projectionSources, ...stored.flatTokens } }