@shellui/core 0.5.0 → 0.5.2

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.
Files changed (51) hide show
  1. package/package.json +2 -2
  2. package/schemas/shellui.config.schema.json +98 -33
  3. package/src/app.tsx +2 -0
  4. package/src/components/ContentView.tsx +3 -5
  5. package/src/components/contentIframeSandbox.spec.ts +25 -0
  6. package/src/components/contentIframeSandbox.ts +43 -0
  7. package/src/features/auth/AuthProvider.tsx +156 -33
  8. package/src/features/auth/backends/index.ts +2 -0
  9. package/src/features/auth/backends/shellui.ts +43 -35
  10. package/src/features/auth/backends/supabase.ts +1 -0
  11. package/src/features/auth/backends/types.ts +5 -0
  12. package/src/features/auth/components/LoginView.tsx +5 -1
  13. package/src/features/auth/components/OAuthCallbackView.tsx +115 -44
  14. package/src/features/auth/constants/oauth.ts +2 -0
  15. package/src/features/auth/hooks/useAuth.tsx +4 -0
  16. package/src/features/auth/utils/authSessionPersistence.spec.ts +93 -0
  17. package/src/features/auth/utils/authSessionPersistence.ts +138 -0
  18. package/src/features/auth/utils/authStorageKeys.ts +8 -0
  19. package/src/features/auth/utils/bffAuthClient.ts +107 -0
  20. package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +22 -0
  21. package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +17 -0
  22. package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +29 -0
  23. package/src/features/auth/utils/buildSessionFromTokenPayload.ts +24 -0
  24. package/src/features/auth/utils/index.ts +18 -3
  25. package/src/features/auth/utils/isBffAuthEnabled.ts +12 -0
  26. package/src/features/config/types.ts +49 -2
  27. package/src/features/messaging/MessagingSecurityBootstrap.tsx +19 -0
  28. package/src/features/messaging/deriveAllowedMessageOrigins.spec.ts +86 -0
  29. package/src/features/messaging/deriveAllowedMessageOrigins.ts +74 -0
  30. package/src/features/modal/ModalContext.spec.ts +13 -2
  31. package/src/features/modal/validateAndNormalizeUrl.ts +9 -23
  32. package/src/features/security/trustedFrames.spec.ts +129 -0
  33. package/src/features/security/trustedFrames.ts +79 -0
  34. package/src/features/security/urlAllowlist.spec.ts +99 -0
  35. package/src/features/security/urlAllowlist.ts +122 -0
  36. package/src/features/settings/SettingsProvider.tsx +10 -46
  37. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +23 -1
  38. package/src/features/settings/utils/buildSettingsForPropagation.ts +7 -0
  39. package/src/features/storage/StorageBridge.spec.ts +82 -0
  40. package/src/features/storage/StorageBridge.tsx +25 -3
  41. package/src/features/storage/StoragePickerContext.tsx +3 -4
  42. package/src/features/storage/uploads/uploadQueue.ts +2 -5
  43. package/src/routes/components/NavigationItemRoute.tsx +30 -15
  44. package/src/routes/utils/navigationRouteAccess.spec.ts +85 -0
  45. package/src/routes/utils/navigationRouteAccess.ts +43 -0
  46. package/src/features/auth/utils/clearStoredAuthSession.spec.ts +0 -23
  47. package/src/features/auth/utils/clearStoredAuthSession.ts +0 -10
  48. package/src/features/auth/utils/persistAuthSession.spec.ts +0 -35
  49. package/src/features/auth/utils/persistAuthSession.ts +0 -12
  50. package/src/features/auth/utils/readStoredAuthSession.spec.ts +0 -34
  51. package/src/features/auth/utils/readStoredAuthSession.ts +0 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shellui/core",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Shellui Core - Core React application runtime",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -72,7 +72,7 @@
72
72
  "workbox-routing": "^7.4.0",
73
73
  "workbox-strategies": "^7.4.0",
74
74
  "workbox-window": "^7.4.0",
75
- "@shellui/sdk": "0.5.0"
75
+ "@shellui/sdk": "0.5.2"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "react": "^18.0.0 || ^19.0.0",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "hosting": {
73
73
  "$ref": "#/definitions/HostingConfig",
74
- "description": "Hosting-service connection for `shellui deploy`. Propagated to iframes via SDK settings when `url` is set. Admin → Hosting appears when `url` is set unless `showInAdmin` is false."
74
+ "description": "Hosting-service connection. Propagated to iframes via SDK settings. Enables `shellui deploy` when `url` is set."
75
75
  },
76
76
  "theme": {
77
77
  "$ref": "#/definitions/ThemeRef",
@@ -111,6 +111,10 @@
111
111
  "$ref": "#/definitions/BackendConfig",
112
112
  "description": "Backend communication config. Defaults to undefined (no backend integration)."
113
113
  },
114
+ "security": {
115
+ "$ref": "#/definitions/SecurityConfig",
116
+ "description": "Host security (postMessage allowlist, BFF / HttpOnly refresh, shell CSP)."
117
+ },
114
118
  "cookieConsent": {
115
119
  "$ref": "#/definitions/CookieConsentConfig",
116
120
  "description": "Cookie consent: list of cookies by category; accepted ids are stored in settings."
@@ -121,7 +125,7 @@
121
125
  },
122
126
  "dev": {
123
127
  "$ref": "#/definitions/DevConfig",
124
- "description": "CLI-only companion for `shellui start` (spawn or follow a colocated app). Never shipped to the browser."
128
+ "description": "CLI-only companion for `shellui start`. Spawn `run` and/or follow `url`. Stripped before the config is sent to the browser."
125
129
  },
126
130
  "$schema": {
127
131
  "type": "string",
@@ -130,25 +134,6 @@
130
134
  },
131
135
  "additionalProperties": false
132
136
  },
133
- "DevConfig": {
134
- "type": "object",
135
- "description": "CLI-only companion for `shellui start`. Not shipped to the browser.",
136
- "properties": {
137
- "run": {
138
- "type": "string",
139
- "description": "Command to spawn in the project root (e.g. `vite`)."
140
- },
141
- "url": {
142
- "type": "string",
143
- "description": "URL (or host:port) to wait for before the shell opens, and to follow in follow-only mode."
144
- },
145
- "name": {
146
- "type": "string",
147
- "description": "Log prefix for the companion (default: `app`)."
148
- }
149
- },
150
- "additionalProperties": false
151
- },
152
137
  "ThemeAsset": {
153
138
  "anyOf": [
154
139
  {
@@ -181,7 +166,7 @@
181
166
  "app-bar-inset",
182
167
  "floating"
183
168
  ],
184
- "description": "Layout mode: 'sidebar' (default) shows navigation sidebar; 'sidebar-inset' is sidebar with a padded, rounded main frame that reveals the chrome background; 'fullscreen' shows only content area; 'windows' shows a taskbar with start menu and multi-window desktop; 'app-bar' shows a compact top bar with a 9-square launcher for start links and icon-only end links; 'app-bar-inset' is app-bar with the same padded, rounded main frame as sidebar-inset; 'floating' is glass navigation over full-bleed content (bottom-centered tabs on phone and tablet, floating sidebar on desktop) with layout-chrome safe insets for iframe apps."
169
+ "description": "Layout mode: 'sidebar' (default) shows navigation sidebar; 'sidebar-inset' is sidebar with a padded, rounded main frame; 'fullscreen' shows only content area; 'windows' shows a taskbar with start menu and multi-window desktop; 'app-bar' shows a compact top bar; 'app-bar-inset' is app-bar with the same padded, rounded main frame as sidebar-inset; 'floating' is glass chrome over full-bleed content (bottom tabs on phone/tablet, floating sidebar on desktop)."
185
170
  },
186
171
  "NavigationItem": {
187
172
  "type": "object",
@@ -257,7 +242,7 @@
257
242
  },
258
243
  "safeForAuthToken": {
259
244
  "type": "boolean",
260
- "description": "Trust control for auth token sharing to iframe apps.\n- undefined/true: trusted (default), token can be shared\n- false: untrusted, token is never shared"
245
+ "description": "Trust control for auth token sharing to iframe apps.\n- undefined/false: untrusted (default), access token is not shared\n- true: trusted (opt-in), access token can be shared to this companion"
261
246
  }
262
247
  },
263
248
  "required": ["label", "path", "url"],
@@ -373,16 +358,15 @@
373
358
  },
374
359
  "publicUrl": {
375
360
  "type": "string",
376
- "description": "Optional public base for browsable hosted app URLs when it differs from `url` (e.g. CDN or reverse proxy)."
361
+ "description": "Optional public base for browsable app URLs when different from `url` (e.g. CDN or path-style gateway). The deploy API returns `urls` when possible."
377
362
  },
378
- "app": {
363
+ "slug": {
379
364
  "type": "string",
380
- "deprecated": true,
381
- "description": "Deprecated. Use `slug` to redeploy to an existing preview site."
365
+ "description": "Optional preview site slug. When set, `shellui deploy` redeploys to this slug (must belong to your company and user). When omitted, each deploy gets a new slug."
382
366
  },
383
- "slug": {
367
+ "app": {
384
368
  "type": "string",
385
- "description": "Optional preview site slug. When set, redeploys to that slug (must belong to your company and user). When omitted, a new slug is created for each deploy."
369
+ "deprecated": "Use `slug` instead."
386
370
  },
387
371
  "showInAdmin": {
388
372
  "type": "boolean",
@@ -391,7 +375,7 @@
391
375
  },
392
376
  "required": ["url"],
393
377
  "additionalProperties": false,
394
- "description": "Optional hosting-service wiring for `shellui deploy` preview uploads. Preview sites expire after 7 days unless redeployed. Admin shows Hosting when `url` is set, unless `showInAdmin` is false."
378
+ "description": "Optional hosting-service wiring for `shellui deploy` preview uploads. Preview sites expire after 7 days unless redeployed to the same slug."
395
379
  },
396
380
  "ThemeRef": {
397
381
  "anyOf": [
@@ -874,6 +858,68 @@
874
858
  "additionalProperties": false,
875
859
  "description": "Sentry error reporting configuration. Only used in production; ignored in dev."
876
860
  },
861
+ "SecurityConfig": {
862
+ "type": "object",
863
+ "properties": {
864
+ "allowedMessageOrigins": {
865
+ "type": "array",
866
+ "items": {
867
+ "type": "string"
868
+ },
869
+ "description": "Extra http(s) origins (or absolute URLs) allowed for Shellui postMessage traffic. Unioned with origins derived from navigation, storage, and admin URLs."
870
+ },
871
+ "bffAuth": {
872
+ "$ref": "#/definitions/BffAuthConfig"
873
+ },
874
+ "csp": {
875
+ "$ref": "#/definitions/CspConfig"
876
+ }
877
+ },
878
+ "additionalProperties": false,
879
+ "description": "Host security options. Additive namespace for postMessage, CSP, BFF auth, etc."
880
+ },
881
+ "BffAuthConfig": {
882
+ "type": "object",
883
+ "properties": {
884
+ "enabled": {
885
+ "type": "boolean",
886
+ "description": "When true, refresh tokens are stored in an HttpOnly cookie via same-origin /api/auth/* routes."
887
+ },
888
+ "cookieName": {
889
+ "type": "string",
890
+ "description": "HttpOnly refresh cookie name. Default: shellui_refresh."
891
+ }
892
+ },
893
+ "additionalProperties": false
894
+ },
895
+ "CspConfig": {
896
+ "type": "object",
897
+ "properties": {
898
+ "enforce": {
899
+ "type": "boolean",
900
+ "description": "Emit enforcing Content-Security-Policy. Default false (report-only rollout)."
901
+ },
902
+ "reportOnly": {
903
+ "type": "boolean",
904
+ "description": "Emit Content-Security-Policy-Report-Only. Default true when security.csp is set."
905
+ },
906
+ "reportUri": {
907
+ "type": "string",
908
+ "description": "Optional CSP violation report endpoint."
909
+ },
910
+ "connectSrc": {
911
+ "type": "array",
912
+ "items": { "type": "string" },
913
+ "description": "Extra connect-src hosts (companions, analytics)."
914
+ },
915
+ "frameSrc": {
916
+ "type": "array",
917
+ "items": { "type": "string" },
918
+ "description": "Extra frame-src hosts for companion iframes."
919
+ }
920
+ },
921
+ "additionalProperties": false
922
+ },
877
923
  "BackendConfig": {
878
924
  "type": "object",
879
925
  "properties": {
@@ -895,7 +941,7 @@
895
941
  },
896
942
  "loginUrl": {
897
943
  "type": "string",
898
- "description": "Public origin (or URL) of this shell where /login and OAuth /login/callback live. Used by shellui login. Not the iframe admin app (adminUrl)."
944
+ "description": "Public origin (or full URL) of this shell — where `/login` and OAuth `/login/callback` live. Used by `shellui login`. Not the iframe admin app (`adminUrl`). Example: `https://app.example.com` or `http://127.0.0.1:4000`."
899
945
  },
900
946
  "publishableKey": {
901
947
  "type": "string",
@@ -938,11 +984,11 @@
938
984
  },
939
985
  "panelUrl": {
940
986
  "type": "string",
941
- "description": "Full-bleed iframe URL for the login left panel. When set, takes precedence over panelImage."
987
+ "description": "Full-bleed iframe URL for the login left panel (wins over panelImage)."
942
988
  },
943
989
  "panelImage": {
944
990
  "type": "string",
945
- "description": "Centered, ratio-preserving image path or URL for the login left panel (e.g. \"/login-panel.jpg\")."
991
+ "description": "Centered, ratio-preserving image for the login left panel."
946
992
  }
947
993
  },
948
994
  "additionalProperties": false,
@@ -1022,6 +1068,25 @@
1022
1068
  }
1023
1069
  },
1024
1070
  "additionalProperties": false
1071
+ },
1072
+ "DevConfig": {
1073
+ "type": "object",
1074
+ "properties": {
1075
+ "run": {
1076
+ "type": "string",
1077
+ "description": "Command to spawn in the project root (e.g. `vite`)."
1078
+ },
1079
+ "url": {
1080
+ "type": "string",
1081
+ "description": "URL (or host:port) to wait for / follow."
1082
+ },
1083
+ "name": {
1084
+ "type": "string",
1085
+ "description": "Log prefix name (default: `app`)."
1086
+ }
1087
+ },
1088
+ "additionalProperties": false,
1089
+ "description": "Companion process for local `shellui start` (not used at runtime in the shell)."
1025
1090
  }
1026
1091
  },
1027
1092
  "title": "ShellUIConfig",
package/src/app.tsx CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  } from './service-worker/register';
28
28
  import { useSettings } from './features/settings/hooks/useSettings';
29
29
  import { DesktopChrome } from './features/layouts/chrome/DesktopChrome';
30
+ import { MessagingSecurityBootstrap } from './features/messaging/MessagingSecurityBootstrap';
30
31
 
31
32
  const AppContent = () => {
32
33
  const { config } = useConfig();
@@ -130,6 +131,7 @@ const App = () => {
130
131
 
131
132
  return (
132
133
  <ConfigProvider>
134
+ <MessagingSecurityBootstrap />
133
135
  <AuthProvider>
134
136
  <StorageBridge />
135
137
  <SettingsProvider>
@@ -13,6 +13,7 @@ import { useLocation, useNavigate } from 'react-router';
13
13
  import { LOADING_OVERLAY_DURATION_MS } from '../constants/loading';
14
14
  import { LoadingOverlay } from './LoadingOverlay';
15
15
  import { IFRAME_FOREIGN_ATTR } from '../features/layouts/chrome/constants';
16
+ import { resolveContentIframeSandbox } from './contentIframeSandbox';
16
17
 
17
18
  const logger = getLogger('shellcore');
18
19
 
@@ -347,10 +348,7 @@ export const ContentView = ({
347
348
  style={{ width: '100%', height: '100%', display: 'flex', position: 'relative' }}
348
349
  className="min-h-0 flex-1 bg-background"
349
350
  >
350
- {/* Note: allow-same-origin is required for same-origin iframe content (e.g., Vite dev server, cookies, localStorage).
351
- While this allows the iframe to remove its own sandboxing, it's acceptable here because the iframe content
352
- is trusted microfrontend content from the same application origin.
353
- Browser security warnings about this combination cannot be suppressed programmatically. */}
351
+ {/* Sandbox policy: see contentIframeSandbox.ts and docs/features/companion-isolation.md */}
354
352
  {/* Strategy to prevent browser deprioritizing iframe rendering:
355
353
  - loading="eager" explicitly requests immediate loading (not deferred)
356
354
  - opacity:0 hides the iframe during loading while keeping it in the rendering pipeline
@@ -368,7 +366,7 @@ export const ContentView = ({
368
366
  display: 'block',
369
367
  opacity: isLoading ? 0 : 1,
370
368
  }}
371
- sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox"
369
+ sandbox={resolveContentIframeSandbox(iframeUrl)}
372
370
  referrerPolicy="no-referrer-when-downgrade"
373
371
  />
374
372
  {isLoading && <LoadingOverlay />}
@@ -0,0 +1,25 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { LEGACY_POPUP_ESCAPE_TOKEN, resolveContentIframeSandbox } from './contentIframeSandbox';
3
+
4
+ describe('resolveContentIframeSandbox', () => {
5
+ test('uses tightened sandbox without popup escape', () => {
6
+ const sandbox = resolveContentIframeSandbox('http://localhost:5173/', 'http://localhost:4000');
7
+ expect(sandbox).toContain('allow-scripts');
8
+ expect(sandbox).toContain('allow-same-origin');
9
+ expect(sandbox).not.toContain(LEGACY_POPUP_ESCAPE_TOKEN);
10
+ });
11
+
12
+ test('same-origin production companion uses the same tightened set', () => {
13
+ const sandbox = resolveContentIframeSandbox('/app/', 'https://example.com');
14
+ expect(sandbox).not.toContain(LEGACY_POPUP_ESCAPE_TOKEN);
15
+ expect(sandbox.split(' ').sort()).toEqual(
16
+ ['allow-forms', 'allow-popups', 'allow-same-origin', 'allow-scripts'].sort(),
17
+ );
18
+ });
19
+
20
+ test('falls back safely for invalid URLs', () => {
21
+ const sandbox = resolveContentIframeSandbox('not-a-valid-url', 'http://localhost:4000');
22
+ expect(sandbox).toContain('allow-scripts');
23
+ expect(sandbox).not.toContain(LEGACY_POPUP_ESCAPE_TOKEN);
24
+ });
25
+ });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Companion/content iframe sandbox tokens.
3
+ *
4
+ * Threat model (Track F / M-18):
5
+ * - Dev: shell (:4000) and companion (:5173, :3000, …) use distinct origins; templates
6
+ * set `frame-ancestors` so companions accept shell framing.
7
+ * - Prod: companion is served from the same origin as the shell (`/app/`), which keeps
8
+ * postMessage and cookies workable while avoiding cross-origin framing surprises.
9
+ * - `allow-same-origin` + `allow-scripts` lets embedded scripts remove the sandbox
10
+ * attribute when the iframe is same-origin to its document — acceptable only for
11
+ * trusted navigation URLs you configure. Residual risk is documented in
12
+ * docs/features/companion-isolation.md.
13
+ *
14
+ * Incremental tightening: drop `allow-popups-to-escape-sandbox` (popups stay sandboxed).
15
+ */
16
+ const SANDBOX_CONTENT = 'allow-same-origin allow-scripts allow-forms allow-popups';
17
+
18
+ /** @deprecated use SANDBOX_CONTENT — kept for tests asserting legacy tokens are gone */
19
+ export const LEGACY_POPUP_ESCAPE_TOKEN = 'allow-popups-to-escape-sandbox';
20
+
21
+ /**
22
+ * Resolve the `sandbox` attribute for a main content iframe.
23
+ *
24
+ * @param iframeUrl - Absolute or relative URL loaded in the iframe
25
+ * @param shellOrigin - Optional shell origin (for unit tests without `window`)
26
+ */
27
+ export function resolveContentIframeSandbox(iframeUrl: string, shellOrigin?: string): string {
28
+ try {
29
+ const base =
30
+ typeof window !== 'undefined' ? window.location.href : (shellOrigin ?? 'http://localhost/');
31
+ const iframeOrigin = new URL(iframeUrl, base).origin;
32
+ const parentOrigin =
33
+ shellOrigin ?? (typeof window !== 'undefined' ? window.location.origin : iframeOrigin);
34
+ // Same-origin vs cross-origin companions share the tightened token set today.
35
+ // Cross-origin dev companions still require `allow-same-origin` for companion
36
+ // cookies/localStorage on their own origin; distinct-origin framing is the isolation layer.
37
+ void iframeOrigin;
38
+ void parentOrigin;
39
+ return SANDBOX_CONTENT;
40
+ } catch {
41
+ return SANDBOX_CONTENT;
42
+ }
43
+ }