@shellui/core 0.6.2 → 0.7.0-alpha.10

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 (85) hide show
  1. package/package.json +2 -2
  2. package/schemas/shellui.config.schema.json +147 -70
  3. package/src/app.tsx +2 -0
  4. package/src/components/ContentView.tsx +21 -30
  5. package/src/components/iframeUrlSafety.spec.ts +67 -0
  6. package/src/components/iframeUrlSafety.ts +50 -0
  7. package/src/components/ui/sidebar.tsx +11 -5
  8. package/src/features/admin/AdminView.tsx +9 -6
  9. package/src/features/auth/AuthProvider.tsx +49 -5
  10. package/src/features/auth/appBackend/AppBackendSessionHost.tsx +58 -0
  11. package/src/features/auth/appBackend/appBackendSessions.spec.ts +329 -0
  12. package/src/features/auth/appBackend/appBackendSessions.ts +443 -0
  13. package/src/features/auth/appBackend/childFrames.spec.ts +328 -0
  14. package/src/features/auth/appBackend/childFrames.ts +180 -0
  15. package/src/features/auth/appBackend/configSchema.spec.ts +41 -0
  16. package/src/features/auth/appBackend/frameAuth.ts +204 -0
  17. package/src/features/auth/appBackend/identity.spec.ts +201 -0
  18. package/src/features/auth/appBackend/identity.ts +173 -0
  19. package/src/features/auth/appBackend/silentSignIn.spec.ts +225 -0
  20. package/src/features/auth/appBackend/silentSignIn.ts +254 -0
  21. package/src/features/auth/appBackend/tokenExchange.spec.ts +98 -0
  22. package/src/features/auth/appBackend/tokenExchange.ts +76 -0
  23. package/src/features/auth/backends/shellui.spec.ts +51 -19
  24. package/src/features/auth/backends/shellui.ts +20 -5
  25. package/src/features/auth/backends/types.ts +7 -2
  26. package/src/features/auth/components/LoginView.tsx +40 -18
  27. package/src/features/auth/components/OAuthCallbackView.tsx +33 -4
  28. package/src/features/auth/utils/authRequestError.ts +3 -0
  29. package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +42 -1
  30. package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +23 -0
  31. package/src/features/auth/utils/canRestoreStoredSession.spec.ts +29 -0
  32. package/src/features/auth/utils/canRestoreStoredSession.ts +12 -0
  33. package/src/features/auth/utils/index.ts +16 -1
  34. package/src/features/auth/utils/loginCancelTarget.spec.ts +73 -0
  35. package/src/features/auth/utils/loginCancelTarget.ts +45 -0
  36. package/src/features/auth/utils/loginPanelFrame.spec.ts +24 -0
  37. package/src/features/auth/utils/loginPanelFrame.ts +14 -0
  38. package/src/features/auth/utils/resolveSdkLoginRedirectPath.spec.ts +41 -0
  39. package/src/features/auth/utils/resolveSdkLoginRedirectPath.ts +31 -0
  40. package/src/features/auth/utils/webPkce.spec.ts +119 -0
  41. package/src/features/auth/utils/webPkce.ts +169 -0
  42. package/src/features/chromeActions/computeActionInsets.ts +7 -4
  43. package/src/features/config/types.ts +70 -3
  44. package/src/features/layouts/appbar/AppBarLayout.tsx +63 -30
  45. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +12 -23
  46. package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
  47. package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
  48. package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
  49. package/src/features/layouts/chrome/MacStrip.tsx +33 -0
  50. package/src/features/layouts/chrome/constants.ts +33 -8
  51. package/src/features/layouts/chrome/index.ts +8 -0
  52. package/src/features/layouts/chrome/stripDragMap.ts +35 -0
  53. package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
  54. package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
  55. package/src/features/layouts/filterNavigationForAuthState.spec.ts +5 -3
  56. package/src/features/layouts/floating/FloatingBottomDock.tsx +199 -20
  57. package/src/features/layouts/floating/FloatingLayout.tsx +13 -8
  58. package/src/features/layouts/floating/FloatingSidebar.tsx +144 -70
  59. package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
  60. package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
  61. package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
  62. package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
  63. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +38 -10
  64. package/src/features/layouts/sidebar/NavigationContent.tsx +14 -6
  65. package/src/features/layouts/sidebar/SidebarIcons.tsx +3 -9
  66. package/src/features/layouts/sidebar/SidebarInner.tsx +50 -39
  67. package/src/features/layouts/sidebar/SidebarLayout.tsx +8 -11
  68. package/src/features/layouts/utils.ts +4 -3
  69. package/src/features/layouts/windows/DesktopDots.tsx +76 -0
  70. package/src/features/layouts/windows/WindowsLayout.tsx +184 -125
  71. package/src/features/layouts/windows/deskDots.spec.ts +52 -0
  72. package/src/features/layouts/windows/deskDots.ts +314 -0
  73. package/src/features/settings/SettingsProvider.tsx +198 -29
  74. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +379 -4
  75. package/src/features/settings/utils/buildSettingsForPropagation.ts +65 -39
  76. package/src/features/theme/applyTheme.ts +8 -0
  77. package/src/features/theme/navContrast.spec.ts +49 -0
  78. package/src/features/theme/navContrast.ts +108 -0
  79. package/src/features/transfers/transferQueue.spec.ts +6 -2
  80. package/src/i18n/translations/en/common.json +27 -0
  81. package/src/i18n/translations/fr/common.json +27 -0
  82. package/src/index.css +935 -46
  83. package/src/index.ts +2 -0
  84. package/src/routes/hooks/useNavigationItems.ts +14 -3
  85. package/src/routes/hooks/withShellSearch.spec.ts +13 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shellui/core",
3
- "version": "0.6.2",
3
+ "version": "0.7.0-alpha.10",
4
4
  "description": "Shellui Core - Core React application runtime",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -73,7 +73,7 @@
73
73
  "workbox-routing": "^7.4.0",
74
74
  "workbox-strategies": "^7.4.0",
75
75
  "workbox-window": "^7.4.0",
76
- "@shellui/sdk": "0.6.2"
76
+ "@shellui/sdk": "0.7.0-alpha.10"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "react": "^18.0.0 || ^19.0.0",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "email": {
81
81
  "$ref": "#/definitions/EmailConfig",
82
- "description": "Email-service connection. Propagated to iframes via SDK settings. When `email` is set and `url` is omitted, the shell sends `https://email.shellui.com`. `showInAdmin: false` hides Admin → Email."
82
+ "description": "Email-service connection. Propagated to iframes via SDK settings. Without `url`, the shell sends no email service (`null`). `showInAdmin: false` hides Admin → Email."
83
83
  },
84
84
  "theme": {
85
85
  "$ref": "#/definitions/ThemeRef",
@@ -255,6 +255,26 @@
255
255
  "safeForAuthToken": {
256
256
  "type": "boolean",
257
257
  "description": "Trust control for auth token sharing to iframe apps.\n- undefined/false: untrusted (default), access token is not shared\n- true: trusted, access token can be shared (opt-in)"
258
+ },
259
+ "backend": {
260
+ "$ref": "#/definitions/AppBackendConfig",
261
+ "description": "Identity server for this embedded app when it is not the shell `backend`. The shell keeps a separate session and sends this URL plus that session's access token. Omit to use the shell backend and token. The shell token is never sent when this server differs."
262
+ },
263
+ "childFrames": {
264
+ "$ref": "#/definitions/ChildFramesConfig",
265
+ "description": "Lets this app host other Shellui apps in its own iframes (`createAppFrame`). Off when omitted. Only exact origins listed here are accepted."
266
+ },
267
+ "email": {
268
+ "$ref": "#/definitions/EmailConfig",
269
+ "description": "Email service for this app. Omit to use the shell `email` when the app uses the shell identity server. When `backend` names a different server and this is omitted, the app receives no email URL."
270
+ },
271
+ "storage": {
272
+ "$ref": "#/definitions/StorageConfig",
273
+ "description": "Storage service for this app. Same fallback as `email`."
274
+ },
275
+ "hosting": {
276
+ "$ref": "#/definitions/HostingConfig",
277
+ "description": "Hosting service for this app. Same fallback as `email`."
258
278
  }
259
279
  },
260
280
  "required": ["label", "path", "url"],
@@ -287,59 +307,82 @@
287
307
  "enum": ["top", "bottom", "left", "right"],
288
308
  "description": "Drawer position when opening a link in a drawer (optional, used when openIn === 'drawer')."
289
309
  },
290
- "NavigationGroup": {
310
+ "AppBackendConfig": {
291
311
  "type": "object",
292
312
  "properties": {
293
- "title": {
294
- "anyOf": [
295
- {
296
- "type": "string"
297
- },
298
- {
299
- "$ref": "#/definitions/LocalizedString"
300
- }
301
- ]
313
+ "type": {
314
+ "$ref": "#/definitions/BackendType",
315
+ "description": "`shellui` or `supabase`. When omitted, the shell backend type is used."
302
316
  },
303
- "items": {
304
- "type": "array",
305
- "items": {
306
- "$ref": "#/definitions/NavigationItem"
307
- }
317
+ "url": {
318
+ "type": "string",
319
+ "description": "Base URL of this app's identity server."
308
320
  },
309
- "position": {
321
+ "companyId": {
322
+ "type": ["string", "number"],
323
+ "description": "Tenant id for this server. Not taken from the shell `backend.companyId`."
324
+ },
325
+ "publishableKey": {
310
326
  "type": "string",
311
- "enum": ["start", "end"],
312
- "description": "Sidebar position: 'start' (default) or 'end'. End groups are rendered in the sidebar footer."
327
+ "description": "Public key when `type` is `supabase`."
328
+ },
329
+ "provider": {
330
+ "type": "string",
331
+ "description": "`upstream`: the shell gets the app session by OAuth token exchange (RFC 8693), trading its own access token at this server. Recommended for Shellui regions. Any other value, such as `google`, is the OAuth provider for silent sign-in. When omitted, the shell uses the first `backend.login.oauthProviders` entry."
313
332
  }
314
333
  },
315
- "required": ["title", "items"],
316
- "additionalProperties": false
334
+ "required": ["url"],
335
+ "additionalProperties": false,
336
+ "description": "Identity server for one embedded app when it differs from the shell `backend`. `type` defaults to the shell backend type. `companyId` is not copied from the shell."
317
337
  },
318
- "AdministrationConfig": {
338
+ "BackendType": {
339
+ "type": "string",
340
+ "enum": ["shellui", "supabase"],
341
+ "description": "Supported backend providers for auth/API communication."
342
+ },
343
+ "ChildFramesConfig": {
319
344
  "type": "object",
320
345
  "properties": {
321
- "title": {
322
- "anyOf": [
323
- {
324
- "type": "string"
325
- },
326
- {
327
- "$ref": "#/definitions/LocalizedString"
328
- }
329
- ],
330
- "description": "Section title shown in the admin sidebar below Dashboard."
346
+ "origins": {
347
+ "type": "array",
348
+ "items": {
349
+ "type": "string"
350
+ },
351
+ "description": "Exact origins of child apps, such as `https://admin.shellui.com`. No wildcards."
331
352
  },
332
- "navigation": {
353
+ "backendOrigins": {
333
354
  "type": "array",
334
355
  "items": {
335
- "$ref": "#/definitions/NavigationItem"
356
+ "type": "string"
336
357
  },
337
- "description": "Flat list of navigation items (same shape as top-level `navigation` items). Order is preserved in the admin sidebar."
358
+ "description": "Exact origins of identity servers a child may sign in to, such as `https://id.eu.shellui.com`. The shell keeps a separate session per server and never sends its own token to a child. Omit to give children no token."
359
+ },
360
+ "serviceOrigins": {
361
+ "type": "array",
362
+ "items": {
363
+ "type": "string"
364
+ },
365
+ "description": "Exact origins of service URLs (email, storage, files, hosting) a host may pass to a child with `ShelluiFrame` or `createAppFrame`, such as `https://storage.eu.shellui.com`. No wildcards. A URL outside this list, or a missing one, reaches the child as `null`. Omit to send children no service URLs."
338
366
  }
339
367
  },
340
- "required": ["title", "navigation"],
368
+ "required": ["origins"],
341
369
  "additionalProperties": false,
342
- "description": "Custom navigation section for the staff administration panel. Admin app URL remains `backend.adminUrl` / `backend.adminPathname`. v1 is a flat list only (no nested groups)."
370
+ "description": "Child apps an embedded app may host, and the identity servers they may use."
371
+ },
372
+ "EmailConfig": {
373
+ "type": "object",
374
+ "properties": {
375
+ "url": {
376
+ "type": "string",
377
+ "description": "Base URL of email-service. Required for apps to get email. There is no built-in default. Local: `http://localhost:8003`."
378
+ },
379
+ "showInAdmin": {
380
+ "type": "boolean",
381
+ "description": "When false, hide Admin → Email. Default: true (shown) when `email` is set."
382
+ }
383
+ },
384
+ "additionalProperties": false,
385
+ "description": "Optional email-service wiring for Admin → Email and iframe apps. The shell never invents a URL: without `url`, apps get no email service."
343
386
  },
344
387
  "StorageConfig": {
345
388
  "type": "object",
@@ -361,17 +404,6 @@
361
404
  "additionalProperties": false,
362
405
  "description": "Optional storage-service wiring for the shell and admin panel. When set, admin shows the Storage sidebar (files explorer, statistics, Django admin). Settings → Storage (quota) appears when `url` is set, unless `showInSettings` is false. Shellui will also use this for the SDK file API (`shellui.storage`)."
363
406
  },
364
- "AiConfig": {
365
- "type": "object",
366
- "properties": {
367
- "enabled": {
368
- "type": "boolean",
369
- "description": "Deploy-time opt-in for the whole AI feature. Default: false. Only `true` enables it. Otherwise: no AiBridge, no Settings → AI, SDK AI calls answer `unavailable`, and no WebLLM chunk/worker is loaded. Opt in with `\"ai\": { \"enabled\": true }`."
370
- }
371
- },
372
- "additionalProperties": false,
373
- "description": "On-device AI product feature (Ollama + browser / WebLLM). Distinct from the per-user Settings → AI “Allow apps to use AI” toggle."
374
- },
375
407
  "HostingConfig": {
376
408
  "type": "object",
377
409
  "properties": {
@@ -400,20 +432,70 @@
400
432
  "additionalProperties": false,
401
433
  "description": "Optional hosting-service wiring for `shellui deploy` preview uploads. Preview sites expire after 7 days unless redeployed to the same slug."
402
434
  },
403
- "EmailConfig": {
435
+ "NavigationGroup": {
404
436
  "type": "object",
405
437
  "properties": {
406
- "url": {
438
+ "title": {
439
+ "anyOf": [
440
+ {
441
+ "type": "string"
442
+ },
443
+ {
444
+ "$ref": "#/definitions/LocalizedString"
445
+ }
446
+ ]
447
+ },
448
+ "items": {
449
+ "type": "array",
450
+ "items": {
451
+ "$ref": "#/definitions/NavigationItem"
452
+ }
453
+ },
454
+ "position": {
407
455
  "type": "string",
408
- "description": "Base URL of email-service. Default: `https://email.shellui.com` when `email` is set and this is omitted. Local: `http://localhost:8003`."
456
+ "enum": ["start", "end"],
457
+ "description": "Sidebar position: 'start' (default) or 'end'. End groups are rendered in the sidebar footer."
458
+ }
459
+ },
460
+ "required": ["title", "items"],
461
+ "additionalProperties": false
462
+ },
463
+ "AdministrationConfig": {
464
+ "type": "object",
465
+ "properties": {
466
+ "title": {
467
+ "anyOf": [
468
+ {
469
+ "type": "string"
470
+ },
471
+ {
472
+ "$ref": "#/definitions/LocalizedString"
473
+ }
474
+ ],
475
+ "description": "Section title shown in the admin sidebar below Dashboard."
409
476
  },
410
- "showInAdmin": {
477
+ "navigation": {
478
+ "type": "array",
479
+ "items": {
480
+ "$ref": "#/definitions/NavigationItem"
481
+ },
482
+ "description": "Flat list of navigation items (same shape as top-level `navigation` items). Order is preserved in the admin sidebar."
483
+ }
484
+ },
485
+ "required": ["title", "navigation"],
486
+ "additionalProperties": false,
487
+ "description": "Custom navigation section for the staff administration panel. Admin app URL remains `backend.adminUrl` / `backend.adminPathname`. v1 is a flat list only (no nested groups)."
488
+ },
489
+ "AiConfig": {
490
+ "type": "object",
491
+ "properties": {
492
+ "enabled": {
411
493
  "type": "boolean",
412
- "description": "When false, hide Admin → Email. Default: true (shown) when `email` is set."
494
+ "description": "Deploy-time opt-in for the whole AI feature. Default: false. Only `true` enables it. Otherwise: no AiBridge, no Settings → AI, SDK AI calls answer `unavailable`, and no WebLLM chunk/worker is loaded. Opt in with `\"ai\": { \"enabled\": true }`."
413
495
  }
414
496
  },
415
497
  "additionalProperties": false,
416
- "description": "Optional email-service wiring for Admin → Email and iframe apps. When `email` is set and `url` is omitted, the shell uses `https://email.shellui.com`."
498
+ "description": "On-device AI product feature (Ollama + browser / WebLLM). Distinct from the per-user Settings → AI “Allow apps to use AI” toggle."
417
499
  },
418
500
  "ThemeRef": {
419
501
  "anyOf": [
@@ -896,17 +978,6 @@
896
978
  "additionalProperties": false,
897
979
  "description": "Sentry error reporting configuration. Only used in production; ignored in dev."
898
980
  },
899
- "AuthConfig": {
900
- "type": "object",
901
- "properties": {
902
- "desktopScheme": {
903
- "type": "string",
904
- "description": "Custom URL scheme for Tauri sign-in, such as `shellui-playground`. Lowercase. Not `http`, `https`, or another browser scheme."
905
- }
906
- },
907
- "additionalProperties": false,
908
- "description": "Desktop (Tauri) sign-in. Ignored in the browser, so the web OAuth redirect stays as it is. The scheme must match the OAuth application's `desktop_redirect_scheme`."
909
- },
910
981
  "BackendConfig": {
911
982
  "type": "object",
912
983
  "properties": {
@@ -947,11 +1018,6 @@
947
1018
  "additionalProperties": false,
948
1019
  "description": "Backend API configuration."
949
1020
  },
950
- "BackendType": {
951
- "type": "string",
952
- "enum": ["shellui", "supabase"],
953
- "description": "Supported backend providers for auth/API communication."
954
- },
955
1021
  "BackendLoginConfig": {
956
1022
  "type": "object",
957
1023
  "properties": {
@@ -986,6 +1052,17 @@
986
1052
  "enum": ["password", "oauth", "magic_link", "web3"],
987
1053
  "description": "Supported auth login methods that can be declared in config."
988
1054
  },
1055
+ "AuthConfig": {
1056
+ "type": "object",
1057
+ "properties": {
1058
+ "desktopScheme": {
1059
+ "type": "string",
1060
+ "description": "Custom URL scheme for Tauri sign-in, such as `shellui-playground`. Lowercase. Not `http`, `https`, or another browser scheme."
1061
+ }
1062
+ },
1063
+ "additionalProperties": false,
1064
+ "description": "Desktop (Tauri) sign-in. Ignored in the browser, so the web OAuth redirect stays as it is. The scheme must match the OAuth application's `desktop_redirect_scheme`."
1065
+ },
989
1066
  "SecurityConfig": {
990
1067
  "type": "object",
991
1068
  "properties": {
package/src/app.tsx CHANGED
@@ -9,6 +9,7 @@ import { ThemeProvider } from './features/theme/ThemeProvider';
9
9
  import { I18nProvider } from './i18n/I18nProvider';
10
10
  import { DialogProvider } from './features/alertDialog/DialogContext';
11
11
  import { CookieConsentModal } from './features/cookieConsent/CookieConsentModal';
12
+ import { AppBackendSessionHost } from './features/auth/appBackend/AppBackendSessionHost';
12
13
  import { AuthProvider } from './features/auth/AuthProvider';
13
14
  import { StorageBridge } from './features/storage/StorageBridge';
14
15
  import { ShellAiHost } from './features/ai/ShellAiHost';
@@ -134,6 +135,7 @@ const App = () => {
134
135
  <ConfigProvider>
135
136
  <MessagingSecurityBootstrap />
136
137
  <AuthProvider>
138
+ <AppBackendSessionHost />
137
139
  <StorageBridge />
138
140
  <SettingsProvider>
139
141
  <ShellAiHost />
@@ -14,6 +14,7 @@ import { LoadingOverlay } from './LoadingOverlay';
14
14
  import { LOADING_OVERLAY_DURATION_MS } from '../constants/loading';
15
15
  import { IFRAME_FOREIGN_ATTR } from '../features/layouts/chrome/constants';
16
16
  import { resolveContentIframeSandbox } from './contentIframeSandbox';
17
+ import { isSafeIframeUrl, isSameOrigin } from './iframeUrlSafety';
17
18
 
18
19
  const logger = getLogger('shellcore');
19
20
 
@@ -30,29 +31,8 @@ function isSafeShellPath(path: string): boolean {
30
31
  return true;
31
32
  }
32
33
 
33
- function isSafeIframeUrl(url: string): boolean {
34
- try {
35
- const parsed = new URL(url, typeof window !== 'undefined' ? window.location.href : undefined);
36
- return parsed.protocol === 'http:' || parsed.protocol === 'https:';
37
- } catch {
38
- return false;
39
- }
40
- }
41
-
42
34
  function isSameOriginAsNavItem(targetUrl: string, navItem: NavigationItem): boolean {
43
- try {
44
- const target = new URL(
45
- targetUrl,
46
- typeof window !== 'undefined' ? window.location.href : undefined,
47
- );
48
- const allowed = new URL(
49
- navItem.url,
50
- typeof window !== 'undefined' ? window.location.href : undefined,
51
- );
52
- return target.origin === allowed.origin;
53
- } catch {
54
- return false;
55
- }
35
+ return isSameOrigin(targetUrl, navItem.url);
56
36
  }
57
37
 
58
38
  /** Apply a URL inside the iframe without adding a joint session-history entry. */
@@ -93,8 +73,10 @@ export const ContentView = ({
93
73
  const iframeRef = useRef<HTMLIFrameElement>(null);
94
74
  const cancelRevealRef = useRef<(() => void) | null>(null);
95
75
  const mountTimeRef = useRef(Date.now());
96
- /** Shell path last reported by the iframe — skip driving iframe when we caused the location change. */
76
+ /** Shell path last synced with the iframe. */
97
77
  const lastShellPathFromIframeRef = useRef<string | null>(null);
78
+ /** Iframe reports not rendered back yet: their echo must not drive the iframe. */
79
+ const pendingFromIframeRef = useRef<string[]>([]);
98
80
  const skipInitialShellSyncRef = useRef(true);
99
81
  const prevNavPathRef = useRef(navItem?.path ?? '');
100
82
 
@@ -139,9 +121,16 @@ export const ContentView = ({
139
121
  return;
140
122
  }
141
123
 
124
+ const echo = pendingFromIframeRef.current.indexOf(currentShellPath);
125
+ if (echo >= 0 && !navItemChanged) {
126
+ pendingFromIframeRef.current = pendingFromIframeRef.current.slice(echo + 1);
127
+ lastShellPathFromIframeRef.current = currentShellPath;
128
+ return;
129
+ }
142
130
  if (lastShellPathFromIframeRef.current === currentShellPath && !navItemChanged) {
143
131
  return;
144
132
  }
133
+ pendingFromIframeRef.current = [];
145
134
 
146
135
  lastShellPathFromIframeRef.current = currentShellPath;
147
136
  mountTimeRef.current = Date.now();
@@ -193,7 +182,7 @@ export const ContentView = ({
193
182
  return;
194
183
  }
195
184
 
196
- const { pathname, search, hash } = data.payload as ShellUIUrlPayload;
185
+ const { pathname, search, hash, replace } = data.payload as ShellUIUrlPayload;
197
186
  // Shell URL is always path + search only (no hash) so it's transparent whether the sub-app uses hash routing or not
198
187
  let pathSegment: string;
199
188
  if (isHashRouterNavItem(navItem) && hash) {
@@ -243,17 +232,19 @@ export const ContentView = ({
243
232
  const normalizedNewPathname = newPathParts?.[1]?.replace(/\/+$/, '') || '/';
244
233
  const normalizedNewPath = normalizedNewPathname + (newPathParts?.[2] || '');
245
234
 
246
- // Mark before navigate so the shell-sync effect does not reload the iframe
247
- lastShellPathFromIframeRef.current = normalizedNewPath;
248
-
249
235
  if (currentPath !== normalizedNewPath) {
250
236
  if (!isSafeShellPath(normalizedNewPath)) {
251
237
  logger.warn('ContentView: refused unsafe shell path from iframe', normalizedNewPath);
252
238
  return;
253
239
  }
254
- // Push — iframe pushState is replace-only when embedded, so the shell
255
- // is the sole owner of back/forward entries.
256
- navigate(newShellPath);
240
+ // Mark before navigate so the shell-sync effect does not drive the iframe back.
241
+ pendingFromIframeRef.current = [
242
+ ...pendingFromIframeRef.current.slice(-19),
243
+ normalizedNewPath,
244
+ ];
245
+ // Iframe pushState is replace-only when embedded, so the shell owns back and
246
+ // forward. A child redirect replaces, so it never adds an entry.
247
+ navigate(newShellPath, { replace: replace === true });
257
248
  }
258
249
  },
259
250
  );
@@ -0,0 +1,67 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { isSafeIframeUrl, isSameOrigin } from './iframeUrlSafety';
3
+
4
+ const shellAt = (href: string) => {
5
+ const url = new URL(href);
6
+ return { href: url.href, protocol: url.protocol, host: url.host };
7
+ };
8
+
9
+ describe('isSafeIframeUrl', () => {
10
+ const tauriShell = shellAt('tauri://localhost/dialog');
11
+
12
+ test('accepts relative app URLs under a tauri://localhost shell', () => {
13
+ expect(isSafeIframeUrl('/app#/toaster', tauriShell)).toBe(true);
14
+ expect(isSafeIframeUrl('/app/#/dialog', tauriShell)).toBe(true);
15
+ expect(isSafeIframeUrl('tauri://localhost/app#/layout', tauriShell)).toBe(true);
16
+ });
17
+
18
+ test('accepts http(s) URLs from any shell', () => {
19
+ expect(isSafeIframeUrl('https://shellui.com/', tauriShell)).toBe(true);
20
+ expect(isSafeIframeUrl('/app#/toaster', shellAt('https://playground.shellui.com/dialog'))).toBe(
21
+ true,
22
+ );
23
+ });
24
+
25
+ test('refuses another custom-scheme host than the shell', () => {
26
+ expect(isSafeIframeUrl('tauri://evil/app', tauriShell)).toBe(false);
27
+ expect(isSafeIframeUrl('other://localhost/app', tauriShell)).toBe(false);
28
+ });
29
+
30
+ test('still refuses javascript:, data: and invalid URLs', () => {
31
+ for (const shell of [tauriShell, shellAt('https://playground.shellui.com/')]) {
32
+ expect(isSafeIframeUrl('javascript:alert(1)', shell)).toBe(false);
33
+ expect(isSafeIframeUrl('data:text/html,<script>alert(1)</script>', shell)).toBe(false);
34
+ expect(isSafeIframeUrl('blob:https://playground.shellui.com/x', shell)).toBe(false);
35
+ }
36
+ expect(isSafeIframeUrl('http://[bad', tauriShell)).toBe(false);
37
+ });
38
+ });
39
+
40
+ describe('isSameOrigin', () => {
41
+ const tauriShell = shellAt('tauri://localhost/dialog');
42
+
43
+ test('page-to-page under tauri://localhost stays on the nav item origin', () => {
44
+ // Shell at /dialog switches to the Toaster item: URL built from the nav item URL.
45
+ expect(isSameOrigin('/app#/toaster', '/app/#/toaster', tauriShell)).toBe(true);
46
+ expect(
47
+ isSafeIframeUrl('/app#/toaster', tauriShell) &&
48
+ isSameOrigin('/app#/toaster', '/app/#/toaster', tauriShell),
49
+ ).toBe(true);
50
+ });
51
+
52
+ test('different tauri hosts are not equal', () => {
53
+ expect(isSameOrigin('tauri://localhost/app', 'tauri://other/app', tauriShell)).toBe(false);
54
+ expect(isSameOrigin('tauri://localhost/app', 'other://localhost/app', tauriShell)).toBe(false);
55
+ });
56
+
57
+ test('compares http(s) origins as before', () => {
58
+ expect(isSameOrigin('https://shellui.com/docs', 'https://shellui.com/', tauriShell)).toBe(true);
59
+ expect(isSameOrigin('https://evil.com/', 'https://shellui.com/', tauriShell)).toBe(false);
60
+ expect(isSameOrigin('http://shellui.com/', 'https://shellui.com/', tauriShell)).toBe(false);
61
+ });
62
+
63
+ test('opaque URLs never match', () => {
64
+ expect(isSameOrigin('data:text/html,x', 'data:text/html,y', tauriShell)).toBe(false);
65
+ expect(isSameOrigin('javascript:void 0', 'javascript:void 0', tauriShell)).toBe(false);
66
+ });
67
+ });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * URL checks for content iframes driven by the shell.
3
+ *
4
+ * The desktop app serves the shell from a custom scheme (`tauri://localhost` on
5
+ * macOS and Linux), so relative nav URLs like `/app#/dialog` resolve to that
6
+ * scheme. Those are as safe as the shell itself. Anything else must be http(s).
7
+ * `javascript:`, `data:` and other schemes are always refused.
8
+ */
9
+
10
+ type ShellLocation = Pick<Location, 'href' | 'protocol' | 'host'>;
11
+
12
+ const currentShellLocation = (): ShellLocation | undefined =>
13
+ typeof window !== 'undefined' ? window.location : undefined;
14
+
15
+ const parse = (url: string, base?: string): URL | null => {
16
+ try {
17
+ return new URL(url, base);
18
+ } catch {
19
+ return null;
20
+ }
21
+ };
22
+
23
+ /** Protocol + host, which stays meaningful for custom schemes whose `.origin` is "null". */
24
+ const originKey = (url: URL): string => `${url.protocol}//${url.host}`;
25
+
26
+ const isShellOrigin = (url: URL, shell: ShellLocation): boolean =>
27
+ // Only hierarchical URLs with a host can match (`javascript:` and `data:` have none).
28
+ url.host !== '' && url.protocol === shell.protocol && url.host === shell.host;
29
+
30
+ export function isSafeIframeUrl(
31
+ url: string,
32
+ shell: ShellLocation | undefined = currentShellLocation(),
33
+ ): boolean {
34
+ const parsed = parse(url, shell?.href);
35
+ if (!parsed) return false;
36
+ if (parsed.protocol === 'http:' || parsed.protocol === 'https:') return true;
37
+ return shell ? isShellOrigin(parsed, shell) : false;
38
+ }
39
+
40
+ export function isSameOrigin(
41
+ targetUrl: string,
42
+ allowedUrl: string,
43
+ shell: ShellLocation | undefined = currentShellLocation(),
44
+ ): boolean {
45
+ const target = parse(targetUrl, shell?.href);
46
+ const allowed = parse(allowedUrl, shell?.href);
47
+ if (!target || !allowed) return false;
48
+ if (!target.host || !allowed.host) return false;
49
+ return originKey(target) === originKey(allowed);
50
+ }
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { cva, type VariantProps } from 'class-variance-authority';
3
3
  import { Slot } from '@radix-ui/react-slot';
4
+ import { useTranslation } from 'react-i18next';
4
5
 
5
6
  import { useIsMobile } from '../../hooks/use-mobile';
6
7
  import { cn } from '../../lib/utils';
@@ -260,6 +261,7 @@ function Sidebar({
260
261
  variant?: 'sidebar' | 'floating' | 'inset';
261
262
  collapsible?: 'offcanvas' | 'icon' | 'none';
262
263
  }) {
264
+ const { t } = useTranslation();
263
265
  const context = React.useContext(SidebarContext);
264
266
 
265
267
  if (collapsible === 'none') {
@@ -305,8 +307,8 @@ function Sidebar({
305
307
  side={side}
306
308
  >
307
309
  <SheetHeader className="sr-only">
308
- <SheetTitle>Sidebar</SheetTitle>
309
- <SheetDescription>Displays the mobile sidebar.</SheetDescription>
310
+ <SheetTitle>{t('desktopChrome.navigation')}</SheetTitle>
311
+ <SheetDescription>{t('shellChrome.sheetDescription')}</SheetDescription>
310
312
  </SheetHeader>
311
313
  <div className="flex h-full min-h-0 w-full flex-col overflow-hidden pt-[var(--shellui-safe-area-top)] pr-[var(--shellui-safe-area-right)] pl-[var(--shellui-safe-area-left)]">
312
314
  {children}
@@ -376,6 +378,7 @@ function Sidebar({
376
378
 
377
379
  function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<typeof Button>) {
378
380
  const { toggleSidebar } = useSidebar();
381
+ const { t } = useTranslation();
379
382
 
380
383
  return (
381
384
  <Button
@@ -384,7 +387,7 @@ function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<t
384
387
  data-slot="sidebar-trigger"
385
388
  variant="ghost"
386
389
  size="icon"
387
- aria-label="Toggle Sidebar"
390
+ aria-label={t('shellChrome.toggleSidebar')}
388
391
  className={cn(
389
392
  'size-7 touch-manipulation select-none [-webkit-touch-callout:none]',
390
393
  className,
@@ -413,6 +416,7 @@ function SidebarRail({
413
416
  side?: 'left' | 'right';
414
417
  }) {
415
418
  const { toggleSidebar, state, width, setWidth, setIsResizing } = useSidebar();
419
+ const { t } = useTranslation();
416
420
  const dragRef = React.useRef<{
417
421
  startX: number;
418
422
  startWidth: number;
@@ -486,9 +490,11 @@ function SidebarRail({
486
490
  data-slot="sidebar-rail"
487
491
  data-shellui-no-drag=""
488
492
  data-placement={placement}
489
- aria-label={state === 'expanded' ? 'Resize Sidebar' : 'Toggle Sidebar'}
493
+ aria-label={
494
+ state === 'expanded' ? t('shellChrome.resizeSidebar') : t('shellChrome.toggleSidebar')
495
+ }
490
496
  tabIndex={-1}
491
- title={state === 'expanded' ? 'Drag to resize' : 'Toggle Sidebar'}
497
+ title={state === 'expanded' ? t('shellChrome.dragToResize') : t('shellChrome.toggleSidebar')}
492
498
  onClick={(event) => {
493
499
  if (didDragRef.current) {
494
500
  didDragRef.current = false;