eslint-plugin-secure-coding 3.3.1 → 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.
@@ -158,7 +158,7 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
158
158
  ],
159
159
  create(context) {
160
160
  const options = context.options[0] || {};
161
- const { xpathFunctions = ['evaluate', 'selectSingleNode', 'selectNodes', 'xpath', 'select'], safeXpathConstructors = ['buildXPath', 'createXPath', 'safeXPath', 'xpathBuilder'], xpathValidationFunctions = ['validateXPath', 'escapeXPath', 'sanitizeXPath', 'cleanXPath'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
161
+ const { xpathFunctions = ['evaluate', 'selectSingleNode', 'selectNodes', 'xpath', 'select'], xpathValidationFunctions = ['validateXPath', 'escapeXPath', 'sanitizeXPath', 'cleanXPath'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
162
162
  const sourceCode = context.sourceCode;
163
163
  const filename = context.filename;
164
164
  // Create safety checker for false positive detection
@@ -291,21 +291,6 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
291
291
  }
292
292
  return false;
293
293
  };
294
- /**
295
- * Check if XPath is constructed safely
296
- */
297
- const isSafeXpathConstruction = (node) => {
298
- let current = node;
299
- while (current) {
300
- if (current.type === 'CallExpression' &&
301
- current.callee.type === 'Identifier' &&
302
- safeXpathConstructors.includes(current.callee.name)) {
303
- return true;
304
- }
305
- current = current.parent;
306
- }
307
- return false;
308
- };
309
294
  return {
310
295
  // Check XPath function calls
311
296
  CallExpression(node) {
@@ -437,30 +422,24 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
437
422
  if (!fullText.includes('/') && !fullText.includes('[')) {
438
423
  return;
439
424
  }
440
- // Check if either side contains XPath-like patterns
441
- const leftText = sourceCode.getText(node.left);
442
- const rightText = sourceCode.getText(node.right);
443
- if ((leftText.includes('/') || leftText.includes('[')) ||
444
- (rightText.includes('/') || rightText.includes('['))) {
445
- // Check if untrusted input is involved
446
- const leftUntrusted = isUntrustedXpathInput(node.left) && !isXpathInputValidated(node.left) && !(node.left.type === 'Identifier' && validatedVariables.has(node.left.name));
447
- const rightUntrusted = isUntrustedXpathInput(node.right) && !isXpathInputValidated(node.right) && !(node.right.type === 'Identifier' && validatedVariables.has(node.right.name));
448
- if (leftUntrusted || rightUntrusted) {
449
- // FALSE POSITIVE REDUCTION
450
- if (safetyChecker.isSafe(node, context) || hasSafeAnnotationOnStatement(node)) {
451
- return;
452
- }
453
- context.report({
454
- node,
455
- messageId: 'xpathInjection',
456
- data: {
457
- filePath: filename,
458
- line: String(node.loc?.start.line ?? 0),
459
- severity: 'HIGH',
460
- safeAlternative: 'Use parameterized XPath construction with input validation',
461
- },
462
- });
425
+ // Check if untrusted input is involved
426
+ const leftUntrusted = isUntrustedXpathInput(node.left) && !isXpathInputValidated(node.left) && !(node.left.type === 'Identifier' && validatedVariables.has(node.left.name));
427
+ const rightUntrusted = isUntrustedXpathInput(node.right) && !isXpathInputValidated(node.right) && !(node.right.type === 'Identifier' && validatedVariables.has(node.right.name));
428
+ if (leftUntrusted || rightUntrusted) {
429
+ // FALSE POSITIVE REDUCTION
430
+ if (safetyChecker.isSafe(node, context) || hasSafeAnnotationOnStatement(node)) {
431
+ return;
463
432
  }
433
+ context.report({
434
+ node,
435
+ messageId: 'xpathInjection',
436
+ data: {
437
+ filePath: filename,
438
+ line: String(node.loc?.start.line ?? 0),
439
+ severity: 'HIGH',
440
+ safeAlternative: 'Use parameterized XPath construction with input validation',
441
+ },
442
+ });
464
443
  }
465
444
  },
466
445
  // Check variable assignments with XPath expressions
@@ -496,12 +475,7 @@ exports.noXpathInjection = (0, eslint_devkit_1.createRule)({
496
475
  });
497
476
  }
498
477
  }
499
- else if (isUntrustedXpathInput(node.init) && !isSafeXpathConstruction(node.init)) {
500
- /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
501
- if (safetyChecker.isSafe(node.init, context)) {
502
- return;
503
- }
504
- /* c8 ignore stop */
478
+ else if (isUntrustedXpathInput(node.init)) {
505
479
  context.report({
506
480
  node: node.init,
507
481
  messageId: 'xpathInjection',
@@ -125,7 +125,10 @@ exports.noXxeInjection = (0, eslint_devkit_1.createRule)({
125
125
  },
126
126
  ],
127
127
  create(context, [options]) {
128
- const { safeParserOptions = ['noent', 'resolveExternals', 'expandEntityReferences', 'entityResolver'], xmlValidationFunctions = ['validateXml', 'sanitizeXml', 'cleanXml', 'parseXmlSafe'], } = options || {};
128
+ // `options` is guaranteed defined here: createRule's RuleCreator wrapper
129
+ // (@typescript-eslint/utils applyDefault) always seeds it from
130
+ // `defaultOptions` above, so it can never be undefined at runtime.
131
+ const { safeParserOptions = ['noent', 'resolveExternals', 'expandEntityReferences', 'entityResolver'], xmlValidationFunctions = ['validateXml', 'sanitizeXml', 'cleanXml', 'parseXmlSafe'], } = options;
129
132
  const filename = context.filename;
130
133
  /**
131
134
  * Check if parser options are secure