eslint-plugin-secure-coding 3.4.2 → 3.4.4
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 -3
- package/src/index.js +1 -134
- package/src/oxlint.js +1 -3
- package/src/rules/detect-non-literal-regexp/index.js +1 -329
- package/src/rules/detect-object-injection/index.js +1 -691
- package/src/rules/detect-weak-password-validation/index.js +1 -54
- package/src/rules/no-directive-injection/index.js +1 -416
- package/src/rules/no-electron-security-issues/index.js +1 -385
- package/src/rules/no-format-string-injection/index.js +1 -565
- package/src/rules/no-graphql-injection/index.js +1 -612
- package/src/rules/no-hardcoded-credentials/index.js +1 -658
- package/src/rules/no-hardcoded-session-tokens/index.js +1 -56
- package/src/rules/no-improper-sanitization/index.js +1 -391
- package/src/rules/no-improper-type-validation/index.js +1 -422
- package/src/rules/no-insecure-comparison/index.js +1 -249
- package/src/rules/no-ldap-injection/index.js +1 -403
- package/src/rules/no-missing-authentication/index.js +1 -282
- package/src/rules/no-pii-in-logs/index.js +1 -63
- package/src/rules/no-privilege-escalation/index.js +1 -282
- package/src/rules/no-redos-vulnerable-regex/index.js +0 -0
- package/src/rules/no-sensitive-data-exposure/index.js +1 -249
- package/src/rules/no-template-injection/index.js +1 -84
- package/src/rules/no-unchecked-loop-condition/index.js +1 -541
- package/src/rules/no-unlimited-resource-allocation/index.js +1 -554
- package/src/rules/no-unsafe-deserialization/index.js +1 -497
- package/src/rules/no-unsafe-regex-construction/index.js +1 -275
- package/src/rules/no-weak-password-recovery/index.js +1 -382
- package/src/rules/no-xpath-injection/index.js +1 -431
- package/src/rules/no-xxe-injection/index.js +1 -230
- package/src/rules/require-backend-authorization/index.js +1 -58
- package/src/rules/require-secure-defaults/index.js +1 -41
- package/src/types/index.js +1 -2
|
@@ -1,385 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noElectronSecurityIssues = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
const eslint_devkit_3 = require("@interlace/eslint-devkit");
|
|
7
|
-
exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
|
|
8
|
-
name: 'no-electron-security-issues',
|
|
9
|
-
meta: {
|
|
10
|
-
type: 'problem',
|
|
11
|
-
docs: {
|
|
12
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-electron-security-issues.md',
|
|
13
|
-
description: 'Detects Electron security vulnerabilities and insecure configurations',
|
|
14
|
-
cwe: 'CWE-16',
|
|
15
|
-
},
|
|
16
|
-
hasSuggestions: true,
|
|
17
|
-
messages: {
|
|
18
|
-
electronSecurityIssue: (0, eslint_devkit_2.formatLLMMessage)({
|
|
19
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
20
|
-
issueName: 'Electron Security Issue',
|
|
21
|
-
cwe: 'CWE-16',
|
|
22
|
-
description: 'Electron security vulnerability detected',
|
|
23
|
-
severity: '{{severity}}',
|
|
24
|
-
fix: '{{safeAlternative}}',
|
|
25
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security',
|
|
26
|
-
}),
|
|
27
|
-
nodeIntegrationEnabled: (0, eslint_devkit_2.formatLLMMessage)({
|
|
28
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
29
|
-
issueName: 'Node Integration Enabled',
|
|
30
|
-
cwe: 'CWE-16',
|
|
31
|
-
description: 'nodeIntegration enabled allows Node.js access in renderer',
|
|
32
|
-
severity: 'CRITICAL',
|
|
33
|
-
fix: 'Set nodeIntegration: false and use secure preload scripts',
|
|
34
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content',
|
|
35
|
-
}),
|
|
36
|
-
contextIsolationDisabled: (0, eslint_devkit_2.formatLLMMessage)({
|
|
37
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
38
|
-
issueName: 'Context Isolation Disabled',
|
|
39
|
-
cwe: 'CWE-16',
|
|
40
|
-
description: 'contextIsolation disabled removes security boundary',
|
|
41
|
-
severity: 'CRITICAL',
|
|
42
|
-
fix: 'Enable contextIsolation and use preload scripts',
|
|
43
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/context-isolation',
|
|
44
|
-
}),
|
|
45
|
-
webSecurityDisabled: (0, eslint_devkit_2.formatLLMMessage)({
|
|
46
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
47
|
-
issueName: 'Web Security Disabled',
|
|
48
|
-
cwe: 'CWE-16',
|
|
49
|
-
description: 'webSecurity disabled removes CORS and security protections',
|
|
50
|
-
severity: 'HIGH',
|
|
51
|
-
fix: 'Keep webSecurity enabled',
|
|
52
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security#6-define-a-content-security-policy',
|
|
53
|
-
}),
|
|
54
|
-
insecureContentEnabled: (0, eslint_devkit_2.formatLLMMessage)({
|
|
55
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
56
|
-
issueName: 'Insecure Content Enabled',
|
|
57
|
-
cwe: 'CWE-16',
|
|
58
|
-
description: 'allowRunningInsecureContent allows mixed content',
|
|
59
|
-
severity: 'MEDIUM',
|
|
60
|
-
fix: 'Set allowRunningInsecureContent: false',
|
|
61
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security#5-do-not-disable-websecurity',
|
|
62
|
-
}),
|
|
63
|
-
unsafePreloadScript: (0, eslint_devkit_2.formatLLMMessage)({
|
|
64
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
65
|
-
issueName: 'Unsafe Preload Script',
|
|
66
|
-
cwe: 'CWE-16',
|
|
67
|
-
description: 'Preload script may expose sensitive APIs',
|
|
68
|
-
severity: 'HIGH',
|
|
69
|
-
fix: 'Use minimal, secure preload scripts',
|
|
70
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content',
|
|
71
|
-
}),
|
|
72
|
-
directNodeAccess: (0, eslint_devkit_2.formatLLMMessage)({
|
|
73
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
74
|
-
issueName: 'Direct Node Access',
|
|
75
|
-
cwe: 'CWE-16',
|
|
76
|
-
description: 'Direct access to Node.js APIs in renderer process',
|
|
77
|
-
severity: 'HIGH',
|
|
78
|
-
fix: 'Access Node.js APIs only through secure IPC channels',
|
|
79
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content',
|
|
80
|
-
}),
|
|
81
|
-
insecureIpcPattern: (0, eslint_devkit_2.formatLLMMessage)({
|
|
82
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
83
|
-
issueName: 'Insecure IPC Pattern',
|
|
84
|
-
cwe: 'CWE-16',
|
|
85
|
-
description: 'IPC communication lacks proper validation',
|
|
86
|
-
severity: 'MEDIUM',
|
|
87
|
-
fix: 'Validate IPC messages and restrict channels',
|
|
88
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security#7-do-not-use-the-ipc-transport-for-sensitive-data',
|
|
89
|
-
}),
|
|
90
|
-
missingSandbox: (0, eslint_devkit_2.formatLLMMessage)({
|
|
91
|
-
icon: eslint_devkit_2.MessageIcons.SECURITY,
|
|
92
|
-
issueName: 'Missing Sandbox',
|
|
93
|
-
cwe: 'CWE-16',
|
|
94
|
-
description: 'BrowserWindow not sandboxed',
|
|
95
|
-
severity: 'MEDIUM',
|
|
96
|
-
fix: 'Enable sandbox for untrusted content',
|
|
97
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/sandbox',
|
|
98
|
-
}),
|
|
99
|
-
enableSecurityFeatures: (0, eslint_devkit_2.formatLLMMessage)({
|
|
100
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
101
|
-
issueName: 'Enable Security Features',
|
|
102
|
-
description: 'Enable Electron security features',
|
|
103
|
-
severity: 'LOW',
|
|
104
|
-
fix: 'Set contextIsolation: true, nodeIntegration: false',
|
|
105
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security',
|
|
106
|
-
}),
|
|
107
|
-
useContextIsolation: (0, eslint_devkit_2.formatLLMMessage)({
|
|
108
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
109
|
-
issueName: 'Use Context Isolation',
|
|
110
|
-
description: 'Use context isolation for security',
|
|
111
|
-
severity: 'LOW',
|
|
112
|
-
fix: 'Enable contextIsolation in BrowserWindow options',
|
|
113
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/context-isolation',
|
|
114
|
-
}),
|
|
115
|
-
securePreloadScripts: (0, eslint_devkit_2.formatLLMMessage)({
|
|
116
|
-
icon: eslint_devkit_2.MessageIcons.INFO,
|
|
117
|
-
issueName: 'Secure Preload Scripts',
|
|
118
|
-
description: 'Use secure preload scripts',
|
|
119
|
-
severity: 'LOW',
|
|
120
|
-
fix: 'Limit APIs exposed in preload scripts',
|
|
121
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content',
|
|
122
|
-
}),
|
|
123
|
-
strategySecureDefaults: (0, eslint_devkit_2.formatLLMMessage)({
|
|
124
|
-
icon: eslint_devkit_2.MessageIcons.STRATEGY,
|
|
125
|
-
issueName: 'Secure Defaults Strategy',
|
|
126
|
-
description: 'Use secure defaults for Electron applications',
|
|
127
|
-
severity: 'LOW',
|
|
128
|
-
fix: 'Start with secure configuration and relax only when necessary',
|
|
129
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security',
|
|
130
|
-
}),
|
|
131
|
-
strategyProcessSeparation: (0, eslint_devkit_2.formatLLMMessage)({
|
|
132
|
-
icon: eslint_devkit_2.MessageIcons.STRATEGY,
|
|
133
|
-
issueName: 'Process Separation Strategy',
|
|
134
|
-
description: 'Separate main and renderer processes properly',
|
|
135
|
-
severity: 'LOW',
|
|
136
|
-
fix: 'Keep Node.js APIs in main process, use IPC for communication',
|
|
137
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/application-architecture',
|
|
138
|
-
}),
|
|
139
|
-
strategyInputValidation: (0, eslint_devkit_2.formatLLMMessage)({
|
|
140
|
-
icon: eslint_devkit_2.MessageIcons.STRATEGY,
|
|
141
|
-
issueName: 'Input Validation Strategy',
|
|
142
|
-
description: 'Validate all inputs in Electron applications',
|
|
143
|
-
severity: 'LOW',
|
|
144
|
-
fix: 'Validate IPC messages and user inputs',
|
|
145
|
-
documentationLink: 'https://electronjs.org/docs/tutorial/security#7-do-not-use-the-ipc-transport-for-sensitive-data',
|
|
146
|
-
})
|
|
147
|
-
},
|
|
148
|
-
schema: [
|
|
149
|
-
{
|
|
150
|
-
type: 'object',
|
|
151
|
-
properties: {
|
|
152
|
-
allowInDev: {
|
|
153
|
-
type: 'boolean',
|
|
154
|
-
default: false,
|
|
155
|
-
description: 'Allow insecure settings in development'
|
|
156
|
-
},
|
|
157
|
-
safePreloadPatterns: {
|
|
158
|
-
type: 'array',
|
|
159
|
-
items: { type: 'string' },
|
|
160
|
-
default: ['contextBridge', 'ipcRenderer'],
|
|
161
|
-
},
|
|
162
|
-
allowedIpcChannels: {
|
|
163
|
-
type: 'array',
|
|
164
|
-
items: { type: 'string' },
|
|
165
|
-
default: [],
|
|
166
|
-
},
|
|
167
|
-
trustedSanitizers: {
|
|
168
|
-
type: 'array',
|
|
169
|
-
items: { type: 'string' },
|
|
170
|
-
default: [],
|
|
171
|
-
description: 'Additional function names to consider as safe',
|
|
172
|
-
},
|
|
173
|
-
trustedAnnotations: {
|
|
174
|
-
type: 'array',
|
|
175
|
-
items: { type: 'string' },
|
|
176
|
-
default: [],
|
|
177
|
-
description: 'Additional JSDoc annotations to consider as safe markers',
|
|
178
|
-
},
|
|
179
|
-
strictMode: {
|
|
180
|
-
type: 'boolean',
|
|
181
|
-
default: false,
|
|
182
|
-
description: 'Disable all false positive detection (strict mode)',
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
additionalProperties: false,
|
|
186
|
-
},
|
|
187
|
-
],
|
|
188
|
-
},
|
|
189
|
-
defaultOptions: [
|
|
190
|
-
{
|
|
191
|
-
allowInDev: false,
|
|
192
|
-
safePreloadPatterns: ['contextBridge', 'ipcRenderer'],
|
|
193
|
-
allowedIpcChannels: [],
|
|
194
|
-
trustedSanitizers: [],
|
|
195
|
-
trustedAnnotations: [],
|
|
196
|
-
strictMode: false,
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
create(context) {
|
|
200
|
-
const options = context.options[0] || {};
|
|
201
|
-
const { allowedIpcChannels = [], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
|
|
202
|
-
const filename = context.filename;
|
|
203
|
-
const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
|
|
204
|
-
trustedSanitizers,
|
|
205
|
-
trustedAnnotations,
|
|
206
|
-
trustedOrmPatterns: [],
|
|
207
|
-
strictMode,
|
|
208
|
-
});
|
|
209
|
-
const isBrowserWindowCreation = (node) => {
|
|
210
|
-
return node.callee.type === 'Identifier' &&
|
|
211
|
-
node.callee.name === 'BrowserWindow';
|
|
212
|
-
};
|
|
213
|
-
const checkBrowserWindowOptions = (optionsNode) => {
|
|
214
|
-
for (const prop of optionsNode.properties) {
|
|
215
|
-
if (prop.type === 'Property' &&
|
|
216
|
-
prop.key.type === 'Identifier') {
|
|
217
|
-
const key = prop.key.name;
|
|
218
|
-
const value = prop.value;
|
|
219
|
-
if (['nodeIntegration', 'contextIsolation', 'webSecurity', 'allowRunningInsecureContent', 'sandbox'].includes(key)) {
|
|
220
|
-
if (value.type === 'Literal') {
|
|
221
|
-
const isInsecure = ((key === 'nodeIntegration' && value.value === true) ||
|
|
222
|
-
(key === 'contextIsolation' && value.value === false) ||
|
|
223
|
-
(key === 'webSecurity' && value.value === false) ||
|
|
224
|
-
(key === 'allowRunningInsecureContent' && value.value === true) ||
|
|
225
|
-
(key === 'sandbox' && value.value === false));
|
|
226
|
-
if (isInsecure) {
|
|
227
|
-
if (safetyChecker.isSafe(prop, context)) {
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
const messageId = (key === 'nodeIntegration' ? 'nodeIntegrationEnabled' :
|
|
231
|
-
key === 'contextIsolation' ? 'contextIsolationDisabled' :
|
|
232
|
-
key === 'webSecurity' ? 'webSecurityDisabled' :
|
|
233
|
-
key === 'allowRunningInsecureContent' ? 'insecureContentEnabled' :
|
|
234
|
-
'missingSandbox');
|
|
235
|
-
context.report({
|
|
236
|
-
node: prop,
|
|
237
|
-
messageId,
|
|
238
|
-
data: {
|
|
239
|
-
filePath: filename,
|
|
240
|
-
line: String(prop.loc?.start.line ?? 0),
|
|
241
|
-
},
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
const isIpcCall = (node) => {
|
|
250
|
-
const callee = node.callee;
|
|
251
|
-
if (callee.type === 'MemberExpression' &&
|
|
252
|
-
callee.object.type === 'Identifier' &&
|
|
253
|
-
['ipcMain', 'ipcRenderer'].includes(callee.object.name) &&
|
|
254
|
-
callee.property.type === 'Identifier') {
|
|
255
|
-
return ['send', 'invoke', 'handle', 'on', 'once'].includes(callee.property.name);
|
|
256
|
-
}
|
|
257
|
-
return false;
|
|
258
|
-
};
|
|
259
|
-
const checkIpcCall = (node) => {
|
|
260
|
-
const args = node.arguments;
|
|
261
|
-
if (args.length === 0) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
const channelArg = args[0];
|
|
265
|
-
if (channelArg.type === 'Literal' && typeof channelArg.value === 'string') {
|
|
266
|
-
const channel = channelArg.value;
|
|
267
|
-
if (allowedIpcChannels.length > 0 && !allowedIpcChannels.includes(channel)) {
|
|
268
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
context.report({
|
|
272
|
-
node: channelArg,
|
|
273
|
-
messageId: 'insecureIpcPattern',
|
|
274
|
-
data: {
|
|
275
|
-
filePath: filename,
|
|
276
|
-
line: String(node.loc?.start.line ?? 0),
|
|
277
|
-
},
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
const isRendererFile = () => {
|
|
283
|
-
const fileName = filename.toLowerCase();
|
|
284
|
-
return fileName.includes('renderer') ||
|
|
285
|
-
fileName.includes('preload') ||
|
|
286
|
-
fileName.includes('ui') ||
|
|
287
|
-
fileName.includes('view');
|
|
288
|
-
};
|
|
289
|
-
const isNodeApiCall = (node) => {
|
|
290
|
-
const callee = node.callee;
|
|
291
|
-
if (callee.type === 'Identifier' && callee.name === 'require') {
|
|
292
|
-
const arg = node.arguments[0];
|
|
293
|
-
if (arg?.type === 'Literal' && typeof arg.value === 'string') {
|
|
294
|
-
const moduleName = arg.value;
|
|
295
|
-
return ['fs', 'child_process', 'os', 'path', 'crypto', 'http', 'https'].includes(moduleName);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
if (callee.type === 'MemberExpression' &&
|
|
299
|
-
callee.object.type === 'Identifier' &&
|
|
300
|
-
['process', 'global', '__dirname', '__filename'].includes(callee.object.name)) {
|
|
301
|
-
return true;
|
|
302
|
-
}
|
|
303
|
-
return false;
|
|
304
|
-
};
|
|
305
|
-
return {
|
|
306
|
-
NewExpression(node) {
|
|
307
|
-
try {
|
|
308
|
-
if (isBrowserWindowCreation(node)) {
|
|
309
|
-
const args = node.arguments;
|
|
310
|
-
if (args.length > 0 && args[0]?.type === 'ObjectExpression') {
|
|
311
|
-
checkBrowserWindowOptions(args[0]);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
catch {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
},
|
|
319
|
-
CallExpression(node) {
|
|
320
|
-
try {
|
|
321
|
-
if (isIpcCall(node)) {
|
|
322
|
-
checkIpcCall(node);
|
|
323
|
-
}
|
|
324
|
-
if (isRendererFile() && isNodeApiCall(node)) {
|
|
325
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
context.report({
|
|
329
|
-
node,
|
|
330
|
-
messageId: 'directNodeAccess',
|
|
331
|
-
data: {
|
|
332
|
-
filePath: filename,
|
|
333
|
-
line: String(node.loc?.start.line ?? 0),
|
|
334
|
-
},
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
catch {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
},
|
|
342
|
-
AssignmentExpression(node) {
|
|
343
|
-
try {
|
|
344
|
-
if (node.left.type === 'MemberExpression' &&
|
|
345
|
-
node.left.property.type === 'Identifier' &&
|
|
346
|
-
node.left.property.name === 'preload') {
|
|
347
|
-
if (node.right.type === 'Literal' && typeof node.right.value === 'string') {
|
|
348
|
-
const preloadPath = node.right.value;
|
|
349
|
-
if (preloadPath.includes('node_modules') ||
|
|
350
|
-
preloadPath.includes('http') ||
|
|
351
|
-
preloadPath.includes('remote')) {
|
|
352
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
context.report({
|
|
356
|
-
node: node.right,
|
|
357
|
-
messageId: 'unsafePreloadScript',
|
|
358
|
-
data: {
|
|
359
|
-
filePath: filename,
|
|
360
|
-
line: String(node.loc?.start.line ?? 0),
|
|
361
|
-
},
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
catch {
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
Property(node) {
|
|
372
|
-
try {
|
|
373
|
-
if (node.key.type === 'Identifier' && node.key.name === 'webPreferences') {
|
|
374
|
-
if (node.value.type === 'ObjectExpression') {
|
|
375
|
-
checkBrowserWindowOptions(node.value);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
catch {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
},
|
|
385
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noElectronSecurityIssues=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const eslint_devkit_3=require("@interlace/eslint-devkit");exports.noElectronSecurityIssues=(0,eslint_devkit_1.createRule)({name:"no-electron-security-issues",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-electron-security-issues.md",description:"Detects Electron security vulnerabilities and insecure configurations",cwe:"CWE-16"},hasSuggestions:true,messages:{electronSecurityIssue:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Electron Security Issue",cwe:"CWE-16",description:"Electron security vulnerability detected",severity:"{{severity}}",fix:"{{safeAlternative}}",documentationLink:"https://electronjs.org/docs/tutorial/security"}),nodeIntegrationEnabled:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Node Integration Enabled",cwe:"CWE-16",description:"nodeIntegration enabled allows Node.js access in renderer",severity:"CRITICAL",fix:"Set nodeIntegration: false and use secure preload scripts",documentationLink:"https://electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content"}),contextIsolationDisabled:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Context Isolation Disabled",cwe:"CWE-16",description:"contextIsolation disabled removes security boundary",severity:"CRITICAL",fix:"Enable contextIsolation and use preload scripts",documentationLink:"https://electronjs.org/docs/tutorial/context-isolation"}),webSecurityDisabled:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Web Security Disabled",cwe:"CWE-16",description:"webSecurity disabled removes CORS and security protections",severity:"HIGH",fix:"Keep webSecurity enabled",documentationLink:"https://electronjs.org/docs/tutorial/security#6-define-a-content-security-policy"}),insecureContentEnabled:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Insecure Content Enabled",cwe:"CWE-16",description:"allowRunningInsecureContent allows mixed content",severity:"MEDIUM",fix:"Set allowRunningInsecureContent: false",documentationLink:"https://electronjs.org/docs/tutorial/security#5-do-not-disable-websecurity"}),unsafePreloadScript:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Unsafe Preload Script",cwe:"CWE-16",description:"Preload script may expose sensitive APIs",severity:"HIGH",fix:"Use minimal, secure preload scripts",documentationLink:"https://electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content"}),directNodeAccess:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Direct Node Access",cwe:"CWE-16",description:"Direct access to Node.js APIs in renderer process",severity:"HIGH",fix:"Access Node.js APIs only through secure IPC channels",documentationLink:"https://electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content"}),insecureIpcPattern:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Insecure IPC Pattern",cwe:"CWE-16",description:"IPC communication lacks proper validation",severity:"MEDIUM",fix:"Validate IPC messages and restrict channels",documentationLink:"https://electronjs.org/docs/tutorial/security#7-do-not-use-the-ipc-transport-for-sensitive-data"}),missingSandbox:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Missing Sandbox",cwe:"CWE-16",description:"BrowserWindow not sandboxed",severity:"MEDIUM",fix:"Enable sandbox for untrusted content",documentationLink:"https://electronjs.org/docs/tutorial/sandbox"}),enableSecurityFeatures:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Enable Security Features",description:"Enable Electron security features",severity:"LOW",fix:"Set contextIsolation: true, nodeIntegration: false",documentationLink:"https://electronjs.org/docs/tutorial/security"}),useContextIsolation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use Context Isolation",description:"Use context isolation for security",severity:"LOW",fix:"Enable contextIsolation in BrowserWindow options",documentationLink:"https://electronjs.org/docs/tutorial/context-isolation"}),securePreloadScripts:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Secure Preload Scripts",description:"Use secure preload scripts",severity:"LOW",fix:"Limit APIs exposed in preload scripts",documentationLink:"https://electronjs.org/docs/tutorial/security#3-enable-context-isolation-for-remote-content"}),strategySecureDefaults:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Secure Defaults Strategy",description:"Use secure defaults for Electron applications",severity:"LOW",fix:"Start with secure configuration and relax only when necessary",documentationLink:"https://electronjs.org/docs/tutorial/security"}),strategyProcessSeparation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Process Separation Strategy",description:"Separate main and renderer processes properly",severity:"LOW",fix:"Keep Node.js APIs in main process, use IPC for communication",documentationLink:"https://electronjs.org/docs/tutorial/application-architecture"}),strategyInputValidation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Input Validation Strategy",description:"Validate all inputs in Electron applications",severity:"LOW",fix:"Validate IPC messages and user inputs",documentationLink:"https://electronjs.org/docs/tutorial/security#7-do-not-use-the-ipc-transport-for-sensitive-data"})},schema:[{type:"object",properties:{allowInDev:{type:"boolean",default:false,description:"Allow insecure settings in development"},safePreloadPatterns:{type:"array",items:{type:"string"},default:["contextBridge","ipcRenderer"],description:"Preload-script APIs treated as safe"},allowedIpcChannels:{type:"array",items:{type:"string"},default:[],description:"IPC channel names allowed without validation"},trustedSanitizers:{type:"array",items:{type:"string"},default:[],description:"Additional function names to consider as safe"},trustedAnnotations:{type:"array",items:{type:"string"},default:[],description:"Additional JSDoc annotations to consider as safe markers"},strictMode:{type:"boolean",default:false,description:"Disable all false positive detection (strict mode)"}},additionalProperties:false}]},defaultOptions:[{allowInDev:false,safePreloadPatterns:["contextBridge","ipcRenderer"],allowedIpcChannels:[],trustedSanitizers:[],trustedAnnotations:[],strictMode:false}],create(context){const options=context.options[0]||{};const{allowedIpcChannels=[],trustedSanitizers=[],trustedAnnotations=[],strictMode=false}=options;const filename=context.filename;const safetyChecker=(0,eslint_devkit_3.createSafetyChecker)({trustedSanitizers,trustedAnnotations,trustedOrmPatterns:[],strictMode});const isBrowserWindowCreation=node=>{return node.callee.type==="Identifier"&&node.callee.name==="BrowserWindow"};const checkBrowserWindowOptions=optionsNode=>{for(const prop of optionsNode.properties){if(prop.type==="Property"&&prop.key.type==="Identifier"){const key=prop.key.name;const value=prop.value;if(["nodeIntegration","contextIsolation","webSecurity","allowRunningInsecureContent","sandbox"].includes(key)){if(value.type==="Literal"){const isInsecure=key==="nodeIntegration"&&value.value===true||key==="contextIsolation"&&value.value===false||key==="webSecurity"&&value.value===false||key==="allowRunningInsecureContent"&&value.value===true||key==="sandbox"&&value.value===false;if(isInsecure){if(safetyChecker.isSafe(prop,context)){continue}const messageId=key==="nodeIntegration"?"nodeIntegrationEnabled":key==="contextIsolation"?"contextIsolationDisabled":key==="webSecurity"?"webSecurityDisabled":key==="allowRunningInsecureContent"?"insecureContentEnabled":"missingSandbox";context.report({node:prop,messageId,data:{filePath:filename,line:String(prop.loc?.start.line??0)}})}}}}}};const isIpcCall=node=>{const callee=node.callee;if(callee.type==="MemberExpression"&&callee.object.type==="Identifier"&&["ipcMain","ipcRenderer"].includes(callee.object.name)&&callee.property.type==="Identifier"){return["send","invoke","handle","on","once"].includes(callee.property.name)}return false};const checkIpcCall=node=>{const args=node.arguments;if(args.length===0){return}const channelArg=args[0];if(channelArg.type==="Literal"&&typeof channelArg.value==="string"){const channel=channelArg.value;if(allowedIpcChannels.length>0&&!allowedIpcChannels.includes(channel)){if(safetyChecker.isSafe(node,context)){return}context.report({node:channelArg,messageId:"insecureIpcPattern",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}};const isRendererFile=()=>{const fileName=filename.toLowerCase();return fileName.includes("renderer")||fileName.includes("preload")||fileName.includes("ui")||fileName.includes("view")};const isNodeApiCall=node=>{const callee=node.callee;if(callee.type==="Identifier"&&callee.name==="require"){const arg=node.arguments[0];if(arg?.type==="Literal"&&typeof arg.value==="string"){const moduleName=arg.value;return["fs","child_process","os","path","crypto","http","https"].includes(moduleName)}}if(callee.type==="MemberExpression"&&callee.object.type==="Identifier"&&["process","global","__dirname","__filename"].includes(callee.object.name)){return true}return false};return{NewExpression(node){try{if(isBrowserWindowCreation(node)){const args=node.arguments;if(args.length>0&&args[0]?.type==="ObjectExpression"){checkBrowserWindowOptions(args[0])}}}catch{return}},CallExpression(node){try{if(isIpcCall(node)){checkIpcCall(node)}if(isRendererFile()&&isNodeApiCall(node)){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"directNodeAccess",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}catch{return}},AssignmentExpression(node){try{if(node.left.type==="MemberExpression"&&node.left.property.type==="Identifier"&&node.left.property.name==="preload"){if(node.right.type==="Literal"&&typeof node.right.value==="string"){const preloadPath=node.right.value;if(preloadPath.includes("node_modules")||preloadPath.includes("http")||preloadPath.includes("remote")){if(safetyChecker.isSafe(node,context)){return}context.report({node:node.right,messageId:"unsafePreloadScript",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}}catch{return}},Property(node){try{if(node.key.type==="Identifier"&&node.key.name==="webPreferences"){if(node.value.type==="ObjectExpression"){checkBrowserWindowOptions(node.value)}}}catch{return}}}}});
|