eslint-plugin-secure-coding 3.4.0 → 3.4.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 (65) hide show
  1. package/README.md +4 -2
  2. package/package.json +5 -18
  3. package/src/index.d.ts +17 -23
  4. package/src/index.js +2 -131
  5. package/src/oxlint.d.ts +17 -20
  6. package/src/oxlint.js +0 -18
  7. package/src/rules/detect-non-literal-regexp/index.js +5 -79
  8. package/src/rules/detect-object-injection/index.js +2 -221
  9. package/src/rules/detect-weak-password-validation/index.js +0 -12
  10. package/src/rules/no-directive-injection/index.js +0 -33
  11. package/src/rules/no-electron-security-issues/index.js +0 -41
  12. package/src/rules/no-format-string-injection/index.js +0 -82
  13. package/src/rules/no-graphql-injection/index.js +8 -133
  14. package/src/rules/no-hardcoded-credentials/index.js +3 -297
  15. package/src/rules/no-hardcoded-session-tokens/index.js +0 -11
  16. package/src/rules/no-improper-sanitization/index.js +0 -44
  17. package/src/rules/no-improper-type-validation/index.js +1 -51
  18. package/src/rules/no-insecure-comparison/index.js +8 -47
  19. package/src/rules/no-ldap-injection/index.js +8 -61
  20. package/src/rules/no-missing-authentication/index.js +2 -56
  21. package/src/rules/no-pii-in-logs/index.js +0 -13
  22. package/src/rules/no-privilege-escalation/index.js +2 -49
  23. package/src/rules/no-redos-vulnerable-regex/index.js +3 -49
  24. package/src/rules/no-sensitive-data-exposure/index.js +5 -29
  25. package/src/rules/no-template-injection/index.js +0 -6
  26. package/src/rules/no-unchecked-loop-condition/index.js +3 -99
  27. package/src/rules/no-unlimited-resource-allocation/index.js +2 -75
  28. package/src/rules/no-unsafe-deserialization/index.js +1 -111
  29. package/src/rules/no-unsafe-regex-construction/index.js +22 -62
  30. package/src/rules/no-weak-password-recovery/index.js +0 -43
  31. package/src/rules/no-xpath-injection/index.js +13 -75
  32. package/src/rules/no-xxe-injection/index.js +1 -47
  33. package/src/rules/require-backend-authorization/index.js +0 -10
  34. package/src/rules/require-secure-defaults/index.js +0 -10
  35. package/src/types/index.js +0 -5
  36. package/AGENTS.md +0 -131
  37. package/CHANGELOG.md +0 -379
  38. package/src/rules/detect-non-literal-regexp/index.d.ts +0 -28
  39. package/src/rules/detect-object-injection/index.d.ts +0 -35
  40. package/src/rules/detect-weak-password-validation/index.d.ts +0 -12
  41. package/src/rules/no-directive-injection/index.d.ts +0 -38
  42. package/src/rules/no-electron-security-issues/index.d.ts +0 -36
  43. package/src/rules/no-format-string-injection/index.d.ts +0 -44
  44. package/src/rules/no-graphql-injection/index.d.ts +0 -47
  45. package/src/rules/no-hardcoded-credentials/index.d.ts +0 -95
  46. package/src/rules/no-hardcoded-session-tokens/index.d.ts +0 -12
  47. package/src/rules/no-improper-sanitization/index.d.ts +0 -38
  48. package/src/rules/no-improper-type-validation/index.d.ts +0 -36
  49. package/src/rules/no-insecure-comparison/index.d.ts +0 -26
  50. package/src/rules/no-ldap-injection/index.d.ts +0 -53
  51. package/src/rules/no-missing-authentication/index.d.ts +0 -32
  52. package/src/rules/no-pii-in-logs/index.d.ts +0 -12
  53. package/src/rules/no-privilege-escalation/index.d.ts +0 -32
  54. package/src/rules/no-redos-vulnerable-regex/index.d.ts +0 -28
  55. package/src/rules/no-sensitive-data-exposure/index.d.ts +0 -30
  56. package/src/rules/no-template-injection/index.d.ts +0 -23
  57. package/src/rules/no-unchecked-loop-condition/index.d.ts +0 -38
  58. package/src/rules/no-unlimited-resource-allocation/index.d.ts +0 -38
  59. package/src/rules/no-unsafe-deserialization/index.d.ts +0 -40
  60. package/src/rules/no-unsafe-regex-construction/index.d.ts +0 -30
  61. package/src/rules/no-weak-password-recovery/index.d.ts +0 -38
  62. package/src/rules/no-xpath-injection/index.d.ts +0 -39
  63. package/src/rules/no-xxe-injection/index.d.ts +0 -36
  64. package/src/rules/require-backend-authorization/index.d.ts +0 -12
  65. package/src/rules/require-secure-defaults/index.d.ts +0 -12
@@ -1,24 +1,6 @@
1
1
  "use strict";
2
- /**
3
- * Copyright (c) 2025 Ofri Peretz
4
- * Licensed under the MIT License. Use of this source code is governed by the
5
- * MIT license that can be found in the LICENSE file.
6
- */
7
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.detectObjectInjection = void 0;
9
- /**
10
- * ESLint Rule: detect-object-injection
11
- * Detects variable[key] as a left- or right-hand assignment operand (prototype pollution)
12
- * LLM-optimized with comprehensive object injection prevention guidance
13
- *
14
- * Type-Aware Enhancement:
15
- * This rule uses TypeScript type information when available to reduce false positives.
16
- * If a property key is constrained to a union of string literals (e.g., 'name' | 'email'),
17
- * the access is considered safe because the values are statically known at compile time.
18
- *
19
- * @see https://portswigger.net/web-security/prototype-pollution
20
- * @see https://cwe.mitre.org/data/definitions/915.html
21
- */
22
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
23
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
24
6
  const eslint_devkit_3 = require("@interlace/eslint-devkit");
@@ -78,7 +60,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
78
60
  confidence: 'low',
79
61
  },
80
62
  messages: {
81
- // 🎯 Token optimization: 37% reduction (54→34 tokens) - removes verbose current/fix/doc labels
82
63
  objectInjection: (0, eslint_devkit_2.formatLLMMessage)({
83
64
  icon: eslint_devkit_2.MessageIcons.WARNING,
84
65
  issueName: 'Object injection',
@@ -195,20 +176,8 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
195
176
  ],
196
177
  create(context) {
197
178
  const options = context.options[0] || {};
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;
203
- // Track MemberExpressions that are part of AssignmentExpressions to avoid double-reporting
179
+ const { allowLiterals: _allowLiterals = false, dangerousProperties = ['__proto__', 'prototype', 'constructor'], } = options;
204
180
  const handledMemberExpressions = new WeakSet();
205
- // ── AST-walker / codemod context detection (closes the audit FP
206
- // surfaced by `npm run ilb:stress-test`). When the file imports any
207
- // AST library (`@babel/types`, `recast`, `jscodeshift`, `eslint`,
208
- // `estree-walker`, `unist-util-visit`), `node[name]`-style access is
209
- // tree traversal, not user-input indexing. The same helper landed
210
- // for `no-insecure-comparison` in audit iter-2; this is the port to
211
- // `detect-object-injection`. See benchmarks/AUDIT_PATTERNS.md §2.1.
212
181
  const sourceCode = context.sourceCode;
213
182
  const isInCodemodContext = (() => {
214
183
  const filename = context.filename;
@@ -231,9 +200,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
231
200
  src.startsWith('@typescript-eslint/'));
232
201
  });
233
202
  })();
234
- // Test-file skip — bracket access in tests is universally safe (fixture data,
235
- // assertion helpers, mock objects). This closes the largest class of
236
- // ILB-Wild FPs without any precision loss on real application code.
237
203
  const isTestFile = (() => {
238
204
  const f = context.filename;
239
205
  return (/\.test\.[mc]?[jt]sx?$/.test(f) ||
@@ -242,33 +208,15 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
242
208
  /\/test\//.test(f) ||
243
209
  /\.fixture\.[mc]?[jt]sx?$/.test(f));
244
210
  })();
245
- /**
246
- * Check if a node is a literal string (potentially safe)
247
- */
248
211
  const isLiteralString = (node) => {
249
212
  return node.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof node.value === 'string';
250
213
  };
251
- /**
252
- * Check if the property key has been validated before use.
253
- *
254
- * Detects patterns like:
255
- * - if (ARRAY.includes(key)) { obj[key] = value; }
256
- * - if (Object.prototype.hasOwnProperty.call(obj, key)) { return obj[key]; }
257
- * - if (Object.hasOwn(obj, key)) { return obj[key]; }
258
- *
259
- * @param propertyNode - The property node (key in obj[key])
260
- * @param node - The current node being checked
261
- * @returns true if the key has been validated, false otherwise
262
- */
263
214
  const hasPrecedingValidation = (propertyNode, node) => {
264
- // Only check for identifier keys (obj[key] where key is a variable)
265
215
  if (propertyNode.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier) {
266
216
  return false;
267
217
  }
268
218
  const keyName = propertyNode.name;
269
- // AST-based validation detection (faster than getText + regex)
270
219
  const isIncludesCall = (testNode) => {
271
- // Pattern: ARRAY.includes(keyName)
272
220
  if (testNode.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
273
221
  testNode.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
274
222
  testNode.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
@@ -278,7 +226,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
278
226
  testNode.arguments[0].name === keyName) {
279
227
  return true;
280
228
  }
281
- // Handle negation: !ARRAY.includes(key)
282
229
  if (testNode.type === eslint_devkit_1.AST_NODE_TYPES.UnaryExpression &&
283
230
  testNode.operator === '!' &&
284
231
  testNode.argument.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
@@ -287,12 +234,10 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
287
234
  return false;
288
235
  };
289
236
  const isHasOwnPropertyCall = (testNode) => {
290
- // Pattern: Object.prototype.hasOwnProperty.call(obj, key) OR obj.hasOwnProperty(key) OR Object.hasOwn(obj, key)
291
237
  if (testNode.type !== eslint_devkit_1.AST_NODE_TYPES.CallExpression)
292
238
  return false;
293
239
  const callee = testNode.callee;
294
240
  const args = testNode.arguments;
295
- // Object.prototype.hasOwnProperty.call(obj, key)
296
241
  if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
297
242
  callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
298
243
  callee.property.name === 'call' &&
@@ -301,7 +246,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
301
246
  args[1].name === keyName) {
302
247
  return true;
303
248
  }
304
- // obj.hasOwnProperty(key) OR Object.hasOwn(obj, key)
305
249
  if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
306
250
  callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
307
251
  (callee.property.name === 'hasOwnProperty' || callee.property.name === 'hasOwn')) {
@@ -313,7 +257,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
313
257
  return false;
314
258
  };
315
259
  const isInOperator = (testNode) => {
316
- // Pattern: key in obj
317
260
  return testNode.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression &&
318
261
  testNode.operator === 'in' &&
319
262
  testNode.left.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
@@ -323,7 +266,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
323
266
  return isIncludesCall(testNode) || isHasOwnPropertyCall(testNode) || isInOperator(testNode);
324
267
  };
325
268
  const hasEarlyExit = (consequent) => {
326
- // Check if block contains throw or return
327
269
  if (consequent.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement) {
328
270
  return consequent.body.some(stmt => stmt.type === eslint_devkit_1.AST_NODE_TYPES.ThrowStatement ||
329
271
  stmt.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement);
@@ -331,17 +273,14 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
331
273
  return consequent.type === eslint_devkit_1.AST_NODE_TYPES.ThrowStatement ||
332
274
  consequent.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement;
333
275
  };
334
- // Walk up to find enclosing IfStatement with validation
335
276
  let current = node.parent;
336
277
  let foundFunctionBody = false;
337
278
  while (current && !foundFunctionBody) {
338
- // Check if we're inside an if-block with validation in the condition
339
279
  if (current.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement) {
340
280
  if (hasValidation(current.test)) {
341
281
  return true;
342
282
  }
343
283
  }
344
- // Check for function body - look for preceding sibling if-statements with early exit
345
284
  if (current.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement && current.parent && (current.parent.type === eslint_devkit_1.AST_NODE_TYPES.FunctionDeclaration ||
346
285
  current.parent.type === eslint_devkit_1.AST_NODE_TYPES.FunctionExpression ||
347
286
  current.parent.type === eslint_devkit_1.AST_NODE_TYPES.ArrowFunctionExpression)) {
@@ -356,7 +295,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
356
295
  }
357
296
  return false;
358
297
  });
359
- // Look at preceding statements for validation patterns with early exit
360
298
  for (let i = 0; i < nodeIndex; i++) {
361
299
  const stmt = blockBody[i];
362
300
  if (stmt.type === eslint_devkit_1.AST_NODE_TYPES.IfStatement &&
@@ -370,12 +308,7 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
370
308
  }
371
309
  return false;
372
310
  };
373
- /**
374
- * Check if property access is potentially dangerous
375
- */
376
311
  const isDangerousPropertyAccess = (propertyNode) => {
377
- // SAFE: Common numeric index variable names (i, j, k, index, idx, n)
378
- // These are typically loop counters for array access
379
312
  if (propertyNode.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
380
313
  const name = propertyNode.name;
381
314
  const numericIndexNames = new Set(['i', 'j', 'k', 'index', 'idx', 'n', 'len']);
@@ -383,47 +316,30 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
383
316
  return false;
384
317
  }
385
318
  }
386
- // SAFE: SCREAMING_SNAKE_CASE identifiers are TypeScript module-level constants
387
- // (e.g. PATH_METADATA, METHOD_METADATA, PARAMTYPES_METADATA, BRANCH_EFFECT).
388
- // They are compile-time string/symbol values defined in the codebase, never
389
- // derived from user input — prototype pollution via a constant key is impossible.
390
- // Pattern: at least 3 chars, ALL_CAPS letters, digits, underscores only.
391
319
  if (propertyNode.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
392
320
  const name = propertyNode.name;
393
321
  if (/^[A-Z][A-Z0-9_]{2,}$/.test(name)) {
394
322
  return false;
395
323
  }
396
- // SAFE: camelCase identifiers whose suffix implies a typed/enumerated value.
397
- // HTTP status codes, version numbers, type discriminants, mode flags — these
398
- // are never raw user input. Examples: errorHttpStatusCode, uuidVersion, reqType.
399
324
  if (/^[a-z]/.test(name) &&
400
325
  /(?:Code|Status|Version|Kind|Mode|Type|Stage|Level|Phase|Step|Flag|Num|Count)$/.test(name)) {
401
326
  return false;
402
327
  }
403
328
  }
404
- // Check if it's a literal string first
405
329
  if (isLiteralString(propertyNode)) {
406
330
  const propName = String(propertyNode.value);
407
- // DANGEROUS: Literal strings that match dangerous properties (always flag these)
408
- // Check this BEFORE checking typed union access
409
331
  if (dangerousProperties.includes(propName)) {
410
332
  return true;
411
333
  }
412
- return false; // safe non-dangerous literal
334
+ return false;
413
335
  }
414
- // DANGEROUS: Any untyped/dynamic property access (e.g., obj[userInput])
415
336
  return true;
416
337
  };
417
- /**
418
- * Check if the object is a prototype-less object (Object.create(null))
419
- * or is derived from an array spread/copy pattern
420
- */
421
338
  const isPrototypelessObject = (objectNode) => {
422
339
  if (objectNode.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier) {
423
340
  return false;
424
341
  }
425
342
  const varName = objectNode.name;
426
- // Walk up to find the variable declaration
427
343
  let current = objectNode;
428
344
  while (current) {
429
345
  if (current.type === eslint_devkit_1.AST_NODE_TYPES.BlockStatement ||
@@ -437,7 +353,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
437
353
  if (decl.id.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
438
354
  decl.id.name === varName &&
439
355
  decl.init) {
440
- // Check for Object.create(null)
441
356
  if (decl.init.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
442
357
  decl.init.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
443
358
  decl.init.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
@@ -449,7 +364,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
449
364
  decl.init.arguments[0].value === null) {
450
365
  return true;
451
366
  }
452
- // Check for array spread: [...array]
453
367
  if (decl.init.type === eslint_devkit_1.AST_NODE_TYPES.ArrayExpression &&
454
368
  decl.init.elements.length > 0 &&
455
369
  decl.init.elements[0]?.type === eslint_devkit_1.AST_NODE_TYPES.SpreadElement) {
@@ -464,91 +378,54 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
464
378
  }
465
379
  return false;
466
380
  };
467
- /**
468
- * Extract property access information
469
- */
470
381
  const extractPropertyAccess = (node) => {
471
382
  let object;
472
383
  let property;
473
384
  let propertyNode;
474
385
  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.
484
386
  if (node.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression && node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
485
- // Assignment: obj[key] = value
486
387
  object = sourceCode.getText(node.left.object);
487
388
  property = sourceCode.getText(node.left.property);
488
389
  propertyNode = node.left.property;
489
390
  isAssignment = true;
490
391
  }
491
392
  else {
492
- // Access: obj[key]. By contract with every call site, `node` is a
493
- // plain MemberExpression whenever the branch above doesn't match.
494
393
  const memberNode = node;
495
394
  object = sourceCode.getText(memberNode.object);
496
395
  property = sourceCode.getText(memberNode.property);
497
396
  propertyNode = memberNode.property;
498
397
  isAssignment = false;
499
398
  }
500
- // Check if property matches dangerous patterns
501
399
  const pattern = OBJECT_INJECTION_PATTERNS.find(p => new RegExp(p.pattern, 'i').test(property) ||
502
400
  dangerousProperties.includes(property.replace(/['"]/g, ''))) || null;
503
401
  return { object, property, propertyNode, isAssignment, pattern };
504
402
  };
505
- /**
506
- * Determine if this is a high-risk assignment
507
- */
508
403
  const isHighRiskAssignment = (node) => {
509
404
  if (node.left.type !== 'MemberExpression') {
510
405
  return false;
511
406
  }
512
- // Only check computed member access (bracket notation)
513
- // Dot notation (obj.name) is safe
514
407
  if (!node.left.computed) {
515
408
  return false;
516
409
  }
517
- // SAFE: Object.create(null) objects have no prototype to pollute
518
410
  if (isPrototypelessObject(node.left.object)) {
519
411
  return false;
520
412
  }
521
- // SAFE: typed-array element assignment is numeric, not a string-key injection
522
413
  if (isTypedArrayObject(node.left.object)) {
523
414
  return false;
524
415
  }
525
416
  const { propertyNode } = extractPropertyAccess(node);
526
- // SAFE: numeric keys can't pollute Object prototypes (typed-array
527
- // / numeric-array assignment is structurally safe).
528
417
  if (isNumericKey(propertyNode)) {
529
418
  return false;
530
419
  }
531
- // SAFE: key originates from for..in or Object.keys/entries iteration
532
420
  if (isForInOrObjectKeysKey(propertyNode)) {
533
421
  return false;
534
422
  }
535
- // Skip if the key has been validated (e.g., includes() or hasOwnProperty check)
536
423
  if (hasPrecedingValidation(propertyNode, node)) {
537
424
  return false;
538
425
  }
539
- // Check for dangerous property access in assignment
540
426
  return isDangerousPropertyAccess(propertyNode);
541
427
  };
542
- /**
543
- * Returns true if the object being indexed is the result of a Reflect.*
544
- * method call (e.g. Reflect.getMetadata, Reflect.ownKeys).
545
- * Reflect metadata objects contain known framework-managed keys; they are
546
- * not populated from user input and cannot be exploited for prototype
547
- * pollution. This closes FPs from NestJS decorator metadata access patterns:
548
- * Reflect.getMetadata(PARAMTYPES_METADATA, target, key!)?.[index!]
549
- */
550
428
  const isReflectResultAccess = (objectNode) => {
551
- // Direct call: Reflect.getMetadata(...)
552
429
  if (objectNode.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
553
430
  const callee = objectNode.callee;
554
431
  if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
@@ -557,62 +434,33 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
557
434
  return true;
558
435
  }
559
436
  }
560
- // Optional chain: Reflect.getMetadata(...)?.[key]
561
437
  if (objectNode.type === eslint_devkit_1.AST_NODE_TYPES.ChainExpression) {
562
438
  return isReflectResultAccess(objectNode.expression);
563
439
  }
564
440
  return false;
565
441
  };
566
- /**
567
- * Determine if this is a high-risk member access
568
- */
569
442
  const isHighRiskMemberAccess = (node) => {
570
- // Only check computed member access (bracket notation)
571
443
  if (!node.computed) {
572
444
  return false;
573
445
  }
574
- // SAFE: accessing result of Reflect.* call (framework-managed metadata)
575
446
  if (isReflectResultAccess(node.object)) {
576
447
  return false;
577
448
  }
578
- // SAFE: typed-array element read is numeric, not a string-key injection
579
449
  if (isTypedArrayObject(node.object)) {
580
450
  return false;
581
451
  }
582
452
  const { propertyNode } = extractPropertyAccess(node);
583
- // Numeric keys cannot pollute Object prototypes — typed-array and
584
- // numeric-array access (`arr[0]`, `arr[i]` where i is a for-loop
585
- // counter) is structurally safe. This eliminates the bulk of false
586
- // positives on numeric/buffer-heavy codebases (Three.js, webpack,
587
- // image/audio/geometry libraries) without weakening detection of
588
- // string-key prototype pollution.
589
453
  if (isNumericKey(propertyNode)) {
590
454
  return false;
591
455
  }
592
- // SAFE: key originates from for..in or Object.keys/entries iteration
593
456
  if (isForInOrObjectKeysKey(propertyNode)) {
594
457
  return false;
595
458
  }
596
- // Skip if the key has been validated (e.g., includes() or hasOwnProperty check)
597
459
  if (hasPrecedingValidation(propertyNode, node)) {
598
460
  return false;
599
461
  }
600
- // Check for dangerous property access
601
462
  return isDangerousPropertyAccess(propertyNode);
602
463
  };
603
- /**
604
- * Returns true if the property expression is provably a numeric key
605
- * (and therefore cannot trigger prototype pollution).
606
- *
607
- * Detected as numeric:
608
- * - Numeric literal: arr[0], arr[42]
609
- * - Unary plus on number: arr[+x]
610
- * - Number(...) coercion: arr[Number(x)]
611
- * - parseInt/parseFloat: arr[parseInt(x)]
612
- * - Bitwise on identifier: arr[x | 0], arr[x >>> 0]
613
- * - Identifier whose declaration is the init of a `for` statement
614
- * (the standard `for (let i = 0; i < n; i++)` counter pattern)
615
- */
616
464
  const isNumericKey = (node) => {
617
465
  if (node.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof node.value === 'number') {
618
466
  return true;
@@ -639,18 +487,12 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
639
487
  }
640
488
  return false;
641
489
  };
642
- /**
643
- * Returns true if the identifier is the loop variable of an enclosing
644
- * `for` statement, e.g. `for (let i = 0; i < n; i++) arr[i]`. The loop
645
- * counter is by construction numeric, so the access is safe.
646
- */
647
490
  const isLoopCounterIdentifier = (node) => {
648
491
  const scope = context.sourceCode.getScope(node);
649
492
  const variable = scope.references.find((r) => r.identifier === node)?.resolved;
650
493
  if (!variable || variable.defs.length === 0)
651
494
  return false;
652
495
  const def = variable.defs[0];
653
- // Look for `for (let i = <numeric init>; ...; ...)` shape.
654
496
  const parent = def.node?.parent;
655
497
  const grand = parent?.parent;
656
498
  if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration &&
@@ -659,21 +501,12 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
659
501
  const init = def.node.init;
660
502
  if (!init)
661
503
  return false;
662
- // Initializer must itself be numeric.
663
504
  if (init.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof init.value === 'number') {
664
505
  return true;
665
506
  }
666
507
  }
667
508
  return false;
668
509
  };
669
- /**
670
- * Returns true if the identifier is the iteration variable of a `for...in`
671
- * statement or a `for...of Object.keys()/Object.entries()` statement. Keys
672
- * from these loops are guaranteed to be actual property names on the object
673
- * (not user-controlled inputs), so `obj[key]` inside such a loop is safe
674
- * from prototype-pollution injection. Closes the bulk of ILB-Wild FPs on
675
- * utility and serialisation code.
676
- */
677
510
  const isForInOrObjectKeysKey = (node) => {
678
511
  if (node.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
679
512
  return false;
@@ -686,11 +519,9 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
686
519
  const loopStmt = varDecl?.parent;
687
520
  if (!varDecl || varDecl.type !== eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration)
688
521
  return false;
689
- // for (const key in obj) { ... obj[key] ... }
690
522
  if (loopStmt?.type === eslint_devkit_1.AST_NODE_TYPES.ForInStatement && loopStmt.left === varDecl) {
691
523
  return true;
692
524
  }
693
- // for (const key of Object.keys(obj)) / Object.entries(obj)
694
525
  if (loopStmt?.type === eslint_devkit_1.AST_NODE_TYPES.ForOfStatement && loopStmt.left === varDecl) {
695
526
  const right = loopStmt.right;
696
527
  return (right.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
@@ -703,13 +534,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
703
534
  }
704
535
  return false;
705
536
  };
706
- /**
707
- * Returns true if the object being indexed was declared as a typed array
708
- * (Int8Array…Float64Array, BigInt64Array, BigUint64Array). Typed-array
709
- * element access is numeric by construction; string-keyed prototype
710
- * pollution is impossible. This closes FPs on geometry, audio, image, and
711
- * buffer-heavy code (Three.js, WebGL, wasm adapters, etc.).
712
- */
713
537
  const isTypedArrayObject = (objectNode) => {
714
538
  if (objectNode.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
715
539
  return false;
@@ -734,10 +558,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
734
558
  }
735
559
  return false;
736
560
  };
737
- /**
738
- * Determine risk level based on the pattern and context
739
- */
740
- // oxlint-disable-next-line consistent-function-scoping
741
561
  const determineRiskLevel = (pattern, isAssignment) => {
742
562
  if (pattern?.riskLevel === 'critical' || (pattern && isAssignment)) {
743
563
  return 'CRITICAL';
@@ -747,23 +567,12 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
747
567
  }
748
568
  return 'MEDIUM';
749
569
  };
750
- /**
751
- * Check assignment expressions for object injection
752
- */
753
570
  const checkAssignmentExpression = (node) => {
754
571
  if (!isHighRiskAssignment(node)) {
755
572
  return;
756
573
  }
757
- // Mark the entire left-side MemberExpression chain as handled.
758
- // For chained access like `a[b][c] = val`, the rule reports on the
759
- // AssignmentExpression (outer), then the MemberExpression visitor
760
- // would fire again for the INNER `a[b]` access. We walk the object
761
- // chain and mark every intermediate computed MemberExpression so the
762
- // MemberExpression visitor skips them — preventing exact duplicates.
763
- // isHighRiskAssignment already verified node.left.type === 'MemberExpression'
764
574
  let me = node.left;
765
575
  handledMemberExpressions.add(me);
766
- // Walk into chained computed accesses: a[b][c] → also mark a[b]
767
576
  while (me.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression && me.object.computed) {
768
577
  me = me.object;
769
578
  handledMemberExpressions.add(me);
@@ -803,29 +612,19 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
803
612
  ]
804
613
  });
805
614
  };
806
- /**
807
- * Check member expressions for object injection
808
- */
809
615
  const checkMemberExpression = (node) => {
810
616
  if (!isHighRiskMemberAccess(node)) {
811
617
  return;
812
618
  }
813
- // Skip if this MemberExpression was already handled as part of an AssignmentExpression
814
619
  if (handledMemberExpressions.has(node)) {
815
620
  return;
816
621
  }
817
- // Skip inner chained computed accesses — report only the OUTERMOST MemberExpression.
818
- // For `a[b][c]`, both `a[b]` and `a[b][c]` start at the same source position, so
819
- // reporting both produces exact duplicate findings. Skip the inner `a[b]` here;
820
- // the outer `a[b][c]` will be reported by a subsequent call to this handler.
821
622
  const parent = node.parent;
822
623
  if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
823
624
  parent.computed &&
824
625
  parent.object === node) {
825
626
  return;
826
627
  }
827
- // Also check parent - if it's an AssignmentExpression and this node is the left side, skip
828
- // (This handles cases where WeakSet check didn't work due to visitor order)
829
628
  if (parent && parent.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression && parent.left === node) {
830
629
  return;
831
630
  }
@@ -842,22 +641,7 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
842
641
  }
843
642
  });
844
643
  };
845
- /**
846
- * Object.assign(target, untrustedSource) and `{ ...untrustedSource }`
847
- * spread into an object are functionally equivalent to `obj[k] = v`
848
- * for prototype-pollution purposes — they copy every enumerable
849
- * property of `source` onto `target`, including any `__proto__` /
850
- * `constructor` / `prototype` keys the source carries. The hand-
851
- * curated stress test surfaced this as an FN; closing it requires a
852
- * separate visitor since Object.assign is a CallExpression and
853
- * spread is a SpreadElement, not a MemberExpression. See
854
- * benchmarks/AUDIT_PATTERNS.md §3.4 ("equivalent merger patterns").
855
- */
856
644
  const checkObjectAssignSpread = (node) => {
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.
861
645
  if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
862
646
  return;
863
647
  const callee = node.callee;
@@ -868,11 +652,8 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
868
652
  callee.property.name === 'assign';
869
653
  if (!objectIsObject || !propIsAssign)
870
654
  return;
871
- // Object.assign({}, …) — first arg is fresh literal, no taint risk.
872
655
  if (node.arguments[0]?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression)
873
656
  return;
874
- // Sources are arguments[1...]. Any non-literal source is an
875
- // assumed taint source. Literals are safe (they're inline data).
876
657
  const sources = node.arguments.slice(1);
877
658
  const anyTaintedSource = sources.some((s) => s.type !== eslint_devkit_1.AST_NODE_TYPES.ObjectExpression &&
878
659
  s.type !== eslint_devkit_1.AST_NODE_TYPES.Literal);
@@ -1,14 +1,6 @@
1
1
  "use strict";
2
- /**
3
- * Copyright (c) 2025 Ofri Peretz
4
- * Licensed under the MIT License. Use of this source code is governed by the
5
- * MIT license that can be found in the LICENSE file.
6
- */
7
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.detectWeakPasswordValidation = void 0;
9
- /**
10
- * @fileoverview Identify weak password requirements
11
- */
12
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
13
5
  exports.detectWeakPasswordValidation = (0, eslint_devkit_1.createRule)({
14
6
  name: 'detect-weak-password-validation',
@@ -40,17 +32,13 @@ exports.detectWeakPasswordValidation = (0, eslint_devkit_1.createRule)({
40
32
  }
41
33
  return {
42
34
  BinaryExpression(node) {
43
- // Detect weak length requirements like password.length >= 4
44
35
  if (['>=', '>', '==', '==='].includes(node.operator)) {
45
- // Check if left side is .length
46
36
  if (node.left.type === 'MemberExpression' &&
47
37
  node.left.property.type === 'Identifier' &&
48
38
  node.left.property.name === 'length') {
49
- // Check if comparing to a weak number
50
39
  if (node.right.type === 'Literal' &&
51
40
  typeof node.right.value === 'number' &&
52
41
  node.right.value < 8) {
53
- // Check if variable name suggests password
54
42
  if (node.left.object.type === 'Identifier') {
55
43
  const varName = node.left.object.name.toLowerCase();
56
44
  if (varName.includes('password') || varName.includes('pwd') || varName.includes('pass')) {