eslint-plugin-secure-coding 3.3.0 → 3.3.2
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 +29 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/rules/detect-non-literal-regexp/index.js +48 -61
- package/src/rules/detect-object-injection/index.js +32 -88
- package/src/rules/detect-weak-password-validation/index.js +1 -1
- package/src/rules/no-directive-injection/index.js +0 -16
- package/src/rules/no-electron-security-issues/index.js +0 -6
- package/src/rules/no-format-string-injection/index.js +2 -29
- package/src/rules/no-graphql-injection/index.js +10 -10
- package/src/rules/no-hardcoded-credentials/index.js +13 -8
- package/src/rules/no-hardcoded-session-tokens/index.js +1 -1
- package/src/rules/no-improper-sanitization/index.js +1 -9
- package/src/rules/no-improper-type-validation/index.js +0 -10
- package/src/rules/no-insecure-comparison/index.js +1 -1
- package/src/rules/no-ldap-injection/index.d.ts +14 -0
- package/src/rules/no-ldap-injection/index.js +51 -58
- package/src/rules/no-missing-authentication/index.js +13 -17
- package/src/rules/no-privilege-escalation/index.js +1 -1
- package/src/rules/no-redos-vulnerable-regex/index.js +0 -7
- package/src/rules/no-sensitive-data-exposure/index.js +1 -1
- package/src/rules/no-template-injection/index.js +1 -1
- package/src/rules/no-unchecked-loop-condition/index.js +21 -37
- package/src/rules/no-unlimited-resource-allocation/index.js +42 -79
- package/src/rules/no-unsafe-deserialization/index.js +0 -5
- package/src/rules/no-unsafe-regex-construction/index.js +14 -2
- package/src/rules/no-weak-password-recovery/index.js +0 -6
- package/src/rules/no-xpath-injection/index.js +19 -45
- package/src/rules/no-xxe-injection/index.js +5 -2
- package/src/rules/require-backend-authorization/index.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
## 3.3.2
|
|
2
|
+
|
|
3
|
+
### Patch Changes
|
|
4
|
+
|
|
5
|
+
- [#225](https://github.com/ofri-peretz/eslint/pull/225) [`34ff5a8`](https://github.com/ofri-peretz/eslint/commit/34ff5a8e6f5126c5d1c0a524759e0af2b5476b46) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - CI-only: pin all coverage thresholds at 100% (integration target, merges last).
|
|
6
|
+
|
|
7
|
+
## 3.3.1
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#213](https://github.com/ofri-peretz/eslint/pull/213) [`391dbe6`](https://github.com/ofri-peretz/eslint/commit/391dbe6b39f78d549379218567cb959649f8c614) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Align every security rule's `meta.docs.cvss` to the CVSS its finding actually
|
|
12
|
+
emits. The emitted machine-readable message sources its `CVSS:x` from
|
|
13
|
+
`CWE_MAPPING` via `formatLLMMessage` → `enrichFromCWE`, but the static
|
|
14
|
+
`meta.docs.cvss` documentation field had drifted on 45 rules across these 7
|
|
15
|
+
plugins — e.g. `no-hardcoded-credentials` documented `9.5` while emitting
|
|
16
|
+
`CVSS:9.8` (the value the published article and SARIF/LLM consumers already
|
|
17
|
+
read).
|
|
18
|
+
|
|
19
|
+
This corrects the **documentation metadata only** — no emitted finding changes.
|
|
20
|
+
Locked by `security-cvss-docs-consistency.lock.test.ts` (cross-plugin: every
|
|
21
|
+
security rule's `meta.docs.cvss` must equal the CVSS it emits), the
|
|
22
|
+
`no-hardcoded-credentials` rule lock (real ESLint `Linter` emission), and a
|
|
23
|
+
devkit `enrichFromCWE` contract test pinning `CWE-798 → 9.8`.
|
|
24
|
+
|
|
25
|
+
Follow-up (not in scope): 50 security rules document a CVSS that never appears
|
|
26
|
+
in any emitted message (their messages carry no CWE), and several rules emit the
|
|
27
|
+
generic CWE score where a rule-specific score may be warranted — both change
|
|
28
|
+
emitted output and are separate decisions.
|
|
29
|
+
|
|
1
30
|
## 3.3.0
|
|
2
31
|
|
|
3
32
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<a href="https://www.npmjs.com/package/eslint-plugin-secure-coding" target="_blank"><img src="https://img.shields.io/npm/v/eslint-plugin-secure-coding.svg" alt="NPM Version" /></a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/eslint-plugin-secure-coding" target="_blank"><img src="https://img.shields.io/npm/dm/eslint-plugin-secure-coding.svg" alt="NPM Downloads" /></a>
|
|
12
12
|
<a href="https://opensource.org/licenses/MIT" target="_blank"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Package License" /></a>
|
|
13
|
-
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/
|
|
13
|
+
<a href="https://app.codecov.io/gh/ofri-peretz/eslint/tree/main" target="_blank"><img src="https://codecov.io/gh/ofri-peretz/eslint/graph/badge.svg?flag=eslint-plugin-secure-coding" alt="Codecov" /></a>
|
|
14
14
|
<a href="https://github.com/ofri-peretz/eslint" target="_blank"><img src="https://img.shields.io/badge/Since-Dec_2025-blue?logo=rocket&logoColor=white" alt="Since Dec 2025" /></a>
|
|
15
15
|
</p>
|
|
16
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-secure-coding",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "Security-focused ESLint plugin with 89 AI-parseable rules for detecting and preventing vulnerabilities. OWASP Top 10 2021 + Mobile Top 10 2024 coverage, CWE references, and AI-assisted fix guidance.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/index.js
CHANGED
|
@@ -149,7 +149,9 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
149
149
|
],
|
|
150
150
|
create(context) {
|
|
151
151
|
const options = context.options[0] || {};
|
|
152
|
-
|
|
152
|
+
// `options` is always an object here (defaulted just above), so a
|
|
153
|
+
// second `|| {}` fallback could never fire — removed as dead code.
|
|
154
|
+
const { allowLiterals = false, maxPatternLength = 100, } = options;
|
|
153
155
|
/**
|
|
154
156
|
* Check if a node is a literal string (potentially safe)
|
|
155
157
|
* Includes template literals without expressions
|
|
@@ -267,44 +269,32 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
267
269
|
' 5. Consider alternatives like string methods'
|
|
268
270
|
].join('\n');
|
|
269
271
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
' 3. Validate input against allowed character sets',
|
|
284
|
-
' 4. Add length limits to prevent oversized patterns',
|
|
285
|
-
' 5. Use static patterns when possible'
|
|
286
|
-
].join('\n');
|
|
287
|
-
default:
|
|
288
|
-
return [
|
|
289
|
-
' 1. Identify the specific regex use case',
|
|
290
|
-
' 2. Choose appropriate safe alternative',
|
|
291
|
-
' 3. Add input validation and escaping',
|
|
292
|
-
' 4. Test thoroughly with edge cases',
|
|
293
|
-
' 5. Monitor performance in production'
|
|
294
|
-
].join('\n');
|
|
295
|
-
}
|
|
272
|
+
// Every `RegExpPattern` constructed in this module has
|
|
273
|
+
// `vulnerability: 'redos'` (see REGEXP_PATTERNS above and the two
|
|
274
|
+
// object literals returned from `detectVulnerability`) — there is no
|
|
275
|
+
// code path that ever produces `'injection'` or another value, so
|
|
276
|
+
// this is the only reachable case. Kept as a direct return (not a
|
|
277
|
+
// switch) to avoid unreachable branches that no test could ever hit.
|
|
278
|
+
return [
|
|
279
|
+
' 1. Avoid nested quantifiers and backreferences',
|
|
280
|
+
' 2. Use possessive quantifiers: *+, ++, ?+',
|
|
281
|
+
' 3. Restructure regex to be more specific',
|
|
282
|
+
' 4. Test with potentially malicious inputs',
|
|
283
|
+
' 5. Consider safe-regex library validation'
|
|
284
|
+
].join('\n');
|
|
296
285
|
};
|
|
297
286
|
/**
|
|
298
287
|
* Determine overall risk level
|
|
299
288
|
*/
|
|
289
|
+
// Every `RegExpPattern` ever constructed in this module (REGEXP_PATTERNS
|
|
290
|
+
// entries, and the two object literals in `detectVulnerability`) sets
|
|
291
|
+
// `riskLevel` to only `'high'` or `'critical'` — never `'medium'` or
|
|
292
|
+
// `'low'` — so those two branches are the only reachable outcomes.
|
|
300
293
|
const determineRiskLevel = (vulnerability, pattern) => {
|
|
301
294
|
if (vulnerability.riskLevel === 'critical' || hasReDoSPatterns(pattern)) {
|
|
302
295
|
return 'CRITICAL';
|
|
303
296
|
}
|
|
304
|
-
|
|
305
|
-
return 'HIGH';
|
|
306
|
-
}
|
|
307
|
-
return 'MEDIUM';
|
|
297
|
+
return 'HIGH';
|
|
308
298
|
};
|
|
309
299
|
/**
|
|
310
300
|
* Check RegExp constructor calls for vulnerabilities
|
|
@@ -325,19 +315,13 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
325
315
|
}
|
|
326
316
|
}
|
|
327
317
|
const vulnerability = detectVulnerability(pattern, isDynamic);
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
bad: pattern,
|
|
336
|
-
good: '/^safe-pattern$/'
|
|
337
|
-
},
|
|
338
|
-
effort: '10-15 minutes',
|
|
339
|
-
riskLevel: 'medium'
|
|
340
|
-
} : null);
|
|
318
|
+
// `detectVulnerability` always returns non-null when `isDynamic` is
|
|
319
|
+
// true (either a matched REGEXP_PATTERNS entry or its own generic
|
|
320
|
+
// "dynamic" object), so `vulnerability` can only be null when
|
|
321
|
+
// `isDynamic` is false — meaning a synthetic `isDynamic ? {...} :
|
|
322
|
+
// null` fallback here could never construct the object literal it
|
|
323
|
+
// used to; it always reduced to `null`. Removed as dead code.
|
|
324
|
+
const effectiveVulnerability = vulnerability;
|
|
341
325
|
if (!effectiveVulnerability) {
|
|
342
326
|
return;
|
|
343
327
|
}
|
|
@@ -386,25 +370,28 @@ exports.detectNonLiteralRegexp = (0, eslint_devkit_2.createRule)({
|
|
|
386
370
|
return;
|
|
387
371
|
}
|
|
388
372
|
const pattern = node.regex.pattern;
|
|
389
|
-
// Check for ReDoS patterns
|
|
373
|
+
// Check for ReDoS patterns. `detectVulnerability(pattern, false)`
|
|
374
|
+
// re-tests the identical `hasReDoSPatterns(pattern)` condition just
|
|
375
|
+
// checked above (see its `isDynamic === false` branch) and always
|
|
376
|
+
// returns non-null when that's true — so `vulnerability` here can
|
|
377
|
+
// never be null. No `if (vulnerability)` guard, to avoid an
|
|
378
|
+
// unreachable false branch.
|
|
390
379
|
if (hasReDoSPatterns(pattern)) {
|
|
391
380
|
const vulnerability = detectVulnerability(pattern, false);
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
});
|
|
407
|
-
}
|
|
381
|
+
const riskLevel = determineRiskLevel(vulnerability, pattern);
|
|
382
|
+
const steps = generateRefactoringSteps(vulnerability);
|
|
383
|
+
context.report({
|
|
384
|
+
node,
|
|
385
|
+
messageId: 'regexpReDoS',
|
|
386
|
+
data: {
|
|
387
|
+
pattern: pattern.substring(0, 30) + (pattern.length > 30 ? '...' : ''),
|
|
388
|
+
riskLevel,
|
|
389
|
+
vulnerability: vulnerability.vulnerability,
|
|
390
|
+
safeAlternative: vulnerability.safeAlternative,
|
|
391
|
+
steps,
|
|
392
|
+
effort: vulnerability.effort
|
|
393
|
+
}
|
|
394
|
+
});
|
|
408
395
|
}
|
|
409
396
|
};
|
|
410
397
|
return {
|
|
@@ -195,7 +195,11 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
|
|
|
195
195
|
],
|
|
196
196
|
create(context) {
|
|
197
197
|
const options = context.options[0] || {};
|
|
198
|
-
const {
|
|
198
|
+
const {
|
|
199
|
+
// `allowLiterals` is accepted for backward-compatible schema/options
|
|
200
|
+
// parity (see comment near `isTypedUnionAccess` usage below) but no
|
|
201
|
+
// longer changes runtime behavior, so it is intentionally unused here.
|
|
202
|
+
allowLiterals: _allowLiterals = false, dangerousProperties = ['__proto__', 'prototype', 'constructor'], } = options;
|
|
199
203
|
// Track MemberExpressions that are part of AssignmentExpressions to avoid double-reporting
|
|
200
204
|
const handledMemberExpressions = new WeakSet();
|
|
201
205
|
// ── AST-walker / codemod context detection (closes the audit FP
|
|
@@ -238,66 +242,12 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
|
|
|
238
242
|
/\/test\//.test(f) ||
|
|
239
243
|
/\.fixture\.[mc]?[jt]sx?$/.test(f));
|
|
240
244
|
})();
|
|
241
|
-
// Check if TypeScript parser services are available for type-aware checking
|
|
242
|
-
const hasTypeInfo = (0, eslint_devkit_2.hasParserServices)(context);
|
|
243
|
-
const parserServices = hasTypeInfo ? (0, eslint_devkit_2.getParserServices)(context) : null;
|
|
244
245
|
/**
|
|
245
246
|
* Check if a node is a literal string (potentially safe)
|
|
246
247
|
*/
|
|
247
248
|
const isLiteralString = (node) => {
|
|
248
249
|
return node.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof node.value === 'string';
|
|
249
250
|
};
|
|
250
|
-
/**
|
|
251
|
-
* Check if a property is part of a typed union (safe access)
|
|
252
|
-
*
|
|
253
|
-
* Type-Aware Enhancement:
|
|
254
|
-
* When TypeScript parser services are available, we can check if a variable
|
|
255
|
-
* is typed as a union of string literals (e.g., 'name' | 'email').
|
|
256
|
-
* Such accesses are safe because the values are statically constrained.
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* // This is now detected as SAFE (no false positive):
|
|
260
|
-
* const key: 'name' | 'email' = getKey();
|
|
261
|
-
* obj[key] = value;
|
|
262
|
-
*
|
|
263
|
-
* // This is still detected as DANGEROUS:
|
|
264
|
-
* const key: string = getUserInput();
|
|
265
|
-
* obj[key] = value;
|
|
266
|
-
*/
|
|
267
|
-
const isTypedUnionAccess = (propertyNode) => {
|
|
268
|
-
// Check if property is a literal string (typed access like obj['name'])
|
|
269
|
-
if (isLiteralString(propertyNode)) {
|
|
270
|
-
return true; // Literal strings are safe - they're typed at compile time
|
|
271
|
-
}
|
|
272
|
-
// Type-aware check: If we have TypeScript type information, check if the
|
|
273
|
-
// property key is constrained to a union of safe string literals
|
|
274
|
-
/* c8 ignore start -- TypeScript parser services often unavailable in RuleTester */
|
|
275
|
-
if (parserServices && propertyNode.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
276
|
-
try {
|
|
277
|
-
const type = (0, eslint_devkit_2.getTypeOfNode)(propertyNode, parserServices);
|
|
278
|
-
// Check if the type is a union of safe string literals
|
|
279
|
-
// (excludes '__proto__', 'prototype', 'constructor')
|
|
280
|
-
if ((0, eslint_devkit_2.isUnionOfSafeStringLiterals)(type, dangerousProperties)) {
|
|
281
|
-
return true; // Safe - statically constrained to safe values
|
|
282
|
-
}
|
|
283
|
-
// Also check for single string literal type (e.g., const key: 'name' = ...)
|
|
284
|
-
const literalValues = (0, eslint_devkit_2.getStringLiteralValues)(type);
|
|
285
|
-
if (literalValues && literalValues.length === 1) {
|
|
286
|
-
// Single literal - safe if not dangerous
|
|
287
|
-
if (!dangerousProperties.includes(literalValues[0])) {
|
|
288
|
-
return true;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
catch {
|
|
293
|
-
// If type checking fails, fall back to treating as potentially dangerous
|
|
294
|
-
// This can happen with malformed AST or missing type information
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
/* c8 ignore stop */
|
|
298
|
-
// Without type information, treat all identifiers as potentially dangerous
|
|
299
|
-
return false;
|
|
300
|
-
};
|
|
301
251
|
/**
|
|
302
252
|
* Check if the property key has been validated before use.
|
|
303
253
|
*
|
|
@@ -424,10 +374,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
|
|
|
424
374
|
* Check if property access is potentially dangerous
|
|
425
375
|
*/
|
|
426
376
|
const isDangerousPropertyAccess = (propertyNode) => {
|
|
427
|
-
// SAFE: Numeric literals (array index access like items[0], items[1])
|
|
428
|
-
if (propertyNode.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof propertyNode.value === 'number') {
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
377
|
// SAFE: Common numeric index variable names (i, j, k, index, idx, n)
|
|
432
378
|
// These are typically loop counters for array access
|
|
433
379
|
if (propertyNode.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
@@ -463,18 +409,7 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
|
|
|
463
409
|
if (dangerousProperties.includes(propName)) {
|
|
464
410
|
return true;
|
|
465
411
|
}
|
|
466
|
-
|
|
467
|
-
// Only safe if it's NOT a dangerous property
|
|
468
|
-
if (isTypedUnionAccess(propertyNode)) {
|
|
469
|
-
return false;
|
|
470
|
-
}
|
|
471
|
-
// SAFE: Literal strings that are NOT dangerous properties (if allowLiterals is true)
|
|
472
|
-
if (allowLiterals) {
|
|
473
|
-
return false;
|
|
474
|
-
}
|
|
475
|
-
// If allowLiterals is false, non-dangerous literal strings are still considered safe
|
|
476
|
-
// (they're static and known at compile time)
|
|
477
|
-
return false;
|
|
412
|
+
return false; // safe non-dangerous literal
|
|
478
413
|
}
|
|
479
414
|
// DANGEROUS: Any untyped/dynamic property access (e.g., obj[userInput])
|
|
480
415
|
return true;
|
|
@@ -537,6 +472,15 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
|
|
|
537
472
|
let property;
|
|
538
473
|
let propertyNode;
|
|
539
474
|
let isAssignment = false;
|
|
475
|
+
// Note: the `node.left.type !== MemberExpression` / plain-MemberExpression
|
|
476
|
+
// shapes are the only two forms ever passed in — every call site
|
|
477
|
+
// (isHighRiskAssignment / isHighRiskMemberAccess and their two
|
|
478
|
+
// downstream checkAssignmentExpression / checkMemberExpression callers)
|
|
479
|
+
// already guards on the same discriminants before calling this
|
|
480
|
+
// function, so a "neither shape matched" fallback is unreachable dead
|
|
481
|
+
// code. The `if`/`else if` below is kept (rather than a non-null
|
|
482
|
+
// assertion) purely for TypeScript exhaustiveness over the declared
|
|
483
|
+
// union parameter type.
|
|
540
484
|
if (node.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression && node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
541
485
|
// Assignment: obj[key] = value
|
|
542
486
|
object = sourceCode.getText(node.left.object);
|
|
@@ -544,15 +488,14 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
|
|
|
544
488
|
propertyNode = node.left.property;
|
|
545
489
|
isAssignment = true;
|
|
546
490
|
}
|
|
547
|
-
else if (node.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
|
|
548
|
-
// Access: obj[key]
|
|
549
|
-
object = sourceCode.getText(node.object);
|
|
550
|
-
property = sourceCode.getText(node.property);
|
|
551
|
-
propertyNode = node.property;
|
|
552
|
-
isAssignment = false;
|
|
553
|
-
}
|
|
554
491
|
else {
|
|
555
|
-
|
|
492
|
+
// Access: obj[key]. By contract with every call site, `node` is a
|
|
493
|
+
// plain MemberExpression whenever the branch above doesn't match.
|
|
494
|
+
const memberNode = node;
|
|
495
|
+
object = sourceCode.getText(memberNode.object);
|
|
496
|
+
property = sourceCode.getText(memberNode.property);
|
|
497
|
+
propertyNode = memberNode.property;
|
|
498
|
+
isAssignment = false;
|
|
556
499
|
}
|
|
557
500
|
// Check if property matches dangerous patterns
|
|
558
501
|
const pattern = OBJECT_INJECTION_PATTERNS.find(p => new RegExp(p.pattern, 'i').test(property) ||
|
|
@@ -817,14 +760,13 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
|
|
|
817
760
|
// would fire again for the INNER `a[b]` access. We walk the object
|
|
818
761
|
// chain and mark every intermediate computed MemberExpression so the
|
|
819
762
|
// MemberExpression visitor skips them — preventing exact duplicates.
|
|
820
|
-
|
|
821
|
-
|
|
763
|
+
// isHighRiskAssignment already verified node.left.type === 'MemberExpression'
|
|
764
|
+
let me = node.left;
|
|
765
|
+
handledMemberExpressions.add(me);
|
|
766
|
+
// Walk into chained computed accesses: a[b][c] → also mark a[b]
|
|
767
|
+
while (me.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression && me.object.computed) {
|
|
768
|
+
me = me.object;
|
|
822
769
|
handledMemberExpressions.add(me);
|
|
823
|
-
// Walk into chained computed accesses: a[b][c] → also mark a[b]
|
|
824
|
-
while (me.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression && me.object.computed) {
|
|
825
|
-
me = me.object;
|
|
826
|
-
handledMemberExpressions.add(me);
|
|
827
|
-
}
|
|
828
770
|
}
|
|
829
771
|
const { object, property, isAssignment, pattern } = extractPropertyAccess(node);
|
|
830
772
|
const riskLevel = determineRiskLevel(pattern, isAssignment);
|
|
@@ -912,8 +854,10 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
|
|
|
912
854
|
* benchmarks/AUDIT_PATTERNS.md §3.4 ("equivalent merger patterns").
|
|
913
855
|
*/
|
|
914
856
|
const checkObjectAssignSpread = (node) => {
|
|
915
|
-
|
|
916
|
-
|
|
857
|
+
// Note: no isInCodemodContext guard here — the sole call site (the
|
|
858
|
+
// CallExpression listener below) already returns before invoking this
|
|
859
|
+
// function when isInCodemodContext is true, so a duplicate check here
|
|
860
|
+
// would be unreachable dead code.
|
|
917
861
|
if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
|
|
918
862
|
return;
|
|
919
863
|
const callee = node.callee;
|
|
@@ -18,7 +18,7 @@ exports.detectWeakPasswordValidation = (0, eslint_devkit_1.createRule)({
|
|
|
18
18
|
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/detect-weak-password-validation.md',
|
|
19
19
|
description: 'Identify weak password requirements',
|
|
20
20
|
cwe: 'CWE-521',
|
|
21
|
-
cvss:
|
|
21
|
+
cvss: 5.3,
|
|
22
22
|
},
|
|
23
23
|
messages: {
|
|
24
24
|
violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -228,11 +228,9 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
|
|
|
228
228
|
// Check if the expression contains user input
|
|
229
229
|
const expressionText = sourceCode.getText(expression);
|
|
230
230
|
if (userInputVariables.some(input => expressionText.includes(input))) {
|
|
231
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
232
231
|
if (safetyChecker.isSafe(node, context)) {
|
|
233
232
|
return;
|
|
234
233
|
}
|
|
235
|
-
/* c8 ignore stop */
|
|
236
234
|
context.report({
|
|
237
235
|
node: attrValue,
|
|
238
236
|
messageId: 'dangerousInnerHTML',
|
|
@@ -253,11 +251,9 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
|
|
|
253
251
|
const expression = attrValue.expression;
|
|
254
252
|
// Check if directive value comes from user input
|
|
255
253
|
if (expression.type === 'Identifier' && isUserInput(expression.name)) {
|
|
256
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
257
254
|
if (safetyChecker.isSafe(node, context)) {
|
|
258
255
|
return;
|
|
259
256
|
}
|
|
260
|
-
/* c8 ignore stop */
|
|
261
257
|
context.report({
|
|
262
258
|
node: attrValue,
|
|
263
259
|
messageId: 'directiveInjection',
|
|
@@ -279,11 +275,9 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
|
|
|
279
275
|
if (attrValue.type === 'JSXExpressionContainer') {
|
|
280
276
|
const expression = attrValue.expression;
|
|
281
277
|
if (expression.type === 'Identifier' && isUserInput(expression.name)) {
|
|
282
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
283
278
|
if (safetyChecker.isSafe(node, context)) {
|
|
284
279
|
return;
|
|
285
280
|
}
|
|
286
|
-
/* c8 ignore stop */
|
|
287
281
|
context.report({
|
|
288
282
|
node: attrValue,
|
|
289
283
|
messageId: 'unsafeComponentBinding',
|
|
@@ -308,11 +302,9 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
|
|
|
308
302
|
// Check if right side contains user input
|
|
309
303
|
const rightText = sourceCode.getText(right);
|
|
310
304
|
if (userInputVariables.some(input => rightText.includes(input))) {
|
|
311
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
312
305
|
if (safetyChecker.isSafe(node, context)) {
|
|
313
306
|
return;
|
|
314
307
|
}
|
|
315
|
-
/* c8 ignore stop */
|
|
316
308
|
context.report({
|
|
317
309
|
node: right,
|
|
318
310
|
messageId: 'dangerousInnerHTML',
|
|
@@ -344,11 +336,9 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
|
|
|
344
336
|
const templateArg = args[0];
|
|
345
337
|
// Check if template comes from user input
|
|
346
338
|
if (templateArg.type === 'Identifier' && isUserInput(templateArg.name)) {
|
|
347
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
348
339
|
if (safetyChecker.isSafe(node, context)) {
|
|
349
340
|
return;
|
|
350
341
|
}
|
|
351
|
-
/* c8 ignore stop */
|
|
352
342
|
context.report({
|
|
353
343
|
node: templateArg,
|
|
354
344
|
messageId: 'userControlledTemplate',
|
|
@@ -366,11 +356,9 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
|
|
|
366
356
|
if (args.length >= 2) {
|
|
367
357
|
const directiveName = args[0];
|
|
368
358
|
if (directiveName.type === 'Identifier' && isUserInput(directiveName.name)) {
|
|
369
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
370
359
|
if (safetyChecker.isSafe(node, context)) {
|
|
371
360
|
return;
|
|
372
361
|
}
|
|
373
|
-
/* c8 ignore stop */
|
|
374
362
|
context.report({
|
|
375
363
|
node: directiveName,
|
|
376
364
|
messageId: 'unsafeDirectiveName',
|
|
@@ -389,11 +377,9 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
|
|
|
389
377
|
if (args.length >= 2) {
|
|
390
378
|
const directiveName = args[0];
|
|
391
379
|
if (directiveName.type === 'Identifier' && isUserInput(directiveName.name)) {
|
|
392
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
393
380
|
if (safetyChecker.isSafe(node, context)) {
|
|
394
381
|
return;
|
|
395
382
|
}
|
|
396
|
-
/* c8 ignore stop */
|
|
397
383
|
context.report({
|
|
398
384
|
node: directiveName,
|
|
399
385
|
messageId: 'dynamicDirectiveCreation',
|
|
@@ -442,11 +428,9 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
|
|
|
442
428
|
expr.object.type === 'Identifier' &&
|
|
443
429
|
isUserInput(expr.object.name)));
|
|
444
430
|
if (hasUserInput) {
|
|
445
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
446
431
|
if (safetyChecker.isSafe(node, context)) {
|
|
447
432
|
return;
|
|
448
433
|
}
|
|
449
|
-
/* c8 ignore stop */
|
|
450
434
|
context.report({
|
|
451
435
|
node,
|
|
452
436
|
messageId: 'templateInjection',
|
|
@@ -289,11 +289,9 @@ exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
|
|
|
289
289
|
const channel = channelArg.value;
|
|
290
290
|
// Check if channel is allowed
|
|
291
291
|
if (allowedIpcChannels.length > 0 && !allowedIpcChannels.includes(channel)) {
|
|
292
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
293
292
|
if (safetyChecker.isSafe(node, context)) {
|
|
294
293
|
return;
|
|
295
294
|
}
|
|
296
|
-
/* c8 ignore stop */
|
|
297
295
|
context.report({
|
|
298
296
|
node: channelArg,
|
|
299
297
|
messageId: 'insecureIpcPattern',
|
|
@@ -360,11 +358,9 @@ exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
|
|
|
360
358
|
}
|
|
361
359
|
// Check for Node.js API usage in renderer files
|
|
362
360
|
if (isRendererFile() && isNodeApiCall(node)) {
|
|
363
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
364
361
|
if (safetyChecker.isSafe(node, context)) {
|
|
365
362
|
return;
|
|
366
363
|
}
|
|
367
|
-
/* c8 ignore stop */
|
|
368
364
|
context.report({
|
|
369
365
|
node,
|
|
370
366
|
messageId: 'directNodeAccess',
|
|
@@ -393,11 +389,9 @@ exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
|
|
|
393
389
|
if (preloadPath.includes('node_modules') ||
|
|
394
390
|
preloadPath.includes('http') ||
|
|
395
391
|
preloadPath.includes('remote')) {
|
|
396
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
397
392
|
if (safetyChecker.isSafe(node, context)) {
|
|
398
393
|
return;
|
|
399
394
|
}
|
|
400
|
-
/* c8 ignore stop */
|
|
401
395
|
context.report({
|
|
402
396
|
node: node.right,
|
|
403
397
|
messageId: 'unsafePreloadScript',
|