Skip to content

Commit edad15c

Browse files
committed
Add security quick wins and lint workflow
1 parent 826f55b commit edad15c

8 files changed

Lines changed: 573 additions & 28 deletions

File tree

electron.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ const crypto = require('crypto');
88
const https = require('https');
99

1010
let mainWindow;
11+
12+
function isSafeExternalUrl(url) {
13+
try {
14+
const parsed = new URL(url);
15+
return parsed.protocol === 'https:' || parsed.protocol === 'http:';
16+
} catch {
17+
return false;
18+
}
19+
}
20+
1121
let proxyProcess;
1222

1323
// ============================================================
@@ -69,7 +79,9 @@ function createWindow() {
6979

7080
// Link esterni si aprono nel browser di sistema
7181
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
72-
shell.openExternal(url);
82+
if (isSafeExternalUrl(url)) {
83+
shell.openExternal(url);
84+
}
7385
return { action: 'deny' };
7486
});
7587

@@ -568,7 +580,7 @@ ipcMain.handle('check-for-updates', async () => {
568580

569581
// Apri link esterno
570582
ipcMain.handle('open-external', async (event, url) => {
571-
if (typeof url === 'string' && (url.startsWith('https://') || url.startsWith('http://'))) {
583+
if (typeof url === 'string' && isSafeExternalUrl(url)) {
572584
await shell.openExternal(url);
573585
return { success: true };
574586
}

eslint.config.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ import reactRefresh from 'eslint-plugin-react-refresh'
55
import { defineConfig, globalIgnores } from 'eslint/config'
66

77
export default defineConfig([
8-
globalIgnores(['dist']),
8+
globalIgnores([
9+
'dist/**',
10+
'release/**',
11+
'node_modules/**',
12+
'src.backup-*/**',
13+
'src/**/*.backup*',
14+
'src/**/*backup*',
15+
'tools/**',
16+
]),
17+
918
{
10-
files: ['**/*.{js,jsx}'],
19+
files: ['src/**/*.{js,jsx}'],
1120
extends: [
1221
js.configs.recommended,
1322
reactHooks.configs.flat.recommended,
@@ -23,7 +32,30 @@ export default defineConfig([
2332
},
2433
},
2534
rules: {
26-
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
35+
'no-unused-vars': ['warn', { varsIgnorePattern: '^[A-Z_]', argsIgnorePattern: '^_' }],
36+
'no-empty': 'warn',
37+
'no-control-regex': 'off',
38+
'react-hooks/exhaustive-deps': 'warn',
39+
'react-hooks/set-state-in-effect': 'off',
40+
},
41+
},
42+
43+
{
44+
files: ['electron.js', 'preload.js', 'server.js', 'vite.config.js'],
45+
extends: [js.configs.recommended],
46+
languageOptions: {
47+
ecmaVersion: 2020,
48+
globals: {
49+
...globals.node,
50+
},
51+
parserOptions: {
52+
ecmaVersion: 'latest',
53+
sourceType: 'commonjs',
54+
},
55+
},
56+
rules: {
57+
'no-unused-vars': ['warn', { varsIgnorePattern: '^[A-Z_]', argsIgnorePattern: '^_' }],
58+
'no-useless-escape': 'warn',
2759
},
2860
},
2961
])

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<head>
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6+
<meta
7+
http-equiv="Content-Security-Policy"
8+
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' http://127.0.0.1:3001 http://localhost:3001 http://127.0.0.1:11434 http://localhost:11434; object-src 'none'; base-uri 'self';"
9+
/>
610
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
711
<title>sysai-assistant</title>
812
</head>

0 commit comments

Comments
 (0)