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.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/rules/detect-non-literal-regexp/index.js +48 -61
- package/src/rules/detect-object-injection/index.js +32 -88
- package/src/rules/no-directive-injection/index.js +0 -16
- package/src/rules/no-electron-security-issues/index.js +0 -6
- package/src/rules/no-format-string-injection/index.js +2 -29
- package/src/rules/no-graphql-injection/index.js +10 -10
- package/src/rules/no-hardcoded-credentials/index.js +12 -7
- package/src/rules/no-improper-sanitization/index.js +1 -9
- package/src/rules/no-improper-type-validation/index.js +0 -10
- package/src/rules/no-ldap-injection/index.d.ts +14 -0
- package/src/rules/no-ldap-injection/index.js +51 -58
- package/src/rules/no-missing-authentication/index.js +12 -16
- package/src/rules/no-redos-vulnerable-regex/index.js +0 -7
- package/src/rules/no-unchecked-loop-condition/index.js +21 -37
- package/src/rules/no-unlimited-resource-allocation/index.js +42 -79
- package/src/rules/no-unsafe-deserialization/index.js +0 -5
- package/src/rules/no-unsafe-regex-construction/index.js +14 -2
- package/src/rules/no-weak-password-recovery/index.js +0 -6
- package/src/rules/no-xpath-injection/index.js +19 -45
- package/src/rules/no-xxe-injection/index.js +4 -1
|
@@ -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'],
|
|
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
|
|
441
|
-
const
|
|
442
|
-
const
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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)
|
|
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
|
-
|
|
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
|