Skip to content

Commit

Permalink
Upgrade to latest electron. Add some form of csp.
Browse files Browse the repository at this point in the history
  • Loading branch information
blackshadev committed Aug 15, 2023
1 parent 442e490 commit 28fcaa9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 217 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dive-downloader",
"description": "Download dives from any divecomputer with an electron app",
"productName": "dive-downloader",
"version": "0.1.5",
"version": "0.1.6",
"main": ".webpack/main",
"scripts": {
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
Expand Down Expand Up @@ -96,7 +96,7 @@
"@typescript-eslint/parser": "^6.4.0",
"@vercel/webpack-asset-relocator-loader": "^1.7.3",
"css-loader": "^6.7.1",
"electron": "^19.0.10",
"electron": "^26.0.0",
"eslint": "^8.21.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-compat": "^4.0.2",
Expand Down
9 changes: 8 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import path from 'path';
import { app, BrowserWindow, shell, ipcMain, dialog, session } from 'electron';
import MenuBuilder from './menu';
import { serviceOrigin } from '../services/api/config';

declare const MAIN_WINDOW_WEBPACK_ENTRY: string;

Expand Down Expand Up @@ -79,11 +80,17 @@ const createWindow = async () => {
mainWindow = null;
});

const cspConnectSrc = ["'self'", serviceOrigin];
const cspDefaultSrc = ["'self'", 'data:', "'unsafe-inline'"];
if (isDebug) {
cspDefaultSrc.push("'unsafe-eval'")
}

session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': ['default-src \'self\' \'unsafe-inline\' \'unsafe-eval\' data: https://api.dive.littledev.nl http://api.littledivelog.local']
'Content-Security-Policy': [`default-src ${cspDefaultSrc.join(' ')}; connect-src ${cspConnectSrc.join(' ')}`]
}
})
})
Expand Down
8 changes: 5 additions & 3 deletions src/services/api/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const useProduction = process.env.NODE_ENV === 'production';

export const serviceUrl = useProduction
? 'https://api.dive.littledev.nl/api'
: 'http://api.littledivelog.local/api';
export const serviceOrigin = useProduction
? 'https://api.dive.littledev.nl'
: 'http://api.littledivelog.local'

export const serviceUrl = `${serviceOrigin}/api`;

export default serviceUrl;
Loading

0 comments on commit 28fcaa9

Please sign in to comment.