@shellui/core 0.6.2 → 0.7.0-alpha.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/package.json +2 -2
- package/schemas/shellui.config.schema.json +116 -72
- package/src/app.tsx +2 -0
- package/src/components/ContentView.tsx +2 -22
- package/src/components/iframeUrlSafety.spec.ts +67 -0
- package/src/components/iframeUrlSafety.ts +50 -0
- package/src/features/auth/AuthProvider.tsx +24 -1
- package/src/features/auth/appBackend/AppBackendSessionHost.tsx +58 -0
- package/src/features/auth/appBackend/appBackendSessions.spec.ts +195 -0
- package/src/features/auth/appBackend/appBackendSessions.ts +292 -0
- package/src/features/auth/appBackend/configSchema.spec.ts +41 -0
- package/src/features/auth/appBackend/frameAuth.ts +167 -0
- package/src/features/auth/appBackend/identity.spec.ts +201 -0
- package/src/features/auth/appBackend/identity.ts +173 -0
- package/src/features/auth/appBackend/silentSignIn.spec.ts +207 -0
- package/src/features/auth/appBackend/silentSignIn.ts +240 -0
- package/src/features/auth/backends/shellui.spec.ts +51 -19
- package/src/features/auth/backends/shellui.ts +20 -5
- package/src/features/auth/backends/types.ts +7 -2
- package/src/features/auth/components/LoginView.tsx +40 -18
- package/src/features/auth/components/OAuthCallbackView.tsx +29 -2
- package/src/features/auth/utils/authRequestError.ts +3 -0
- package/src/features/auth/utils/index.ts +9 -0
- package/src/features/auth/utils/loginCancelTarget.spec.ts +73 -0
- package/src/features/auth/utils/loginCancelTarget.ts +45 -0
- package/src/features/auth/utils/loginPanelFrame.spec.ts +24 -0
- package/src/features/auth/utils/loginPanelFrame.ts +14 -0
- package/src/features/auth/utils/webPkce.spec.ts +96 -0
- package/src/features/auth/utils/webPkce.ts +152 -0
- package/src/features/config/types.ts +41 -0
- package/src/features/settings/SettingsProvider.tsx +45 -32
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +374 -0
- package/src/features/settings/utils/buildSettingsForPropagation.ts +61 -33
- package/src/i18n/translations/en/common.json +2 -0
- package/src/i18n/translations/fr/common.json +2 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shellui/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-alpha.1",
|
|
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.
|
|
76
|
+
"@shellui/sdk": "0.7.0-alpha.1"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -255,6 +255,22 @@
|
|
|
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
|
+
"email": {
|
|
264
|
+
"$ref": "#/definitions/EmailConfig",
|
|
265
|
+
"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."
|
|
266
|
+
},
|
|
267
|
+
"storage": {
|
|
268
|
+
"$ref": "#/definitions/StorageConfig",
|
|
269
|
+
"description": "Storage service for this app. Same fallback as `email`."
|
|
270
|
+
},
|
|
271
|
+
"hosting": {
|
|
272
|
+
"$ref": "#/definitions/HostingConfig",
|
|
273
|
+
"description": "Hosting service for this app. Same fallback as `email`."
|
|
258
274
|
}
|
|
259
275
|
},
|
|
260
276
|
"required": ["label", "path", "url"],
|
|
@@ -287,59 +303,53 @@
|
|
|
287
303
|
"enum": ["top", "bottom", "left", "right"],
|
|
288
304
|
"description": "Drawer position when opening a link in a drawer (optional, used when openIn === 'drawer')."
|
|
289
305
|
},
|
|
290
|
-
"
|
|
306
|
+
"AppBackendConfig": {
|
|
291
307
|
"type": "object",
|
|
292
308
|
"properties": {
|
|
293
|
-
"
|
|
294
|
-
"
|
|
295
|
-
|
|
296
|
-
"type": "string"
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
"$ref": "#/definitions/LocalizedString"
|
|
300
|
-
}
|
|
301
|
-
]
|
|
309
|
+
"type": {
|
|
310
|
+
"$ref": "#/definitions/BackendType",
|
|
311
|
+
"description": "`shellui` or `supabase`. When omitted, the shell backend type is used."
|
|
302
312
|
},
|
|
303
|
-
"
|
|
304
|
-
"type": "
|
|
305
|
-
"
|
|
306
|
-
"$ref": "#/definitions/NavigationItem"
|
|
307
|
-
}
|
|
313
|
+
"url": {
|
|
314
|
+
"type": "string",
|
|
315
|
+
"description": "Base URL of this app's identity server."
|
|
308
316
|
},
|
|
309
|
-
"
|
|
317
|
+
"companyId": {
|
|
318
|
+
"type": ["string", "number"],
|
|
319
|
+
"description": "Tenant id for this server. Not taken from the shell `backend.companyId`."
|
|
320
|
+
},
|
|
321
|
+
"publishableKey": {
|
|
310
322
|
"type": "string",
|
|
311
|
-
"
|
|
312
|
-
|
|
323
|
+
"description": "Public key when `type` is `supabase`."
|
|
324
|
+
},
|
|
325
|
+
"provider": {
|
|
326
|
+
"type": "string",
|
|
327
|
+
"description": "OAuth provider for silent sign-in, such as `google`. When omitted, the shell uses the first `backend.login.oauthProviders` entry."
|
|
313
328
|
}
|
|
314
329
|
},
|
|
315
|
-
"required": ["
|
|
316
|
-
"additionalProperties": false
|
|
330
|
+
"required": ["url"],
|
|
331
|
+
"additionalProperties": false,
|
|
332
|
+
"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
333
|
},
|
|
318
|
-
"
|
|
334
|
+
"BackendType": {
|
|
335
|
+
"type": "string",
|
|
336
|
+
"enum": ["shellui", "supabase"],
|
|
337
|
+
"description": "Supported backend providers for auth/API communication."
|
|
338
|
+
},
|
|
339
|
+
"EmailConfig": {
|
|
319
340
|
"type": "object",
|
|
320
341
|
"properties": {
|
|
321
|
-
"
|
|
322
|
-
"
|
|
323
|
-
|
|
324
|
-
"type": "string"
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
"$ref": "#/definitions/LocalizedString"
|
|
328
|
-
}
|
|
329
|
-
],
|
|
330
|
-
"description": "Section title shown in the admin sidebar below Dashboard."
|
|
342
|
+
"url": {
|
|
343
|
+
"type": "string",
|
|
344
|
+
"description": "Base URL of email-service. Default: `https://email.shellui.com` when `email` is set and this is omitted. Local: `http://localhost:8003`."
|
|
331
345
|
},
|
|
332
|
-
"
|
|
333
|
-
"type": "
|
|
334
|
-
"
|
|
335
|
-
"$ref": "#/definitions/NavigationItem"
|
|
336
|
-
},
|
|
337
|
-
"description": "Flat list of navigation items (same shape as top-level `navigation` items). Order is preserved in the admin sidebar."
|
|
346
|
+
"showInAdmin": {
|
|
347
|
+
"type": "boolean",
|
|
348
|
+
"description": "When false, hide Admin → Email. Default: true (shown) when `email` is set."
|
|
338
349
|
}
|
|
339
350
|
},
|
|
340
|
-
"required": ["title", "navigation"],
|
|
341
351
|
"additionalProperties": false,
|
|
342
|
-
"description": "
|
|
352
|
+
"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`."
|
|
343
353
|
},
|
|
344
354
|
"StorageConfig": {
|
|
345
355
|
"type": "object",
|
|
@@ -361,17 +371,6 @@
|
|
|
361
371
|
"additionalProperties": false,
|
|
362
372
|
"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
373
|
},
|
|
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
374
|
"HostingConfig": {
|
|
376
375
|
"type": "object",
|
|
377
376
|
"properties": {
|
|
@@ -400,20 +399,70 @@
|
|
|
400
399
|
"additionalProperties": false,
|
|
401
400
|
"description": "Optional hosting-service wiring for `shellui deploy` preview uploads. Preview sites expire after 7 days unless redeployed to the same slug."
|
|
402
401
|
},
|
|
403
|
-
"
|
|
402
|
+
"NavigationGroup": {
|
|
404
403
|
"type": "object",
|
|
405
404
|
"properties": {
|
|
406
|
-
"
|
|
405
|
+
"title": {
|
|
406
|
+
"anyOf": [
|
|
407
|
+
{
|
|
408
|
+
"type": "string"
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
"$ref": "#/definitions/LocalizedString"
|
|
412
|
+
}
|
|
413
|
+
]
|
|
414
|
+
},
|
|
415
|
+
"items": {
|
|
416
|
+
"type": "array",
|
|
417
|
+
"items": {
|
|
418
|
+
"$ref": "#/definitions/NavigationItem"
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
"position": {
|
|
407
422
|
"type": "string",
|
|
408
|
-
"
|
|
423
|
+
"enum": ["start", "end"],
|
|
424
|
+
"description": "Sidebar position: 'start' (default) or 'end'. End groups are rendered in the sidebar footer."
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
"required": ["title", "items"],
|
|
428
|
+
"additionalProperties": false
|
|
429
|
+
},
|
|
430
|
+
"AdministrationConfig": {
|
|
431
|
+
"type": "object",
|
|
432
|
+
"properties": {
|
|
433
|
+
"title": {
|
|
434
|
+
"anyOf": [
|
|
435
|
+
{
|
|
436
|
+
"type": "string"
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
"$ref": "#/definitions/LocalizedString"
|
|
440
|
+
}
|
|
441
|
+
],
|
|
442
|
+
"description": "Section title shown in the admin sidebar below Dashboard."
|
|
409
443
|
},
|
|
410
|
-
"
|
|
444
|
+
"navigation": {
|
|
445
|
+
"type": "array",
|
|
446
|
+
"items": {
|
|
447
|
+
"$ref": "#/definitions/NavigationItem"
|
|
448
|
+
},
|
|
449
|
+
"description": "Flat list of navigation items (same shape as top-level `navigation` items). Order is preserved in the admin sidebar."
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
"required": ["title", "navigation"],
|
|
453
|
+
"additionalProperties": false,
|
|
454
|
+
"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)."
|
|
455
|
+
},
|
|
456
|
+
"AiConfig": {
|
|
457
|
+
"type": "object",
|
|
458
|
+
"properties": {
|
|
459
|
+
"enabled": {
|
|
411
460
|
"type": "boolean",
|
|
412
|
-
"description": "
|
|
461
|
+
"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
462
|
}
|
|
414
463
|
},
|
|
415
464
|
"additionalProperties": false,
|
|
416
|
-
"description": "
|
|
465
|
+
"description": "On-device AI product feature (Ollama + browser / WebLLM). Distinct from the per-user Settings → AI “Allow apps to use AI” toggle."
|
|
417
466
|
},
|
|
418
467
|
"ThemeRef": {
|
|
419
468
|
"anyOf": [
|
|
@@ -896,17 +945,6 @@
|
|
|
896
945
|
"additionalProperties": false,
|
|
897
946
|
"description": "Sentry error reporting configuration. Only used in production; ignored in dev."
|
|
898
947
|
},
|
|
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
948
|
"BackendConfig": {
|
|
911
949
|
"type": "object",
|
|
912
950
|
"properties": {
|
|
@@ -947,11 +985,6 @@
|
|
|
947
985
|
"additionalProperties": false,
|
|
948
986
|
"description": "Backend API configuration."
|
|
949
987
|
},
|
|
950
|
-
"BackendType": {
|
|
951
|
-
"type": "string",
|
|
952
|
-
"enum": ["shellui", "supabase"],
|
|
953
|
-
"description": "Supported backend providers for auth/API communication."
|
|
954
|
-
},
|
|
955
988
|
"BackendLoginConfig": {
|
|
956
989
|
"type": "object",
|
|
957
990
|
"properties": {
|
|
@@ -986,6 +1019,17 @@
|
|
|
986
1019
|
"enum": ["password", "oauth", "magic_link", "web3"],
|
|
987
1020
|
"description": "Supported auth login methods that can be declared in config."
|
|
988
1021
|
},
|
|
1022
|
+
"AuthConfig": {
|
|
1023
|
+
"type": "object",
|
|
1024
|
+
"properties": {
|
|
1025
|
+
"desktopScheme": {
|
|
1026
|
+
"type": "string",
|
|
1027
|
+
"description": "Custom URL scheme for Tauri sign-in, such as `shellui-playground`. Lowercase. Not `http`, `https`, or another browser scheme."
|
|
1028
|
+
}
|
|
1029
|
+
},
|
|
1030
|
+
"additionalProperties": false,
|
|
1031
|
+
"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`."
|
|
1032
|
+
},
|
|
989
1033
|
"SecurityConfig": {
|
|
990
1034
|
"type": "object",
|
|
991
1035
|
"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
|
-
|
|
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. */
|
|
@@ -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
|
+
}
|
|
@@ -11,6 +11,8 @@ import urls from '../../constants/urls';
|
|
|
11
11
|
import { useConfig } from '../config/useConfig';
|
|
12
12
|
import { useIsTauriRuntime } from '../layouts/chrome/runtime';
|
|
13
13
|
import { isShellSettingsFrameMessage } from '../security/trustedFrames';
|
|
14
|
+
import { endAppBackendSessions } from './appBackend/appBackendSessions';
|
|
15
|
+
import { isSilentAuthCallbackFrame } from './appBackend/silentSignIn';
|
|
14
16
|
import { createAuthBackend } from './backends';
|
|
15
17
|
import { AuthContext, type AuthContextValue, type OAuthCallbackResult } from './hooks/useAuth';
|
|
16
18
|
import type { AuthEvent, AuthSession, AuthUser, UserPreferences } from './types';
|
|
@@ -196,6 +198,16 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
196
198
|
return;
|
|
197
199
|
}
|
|
198
200
|
|
|
201
|
+
// The hidden frame that finishes sign-in for another identity server must
|
|
202
|
+
// not read or write the shell session (sessionStorage is shared).
|
|
203
|
+
if (isSilentAuthCallbackFrame()) {
|
|
204
|
+
if (!cancelled) {
|
|
205
|
+
setSession(null);
|
|
206
|
+
setIsLoading(false);
|
|
207
|
+
}
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
199
211
|
const isIframe = window.parent !== window;
|
|
200
212
|
const now = Math.floor(Date.now() / 1000);
|
|
201
213
|
const sessionFromHash = backend.readSessionFromCallback(window.location.hash, now);
|
|
@@ -391,7 +403,12 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
391
403
|
});
|
|
392
404
|
return true;
|
|
393
405
|
}
|
|
394
|
-
backend.startOAuth(provider, redirectPath, oauthClientId)
|
|
406
|
+
void Promise.resolve(backend.startOAuth(provider, redirectPath, oauthClientId)).catch(
|
|
407
|
+
(err) => {
|
|
408
|
+
setError(err instanceof Error ? err.message : 'Unable to start OAuth login.');
|
|
409
|
+
setErrorCode(err instanceof AuthRequestError ? err.code : null);
|
|
410
|
+
},
|
|
411
|
+
);
|
|
395
412
|
return true;
|
|
396
413
|
} catch (err) {
|
|
397
414
|
setError(err instanceof Error ? err.message : 'Unable to start OAuth login.');
|
|
@@ -624,6 +641,12 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
624
641
|
// Even if API sign-out fails, still clear local session.
|
|
625
642
|
}
|
|
626
643
|
|
|
644
|
+
try {
|
|
645
|
+
await endAppBackendSessions();
|
|
646
|
+
} catch {
|
|
647
|
+
// App-server sign-out is best effort. The shell session still clears.
|
|
648
|
+
}
|
|
649
|
+
|
|
627
650
|
clearStoredAuthSession();
|
|
628
651
|
setSession(null);
|
|
629
652
|
setAuthEvent(null);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { useConfig } from '../../config/useConfig';
|
|
3
|
+
import { useAuth } from '../hooks/useAuth';
|
|
4
|
+
import {
|
|
5
|
+
endAppBackendSessions,
|
|
6
|
+
ensureConfiguredAppBackends,
|
|
7
|
+
resetAppBackendSilentAttempts,
|
|
8
|
+
} from './appBackendSessions';
|
|
9
|
+
import { listDistinctAppBackends } from './identity';
|
|
10
|
+
import { isSilentAuthCallbackFrame } from './silentSignIn';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* While the shell has a session, sign in to each embedded app's identity server.
|
|
14
|
+
* The shell session itself is unchanged.
|
|
15
|
+
*/
|
|
16
|
+
export function AppBackendSessionHost() {
|
|
17
|
+
const { config } = useConfig();
|
|
18
|
+
const { session, isLoading } = useAuth();
|
|
19
|
+
const signedInUserRef = useRef<string | null>(null);
|
|
20
|
+
const configRef = useRef(config);
|
|
21
|
+
configRef.current = config;
|
|
22
|
+
|
|
23
|
+
const identityKey = useMemo(
|
|
24
|
+
() =>
|
|
25
|
+
listDistinctAppBackends(config)
|
|
26
|
+
.map((identity) => `${identity.key}|${identity.provider ?? ''}`)
|
|
27
|
+
.join('\n'),
|
|
28
|
+
[config],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const signedIn = Boolean(session?.accessToken);
|
|
32
|
+
const userId = session?.userId ?? null;
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (typeof window === 'undefined' || window.parent !== window) return;
|
|
36
|
+
if (isSilentAuthCallbackFrame()) return;
|
|
37
|
+
if (isLoading) return;
|
|
38
|
+
if (!signedIn) {
|
|
39
|
+
void endAppBackendSessions();
|
|
40
|
+
signedInUserRef.current = null;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (signedInUserRef.current !== userId) {
|
|
44
|
+
signedInUserRef.current = userId;
|
|
45
|
+
resetAppBackendSilentAttempts();
|
|
46
|
+
}
|
|
47
|
+
let cancelled = false;
|
|
48
|
+
void (async () => {
|
|
49
|
+
if (cancelled) return;
|
|
50
|
+
await ensureConfiguredAppBackends(configRef.current, { allowSilent: true });
|
|
51
|
+
})();
|
|
52
|
+
return () => {
|
|
53
|
+
cancelled = true;
|
|
54
|
+
};
|
|
55
|
+
}, [identityKey, isLoading, signedIn, userId]);
|
|
56
|
+
|
|
57
|
+
return null;
|
|
58
|
+
}
|