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.
Files changed (31) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/src/index.js +1 -1
  5. package/src/rules/detect-non-literal-regexp/index.js +48 -61
  6. package/src/rules/detect-object-injection/index.js +32 -88
  7. package/src/rules/detect-weak-password-validation/index.js +1 -1
  8. package/src/rules/no-directive-injection/index.js +0 -16
  9. package/src/rules/no-electron-security-issues/index.js +0 -6
  10. package/src/rules/no-format-string-injection/index.js +2 -29
  11. package/src/rules/no-graphql-injection/index.js +10 -10
  12. package/src/rules/no-hardcoded-credentials/index.js +13 -8
  13. package/src/rules/no-hardcoded-session-tokens/index.js +1 -1
  14. package/src/rules/no-improper-sanitization/index.js +1 -9
  15. package/src/rules/no-improper-type-validation/index.js +0 -10
  16. package/src/rules/no-insecure-comparison/index.js +1 -1
  17. package/src/rules/no-ldap-injection/index.d.ts +14 -0
  18. package/src/rules/no-ldap-injection/index.js +51 -58
  19. package/src/rules/no-missing-authentication/index.js +13 -17
  20. package/src/rules/no-privilege-escalation/index.js +1 -1
  21. package/src/rules/no-redos-vulnerable-regex/index.js +0 -7
  22. package/src/rules/no-sensitive-data-exposure/index.js +1 -1
  23. package/src/rules/no-template-injection/index.js +1 -1
  24. package/src/rules/no-unchecked-loop-condition/index.js +21 -37
  25. package/src/rules/no-unlimited-resource-allocation/index.js +42 -79
  26. package/src/rules/no-unsafe-deserialization/index.js +0 -5
  27. package/src/rules/no-unsafe-regex-construction/index.js +14 -2
  28. package/src/rules/no-weak-password-recovery/index.js +0 -6
  29. package/src/rules/no-xpath-injection/index.js +19 -45
  30. package/src/rules/no-xxe-injection/index.js +5 -2
  31. package/src/rules/require-backend-authorization/index.js +1 -1
@@ -153,10 +153,6 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
153
153
  return true;
154
154
  }
155
155
  }
156
- // Check if the node is a validated/sanitized variable
157
- if (safeNode.type === 'Identifier' && validatedVariables.has(safeNode.name)) {
158
- return true;
159
- }
160
156
  // For CallExpression nodes, check if first argument is safe
161
157
  if (safeNode.type === 'CallExpression' && safeNode.arguments.length > 0) {
162
158
  const firstArg = safeNode.arguments[0];
@@ -350,11 +346,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
350
346
  (formatArg.type === 'Identifier' && dangerousVariables.has(formatArg.name)) ||
351
347
  (formatArg.type === 'BinaryExpression' && hasUserInputInExpression(formatArg));
352
348
  if (isFormatFromUserInput && !isConsoleMethod(node)) {
353
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
354
349
  if (safetyChecker.isSafe(node, context)) {
355
350
  return;
356
351
  }
357
- /* c8 ignore stop */
358
352
  context.report({
359
353
  node: formatArg,
360
354
  messageId: 'userControlledFormatString',
@@ -369,11 +363,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
369
363
  if (formatArg.type === 'TemplateLiteral') {
370
364
  const hasUserInput = formatArg.expressions.some((expr) => isUserInputNode(expr));
371
365
  if (hasUserInput) {
372
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
373
366
  if (safetyChecker.isSafe(node, context)) {
374
367
  return;
375
368
  }
376
- /* c8 ignore stop */
377
369
  context.report({
378
370
  node: formatArg,
379
371
  messageId: 'formatStringInjection',
@@ -390,11 +382,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
390
382
  else if (formatArg.type === 'BinaryExpression' && formatArg.operator === '+') {
391
383
  const hasUserInput = hasUserInputInExpression(formatArg);
392
384
  if (hasUserInput) {
393
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
394
385
  if (safetyChecker.isSafe(node, context)) {
395
386
  return;
396
387
  }
397
- /* c8 ignore stop */
398
388
  context.report({
399
389
  node: formatArg,
400
390
  messageId: 'formatStringInjection',
@@ -444,11 +434,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
444
434
  // Don't report
445
435
  }
446
436
  else if (hasSpecifiersInFormat && hasUserInputInArgs) {
447
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
448
437
  if (safetyChecker.isSafe(node, context)) {
449
438
  return;
450
439
  }
451
- /* c8 ignore stop */
452
440
  // Choose message ID based on format string type
453
441
  const messageId = firstArg.type === 'Literal' ? 'unsafeFormatSpecifier' : 'missingFormatValidation';
454
442
  context.report({
@@ -462,15 +450,8 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
462
450
  {
463
451
  messageId: 'escapeFormatString',
464
452
  fix: (fixer) => {
465
- // Find the argument that needs escaping
466
- // This is a bit heuristic, we try to find the first user input argument
467
- for (let i = 1; i < node.arguments.length; i++) {
468
- const arg = node.arguments[i];
469
- if (isUserInputNode(arg)) {
470
- return fixer.insertTextAfter(arg, '.replace(/%/g, "%%")');
471
- }
472
- }
473
- return null;
453
+ const arg = node.arguments.slice(1).find(a => isUserInputNode(a));
454
+ return fixer.insertTextAfter(arg, '.replace(/%/g, "%%")');
474
455
  },
475
456
  },
476
457
  ],
@@ -537,11 +518,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
537
518
  current = current.parent;
538
519
  }
539
520
  if (isInDangerousContext && containsFormatSpecifiers(text)) {
540
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
541
521
  if (safetyChecker.isSafe(node, context)) {
542
522
  return;
543
523
  }
544
- /* c8 ignore stop */
545
524
  context.report({
546
525
  node,
547
526
  messageId: 'missingFormatValidation',
@@ -586,11 +565,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
586
565
  assignCurrent = assignCurrent.parent;
587
566
  }
588
567
  if (isAssignedToVariable) {
589
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
590
568
  if (safetyChecker.isSafe(node, context)) {
591
569
  return;
592
570
  }
593
- /* c8 ignore stop */
594
571
  context.report({
595
572
  node,
596
573
  messageId: 'formatStringInjection',
@@ -629,11 +606,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
629
606
  const hasSpecifiers = node.init.quasis.some((quasi) => containsFormatSpecifiers(quasi.value.raw));
630
607
  const hasUserInput = node.init.expressions.some((expr) => isUserInputNode(expr));
631
608
  if (hasSpecifiers && hasUserInput) {
632
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
633
609
  if (safetyChecker.isSafe(node, context)) {
634
610
  return;
635
611
  }
636
- /* c8 ignore stop */
637
612
  context.report({
638
613
  node: node.init,
639
614
  messageId: 'formatStringInjection',
@@ -651,11 +626,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
651
626
  const hasSpecifiers = containsFormatSpecifiersInExpression(node.init);
652
627
  const hasUserInput = hasUserInputInExpression(node.init);
653
628
  if (hasSpecifiers && hasUserInput) {
654
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
655
629
  if (safetyChecker.isSafe(node, context)) {
656
630
  return;
657
631
  }
658
- /* c8 ignore stop */
659
632
  context.report({
660
633
  node: node.init,
661
634
  messageId: 'formatStringInjection',
@@ -243,10 +243,6 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
243
243
  if (safeMemberCallers.has(key))
244
244
  return true;
245
245
  }
246
- // Direct function call
247
- if (callee.type === 'Identifier' && safeMemberCallers.has(callee.name)) {
248
- return true;
249
- }
250
246
  break; // Stop at first enclosing call
251
247
  }
252
248
  // new URL(`...`), new Error(`...`)
@@ -286,9 +282,18 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
286
282
  * Find keyword at word boundary in text. Returns index or -1.
287
283
  * Uses simple character checks instead of regex \b.
288
284
  */
285
+ // NOTE: this loop always terminates via one of its two internal `return`
286
+ // statements: `text.indexOf` eventually returns -1 for any finite input,
287
+ // and each successful-but-boundary-failing match only advances `pos` by 1
288
+ // (never past `text.length`) before the next `indexOf` call runs. There is
289
+ // no fallthrough path once the `while` condition becomes false, so the
290
+ // loop is written with `while (true)` + internal returns instead of a
291
+ // trailing `return -1` that static analysis (and coverage) would flag as
292
+ // dead code.
289
293
  const findKeywordAtBoundary = (text, keyword, startFrom = 0) => {
290
294
  let pos = startFrom;
291
- while (pos < text.length) {
295
+ // oxlint-disable-next-line no-constant-condition
296
+ while (true) {
292
297
  const idx = text.indexOf(keyword, pos);
293
298
  if (idx === -1)
294
299
  return -1;
@@ -299,7 +304,6 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
299
304
  return idx;
300
305
  pos = idx + 1;
301
306
  }
302
- return -1;
303
307
  };
304
308
  /**
305
309
  * AST-based: Check if a TemplateLiteral contains GraphQL syntax.
@@ -580,11 +584,9 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
580
584
  // Check for introspection queries
581
585
  const lowerQuery = queryText.toLowerCase();
582
586
  if (!allowIntrospection && (lowerQuery.includes('__schema') || lowerQuery.includes('__type'))) {
583
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
584
587
  if (safetyChecker.isSafe(node, context)) {
585
588
  return;
586
589
  }
587
- /* c8 ignore stop */
588
590
  context.report({
589
591
  node,
590
592
  messageId: 'introspectionQuery',
@@ -627,11 +629,9 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
627
629
  return;
628
630
  }
629
631
  // String concatenation in GraphQL queries is dangerous
630
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
631
632
  if (safetyChecker.isSafe(node, context)) {
632
633
  return;
633
634
  }
634
- /* c8 ignore stop */
635
635
  context.report({
636
636
  node,
637
637
  messageId: 'graphqlInjection',
@@ -130,7 +130,7 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
130
130
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-hardcoded-credentials.md',
131
131
  description: 'Detects hardcoded passwords, API keys, tokens, and other sensitive credentials',
132
132
  cwe: 'CWE-798',
133
- cvss: 9.5,
133
+ cvss: 9.8,
134
134
  confidence: 'medium',
135
135
  },
136
136
  fixable: 'code',
@@ -274,7 +274,7 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
274
274
  ],
275
275
  create(context) {
276
276
  const options = context.options[0] || {};
277
- const { ignorePatterns = [], allowInTests = false, minLength = 8, detectApiKeys = true, detectPasswords = true, detectTokens = true, detectDatabaseStrings = true, customPatterns = [], } = options || {};
277
+ const { ignorePatterns = [], allowInTests = false, minLength = 8, detectApiKeys = true, detectPasswords = true, detectTokens = true, detectDatabaseStrings = true, customPatterns = [], } = options;
278
278
  const filename = context.filename;
279
279
  const isTestFile = allowInTests && (filename.includes('.test.') ||
280
280
  filename.includes('.spec.') ||
@@ -413,10 +413,12 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
413
413
  * secret-key style names. Anything else falls back to `other`, which
414
414
  * the options never gate (e.g. `credentials`, `auth`).
415
415
  */
416
- function inferCredentialTypeFromContext(parent) {
416
+ function inferCredentialTypeFromContext(
417
+ // Non-optional: the sole caller only reaches here after
418
+ // isCredentialContext(node, parent) has already returned true, which
419
+ // requires a truthy parent.
420
+ parent) {
417
421
  const name = (() => {
418
- if (!parent)
419
- return '';
420
422
  if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {
421
423
  return parent.id.name.toLowerCase();
422
424
  }
@@ -424,9 +426,10 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
424
426
  const key = parent.key;
425
427
  if (key.type === 'Identifier')
426
428
  return key.name.toLowerCase();
427
- if (key.type === 'Literal' && typeof key.value === 'string') {
428
- return key.value.toLowerCase();
429
- }
429
+ // isCredentialContext's own Property check only returns true for
430
+ // an Identifier key (handled above) or a string-Literal key, so
431
+ // whatever remains here is always the latter.
432
+ return String(key.value).toLowerCase();
430
433
  }
431
434
  if (parent.type === 'AssignmentExpression') {
432
435
  const left = parent.left;
@@ -573,6 +576,8 @@ exports.noHardcodedCredentials = (0, eslint_devkit_2.createRule)({
573
576
  // honour the option.
574
577
  if (!finalIsCredential && value.length >= detectionOptions.minLength &&
575
578
  isCredentialContext(node, parent)) {
579
+ // isCredentialContext(node, parent) just returned true, which
580
+ // requires a truthy parent.
576
581
  const ctxType = inferCredentialTypeFromContext(parent);
577
582
  const optionAllows = (ctxType === 'password' && detectionOptions.detectPasswords) ||
578
583
  (ctxType === 'token' && detectionOptions.detectTokens) ||
@@ -18,7 +18,7 @@ exports.noHardcodedSessionTokens = (0, eslint_devkit_1.createRule)({
18
18
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-hardcoded-session-tokens.md',
19
19
  description: 'Detect hardcoded session/JWT tokens',
20
20
  cwe: 'CWE-798',
21
- cvss: 9.5,
21
+ cvss: 9.8,
22
22
  },
23
23
  messages: {
24
24
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -264,11 +264,9 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
264
264
  callee.property.type === 'Identifier' &&
265
265
  callee.property.name === 'replace') {
266
266
  if (isIncompleteReplaceSanitization(node)) {
267
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
268
267
  if (safetyChecker.isSafe(node, context)) {
269
268
  return;
270
269
  }
271
- /* c8 ignore stop */
272
270
  context.report({
273
271
  node,
274
272
  messageId: 'incompleteHtmlEscaping',
@@ -301,11 +299,9 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
301
299
  }
302
300
  }
303
301
  if (hasUserInput) {
304
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
305
302
  if (safetyChecker.isSafe(node, context)) {
306
303
  return;
307
304
  }
308
- /* c8 ignore stop */
309
305
  context.report({
310
306
  node,
311
307
  messageId: 'dangerousSanitizerUsage',
@@ -339,11 +335,9 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
339
335
  rightText.includes('query') ||
340
336
  rightText.includes('input');
341
337
  if (hasUserInput) {
342
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
343
338
  if (safetyChecker.isSafe(node, context)) {
344
339
  return;
345
340
  }
346
- /* c8 ignore stop */
347
341
  context.report({
348
342
  node: right,
349
343
  messageId: 'insufficientXssProtection',
@@ -380,7 +374,7 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
380
374
  const left = directParent.left;
381
375
  if (left.property.type === 'Identifier' &&
382
376
  ['innerHTML', 'outerHTML'].includes(left.property.name)) {
383
- const literalValue = typeof node.value === 'string' ? node.value : '';
377
+ const literalValue = node.value;
384
378
  const hasDangerousMarkup = /<script[\s>]|<\/script>|\son\w+\s*=|javascript:/i.test(literalValue);
385
379
  if (!hasDangerousMarkup) {
386
380
  return;
@@ -422,11 +416,9 @@ exports.noImproperSanitization = (0, eslint_devkit_1.createRule)({
422
416
  text.includes('&quot;') || text.includes('&#x27;') ||
423
417
  text.includes('&amp;');
424
418
  if (hasDangerousChars && !hasEscaping) {
425
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
426
419
  if (safetyChecker.isSafe(node, context)) {
427
420
  return;
428
421
  }
429
- /* c8 ignore stop */
430
422
  context.report({
431
423
  node,
432
424
  messageId: 'unsafeReplaceSanitization',
@@ -299,11 +299,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
299
299
  matchesUserInput = true;
300
300
  }
301
301
  if (matchesUserInput) {
302
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
303
302
  if (safetyChecker.isSafe(node, context)) {
304
303
  return;
305
304
  }
306
- /* c8 ignore stop */
307
305
  context.report({
308
306
  node: left,
309
307
  messageId: 'unsafeTypeofCheck',
@@ -344,11 +342,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
344
342
  if ((left.type === 'Identifier' && isUserInput(left.name)) ||
345
343
  (right.type === 'Identifier' && isUserInput(right.name)) ||
346
344
  leftText.includes('null') || rightText.includes('null')) {
347
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
348
345
  if (safetyChecker.isSafe(node, context)) {
349
346
  return;
350
347
  }
351
- /* c8 ignore stop */
352
348
  context.report({
353
349
  node: node,
354
350
  messageId: 'looseEqualityTypeCheck',
@@ -383,11 +379,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
383
379
  }
384
380
  }
385
381
  if (involvesUserInput) {
386
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
387
382
  if (safetyChecker.isSafe(node, context)) {
388
383
  return;
389
384
  }
390
- /* c8 ignore stop */
391
385
  context.report({
392
386
  node,
393
387
  messageId: 'unreliableConstructorCheck',
@@ -435,11 +429,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
435
429
  const test = node.test;
436
430
  // NEW: Check for implicit truthiness check on user input
437
431
  if (test.type === 'Identifier' && isUserInput(test.name)) {
438
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
439
432
  if (safetyChecker.isSafe(node, context)) {
440
433
  return;
441
434
  }
442
- /* c8 ignore stop */
443
435
  context.report({
444
436
  node: test,
445
437
  messageId: 'improperTypeValidation',
@@ -460,11 +452,9 @@ exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
460
452
  // Check if this involves user input
461
453
  if ((test.left.type === 'Identifier' && isUserInput(test.left.name)) ||
462
454
  (test.right.type === 'Identifier' && isUserInput(test.right.name))) {
463
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
464
455
  if (safetyChecker.isSafe(node, context)) {
465
456
  return;
466
457
  }
467
- /* c8 ignore stop */
468
458
  context.report({
469
459
  node: test,
470
460
  messageId: 'missingNullCheck',
@@ -18,7 +18,7 @@ exports.noInsecureComparison = (0, eslint_devkit_2.createRule)({
18
18
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-insecure-comparison.md',
19
19
  description: 'Detects insecure comparison operators (==, !=) that can lead to type coercion vulnerabilities',
20
20
  cwe: 'CWE-697',
21
- cvss: 7.5,
21
+ cvss: 5.3,
22
22
  },
23
23
  fixable: 'code',
24
24
  hasSuggestions: true,
@@ -33,6 +33,20 @@ export interface Options extends SecurityRuleOptions {
33
33
  ldapValidationFunctions?: string[];
34
34
  }
35
35
  type RuleOptions = [Options?];
36
+ /**
37
+ * Check if LDAP filter contains dangerous patterns.
38
+ *
39
+ * Extracted to module scope (from inside `create()`) for direct unit
40
+ * testability — this function is pure and captures no closure state.
41
+ */
42
+ export declare function containsDangerousLdapFilter(filterText: string): boolean;
43
+ /**
44
+ * Check if string contains LDAP filter interpolation.
45
+ *
46
+ * Extracted to module scope (from inside `create()`) for direct unit
47
+ * testability — this function is pure and captures no closure state.
48
+ */
49
+ export declare function containsLdapInterpolation(text: string): boolean;
36
50
  export declare const noLdapInjection: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
37
51
  name: string;
38
52
  };
@@ -6,9 +6,39 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.noLdapInjection = void 0;
9
+ exports.containsDangerousLdapFilter = containsDangerousLdapFilter;
10
+ exports.containsLdapInterpolation = containsLdapInterpolation;
9
11
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
12
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
13
  const eslint_devkit_3 = require("@interlace/eslint-devkit");
14
+ /**
15
+ * Check if LDAP filter contains dangerous patterns.
16
+ *
17
+ * Extracted to module scope (from inside `create()`) for direct unit
18
+ * testability — this function is pure and captures no closure state.
19
+ */
20
+ function containsDangerousLdapFilter(filterText) {
21
+ // Dangerous LDAP filter patterns
22
+ const dangerousPatterns = [
23
+ /\*\)$/, // Ending with *) to match everything
24
+ /\|\)$/, // Ending with |) for OR operations
25
+ /&\)$/, // Ending with &) for AND operations
26
+ /!\)$/, // Ending with !) for NOT operations
27
+ /\*\|\*/, // *|* pattern for matching everything
28
+ /\*&\*/, // *&* pattern
29
+ /\*!/, // NOT operations that could be exploited
30
+ ];
31
+ return dangerousPatterns.some(pattern => pattern.test(filterText));
32
+ }
33
+ /**
34
+ * Check if string contains LDAP filter interpolation.
35
+ *
36
+ * Extracted to module scope (from inside `create()`) for direct unit
37
+ * testability — this function is pure and captures no closure state.
38
+ */
39
+ function containsLdapInterpolation(text) {
40
+ return /\$\{[^}]+\}/.test(text) || /'[^']*\+[^+]*'/.test(text) || /"[^"]*\+[^+]*"/.test(text);
41
+ }
12
42
  exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
13
43
  name: 'no-ldap-injection',
14
44
  meta: {
@@ -181,30 +211,6 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
181
211
  }
182
212
  return false;
183
213
  };
184
- /**
185
- * Check if LDAP filter contains dangerous patterns
186
- */
187
- // oxlint-disable-next-line consistent-function-scoping
188
- const containsDangerousLdapFilter = (filterText) => {
189
- // Dangerous LDAP filter patterns
190
- const dangerousPatterns = [
191
- /\*\)$/, // Ending with *) to match everything
192
- /\|\)$/, // Ending with |) for OR operations
193
- /&\)$/, // Ending with &) for AND operations
194
- /!\)$/, // Ending with !) for NOT operations
195
- /\*\|\*/, // *|* pattern for matching everything
196
- /\*&\*/, // *&* pattern
197
- /\*!/, // NOT operations that could be exploited
198
- ];
199
- return dangerousPatterns.some(pattern => pattern.test(filterText));
200
- };
201
- /**
202
- * Check if string contains LDAP filter interpolation
203
- */
204
- // oxlint-disable-next-line consistent-function-scoping
205
- const containsLdapInterpolation = (text) => {
206
- return /\$\{[^}]+\}/.test(text) || /'[^']*\+[^+]*'/.test(text) || /"[^"]*\+[^+]*"/.test(text);
207
- };
208
214
  /**
209
215
  * Check if LDAP input is from untrusted source
210
216
  */
@@ -266,11 +272,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
266
272
  const filterArg = args[1];
267
273
  // Check if filter argument comes from untrusted input (like req.query.filter)
268
274
  if (isUntrustedLdapInput(filterArg)) {
269
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
270
275
  if (safetyChecker.isSafe(filterArg, context)) {
271
276
  return;
272
277
  }
273
- /* c8 ignore stop */
274
278
  context.report({
275
279
  node: filterArg,
276
280
  messageId: 'unescapedLdapInput',
@@ -288,29 +292,28 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
288
292
  }
289
293
  else if (filterArg.type === 'TemplateLiteral' && filterArg.expressions.length > 0) {
290
294
  // Special handling for template literals with any expressions in LDAP calls
291
- // This is a more aggressive check for LDAP injection in function calls
292
- const hasAnyExpression = filterArg.expressions.some(() => true);
293
- if (hasAnyExpression) {
294
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
295
- if (safetyChecker.isSafe(filterArg, context)) {
296
- return;
297
- }
298
- /* c8 ignore stop */
299
- context.report({
300
- node: filterArg,
301
- messageId: 'unescapedLdapInput',
302
- data: {
303
- filePath: filename,
304
- line: String(node.loc?.start.line ?? 0),
305
- },
306
- suggest: [
307
- {
308
- messageId: 'useLdapEscaping',
309
- fix: () => null,
310
- },
311
- ],
312
- });
295
+ // This is a more aggressive check for LDAP injection in function calls.
296
+ // NOTE: the `expressions.length > 0` guard above already guarantees at
297
+ // least one interpolated expression is present, so a further
298
+ // `.some(() => true)` check was always trivially true and has been
299
+ // removed as provably dead code (behavior-unchanged).
300
+ if (safetyChecker.isSafe(filterArg, context)) {
301
+ return;
313
302
  }
303
+ context.report({
304
+ node: filterArg,
305
+ messageId: 'unescapedLdapInput',
306
+ data: {
307
+ filePath: filename,
308
+ line: String(node.loc?.start.line ?? 0),
309
+ },
310
+ suggest: [
311
+ {
312
+ messageId: 'useLdapEscaping',
313
+ fix: () => null,
314
+ },
315
+ ],
316
+ });
314
317
  }
315
318
  },
316
319
  // Check variable declarations with LDAP filters
@@ -333,11 +336,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
333
336
  // Check if assigned value contains dangerous LDAP patterns
334
337
  if (node.init.type === 'Literal' && typeof node.init.value === 'string') {
335
338
  if (containsDangerousLdapFilter(node.init.value)) {
336
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
337
339
  if (safetyChecker.isSafe(node.init, context)) {
338
340
  return;
339
341
  }
340
- /* c8 ignore stop */
341
342
  context.report({
342
343
  node: node.init,
343
344
  messageId: 'dangerousLdapOperation',
@@ -356,11 +357,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
356
357
  // Check if any interpolated values are untrusted
357
358
  const hasUntrustedInterpolation = node.init.expressions.some((expr) => isUntrustedLdapInput(expr) && !isLdapInputEscaped(expr));
358
359
  if (hasUntrustedInterpolation) {
359
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
360
360
  if (safetyChecker.isSafe(node.init, context)) {
361
361
  return;
362
362
  }
363
- /* c8 ignore stop */
364
363
  context.report({
365
364
  node: node.init,
366
365
  messageId: 'unsafeLdapFilter',
@@ -379,11 +378,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
379
378
  }
380
379
  // Check for dangerous patterns in template literals
381
380
  if (containsDangerousLdapFilter(fullText)) {
382
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
383
381
  if (safetyChecker.isSafe(node.init, context)) {
384
382
  return;
385
383
  }
386
- /* c8 ignore stop */
387
384
  context.report({
388
385
  node: node.init,
389
386
  messageId: 'dangerousLdapOperation',
@@ -410,11 +407,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
410
407
  return false;
411
408
  };
412
409
  if (hasUntrustedInput(node.init.left) || hasUntrustedInput(node.init.right)) {
413
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
414
410
  if (safetyChecker.isSafe(node.init, context)) {
415
411
  return;
416
412
  }
417
- /* c8 ignore stop */
418
413
  context.report({
419
414
  node: node.init,
420
415
  messageId: 'ldapInjection',
@@ -435,11 +430,9 @@ exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
435
430
  }
436
431
  }
437
432
  else if (isUntrustedLdapInput(node.init) && !isLdapInputEscaped(node.init)) {
438
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
439
433
  if (safetyChecker.isSafe(node.init, context)) {
440
434
  return;
441
435
  }
442
- /* c8 ignore stop */
443
436
  context.report({
444
437
  node: node.init,
445
438
  messageId: 'ldapInjection',
@@ -47,14 +47,12 @@ function isInsideAuthMiddleware(node, sourceCode, authPatterns) {
47
47
  // Verify that current is actually an argument of this call
48
48
  const isArgument = callExpr.arguments.some((arg) => arg === current);
49
49
  if (!isArgument) {
50
- // Not an argument, continue traversing
51
- if ('parent' in current && current.parent) {
52
- current = current.parent;
53
- continue;
54
- }
55
- else {
56
- break;
57
- }
50
+ // Not an argument (e.g. `current` is the callee of this call, as in
51
+ // an IIFE) - continue traversing upward. `current.parent` is
52
+ // guaranteed truthy here because the enclosing `if` above already
53
+ // proved it (it matched `current.parent.type === 'CallExpression'`).
54
+ current = current.parent;
55
+ continue;
58
56
  }
59
57
  const callee = callExpr.callee;
60
58
  // Check if it's an authentication middleware call
@@ -111,7 +109,7 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
111
109
  url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-missing-authentication.md',
112
110
  description: 'Detects missing authentication checks in route handlers',
113
111
  cwe: 'CWE-287',
114
- cvss: 9.5,
112
+ cvss: 9.8,
115
113
  },
116
114
  hasSuggestions: true,
117
115
  messages: {
@@ -287,14 +285,12 @@ exports.noMissingAuthentication = (0, eslint_devkit_2.createRule)({
287
285
  hasAuth = true;
288
286
  break;
289
287
  }
290
- // Check if argument is a call to auth middleware
291
- if (arg.type === 'CallExpression' && arg.callee.type === 'Identifier') {
292
- const calleeName = arg.callee.name.toLowerCase();
293
- if (authMiddlewarePatterns.some(pattern => calleeName.includes(pattern.toLowerCase()))) {
294
- hasAuth = true;
295
- break;
296
- }
297
- }
288
+ // NOTE: a prior "is this argument a CallExpression whose callee
289
+ // name matches an auth pattern" check was removed as provably
290
+ // redundant: `argText` above is the full source text of `arg`,
291
+ // which for a CallExpression always begins with the callee's
292
+ // own text. Any pattern that matches `calleeName` therefore
293
+ // already matches `argText` and is caught by the check above.
298
294
  // Check if argument is an identifier assigned from auth middleware
299
295
  if (arg.type === 'Identifier' && isIdentifierFromAuthMiddleware(arg)) {
300
296
  hasAuth = true;