eslint-plugin-secure-coding 3.1.3 โ†’ 3.3.0

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 (35) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +128 -65
  3. package/package.json +23 -4
  4. package/src/index.js +70 -12
  5. package/src/oxlint.d.ts +20 -0
  6. package/src/oxlint.js +21 -0
  7. package/src/rules/detect-non-literal-regexp/index.js +9 -1
  8. package/src/rules/detect-object-injection/index.js +344 -6
  9. package/src/rules/detect-weak-password-validation/index.js +4 -1
  10. package/src/rules/no-directive-injection/index.js +7 -4
  11. package/src/rules/no-electron-security-issues/index.js +6 -2
  12. package/src/rules/no-format-string-injection/index.js +32 -23
  13. package/src/rules/no-graphql-injection/index.js +8 -3
  14. package/src/rules/no-hardcoded-credentials/index.js +366 -52
  15. package/src/rules/no-hardcoded-session-tokens/index.js +3 -0
  16. package/src/rules/no-improper-sanitization/index.js +31 -4
  17. package/src/rules/no-improper-type-validation/index.js +6 -4
  18. package/src/rules/no-insecure-comparison/index.js +39 -3
  19. package/src/rules/no-ldap-injection/index.js +6 -3
  20. package/src/rules/no-missing-authentication/index.js +5 -2
  21. package/src/rules/no-pii-in-logs/index.js +4 -1
  22. package/src/rules/no-privilege-escalation/index.js +5 -2
  23. package/src/rules/no-redos-vulnerable-regex/index.js +79 -0
  24. package/src/rules/no-sensitive-data-exposure/index.js +4 -1
  25. package/src/rules/no-template-injection/index.d.ts +23 -0
  26. package/src/rules/no-template-injection/index.js +90 -0
  27. package/src/rules/no-unchecked-loop-condition/index.js +5 -3
  28. package/src/rules/no-unlimited-resource-allocation/index.js +46 -30
  29. package/src/rules/no-unsafe-deserialization/index.js +22 -5
  30. package/src/rules/no-unsafe-regex-construction/index.js +10 -3
  31. package/src/rules/no-weak-password-recovery/index.js +5 -3
  32. package/src/rules/no-xpath-injection/index.js +6 -3
  33. package/src/rules/no-xxe-injection/index.js +48 -46
  34. package/src/rules/require-backend-authorization/index.js +6 -3
  35. package/src/rules/require-secure-defaults/index.js +3 -0
@@ -22,6 +22,13 @@ exports.detectObjectInjection = void 0;
22
22
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
23
23
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
24
24
  const eslint_devkit_3 = require("@interlace/eslint-devkit");
25
+ const TYPED_ARRAY_CTORS = new Set([
26
+ 'Int8Array', 'Uint8Array', 'Uint8ClampedArray',
27
+ 'Int16Array', 'Uint16Array',
28
+ 'Int32Array', 'Uint32Array',
29
+ 'Float32Array', 'Float64Array',
30
+ 'BigInt64Array', 'BigUint64Array',
31
+ ]);
25
32
  const OBJECT_INJECTION_PATTERNS = [
26
33
  {
27
34
  pattern: '__proto__',
@@ -65,7 +72,10 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
65
72
  meta: {
66
73
  type: 'problem',
67
74
  docs: {
75
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/detect-object-injection.md',
68
76
  description: 'Detects variable[key] as a left- or right-hand assignment operand',
77
+ cwe: 'CWE-915',
78
+ confidence: 'low',
69
79
  },
70
80
  messages: {
71
81
  // ๐ŸŽฏ Token optimization: 37% reduction (54โ†’34 tokens) - removes verbose current/fix/doc labels
@@ -188,6 +198,46 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
188
198
  const { allowLiterals = false, dangerousProperties = ['__proto__', 'prototype', 'constructor'], } = options || {};
189
199
  // Track MemberExpressions that are part of AssignmentExpressions to avoid double-reporting
190
200
  const handledMemberExpressions = new WeakSet();
201
+ // โ”€โ”€ AST-walker / codemod context detection (closes the audit FP
202
+ // surfaced by `npm run ilb:stress-test`). When the file imports any
203
+ // AST library (`@babel/types`, `recast`, `jscodeshift`, `eslint`,
204
+ // `estree-walker`, `unist-util-visit`), `node[name]`-style access is
205
+ // tree traversal, not user-input indexing. The same helper landed
206
+ // for `no-insecure-comparison` in audit iter-2; this is the port to
207
+ // `detect-object-injection`. See benchmarks/AUDIT_PATTERNS.md ยง2.1.
208
+ const sourceCode = context.sourceCode;
209
+ const isInCodemodContext = (() => {
210
+ const filename = context.filename;
211
+ if (/\/codemod[s]?\//i.test(filename))
212
+ return true;
213
+ if (/codemod\.[mc]?[jt]sx?$/i.test(filename))
214
+ return true;
215
+ const imports = sourceCode.ast.body.filter((n) => n.type === eslint_devkit_1.AST_NODE_TYPES.ImportDeclaration);
216
+ return imports.some((i) => {
217
+ const src = String(i.source.value);
218
+ return (src === '@babel/types' ||
219
+ src === '@babel/traverse' ||
220
+ src === 'recast' ||
221
+ src === 'jscodeshift' ||
222
+ src === 'eslint' ||
223
+ src === 'estree-walker' ||
224
+ src === 'ast-types' ||
225
+ src === 'esrap' ||
226
+ src === 'unist-util-visit' ||
227
+ src.startsWith('@typescript-eslint/'));
228
+ });
229
+ })();
230
+ // Test-file skip โ€” bracket access in tests is universally safe (fixture data,
231
+ // assertion helpers, mock objects). This closes the largest class of
232
+ // ILB-Wild FPs without any precision loss on real application code.
233
+ const isTestFile = (() => {
234
+ const f = context.filename;
235
+ return (/\.test\.[mc]?[jt]sx?$/.test(f) ||
236
+ /\.spec\.[mc]?[jt]sx?$/.test(f) ||
237
+ /\/__tests__\//.test(f) ||
238
+ /\/test\//.test(f) ||
239
+ /\.fixture\.[mc]?[jt]sx?$/.test(f));
240
+ })();
191
241
  // Check if TypeScript parser services are available for type-aware checking
192
242
  const hasTypeInfo = (0, eslint_devkit_2.hasParserServices)(context);
193
243
  const parserServices = hasTypeInfo ? (0, eslint_devkit_2.getParserServices)(context) : null;
@@ -387,6 +437,24 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
387
437
  return false;
388
438
  }
389
439
  }
440
+ // SAFE: SCREAMING_SNAKE_CASE identifiers are TypeScript module-level constants
441
+ // (e.g. PATH_METADATA, METHOD_METADATA, PARAMTYPES_METADATA, BRANCH_EFFECT).
442
+ // They are compile-time string/symbol values defined in the codebase, never
443
+ // derived from user input โ€” prototype pollution via a constant key is impossible.
444
+ // Pattern: at least 3 chars, ALL_CAPS letters, digits, underscores only.
445
+ if (propertyNode.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
446
+ const name = propertyNode.name;
447
+ if (/^[A-Z][A-Z0-9_]{2,}$/.test(name)) {
448
+ return false;
449
+ }
450
+ // SAFE: camelCase identifiers whose suffix implies a typed/enumerated value.
451
+ // HTTP status codes, version numbers, type discriminants, mode flags โ€” these
452
+ // are never raw user input. Examples: errorHttpStatusCode, uuidVersion, reqType.
453
+ if (/^[a-z]/.test(name) &&
454
+ /(?:Code|Status|Version|Kind|Mode|Type|Stage|Level|Phase|Step|Flag|Num|Count)$/.test(name)) {
455
+ return false;
456
+ }
457
+ }
390
458
  // Check if it's a literal string first
391
459
  if (isLiteralString(propertyNode)) {
392
460
  const propName = String(propertyNode.value);
@@ -465,7 +533,6 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
465
533
  * Extract property access information
466
534
  */
467
535
  const extractPropertyAccess = (node) => {
468
- const sourceCode = context.sourceCode || context.sourceCode;
469
536
  let object;
470
537
  let property;
471
538
  let propertyNode;
@@ -508,7 +575,20 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
508
575
  if (isPrototypelessObject(node.left.object)) {
509
576
  return false;
510
577
  }
578
+ // SAFE: typed-array element assignment is numeric, not a string-key injection
579
+ if (isTypedArrayObject(node.left.object)) {
580
+ return false;
581
+ }
511
582
  const { propertyNode } = extractPropertyAccess(node);
583
+ // SAFE: numeric keys can't pollute Object prototypes (typed-array
584
+ // / numeric-array assignment is structurally safe).
585
+ if (isNumericKey(propertyNode)) {
586
+ return false;
587
+ }
588
+ // SAFE: key originates from for..in or Object.keys/entries iteration
589
+ if (isForInOrObjectKeysKey(propertyNode)) {
590
+ return false;
591
+ }
512
592
  // Skip if the key has been validated (e.g., includes() or hasOwnProperty check)
513
593
  if (hasPrecedingValidation(propertyNode, node)) {
514
594
  return false;
@@ -516,6 +596,30 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
516
596
  // Check for dangerous property access in assignment
517
597
  return isDangerousPropertyAccess(propertyNode);
518
598
  };
599
+ /**
600
+ * Returns true if the object being indexed is the result of a Reflect.*
601
+ * method call (e.g. Reflect.getMetadata, Reflect.ownKeys).
602
+ * Reflect metadata objects contain known framework-managed keys; they are
603
+ * not populated from user input and cannot be exploited for prototype
604
+ * pollution. This closes FPs from NestJS decorator metadata access patterns:
605
+ * Reflect.getMetadata(PARAMTYPES_METADATA, target, key!)?.[index!]
606
+ */
607
+ const isReflectResultAccess = (objectNode) => {
608
+ // Direct call: Reflect.getMetadata(...)
609
+ if (objectNode.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
610
+ const callee = objectNode.callee;
611
+ if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
612
+ callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
613
+ callee.object.name === 'Reflect') {
614
+ return true;
615
+ }
616
+ }
617
+ // Optional chain: Reflect.getMetadata(...)?.[key]
618
+ if (objectNode.type === eslint_devkit_1.AST_NODE_TYPES.ChainExpression) {
619
+ return isReflectResultAccess(objectNode.expression);
620
+ }
621
+ return false;
622
+ };
519
623
  /**
520
624
  * Determine if this is a high-risk member access
521
625
  */
@@ -524,7 +628,28 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
524
628
  if (!node.computed) {
525
629
  return false;
526
630
  }
631
+ // SAFE: accessing result of Reflect.* call (framework-managed metadata)
632
+ if (isReflectResultAccess(node.object)) {
633
+ return false;
634
+ }
635
+ // SAFE: typed-array element read is numeric, not a string-key injection
636
+ if (isTypedArrayObject(node.object)) {
637
+ return false;
638
+ }
527
639
  const { propertyNode } = extractPropertyAccess(node);
640
+ // Numeric keys cannot pollute Object prototypes โ€” typed-array and
641
+ // numeric-array access (`arr[0]`, `arr[i]` where i is a for-loop
642
+ // counter) is structurally safe. This eliminates the bulk of false
643
+ // positives on numeric/buffer-heavy codebases (Three.js, webpack,
644
+ // image/audio/geometry libraries) without weakening detection of
645
+ // string-key prototype pollution.
646
+ if (isNumericKey(propertyNode)) {
647
+ return false;
648
+ }
649
+ // SAFE: key originates from for..in or Object.keys/entries iteration
650
+ if (isForInOrObjectKeysKey(propertyNode)) {
651
+ return false;
652
+ }
528
653
  // Skip if the key has been validated (e.g., includes() or hasOwnProperty check)
529
654
  if (hasPrecedingValidation(propertyNode, node)) {
530
655
  return false;
@@ -532,9 +657,144 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
532
657
  // Check for dangerous property access
533
658
  return isDangerousPropertyAccess(propertyNode);
534
659
  };
660
+ /**
661
+ * Returns true if the property expression is provably a numeric key
662
+ * (and therefore cannot trigger prototype pollution).
663
+ *
664
+ * Detected as numeric:
665
+ * - Numeric literal: arr[0], arr[42]
666
+ * - Unary plus on number: arr[+x]
667
+ * - Number(...) coercion: arr[Number(x)]
668
+ * - parseInt/parseFloat: arr[parseInt(x)]
669
+ * - Bitwise on identifier: arr[x | 0], arr[x >>> 0]
670
+ * - Identifier whose declaration is the init of a `for` statement
671
+ * (the standard `for (let i = 0; i < n; i++)` counter pattern)
672
+ */
673
+ const isNumericKey = (node) => {
674
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof node.value === 'number') {
675
+ return true;
676
+ }
677
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.UnaryExpression && node.operator === '+') {
678
+ return true;
679
+ }
680
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.BinaryExpression) {
681
+ const op = node.operator;
682
+ if (op === '|' || op === '&' || op === '^' || op === '<<' || op === '>>' || op === '>>>' || op === '*' || op === '/' || op === '%' || op === '-') {
683
+ return true;
684
+ }
685
+ }
686
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
687
+ const callee = node.callee;
688
+ if (callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
689
+ const name = callee.name;
690
+ if (name === 'Number' || name === 'parseInt' || name === 'parseFloat')
691
+ return true;
692
+ }
693
+ }
694
+ if (node.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
695
+ return isLoopCounterIdentifier(node);
696
+ }
697
+ return false;
698
+ };
699
+ /**
700
+ * Returns true if the identifier is the loop variable of an enclosing
701
+ * `for` statement, e.g. `for (let i = 0; i < n; i++) arr[i]`. The loop
702
+ * counter is by construction numeric, so the access is safe.
703
+ */
704
+ const isLoopCounterIdentifier = (node) => {
705
+ const scope = context.sourceCode.getScope(node);
706
+ const variable = scope.references.find((r) => r.identifier === node)?.resolved;
707
+ if (!variable || variable.defs.length === 0)
708
+ return false;
709
+ const def = variable.defs[0];
710
+ // Look for `for (let i = <numeric init>; ...; ...)` shape.
711
+ const parent = def.node?.parent;
712
+ const grand = parent?.parent;
713
+ if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration &&
714
+ grand?.type === eslint_devkit_1.AST_NODE_TYPES.ForStatement &&
715
+ grand.init === parent) {
716
+ const init = def.node.init;
717
+ if (!init)
718
+ return false;
719
+ // Initializer must itself be numeric.
720
+ if (init.type === eslint_devkit_1.AST_NODE_TYPES.Literal && typeof init.value === 'number') {
721
+ return true;
722
+ }
723
+ }
724
+ return false;
725
+ };
726
+ /**
727
+ * Returns true if the identifier is the iteration variable of a `for...in`
728
+ * statement or a `for...of Object.keys()/Object.entries()` statement. Keys
729
+ * from these loops are guaranteed to be actual property names on the object
730
+ * (not user-controlled inputs), so `obj[key]` inside such a loop is safe
731
+ * from prototype-pollution injection. Closes the bulk of ILB-Wild FPs on
732
+ * utility and serialisation code.
733
+ */
734
+ const isForInOrObjectKeysKey = (node) => {
735
+ if (node.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
736
+ return false;
737
+ const scope = context.sourceCode.getScope(node);
738
+ const variable = scope.references.find((r) => r.identifier === node)?.resolved;
739
+ if (!variable || variable.defs.length === 0)
740
+ return false;
741
+ const def = variable.defs[0];
742
+ const varDecl = def.node?.parent;
743
+ const loopStmt = varDecl?.parent;
744
+ if (!varDecl || varDecl.type !== eslint_devkit_1.AST_NODE_TYPES.VariableDeclaration)
745
+ return false;
746
+ // for (const key in obj) { ... obj[key] ... }
747
+ if (loopStmt?.type === eslint_devkit_1.AST_NODE_TYPES.ForInStatement && loopStmt.left === varDecl) {
748
+ return true;
749
+ }
750
+ // for (const key of Object.keys(obj)) / Object.entries(obj)
751
+ if (loopStmt?.type === eslint_devkit_1.AST_NODE_TYPES.ForOfStatement && loopStmt.left === varDecl) {
752
+ const right = loopStmt.right;
753
+ return (right.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression &&
754
+ right.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
755
+ !right.callee.computed &&
756
+ right.callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
757
+ right.callee.object.name === 'Object' &&
758
+ right.callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
759
+ (right.callee.property.name === 'keys' || right.callee.property.name === 'entries'));
760
+ }
761
+ return false;
762
+ };
763
+ /**
764
+ * Returns true if the object being indexed was declared as a typed array
765
+ * (Int8Arrayโ€ฆFloat64Array, BigInt64Array, BigUint64Array). Typed-array
766
+ * element access is numeric by construction; string-keyed prototype
767
+ * pollution is impossible. This closes FPs on geometry, audio, image, and
768
+ * buffer-heavy code (Three.js, WebGL, wasm adapters, etc.).
769
+ */
770
+ const isTypedArrayObject = (objectNode) => {
771
+ if (objectNode.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
772
+ return false;
773
+ const varName = objectNode.name;
774
+ let scope = context.sourceCode.getScope(objectNode);
775
+ while (scope) {
776
+ const variable = scope.variables.find((v) => v.name === varName);
777
+ if (variable) {
778
+ for (const def of variable.defs) {
779
+ const init = def.node.init;
780
+ if (init?.type === eslint_devkit_1.AST_NODE_TYPES.NewExpression &&
781
+ init.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
782
+ TYPED_ARRAY_CTORS.has(init.callee.name)) {
783
+ return true;
784
+ }
785
+ }
786
+ break;
787
+ }
788
+ if (!scope.upper)
789
+ break;
790
+ scope = scope.upper;
791
+ }
792
+ return false;
793
+ };
535
794
  /**
536
795
  * Determine risk level based on the pattern and context
537
796
  */
797
+ // oxlint-disable-next-line consistent-function-scoping
538
798
  const determineRiskLevel = (pattern, isAssignment) => {
539
799
  if (pattern?.riskLevel === 'critical' || (pattern && isAssignment)) {
540
800
  return 'CRITICAL';
@@ -551,9 +811,20 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
551
811
  if (!isHighRiskAssignment(node)) {
552
812
  return;
553
813
  }
554
- // Mark the MemberExpression as handled to avoid double-reporting
814
+ // Mark the entire left-side MemberExpression chain as handled.
815
+ // For chained access like `a[b][c] = val`, the rule reports on the
816
+ // AssignmentExpression (outer), then the MemberExpression visitor
817
+ // would fire again for the INNER `a[b]` access. We walk the object
818
+ // chain and mark every intermediate computed MemberExpression so the
819
+ // MemberExpression visitor skips them โ€” preventing exact duplicates.
555
820
  if (node.left.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
556
- handledMemberExpressions.add(node.left);
821
+ let me = node.left;
822
+ handledMemberExpressions.add(me);
823
+ // Walk into chained computed accesses: a[b][c] โ†’ also mark a[b]
824
+ while (me.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression && me.object.computed) {
825
+ me = me.object;
826
+ handledMemberExpressions.add(me);
827
+ }
557
828
  }
558
829
  const { object, property, isAssignment, pattern } = extractPropertyAccess(node);
559
830
  const riskLevel = determineRiskLevel(pattern, isAssignment);
@@ -601,9 +872,18 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
601
872
  if (handledMemberExpressions.has(node)) {
602
873
  return;
603
874
  }
875
+ // Skip inner chained computed accesses โ€” report only the OUTERMOST MemberExpression.
876
+ // For `a[b][c]`, both `a[b]` and `a[b][c]` start at the same source position, so
877
+ // reporting both produces exact duplicate findings. Skip the inner `a[b]` here;
878
+ // the outer `a[b][c]` will be reported by a subsequent call to this handler.
879
+ const parent = node.parent;
880
+ if (parent?.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
881
+ parent.computed &&
882
+ parent.object === node) {
883
+ return;
884
+ }
604
885
  // Also check parent - if it's an AssignmentExpression and this node is the left side, skip
605
886
  // (This handles cases where WeakSet check didn't work due to visitor order)
606
- const parent = node.parent;
607
887
  if (parent && parent.type === eslint_devkit_1.AST_NODE_TYPES.AssignmentExpression && parent.left === node) {
608
888
  return;
609
889
  }
@@ -620,9 +900,67 @@ exports.detectObjectInjection = (0, eslint_devkit_3.createRule)({
620
900
  }
621
901
  });
622
902
  };
903
+ /**
904
+ * Object.assign(target, untrustedSource) and `{ ...untrustedSource }`
905
+ * spread into an object are functionally equivalent to `obj[k] = v`
906
+ * for prototype-pollution purposes โ€” they copy every enumerable
907
+ * property of `source` onto `target`, including any `__proto__` /
908
+ * `constructor` / `prototype` keys the source carries. The hand-
909
+ * curated stress test surfaced this as an FN; closing it requires a
910
+ * separate visitor since Object.assign is a CallExpression and
911
+ * spread is a SpreadElement, not a MemberExpression. See
912
+ * benchmarks/AUDIT_PATTERNS.md ยง3.4 ("equivalent merger patterns").
913
+ */
914
+ const checkObjectAssignSpread = (node) => {
915
+ if (isInCodemodContext)
916
+ return;
917
+ if (node.callee.type !== eslint_devkit_1.AST_NODE_TYPES.MemberExpression)
918
+ return;
919
+ const callee = node.callee;
920
+ const objectIsObject = callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
921
+ callee.object.name === 'Object';
922
+ const propIsAssign = !callee.computed &&
923
+ callee.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
924
+ callee.property.name === 'assign';
925
+ if (!objectIsObject || !propIsAssign)
926
+ return;
927
+ // Object.assign({}, โ€ฆ) โ€” first arg is fresh literal, no taint risk.
928
+ if (node.arguments[0]?.type === eslint_devkit_1.AST_NODE_TYPES.ObjectExpression)
929
+ return;
930
+ // Sources are arguments[1...]. Any non-literal source is an
931
+ // assumed taint source. Literals are safe (they're inline data).
932
+ const sources = node.arguments.slice(1);
933
+ const anyTaintedSource = sources.some((s) => s.type !== eslint_devkit_1.AST_NODE_TYPES.ObjectExpression &&
934
+ s.type !== eslint_devkit_1.AST_NODE_TYPES.Literal);
935
+ if (!anyTaintedSource)
936
+ return;
937
+ context.report({
938
+ node,
939
+ messageId: 'objectInjection',
940
+ data: {
941
+ pattern: 'Object.assign(target, untrustedSource)',
942
+ riskLevel: 'HIGH',
943
+ vulnerability: 'object injection via Object.assign spread',
944
+ safeAlternative: 'Validate or whitelist keys before merging: `for (const k of Object.keys(src)) if (!ALLOWED.has(k)) continue;`',
945
+ },
946
+ });
947
+ };
623
948
  return {
624
- AssignmentExpression: checkAssignmentExpression,
625
- MemberExpression: checkMemberExpression
949
+ AssignmentExpression: (node) => {
950
+ if (isInCodemodContext || isTestFile)
951
+ return;
952
+ return checkAssignmentExpression(node);
953
+ },
954
+ MemberExpression: (node) => {
955
+ if (isInCodemodContext || isTestFile)
956
+ return;
957
+ return checkMemberExpression(node);
958
+ },
959
+ CallExpression: (node) => {
960
+ if (isInCodemodContext || isTestFile)
961
+ return;
962
+ return checkObjectAssignSpread(node);
963
+ },
626
964
  };
627
965
  },
628
966
  });
@@ -13,9 +13,12 @@ const eslint_devkit_1 = require("@interlace/eslint-devkit");
13
13
  exports.detectWeakPasswordValidation = (0, eslint_devkit_1.createRule)({
14
14
  name: 'detect-weak-password-validation',
15
15
  meta: {
16
- type: 'problem',
16
+ type: 'suggestion',
17
17
  docs: {
18
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/detect-weak-password-validation.md',
18
19
  description: 'Identify weak password requirements',
20
+ cwe: 'CWE-521',
21
+ cvss: 9.5,
19
22
  },
20
23
  messages: {
21
24
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -14,9 +14,10 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
14
14
  meta: {
15
15
  type: 'problem',
16
16
  docs: {
17
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-directive-injection.md',
17
18
  description: 'Detects directive injection vulnerabilities in templates',
19
+ cwe: 'CWE-96',
18
20
  },
19
- fixable: 'code',
20
21
  hasSuggestions: true,
21
22
  messages: {
22
23
  directiveInjection: (0, eslint_devkit_2.formatLLMMessage)({
@@ -199,8 +200,8 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
199
200
  create(context) {
200
201
  const options = context.options[0] || {};
201
202
  const { userInputVariables = ['req', 'request', 'body', 'query', 'params', 'input', 'data', 'userInput'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
202
- const sourceCode = context.sourceCode || context.sourceCode;
203
- const filename = context.filename || context.getFilename();
203
+ const sourceCode = context.sourceCode;
204
+ const filename = context.filename;
204
205
  // Create safety checker for false positive detection
205
206
  const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
206
207
  trustedSanitizers,
@@ -410,7 +411,9 @@ exports.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
410
411
  // Check if template literal is used dangerously
411
412
  let current = node;
412
413
  let isInDangerousContext = false;
413
- while (current && !isInDangerousContext) {
414
+ // Every assignment of `isInDangerousContext = true` is followed by `break`,
415
+ // so the negation is dead (CodeQL: `js/useless-conditional`).
416
+ while (current) {
414
417
  if (current.type === 'JSXExpressionContainer') {
415
418
  // Check if we are inside dangerouslySetInnerHTML attribute
416
419
  if (current.parent?.type === 'JSXAttribute' &&
@@ -14,9 +14,10 @@ exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
14
14
  meta: {
15
15
  type: 'problem',
16
16
  docs: {
17
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-electron-security-issues.md',
17
18
  description: 'Detects Electron security vulnerabilities and insecure configurations',
19
+ cwe: 'CWE-16',
18
20
  },
19
- fixable: 'code',
20
21
  hasSuggestions: true,
21
22
  messages: {
22
23
  electronSecurityIssue: (0, eslint_devkit_2.formatLLMMessage)({
@@ -203,7 +204,7 @@ exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
203
204
  create(context) {
204
205
  const options = context.options[0] || {};
205
206
  const { allowedIpcChannels = [], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
206
- const filename = context.filename || context.getFilename();
207
+ const filename = context.filename;
207
208
  // Create safety checker for false positive detection
208
209
  const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
209
210
  trustedSanitizers,
@@ -214,6 +215,7 @@ exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
214
215
  /**
215
216
  * Check if this is an Electron BrowserWindow creation
216
217
  */
218
+ // oxlint-disable-next-line consistent-function-scoping
217
219
  const isBrowserWindowCreation = (node) => {
218
220
  return node.callee.type === 'Identifier' &&
219
221
  node.callee.name === 'BrowserWindow';
@@ -262,6 +264,7 @@ exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
262
264
  /**
263
265
  * Check if this is an IPC call
264
266
  */
267
+ // oxlint-disable-next-line consistent-function-scoping
265
268
  const isIpcCall = (node) => {
266
269
  const callee = node.callee;
267
270
  if (callee.type === 'MemberExpression' &&
@@ -315,6 +318,7 @@ exports.noElectronSecurityIssues = (0, eslint_devkit_1.createRule)({
315
318
  /**
316
319
  * Check for Node.js API usage
317
320
  */
321
+ // oxlint-disable-next-line consistent-function-scoping
318
322
  const isNodeApiCall = (node) => {
319
323
  const callee = node.callee;
320
324
  // Check for require('fs'), require('child_process'), etc.