Skip to content

Commit 28fcaa9

Browse files
committed
Upgrade to latest electron. Add some form of csp.
1 parent 442e490 commit 28fcaa9

File tree

4 files changed

+34
-217
lines changed

4 files changed

+34
-217
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "dive-downloader",
33
"description": "Download dives from any divecomputer with an electron app",
44
"productName": "dive-downloader",
5-
"version": "0.1.5",
5+
"version": "0.1.6",
66
"main": ".webpack/main",
77
"scripts": {
88
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
@@ -96,7 +96,7 @@
9696
"@typescript-eslint/parser": "^6.4.0",
9797
"@vercel/webpack-asset-relocator-loader": "^1.7.3",
9898
"css-loader": "^6.7.1",
99-
"electron": "^19.0.10",
99+
"electron": "^26.0.0",
100100
"eslint": "^8.21.0",
101101
"eslint-config-prettier": "^9.0.0",
102102
"eslint-plugin-compat": "^4.0.2",

src/main/main.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import path from 'path';
1212
import { app, BrowserWindow, shell, ipcMain, dialog, session } from 'electron';
1313
import MenuBuilder from './menu';
14+
import { serviceOrigin } from '../services/api/config';
1415

1516
declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
1617

@@ -79,11 +80,17 @@ const createWindow = async () => {
7980
mainWindow = null;
8081
});
8182

83+
const cspConnectSrc = ["'self'", serviceOrigin];
84+
const cspDefaultSrc = ["'self'", 'data:', "'unsafe-inline'"];
85+
if (isDebug) {
86+
cspDefaultSrc.push("'unsafe-eval'")
87+
}
88+
8289
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
8390
callback({
8491
responseHeaders: {
8592
...details.responseHeaders,
86-
'Content-Security-Policy': ['default-src \'self\' \'unsafe-inline\' \'unsafe-eval\' data: https://api.dive.littledev.nl http://api.littledivelog.local']
93+
'Content-Security-Policy': [`default-src ${cspDefaultSrc.join(' ')}; connect-src ${cspConnectSrc.join(' ')}`]
8794
}
8895
})
8996
})

src/services/api/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const useProduction = process.env.NODE_ENV === 'production';
22

3-
export const serviceUrl = useProduction
4-
? 'https://api.dive.littledev.nl/api'
5-
: 'http://api.littledivelog.local/api';
3+
export const serviceOrigin = useProduction
4+
? 'https://api.dive.littledev.nl'
5+
: 'http://api.littledivelog.local'
6+
7+
export const serviceUrl = `${serviceOrigin}/api`;
68

79
export default serviceUrl;

0 commit comments

Comments
 (0)