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
|
@@ -111,7 +111,7 @@ exports.noPrivilegeEscalation = (0, eslint_devkit_2.createRule)({
|
|
|
111
111
|
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-privilege-escalation.md',
|
|
112
112
|
description: 'Detects potential privilege escalation vulnerabilities',
|
|
113
113
|
cwe: 'CWE-269',
|
|
114
|
-
cvss:
|
|
114
|
+
cvss: 8.8,
|
|
115
115
|
},
|
|
116
116
|
hasSuggestions: true,
|
|
117
117
|
messages: {
|
|
@@ -299,17 +299,14 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
299
299
|
callee = node.callee;
|
|
300
300
|
}
|
|
301
301
|
else {
|
|
302
|
-
/* c8 ignore next */
|
|
303
302
|
return;
|
|
304
303
|
}
|
|
305
304
|
const isRegExp = callee.type === 'Identifier' && callee.name === 'RegExp';
|
|
306
305
|
if (!isRegExp) {
|
|
307
|
-
/* c8 ignore next */
|
|
308
306
|
return;
|
|
309
307
|
}
|
|
310
308
|
// Check if first argument is a string literal
|
|
311
309
|
if (node.arguments.length === 0) {
|
|
312
|
-
/* c8 ignore next */
|
|
313
310
|
return;
|
|
314
311
|
}
|
|
315
312
|
const firstArg = node.arguments[0];
|
|
@@ -345,23 +342,19 @@ exports.noRedosVulnerableRegex = (0, eslint_devkit_2.createRule)({
|
|
|
345
342
|
return;
|
|
346
343
|
}
|
|
347
344
|
if (firstArg.type !== 'Literal' || typeof firstArg.value !== 'string') {
|
|
348
|
-
/* c8 ignore next */
|
|
349
345
|
return;
|
|
350
346
|
}
|
|
351
347
|
const pattern = firstArg.value;
|
|
352
348
|
// Skip if pattern is too long (performance)
|
|
353
349
|
if (pattern.length > maxPatternLength) {
|
|
354
|
-
/* c8 ignore next */
|
|
355
350
|
return;
|
|
356
351
|
}
|
|
357
352
|
const vulnerability = hasReDoSVulnerability(pattern);
|
|
358
353
|
if (!vulnerability) {
|
|
359
|
-
/* c8 ignore next */
|
|
360
354
|
return;
|
|
361
355
|
}
|
|
362
356
|
// Allow common patterns if configured
|
|
363
357
|
if (allowCommonPatterns && (vulnerability.severity === 'medium' || vulnerability.name === 'Alternation with Quantifier')) {
|
|
364
|
-
/* c8 ignore next */
|
|
365
358
|
return;
|
|
366
359
|
}
|
|
367
360
|
const suggestions = generateFixSuggestions(vulnerability);
|
|
@@ -35,7 +35,7 @@ exports.noSensitiveDataExposure = (0, eslint_devkit_2.createRule)({
|
|
|
35
35
|
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-sensitive-data-exposure.md',
|
|
36
36
|
description: 'Detects PII/credentials in logs, responses, or error messages',
|
|
37
37
|
cwe: 'CWE-532',
|
|
38
|
-
cvss:
|
|
38
|
+
cvss: 5.3,
|
|
39
39
|
},
|
|
40
40
|
hasSuggestions: true,
|
|
41
41
|
messages: {
|
|
@@ -35,7 +35,7 @@ exports.noTemplateInjection = (0, eslint_devkit_1.createRule)({
|
|
|
35
35
|
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-template-injection.md',
|
|
36
36
|
description: 'Disallow dynamic strings as template arguments to server-side template engines (CWE-94)',
|
|
37
37
|
cwe: 'CWE-94',
|
|
38
|
-
cvss: 9.
|
|
38
|
+
cvss: 9.8,
|
|
39
39
|
},
|
|
40
40
|
messages: {
|
|
41
41
|
templateInjection: (0, eslint_devkit_1.formatLLMMessage)({
|
|
@@ -224,8 +224,11 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
224
224
|
const testText = sourceCode.getText(test);
|
|
225
225
|
// Check for Array.isArray validation
|
|
226
226
|
if (testText.includes('Array.isArray(') && testText.includes(collectionText)) {
|
|
227
|
-
// Also check for length validation
|
|
228
|
-
|
|
227
|
+
// Also check for length validation. Only `<`/`>` need checking:
|
|
228
|
+
// any text containing `<=` or `>=` already contains `<`/`>` as a
|
|
229
|
+
// substring, so those two extra disjuncts could never be the
|
|
230
|
+
// deciding factor (dead code, removed rather than tested around).
|
|
231
|
+
if (testText.includes('.length') && (testText.includes('<') || testText.includes('>'))) {
|
|
229
232
|
return true;
|
|
230
233
|
}
|
|
231
234
|
}
|
|
@@ -321,20 +324,25 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
321
324
|
return hasBreak;
|
|
322
325
|
};
|
|
323
326
|
/**
|
|
324
|
-
* Estimate loop iterations from static analysis
|
|
327
|
+
* Estimate loop iterations from static analysis.
|
|
328
|
+
*
|
|
329
|
+
* Only ever called from the ForStatement visitor below with its own
|
|
330
|
+
* `node`, so `loop` is always a ForStatement in practice; the parameter
|
|
331
|
+
* type reflects that (a prior `TSESTree.ForStatement | WhileStatement |
|
|
332
|
+
* DoWhileStatement` signature carried a redundant `loop.type ===
|
|
333
|
+
* 'ForStatement'` guard around the whole body that could never be
|
|
334
|
+
* false through any real call site).
|
|
325
335
|
*/
|
|
326
336
|
// oxlint-disable-next-line consistent-function-scoping
|
|
327
337
|
const estimateIterations = (loop) => {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
return Math.abs(right.value);
|
|
337
|
-
}
|
|
338
|
+
// Try to parse for loop bounds
|
|
339
|
+
const test = loop.test;
|
|
340
|
+
if (test && test.type === 'BinaryExpression') {
|
|
341
|
+
// Look for patterns like i < limit or i <= limit
|
|
342
|
+
if ((test.operator === '<' || test.operator === '<=' || test.operator === '>' || test.operator === '>=')) {
|
|
343
|
+
const right = test.right;
|
|
344
|
+
if (right.type === 'Literal' && typeof right.value === 'number') {
|
|
345
|
+
return Math.abs(right.value);
|
|
338
346
|
}
|
|
339
347
|
}
|
|
340
348
|
}
|
|
@@ -384,11 +392,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
384
392
|
const isTreeTraversal = currentFunction === 'traverseObject';
|
|
385
393
|
// Flag excessive recursion or specific dangerous patterns
|
|
386
394
|
if (callCount > maxRecursionDepth || currentFunction === 'recursiveFunc' || isTreeTraversal) {
|
|
387
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
388
395
|
if (safetyChecker.isSafe(node, context)) {
|
|
389
396
|
return;
|
|
390
397
|
}
|
|
391
|
-
/* c8 ignore stop */
|
|
392
398
|
reportedRecursion.add(functionName);
|
|
393
399
|
context.report({
|
|
394
400
|
node,
|
|
@@ -433,11 +439,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
433
439
|
}
|
|
434
440
|
// Check for user-controlled loop conditions
|
|
435
441
|
if (involvesUserInput(test)) {
|
|
436
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
437
442
|
if (safetyChecker.isSafe(node, context)) {
|
|
438
443
|
return;
|
|
439
444
|
}
|
|
440
|
-
/* c8 ignore stop */
|
|
441
445
|
context.report({
|
|
442
446
|
node: test,
|
|
443
447
|
messageId: 'userControlledLoopBound',
|
|
@@ -450,11 +454,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
450
454
|
}
|
|
451
455
|
// Check for complex DoS patterns (regex loops, pagination, etc.)
|
|
452
456
|
if (checkComplexDoSPatterns(test)) {
|
|
453
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
454
457
|
if (safetyChecker.isSafe(node, context)) {
|
|
455
458
|
return;
|
|
456
459
|
}
|
|
457
|
-
/* c8 ignore stop */
|
|
458
460
|
context.report({
|
|
459
461
|
node: test,
|
|
460
462
|
messageId: 'userControlledLoopBound',
|
|
@@ -474,11 +476,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
474
476
|
varName.toLowerCase().includes('active') ||
|
|
475
477
|
varName.toLowerCase().includes('enabled')) {
|
|
476
478
|
// This could be a state-dependent infinite loop
|
|
477
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
478
479
|
if (safetyChecker.isSafe(node, context)) {
|
|
479
480
|
return;
|
|
480
481
|
}
|
|
481
|
-
/* c8 ignore stop */
|
|
482
482
|
context.report({
|
|
483
483
|
node: test,
|
|
484
484
|
messageId: 'infiniteLoop',
|
|
@@ -495,11 +495,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
495
495
|
ForStatement(node) {
|
|
496
496
|
// Check for for(;;) infinite loops
|
|
497
497
|
if (!node.test && !node.update) {
|
|
498
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
499
498
|
if (safetyChecker.isSafe(node, context)) {
|
|
500
499
|
return;
|
|
501
500
|
}
|
|
502
|
-
/* c8 ignore stop */
|
|
503
501
|
context.report({
|
|
504
502
|
node,
|
|
505
503
|
messageId: 'infiniteLoop',
|
|
@@ -512,11 +510,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
512
510
|
}
|
|
513
511
|
// Check for missing test condition (for(;condition;))
|
|
514
512
|
if (!node.test) {
|
|
515
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
516
513
|
if (safetyChecker.isSafe(node, context)) {
|
|
517
514
|
return;
|
|
518
515
|
}
|
|
519
|
-
/* c8 ignore stop */
|
|
520
516
|
context.report({
|
|
521
517
|
node,
|
|
522
518
|
messageId: 'missingLoopTermination',
|
|
@@ -529,11 +525,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
529
525
|
}
|
|
530
526
|
// Check for user-controlled loop bounds
|
|
531
527
|
if (involvesUserInput(node.test)) {
|
|
532
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
533
528
|
if (safetyChecker.isSafe(node, context)) {
|
|
534
529
|
return;
|
|
535
530
|
}
|
|
536
|
-
/* c8 ignore stop */
|
|
537
531
|
context.report({
|
|
538
532
|
node: node.test,
|
|
539
533
|
messageId: 'userControlledLoopBound',
|
|
@@ -546,11 +540,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
546
540
|
}
|
|
547
541
|
// Check for complex DoS patterns in for loops
|
|
548
542
|
if (checkComplexDoSPatterns(node.test) || checkComplexDoSPatternsInScope(node.test)) {
|
|
549
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
550
543
|
if (safetyChecker.isSafe(node, context)) {
|
|
551
544
|
return;
|
|
552
545
|
}
|
|
553
|
-
/* c8 ignore stop */
|
|
554
546
|
context.report({
|
|
555
547
|
node: node.test,
|
|
556
548
|
messageId: 'userControlledLoopBound',
|
|
@@ -564,11 +556,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
564
556
|
// Check for potentially large iteration counts
|
|
565
557
|
const estimatedIterations = estimateIterations(node);
|
|
566
558
|
if (estimatedIterations && estimatedIterations > maxStaticIterations) {
|
|
567
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
568
559
|
if (safetyChecker.isSafe(node, context)) {
|
|
569
560
|
return;
|
|
570
561
|
}
|
|
571
|
-
/* c8 ignore stop */
|
|
572
562
|
context.report({
|
|
573
563
|
node: node.test,
|
|
574
564
|
messageId: 'largeLoopBound',
|
|
@@ -584,11 +574,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
584
574
|
const test = node.test;
|
|
585
575
|
// Check for user-controlled conditions
|
|
586
576
|
if (involvesUserInput(test)) {
|
|
587
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
588
577
|
if (safetyChecker.isSafe(node, context)) {
|
|
589
578
|
return;
|
|
590
579
|
}
|
|
591
|
-
/* c8 ignore stop */
|
|
592
580
|
context.report({
|
|
593
581
|
node: test,
|
|
594
582
|
messageId: 'userControlledLoopBound',
|
|
@@ -605,11 +593,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
605
593
|
// Check if iterating over user-controlled collections
|
|
606
594
|
if (involvesUserInput(right)) {
|
|
607
595
|
// This could be problematic if the collection is very large
|
|
608
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
609
596
|
if (safetyChecker.isSafe(node, context)) {
|
|
610
597
|
return;
|
|
611
598
|
}
|
|
612
|
-
/* c8 ignore stop */
|
|
613
599
|
context.report({
|
|
614
600
|
node: right,
|
|
615
601
|
messageId: 'uncheckedLoopCondition',
|
|
@@ -631,11 +617,9 @@ exports.noUncheckedLoopCondition = (0, eslint_devkit_1.createRule)({
|
|
|
631
617
|
if (isValidated) {
|
|
632
618
|
return; // Collection is validated, safe to iterate
|
|
633
619
|
}
|
|
634
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
635
620
|
if (safetyChecker.isSafe(node, context)) {
|
|
636
621
|
return;
|
|
637
622
|
}
|
|
638
|
-
/* c8 ignore stop */
|
|
639
623
|
context.report({
|
|
640
624
|
node: right,
|
|
641
625
|
messageId: 'uncheckedLoopCondition',
|
|
@@ -216,11 +216,10 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
216
216
|
/**
|
|
217
217
|
* Check if resource allocation has size validation
|
|
218
218
|
*/
|
|
219
|
+
// All call sites invoke this only after already confirming `args.length > 0`,
|
|
220
|
+
// so the "no arguments" case is unreachable and intentionally not handled here.
|
|
219
221
|
const hasSizeValidation = (node) => {
|
|
220
222
|
const args = node.arguments;
|
|
221
|
-
if (args.length === 0) {
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
223
|
// Check if size argument is a validated expression
|
|
225
224
|
const sizeArg = args[0];
|
|
226
225
|
const sizeText = sourceCode.getText(sizeArg);
|
|
@@ -276,19 +275,23 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
276
275
|
const args = node.arguments;
|
|
277
276
|
if (args.length > 0) {
|
|
278
277
|
const sizeArg = args[0];
|
|
279
|
-
// Check if size comes from user input (but skip if validated)
|
|
280
|
-
|
|
281
|
-
|
|
278
|
+
// Check if size comes from user input (but skip if validated).
|
|
279
|
+
// When `requireResourceValidation` is disabled, callers have opted
|
|
280
|
+
// out of the "must call a validator" requirement entirely, so this
|
|
281
|
+
// branch is skipped regardless of whether validation is present.
|
|
282
|
+
if (requireResourceValidation &&
|
|
283
|
+
sizeArg.type !== 'SpreadElement' &&
|
|
284
|
+
isUserInput(sizeArg) &&
|
|
285
|
+
!hasSizeValidation(node)) {
|
|
282
286
|
if (safetyChecker.isSafe(node, context)) {
|
|
283
287
|
return;
|
|
284
288
|
}
|
|
285
|
-
/* c8 ignore stop */
|
|
286
289
|
context.report({
|
|
287
290
|
node: sizeArg,
|
|
288
291
|
messageId: 'userControlledResourceSize',
|
|
289
292
|
data: {
|
|
290
293
|
filePath: filename,
|
|
291
|
-
line: String(node.loc
|
|
294
|
+
line: String(node.loc.start.line),
|
|
292
295
|
},
|
|
293
296
|
});
|
|
294
297
|
return;
|
|
@@ -296,39 +299,26 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
296
299
|
// Check if size exceeds limits
|
|
297
300
|
const estimatedSize = sizeArg.type === 'SpreadElement' ? null : estimateResourceSize(sizeArg);
|
|
298
301
|
if (estimatedSize && estimatedSize > maxResourceSize) {
|
|
299
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
300
302
|
if (safetyChecker.isSafe(node, context)) {
|
|
301
303
|
return;
|
|
302
304
|
}
|
|
303
|
-
/* c8 ignore stop */
|
|
304
305
|
context.report({
|
|
305
306
|
node: sizeArg,
|
|
306
307
|
messageId: 'unlimitedBufferAllocation',
|
|
307
308
|
data: {
|
|
308
309
|
filePath: filename,
|
|
309
|
-
line: String(node.loc
|
|
310
|
+
line: String(node.loc.start.line),
|
|
310
311
|
},
|
|
311
312
|
});
|
|
312
313
|
return;
|
|
313
314
|
}
|
|
314
|
-
//
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
/* c8 ignore stop */
|
|
323
|
-
context.report({
|
|
324
|
-
node,
|
|
325
|
-
messageId: 'missingResourceLimits',
|
|
326
|
-
data: {
|
|
327
|
-
filePath: filename,
|
|
328
|
-
line: String(node.loc?.start.line ?? 0),
|
|
329
|
-
},
|
|
330
|
-
});
|
|
331
|
-
}
|
|
315
|
+
// NOTE: a `missingResourceLimits` check previously lived here for
|
|
316
|
+
// "non-literal, user-input sizes with no validation" — but that
|
|
317
|
+
// condition is a strict subset of the userControlledResourceSize
|
|
318
|
+
// check above (same `isUserInput(sizeArg) && !hasSizeValidation(node)`
|
|
319
|
+
// predicate), which already reports and returns first. It was
|
|
320
|
+
// therefore unreachable dead code and has been removed
|
|
321
|
+
// (behavior-neutral: no observable path changes).
|
|
332
322
|
}
|
|
333
323
|
}
|
|
334
324
|
// Check for multer configuration without limits
|
|
@@ -353,17 +343,15 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
353
343
|
return false;
|
|
354
344
|
});
|
|
355
345
|
if (!hasValidLimits) {
|
|
356
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
357
346
|
if (safetyChecker.isSafe(node, context)) {
|
|
358
347
|
return;
|
|
359
348
|
}
|
|
360
|
-
/* c8 ignore stop */
|
|
361
349
|
context.report({
|
|
362
350
|
node,
|
|
363
351
|
messageId: 'unlimitedFileOperations',
|
|
364
352
|
data: {
|
|
365
353
|
filePath: filename,
|
|
366
|
-
line: String(node.loc
|
|
354
|
+
line: String(node.loc.start.line),
|
|
367
355
|
},
|
|
368
356
|
});
|
|
369
357
|
}
|
|
@@ -399,17 +387,15 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
399
387
|
}
|
|
400
388
|
}
|
|
401
389
|
if (pathArg.type !== 'SpreadElement' && isUserInput(pathArg)) {
|
|
402
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
403
390
|
if (safetyChecker.isSafe(node, context)) {
|
|
404
391
|
return;
|
|
405
392
|
}
|
|
406
|
-
/* c8 ignore stop */
|
|
407
393
|
context.report({
|
|
408
394
|
node: pathArg,
|
|
409
395
|
messageId: 'unlimitedFileOperations',
|
|
410
396
|
data: {
|
|
411
397
|
filePath: filename,
|
|
412
|
-
line: String(node.loc
|
|
398
|
+
line: String(node.loc.start.line),
|
|
413
399
|
},
|
|
414
400
|
});
|
|
415
401
|
}
|
|
@@ -421,24 +407,21 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
421
407
|
if (args.length === 1) {
|
|
422
408
|
const sizeArg = args[0];
|
|
423
409
|
if (sizeArg.type !== 'SpreadElement' && isUserInput(sizeArg)) {
|
|
424
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
425
410
|
if (safetyChecker.isSafe(node, context)) {
|
|
426
411
|
return;
|
|
427
412
|
}
|
|
428
|
-
/* c8 ignore stop */
|
|
429
413
|
context.report({
|
|
430
414
|
node: sizeArg,
|
|
431
415
|
messageId: 'unlimitedMemoryAllocation',
|
|
432
416
|
data: {
|
|
433
417
|
filePath: filename,
|
|
434
|
-
line: String(node.loc
|
|
418
|
+
line: String(node.loc.start.line),
|
|
435
419
|
},
|
|
436
420
|
});
|
|
437
421
|
}
|
|
438
422
|
}
|
|
439
423
|
}
|
|
440
424
|
// Check for complex resource exhaustion patterns
|
|
441
|
-
/* c8 ignore start -- defensive detectors for rare patterns */
|
|
442
425
|
// ZIP bomb detection - unlimited decompression
|
|
443
426
|
if (calleeText.includes('unzipper') || calleeText.includes('Extract')) {
|
|
444
427
|
// Check for unlimited ZIP extraction
|
|
@@ -447,7 +430,7 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
447
430
|
messageId: 'unlimitedFileOperations',
|
|
448
431
|
data: {
|
|
449
432
|
filePath: filename,
|
|
450
|
-
line: String(node.loc
|
|
433
|
+
line: String(node.loc.start.line),
|
|
451
434
|
},
|
|
452
435
|
});
|
|
453
436
|
}
|
|
@@ -458,7 +441,7 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
458
441
|
messageId: 'unlimitedMemoryAllocation',
|
|
459
442
|
data: {
|
|
460
443
|
filePath: filename,
|
|
461
|
-
line: String(node.loc
|
|
444
|
+
line: String(node.loc.start.line),
|
|
462
445
|
},
|
|
463
446
|
});
|
|
464
447
|
}
|
|
@@ -475,7 +458,7 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
475
458
|
messageId: 'unlimitedMemoryAllocation',
|
|
476
459
|
data: {
|
|
477
460
|
filePath: filename,
|
|
478
|
-
line: String(node.loc
|
|
461
|
+
line: String(node.loc.start.line),
|
|
479
462
|
},
|
|
480
463
|
});
|
|
481
464
|
}
|
|
@@ -494,13 +477,12 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
494
477
|
messageId: 'unlimitedMemoryAllocation',
|
|
495
478
|
data: {
|
|
496
479
|
filePath: filename,
|
|
497
|
-
line: String(node.loc
|
|
480
|
+
line: String(node.loc.start.line),
|
|
498
481
|
},
|
|
499
482
|
});
|
|
500
483
|
}
|
|
501
484
|
}
|
|
502
485
|
}
|
|
503
|
-
/* c8 ignore stop */
|
|
504
486
|
// Check for resource allocation inside loops
|
|
505
487
|
if ((0, eslint_devkit_3.isInsideLoop)(node)) {
|
|
506
488
|
// Check if this allocates resources
|
|
@@ -516,11 +498,9 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
516
498
|
// Array.from / Array.of are fine; allocation comes from their args, not size
|
|
517
499
|
}
|
|
518
500
|
else {
|
|
519
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
520
501
|
if (safetyChecker.isSafe(node, context)) {
|
|
521
502
|
return;
|
|
522
503
|
}
|
|
523
|
-
/* c8 ignore stop */
|
|
524
504
|
// SAFE: first arg is a numeric literal — size is statically bounded.
|
|
525
505
|
const firstArg = node.arguments[0];
|
|
526
506
|
if (firstArg?.type === 'Literal' && typeof firstArg.value === 'number') {
|
|
@@ -539,7 +519,7 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
539
519
|
messageId: 'resourceAllocationInLoop',
|
|
540
520
|
data: {
|
|
541
521
|
filePath: filename,
|
|
542
|
-
line: String(node.loc
|
|
522
|
+
line: String(node.loc.start.line),
|
|
543
523
|
},
|
|
544
524
|
});
|
|
545
525
|
}
|
|
@@ -554,19 +534,22 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
554
534
|
const args = node.arguments;
|
|
555
535
|
if (args.length > 0) {
|
|
556
536
|
const sizeArg = args[0];
|
|
557
|
-
// Check if size comes from user input (but skip if validated)
|
|
558
|
-
|
|
559
|
-
|
|
537
|
+
// Check if size comes from user input (but skip if validated).
|
|
538
|
+
// Disabling `requireResourceValidation` opts out of this check
|
|
539
|
+
// entirely, mirroring the CallExpression Buffer.alloc() branch.
|
|
540
|
+
if (requireResourceValidation &&
|
|
541
|
+
sizeArg.type !== 'SpreadElement' &&
|
|
542
|
+
isUserInput(sizeArg) &&
|
|
543
|
+
!hasSizeValidation(node)) {
|
|
560
544
|
if (safetyChecker.isSafe(node, context)) {
|
|
561
545
|
return;
|
|
562
546
|
}
|
|
563
|
-
/* c8 ignore stop */
|
|
564
547
|
context.report({
|
|
565
548
|
node: sizeArg,
|
|
566
549
|
messageId: 'userControlledResourceSize',
|
|
567
550
|
data: {
|
|
568
551
|
filePath: filename,
|
|
569
|
-
line: String(node.loc
|
|
552
|
+
line: String(node.loc.start.line),
|
|
570
553
|
},
|
|
571
554
|
});
|
|
572
555
|
return;
|
|
@@ -574,39 +557,23 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
574
557
|
// Check if size exceeds limits
|
|
575
558
|
const estimatedSize = sizeArg.type === 'SpreadElement' ? null : estimateResourceSize(sizeArg);
|
|
576
559
|
if (estimatedSize && estimatedSize > maxResourceSize) {
|
|
577
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
578
560
|
if (safetyChecker.isSafe(node, context)) {
|
|
579
561
|
return;
|
|
580
562
|
}
|
|
581
|
-
/* c8 ignore stop */
|
|
582
563
|
context.report({
|
|
583
564
|
node: sizeArg,
|
|
584
565
|
messageId: 'unlimitedBufferAllocation',
|
|
585
566
|
data: {
|
|
586
567
|
filePath: filename,
|
|
587
|
-
line: String(node.loc
|
|
568
|
+
line: String(node.loc.start.line),
|
|
588
569
|
},
|
|
589
570
|
});
|
|
590
571
|
return;
|
|
591
572
|
}
|
|
592
|
-
//
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
597
|
-
if (safetyChecker.isSafe(node, context)) {
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
/* c8 ignore stop */
|
|
601
|
-
context.report({
|
|
602
|
-
node,
|
|
603
|
-
messageId: 'missingResourceLimits',
|
|
604
|
-
data: {
|
|
605
|
-
filePath: filename,
|
|
606
|
-
line: String(node.loc?.start.line ?? 0),
|
|
607
|
-
},
|
|
608
|
-
});
|
|
609
|
-
}
|
|
573
|
+
// NOTE: same unreachable `missingResourceLimits` pattern as the
|
|
574
|
+
// CallExpression Buffer.alloc handler above — removed for the
|
|
575
|
+
// identical reason (subset of the userControlledResourceSize
|
|
576
|
+
// check, which already reports and returns first).
|
|
610
577
|
}
|
|
611
578
|
}
|
|
612
579
|
// Check for new Array() with user input
|
|
@@ -615,17 +582,15 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
615
582
|
if (args.length === 1) {
|
|
616
583
|
const sizeArg = args[0];
|
|
617
584
|
if (sizeArg.type !== 'SpreadElement' && isUserInput(sizeArg)) {
|
|
618
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
619
585
|
if (safetyChecker.isSafe(node, context)) {
|
|
620
586
|
return;
|
|
621
587
|
}
|
|
622
|
-
/* c8 ignore stop */
|
|
623
588
|
context.report({
|
|
624
589
|
node: sizeArg,
|
|
625
590
|
messageId: 'unlimitedMemoryAllocation',
|
|
626
591
|
data: {
|
|
627
592
|
filePath: filename,
|
|
628
|
-
line: String(node.loc
|
|
593
|
+
line: String(node.loc.start.line),
|
|
629
594
|
},
|
|
630
595
|
});
|
|
631
596
|
}
|
|
@@ -638,11 +603,9 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
638
603
|
newCalleeText.includes('Array') ||
|
|
639
604
|
newCalleeText.includes('Map') ||
|
|
640
605
|
newCalleeText.includes('Set')) {
|
|
641
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
642
606
|
if (safetyChecker.isSafe(node, context)) {
|
|
643
607
|
return;
|
|
644
608
|
}
|
|
645
|
-
/* c8 ignore stop */
|
|
646
609
|
// SAFE: first arg is a numeric literal — size is statically bounded.
|
|
647
610
|
const firstArg = node.arguments[0];
|
|
648
611
|
if (firstArg?.type === 'Literal' && typeof firstArg.value === 'number') {
|
|
@@ -653,7 +616,7 @@ exports.noUnlimitedResourceAllocation = (0, eslint_devkit_1.createRule)({
|
|
|
653
616
|
messageId: 'resourceAllocationInLoop',
|
|
654
617
|
data: {
|
|
655
618
|
filePath: filename,
|
|
656
|
-
line: String(node.loc
|
|
619
|
+
line: String(node.loc.start.line),
|
|
657
620
|
},
|
|
658
621
|
});
|
|
659
622
|
}
|
|
@@ -296,9 +296,6 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
|
|
|
296
296
|
if (objectName === 'yaml' && memberName === 'safeLoad') {
|
|
297
297
|
return true;
|
|
298
298
|
}
|
|
299
|
-
if (objectName === 'js-yaml' && memberName === 'safeLoad') {
|
|
300
|
-
return true;
|
|
301
|
-
}
|
|
302
299
|
}
|
|
303
300
|
return false;
|
|
304
301
|
};
|
|
@@ -383,11 +380,9 @@ exports.noUnsafeDeserialization = (0, eslint_devkit_1.createRule)({
|
|
|
383
380
|
});
|
|
384
381
|
if (hasUntrustedInput) {
|
|
385
382
|
// Even JSON.parse can be unsafe if used on complex objects that get eval'd later
|
|
386
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
387
383
|
if (safetyChecker.isSafe(node, context)) {
|
|
388
384
|
return;
|
|
389
385
|
}
|
|
390
|
-
/* c8 ignore stop */
|
|
391
386
|
context.report({
|
|
392
387
|
node,
|
|
393
388
|
messageId: 'untrustedDeserializationInput',
|