@xwiki/cristal-electron-main 0.13.0 → 0.14.0
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/CHANGELOG.md +14 -0
- package/dist/index.cjs +28 -20
- package/package.json +9 -8
- package/src/index.ts +9 -2
- package/src/security-restrictions.ts +20 -5
- package/tsconfig.json +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xwiki/cristal-electron-main",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "LGPL 2.1",
|
|
5
5
|
"author": "XWiki Org Community <contact@xwiki.org>",
|
|
6
6
|
"homepage": "https://cristal.xwiki.org/",
|
|
@@ -13,15 +13,16 @@
|
|
|
13
13
|
"url": "https://jira.xwiki.org/projects/CRISTAL/"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"electron": "
|
|
17
|
-
"@xwiki/cristal-browser-electron": "0.
|
|
18
|
-
"@xwiki/cristal-electron-
|
|
19
|
-
"@xwiki/cristal-electron-storage": "0.
|
|
16
|
+
"electron": "34.0.0",
|
|
17
|
+
"@xwiki/cristal-browser-electron": "0.14.0",
|
|
18
|
+
"@xwiki/cristal-configuration-electron-main": "0.14.0",
|
|
19
|
+
"@xwiki/cristal-electron-storage": "0.14.0",
|
|
20
|
+
"@xwiki/cristal-electron-authentication-xwiki-main": "0.14.0"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"@types/node": "22.10.
|
|
23
|
-
"typescript": "5.
|
|
24
|
-
"vite": "6.0.
|
|
23
|
+
"@types/node": "22.10.7",
|
|
24
|
+
"typescript": "5.7.3",
|
|
25
|
+
"vite": "6.0.11"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "tsc --project tsconfig.json && vite build",
|
package/src/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { loadFile } from "./reload";
|
|
|
23
23
|
import "./security-restrictions";
|
|
24
24
|
// @ts-expect-error shouldn't happen, but we need to generate the types for the whole project once.
|
|
25
25
|
import loadBrowser from "@xwiki/cristal-browser-electron/main";
|
|
26
|
+
import { load as loadConfiguration } from "@xwiki/cristal-configuration-electron-main";
|
|
26
27
|
import { load as loadAuthentication } from "@xwiki/cristal-electron-authentication-xwiki-main";
|
|
27
28
|
// @ts-expect-error shouldn't happen, but we need to generate the types for the whole project once.
|
|
28
29
|
import load from "@xwiki/cristal-electron-storage/main";
|
|
@@ -53,16 +54,22 @@ app.on("window-all-closed", () => {
|
|
|
53
54
|
}
|
|
54
55
|
});
|
|
55
56
|
|
|
57
|
+
if (process.env.NODE_ENV !== "development") {
|
|
58
|
+
// Deactivate debug logs when the environment is not explicitly in development mode.
|
|
59
|
+
console.debug = () => {};
|
|
60
|
+
}
|
|
61
|
+
|
|
56
62
|
/**
|
|
57
63
|
* Create the application window when the background process is ready.
|
|
58
64
|
*/
|
|
59
65
|
app
|
|
60
66
|
.whenReady()
|
|
61
|
-
.then(() => {
|
|
62
|
-
load();
|
|
67
|
+
.then(async () => {
|
|
68
|
+
await load();
|
|
63
69
|
restoreOrCreateWindow().then((w) => {
|
|
64
70
|
loadBrowser(w);
|
|
65
71
|
loadAuthentication(w, loadFile);
|
|
72
|
+
loadConfiguration();
|
|
66
73
|
});
|
|
67
74
|
/**
|
|
68
75
|
* @see https://www.electronjs.org/docs/latest/api/app#event-activate-macos Event: 'activate'.
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import { readConfiguration } from "@xwiki/cristal-configuration-electron-main";
|
|
21
22
|
import { app, shell } from "electron";
|
|
22
23
|
import { URL } from "node:url";
|
|
23
24
|
import type { Session } from "electron";
|
|
@@ -32,7 +33,8 @@ type Permission = Parameters<
|
|
|
32
33
|
/**
|
|
33
34
|
* A list of origins that you allow open INSIDE the application and permissions for them.
|
|
34
35
|
*
|
|
35
|
-
* In development mode you need allow open `VITE_DEV_SERVER_URL`.
|
|
36
|
+
* In development mode, you need allow open `VITE_DEV_SERVER_URL`.
|
|
37
|
+
* @deprecated the allowed origins and permissions should be derived from the configuration.
|
|
36
38
|
*/
|
|
37
39
|
const ALLOWED_ORIGINS_AND_PERMISSIONS: Map<string, Set<Permission>> = new Map<
|
|
38
40
|
string,
|
|
@@ -69,9 +71,20 @@ app.on("web-contents-created", (_, contents) => {
|
|
|
69
71
|
*
|
|
70
72
|
* @see https://www.electronjs.org/docs/latest/tutorial/security#13-disable-or-limit-navigation
|
|
71
73
|
*/
|
|
74
|
+
const configuration = readConfiguration();
|
|
72
75
|
contents.on("will-navigate", (event, url) => {
|
|
73
76
|
const { origin } = new URL(url);
|
|
74
|
-
|
|
77
|
+
const isAllowedOrigin = Object.values(configuration).some(
|
|
78
|
+
(configuration) => {
|
|
79
|
+
const baseURL = configuration.baseURL;
|
|
80
|
+
if (!baseURL) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return new URL(baseURL).origin == origin;
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (isAllowedOrigin) {
|
|
75
88
|
return;
|
|
76
89
|
}
|
|
77
90
|
|
|
@@ -93,6 +106,8 @@ app.on("web-contents-created", (_, contents) => {
|
|
|
93
106
|
(webContents, permission, callback) => {
|
|
94
107
|
const { origin } = new URL(webContents.getURL());
|
|
95
108
|
|
|
109
|
+
// FIXME: this control is currently based on a fixed set of URLs, but seems also unused. We need to check more
|
|
110
|
+
// closely if this check is needed.
|
|
96
111
|
const permissionGranted =
|
|
97
112
|
!!ALLOWED_ORIGINS_AND_PERMISSIONS.get(origin)?.has(permission);
|
|
98
113
|
callback(permissionGranted);
|
|
@@ -108,9 +123,9 @@ app.on("web-contents-created", (_, contents) => {
|
|
|
108
123
|
/**
|
|
109
124
|
* Hyperlinks leading to allowed sites are opened in the default browser.
|
|
110
125
|
*
|
|
111
|
-
* The creation of new `webContents` is a common attack vector. Attackers attempt to convince the app to create new
|
|
112
|
-
* frames, or other renderer processes with more privileges than they had before; or with pages opened that
|
|
113
|
-
* You should deny any unexpected window creation.
|
|
126
|
+
* The creation of new `webContents` is a common attack vector. Attackers attempt to convince the app to create new
|
|
127
|
+
* windows, frames, or other renderer processes with more privileges than they had before; or with pages opened that
|
|
128
|
+
* they couldn't open before. You should deny any unexpected window creation.
|
|
114
129
|
*
|
|
115
130
|
* @see https://www.electronjs.org/docs/latest/tutorial/security#14-disable-or-limit-creation-of-new-windows
|
|
116
131
|
* @see https://www.electronjs.org/docs/latest/tutorial/security#15-do-not-use-openexternal-with-untrusted-content
|