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.
- package/CHANGELOG.md +102 -0
- package/README.md +128 -65
- package/package.json +23 -4
- package/src/index.js +70 -12
- package/src/oxlint.d.ts +20 -0
- package/src/oxlint.js +21 -0
- package/src/rules/detect-non-literal-regexp/index.js +9 -1
- package/src/rules/detect-object-injection/index.js +344 -6
- package/src/rules/detect-weak-password-validation/index.js +4 -1
- package/src/rules/no-directive-injection/index.js +7 -4
- package/src/rules/no-electron-security-issues/index.js +6 -2
- package/src/rules/no-format-string-injection/index.js +32 -23
- package/src/rules/no-graphql-injection/index.js +8 -3
- package/src/rules/no-hardcoded-credentials/index.js +366 -52
- package/src/rules/no-hardcoded-session-tokens/index.js +3 -0
- package/src/rules/no-improper-sanitization/index.js +31 -4
- package/src/rules/no-improper-type-validation/index.js +6 -4
- package/src/rules/no-insecure-comparison/index.js +39 -3
- package/src/rules/no-ldap-injection/index.js +6 -3
- package/src/rules/no-missing-authentication/index.js +5 -2
- package/src/rules/no-pii-in-logs/index.js +4 -1
- package/src/rules/no-privilege-escalation/index.js +5 -2
- package/src/rules/no-redos-vulnerable-regex/index.js +79 -0
- package/src/rules/no-sensitive-data-exposure/index.js +4 -1
- package/src/rules/no-template-injection/index.d.ts +23 -0
- package/src/rules/no-template-injection/index.js +90 -0
- package/src/rules/no-unchecked-loop-condition/index.js +5 -3
- package/src/rules/no-unlimited-resource-allocation/index.js +46 -30
- package/src/rules/no-unsafe-deserialization/index.js +22 -5
- package/src/rules/no-unsafe-regex-construction/index.js +10 -3
- package/src/rules/no-weak-password-recovery/index.js +5 -3
- package/src/rules/no-xpath-injection/index.js +6 -3
- package/src/rules/no-xxe-injection/index.js +48 -46
- package/src/rules/require-backend-authorization/index.js +6 -3
- package/src/rules/require-secure-defaults/index.js +3 -0
|
@@ -13,7 +13,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
13
13
|
meta: {
|
|
14
14
|
type: 'problem',
|
|
15
15
|
docs: {
|
|
16
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-format-string-injection.md',
|
|
16
17
|
description: 'Detects format string injection vulnerabilities',
|
|
18
|
+
cwe: 'CWE-134',
|
|
17
19
|
},
|
|
18
20
|
fixable: 'code',
|
|
19
21
|
hasSuggestions: true,
|
|
@@ -138,26 +140,26 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
138
140
|
trustedAnnotations: [],
|
|
139
141
|
strictMode: false,
|
|
140
142
|
};
|
|
141
|
-
const options = { ...defaultOptions, ...
|
|
143
|
+
const options = { ...defaultOptions, ...context.options[0] };
|
|
142
144
|
const { formatSpecifiers, userInputVariables, trustedSanitizers, } = options;
|
|
143
|
-
const filename = context.filename
|
|
145
|
+
const filename = context.filename;
|
|
144
146
|
// Create safety checker for false positive detection (simplified implementation)
|
|
145
147
|
const safetyChecker = {
|
|
146
|
-
isSafe: (
|
|
148
|
+
isSafe: (safeNode, ruleCtx) => {
|
|
147
149
|
// Check for JSDoc @safe-format annotation
|
|
148
|
-
const comments =
|
|
150
|
+
const comments = ruleCtx.sourceCode.getCommentsBefore(safeNode);
|
|
149
151
|
for (const comment of comments) {
|
|
150
152
|
if (comment.type === 'Block' && comment.value.includes('@safe-format')) {
|
|
151
153
|
return true;
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
156
|
// Check if the node is a validated/sanitized variable
|
|
155
|
-
if (
|
|
157
|
+
if (safeNode.type === 'Identifier' && validatedVariables.has(safeNode.name)) {
|
|
156
158
|
return true;
|
|
157
159
|
}
|
|
158
160
|
// For CallExpression nodes, check if first argument is safe
|
|
159
|
-
if (
|
|
160
|
-
const firstArg =
|
|
161
|
+
if (safeNode.type === 'CallExpression' && safeNode.arguments.length > 0) {
|
|
162
|
+
const firstArg = safeNode.arguments[0];
|
|
161
163
|
if (firstArg.type === 'Identifier' && validatedVariables.has(firstArg.name)) {
|
|
162
164
|
return true;
|
|
163
165
|
}
|
|
@@ -209,6 +211,7 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
209
211
|
/**
|
|
210
212
|
* Get the full name of a member expression (e.g., req.query.format)
|
|
211
213
|
*/
|
|
214
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
212
215
|
const getMemberExpressionName = (node) => {
|
|
213
216
|
if (node.object.type === 'Identifier') {
|
|
214
217
|
if (node.property.type === 'Identifier') {
|
|
@@ -232,6 +235,7 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
232
235
|
/**
|
|
233
236
|
* Check if a call expression uses format functions
|
|
234
237
|
*/
|
|
238
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
235
239
|
const isConsoleMethod = (node) => {
|
|
236
240
|
const callee = node.callee;
|
|
237
241
|
return callee.type === 'MemberExpression' &&
|
|
@@ -240,6 +244,7 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
240
244
|
callee.property.type === 'Identifier' &&
|
|
241
245
|
['log', 'error', 'warn', 'info', 'debug'].includes(callee.property.name);
|
|
242
246
|
};
|
|
247
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
243
248
|
const isFormatFunctionCall = (node) => {
|
|
244
249
|
const callee = node.callee;
|
|
245
250
|
// Check for util.format
|
|
@@ -405,9 +410,9 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
405
410
|
}
|
|
406
411
|
// Check for format specifiers in subsequent arguments (could indicate user input in format position)
|
|
407
412
|
// Only check if the format string itself is not validated/safe
|
|
408
|
-
const
|
|
409
|
-
const isFormatSafe = isInputValidated(
|
|
410
|
-
(
|
|
413
|
+
const fmtArg = args[0];
|
|
414
|
+
const isFormatSafe = isInputValidated(fmtArg) ||
|
|
415
|
+
(fmtArg.type === 'Identifier' && validatedVariables.has(fmtArg.name));
|
|
411
416
|
if (!isFormatSafe) {
|
|
412
417
|
let hasUserInputInArgs = false;
|
|
413
418
|
let hasSpecifiersInFormat = false;
|
|
@@ -484,8 +489,10 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
484
489
|
// Check if this literal is constructed from user input (e.g., concatenation)
|
|
485
490
|
let current = node;
|
|
486
491
|
let isFromUserInput = false;
|
|
487
|
-
// Walk up to find if this literal is part of a concatenation or template with user input
|
|
488
|
-
|
|
492
|
+
// Walk up to find if this literal is part of a concatenation or template with user input.
|
|
493
|
+
// Every path that sets `isFromUserInput = true` is immediately followed by `break`,
|
|
494
|
+
// so the negation in the loop condition is dead (CodeQL: `js/useless-conditional`).
|
|
495
|
+
while (current) {
|
|
489
496
|
if (current.type === 'BinaryExpression' &&
|
|
490
497
|
current.operator === '+' &&
|
|
491
498
|
(current.left === node || current.right === node)) {
|
|
@@ -515,8 +522,10 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
515
522
|
// Check if this string is used in a context where it could be dangerous
|
|
516
523
|
current = node;
|
|
517
524
|
let isInDangerousContext = false;
|
|
518
|
-
// Walk up to find if this is passed to a format function
|
|
519
|
-
|
|
525
|
+
// Walk up to find if this is passed to a format function. Every path that sets
|
|
526
|
+
// `isInDangerousContext = true` is followed by `break`, so the negation in the
|
|
527
|
+
// condition is dead (CodeQL: `js/useless-conditional`).
|
|
528
|
+
while (current) {
|
|
520
529
|
if (current.type === 'CallExpression' && isFormatFunctionCall(current)) {
|
|
521
530
|
// Check if this is the first argument (format string position)
|
|
522
531
|
const args = current.arguments;
|
|
@@ -546,17 +555,17 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
546
555
|
// Check template literals for format string injection
|
|
547
556
|
TemplateLiteral: function (node) {
|
|
548
557
|
// Check if template literal is used as format string
|
|
549
|
-
let
|
|
558
|
+
let templateCurrent = node;
|
|
550
559
|
let isFormatString = false;
|
|
551
|
-
while (
|
|
552
|
-
if (
|
|
553
|
-
const args =
|
|
560
|
+
while (templateCurrent) {
|
|
561
|
+
if (templateCurrent.type === 'CallExpression' && isFormatFunctionCall(templateCurrent)) {
|
|
562
|
+
const args = templateCurrent.arguments;
|
|
554
563
|
if (args.length > 0 && args[0] === node) {
|
|
555
564
|
isFormatString = true;
|
|
556
565
|
break;
|
|
557
566
|
}
|
|
558
567
|
}
|
|
559
|
-
|
|
568
|
+
templateCurrent = templateCurrent.parent;
|
|
560
569
|
}
|
|
561
570
|
if (isFormatString) {
|
|
562
571
|
// Template literal used as format string - let CallExpression visitor handle this
|
|
@@ -567,14 +576,14 @@ exports.noFormatStringInjection = (0, eslint_devkit_1.createRule)({
|
|
|
567
576
|
const hasUserInput = node.expressions.some((expr) => isUserInputNode(expr));
|
|
568
577
|
if (hasUserInput) {
|
|
569
578
|
// Check if this template is assigned to a variable that could be used as format string
|
|
570
|
-
let
|
|
579
|
+
let assignCurrent = node;
|
|
571
580
|
let isAssignedToVariable = false;
|
|
572
|
-
while (
|
|
573
|
-
if (
|
|
581
|
+
while (assignCurrent) {
|
|
582
|
+
if (assignCurrent.type === 'VariableDeclarator') {
|
|
574
583
|
isAssignedToVariable = true;
|
|
575
584
|
break;
|
|
576
585
|
}
|
|
577
|
-
|
|
586
|
+
assignCurrent = assignCurrent.parent;
|
|
578
587
|
}
|
|
579
588
|
if (isAssignedToVariable) {
|
|
580
589
|
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
@@ -14,9 +14,10 @@ exports.noGraphqlInjection = (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-graphql-injection.md',
|
|
17
18
|
description: 'Detects GraphQL injection vulnerabilities and DoS attacks',
|
|
19
|
+
cwe: 'CWE-89',
|
|
18
20
|
},
|
|
19
|
-
fixable: 'code',
|
|
20
21
|
hasSuggestions: true,
|
|
21
22
|
messages: {
|
|
22
23
|
graphqlInjection: (0, eslint_devkit_2.formatLLMMessage)({
|
|
@@ -179,8 +180,8 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
179
180
|
create(context) {
|
|
180
181
|
const options = context.options[0] || {};
|
|
181
182
|
const { allowIntrospection = false, maxQueryDepth = 10, trustedGraphqlLibraries = ['graphql', 'apollo-server', 'graphql-tools', 'graphql-tag'], validationFunctions = ['validate', 'sanitize', 'isValid', 'assertValid'], safeTemplateLiteralCallers = [], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
|
|
182
|
-
const sourceCode = context.sourceCode
|
|
183
|
-
const filename = context.filename
|
|
183
|
+
const sourceCode = context.sourceCode;
|
|
184
|
+
const filename = context.filename;
|
|
184
185
|
// Create safety checker for false positive detection
|
|
185
186
|
const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
|
|
186
187
|
trustedSanitizers,
|
|
@@ -267,6 +268,7 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
267
268
|
return false;
|
|
268
269
|
};
|
|
269
270
|
// ─── AST-based GraphQL detection helpers ──────────────────────────
|
|
271
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
270
272
|
const isWordChar = (ch) => {
|
|
271
273
|
const code = ch.charCodeAt(0);
|
|
272
274
|
return (code >= 65 && code <= 90) || // A-Z
|
|
@@ -274,6 +276,7 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
274
276
|
(code >= 48 && code <= 57) || // 0-9
|
|
275
277
|
code === 95; // _
|
|
276
278
|
};
|
|
279
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
277
280
|
const isWhitespace = (ch) => ch === ' ' || ch === '\n' || ch === '\t' || ch === '\r';
|
|
278
281
|
/** Operation keywords that must be followed by optional name + { or ( */
|
|
279
282
|
const GRAPHQL_OP_KEYWORDS = ['query', 'mutation', 'subscription'];
|
|
@@ -389,6 +392,7 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
389
392
|
* Check if a TemplateLiteral contains introspection patterns.
|
|
390
393
|
* AST-based: scans quasis directly.
|
|
391
394
|
*/
|
|
395
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
392
396
|
const templateHasIntrospection = (node) => {
|
|
393
397
|
return node.quasis.some(q => {
|
|
394
398
|
const text = (q.value.cooked ?? q.value.raw).toLowerCase();
|
|
@@ -398,6 +402,7 @@ exports.noGraphqlInjection = (0, eslint_devkit_1.createRule)({
|
|
|
398
402
|
/**
|
|
399
403
|
* Calculate query depth from template quasis (brace depth scan).
|
|
400
404
|
*/
|
|
405
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
401
406
|
const templateQueryDepth = (node) => {
|
|
402
407
|
let depth = 0;
|
|
403
408
|
let braceCount = 0;
|