eslint-plugin-secure-coding 3.4.3 → 3.4.4
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/package.json +2 -2
- package/src/index.js +1 -107
- package/src/oxlint.js +1 -3
- package/src/rules/detect-non-literal-regexp/index.js +1 -329
- package/src/rules/detect-object-injection/index.js +1 -691
- package/src/rules/detect-weak-password-validation/index.js +1 -54
- package/src/rules/no-directive-injection/index.js +1 -416
- package/src/rules/no-electron-security-issues/index.js +1 -385
- package/src/rules/no-format-string-injection/index.js +1 -565
- package/src/rules/no-graphql-injection/index.js +1 -612
- package/src/rules/no-hardcoded-credentials/index.js +1 -658
- package/src/rules/no-hardcoded-session-tokens/index.js +1 -56
- package/src/rules/no-improper-sanitization/index.js +1 -391
- package/src/rules/no-improper-type-validation/index.js +1 -422
- package/src/rules/no-insecure-comparison/index.js +1 -249
- package/src/rules/no-ldap-injection/index.js +1 -403
- package/src/rules/no-missing-authentication/index.js +1 -282
- package/src/rules/no-pii-in-logs/index.js +1 -63
- package/src/rules/no-privilege-escalation/index.js +1 -282
- package/src/rules/no-redos-vulnerable-regex/index.js +0 -0
- package/src/rules/no-sensitive-data-exposure/index.js +1 -249
- package/src/rules/no-template-injection/index.js +1 -84
- package/src/rules/no-unchecked-loop-condition/index.js +1 -541
- package/src/rules/no-unlimited-resource-allocation/index.js +1 -555
- package/src/rules/no-unsafe-deserialization/index.js +1 -497
- package/src/rules/no-unsafe-regex-construction/index.js +1 -275
- package/src/rules/no-weak-password-recovery/index.js +1 -382
- package/src/rules/no-xpath-injection/index.js +1 -431
- package/src/rules/no-xxe-injection/index.js +1 -230
- package/src/rules/require-backend-authorization/index.js +1 -58
- package/src/rules/require-secure-defaults/index.js +1 -41
- package/src/types/index.js +1 -2
|
@@ -1,249 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noInsecureComparison = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
exports.noInsecureComparison = (0, eslint_devkit_2.createRule)({
|
|
7
|
-
name: 'no-insecure-comparison',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'problem',
|
|
10
|
-
deprecated: true,
|
|
11
|
-
replacedBy: ['node-security/no-timing-unsafe-compare'],
|
|
12
|
-
docs: {
|
|
13
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-insecure-comparison.md',
|
|
14
|
-
description: 'Detects insecure comparison operators (==, !=) that can lead to type coercion vulnerabilities',
|
|
15
|
-
cwe: 'CWE-697',
|
|
16
|
-
cvss: 5.3,
|
|
17
|
-
},
|
|
18
|
-
hasSuggestions: true,
|
|
19
|
-
messages: {
|
|
20
|
-
insecureComparison: (0, eslint_devkit_1.formatLLMMessage)({
|
|
21
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
22
|
-
issueName: 'Insecure Comparison',
|
|
23
|
-
cwe: 'CWE-697',
|
|
24
|
-
description: 'Insecure comparison operator ({{operator}}) detected - can lead to type coercion vulnerabilities',
|
|
25
|
-
severity: 'HIGH',
|
|
26
|
-
fix: 'Use strict equality ({{strictOperator}}) instead: {{example}}',
|
|
27
|
-
documentationLink: 'https://cwe.mitre.org/data/definitions/697.html',
|
|
28
|
-
}),
|
|
29
|
-
useStrictEquality: (0, eslint_devkit_1.formatLLMMessage)({
|
|
30
|
-
icon: eslint_devkit_1.MessageIcons.INFO,
|
|
31
|
-
issueName: 'Use Strict Equality',
|
|
32
|
-
description: 'Use strict equality operator',
|
|
33
|
-
severity: 'LOW',
|
|
34
|
-
fix: 'Replace == with === and != with !==',
|
|
35
|
-
documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality',
|
|
36
|
-
}),
|
|
37
|
-
timingUnsafeComparison: (0, eslint_devkit_1.formatLLMMessage)({
|
|
38
|
-
icon: eslint_devkit_1.MessageIcons.SECURITY,
|
|
39
|
-
issueName: 'Timing Attack Risk',
|
|
40
|
-
cwe: 'CWE-208',
|
|
41
|
-
description: 'Secret comparison with {{operator}} can leak timing information',
|
|
42
|
-
severity: 'HIGH',
|
|
43
|
-
fix: 'Use crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b))',
|
|
44
|
-
documentationLink: 'https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b',
|
|
45
|
-
}),
|
|
46
|
-
},
|
|
47
|
-
schema: [
|
|
48
|
-
{
|
|
49
|
-
type: 'object',
|
|
50
|
-
properties: {
|
|
51
|
-
allowInTests: {
|
|
52
|
-
type: 'boolean',
|
|
53
|
-
default: false,
|
|
54
|
-
description: 'Allow insecure comparison in test files',
|
|
55
|
-
},
|
|
56
|
-
ignorePatterns: {
|
|
57
|
-
type: 'array',
|
|
58
|
-
items: { type: 'string' },
|
|
59
|
-
default: [],
|
|
60
|
-
description: 'Additional patterns to ignore',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
additionalProperties: false,
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
},
|
|
67
|
-
defaultOptions: [
|
|
68
|
-
{
|
|
69
|
-
allowInTests: false,
|
|
70
|
-
ignorePatterns: [],
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
create(context, [options = {}]) {
|
|
74
|
-
const { allowInTests = false, ignorePatterns = [], } = options;
|
|
75
|
-
const filename = context.filename;
|
|
76
|
-
const isTestFile = allowInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
77
|
-
const sourceCode = context.sourceCode;
|
|
78
|
-
const AST_TOOL_PACKAGES = [
|
|
79
|
-
'@babel/types', '@babel/traverse', '@babel/generator', '@babel/parser',
|
|
80
|
-
'recast', 'jscodeshift', 'estree-walker', 'unist-util-visit',
|
|
81
|
-
'@typescript-eslint/utils', '@typescript-eslint/typescript-estree',
|
|
82
|
-
'typescript', 'ts-morph', 'eslint',
|
|
83
|
-
];
|
|
84
|
-
const isCodemodFile = (() => {
|
|
85
|
-
if (/\/codemod[s]?\//i.test(filename))
|
|
86
|
-
return true;
|
|
87
|
-
if (/codemod\.[mc]?[jt]sx?$/i.test(filename))
|
|
88
|
-
return true;
|
|
89
|
-
const program = sourceCode.ast;
|
|
90
|
-
for (const stmt of program.body) {
|
|
91
|
-
if (stmt.type === 'ImportDeclaration') {
|
|
92
|
-
const source = stmt.source.value;
|
|
93
|
-
if (typeof source === 'string' && AST_TOOL_PACKAGES.some((p) => source === p || source.startsWith(p + '/'))) {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return false;
|
|
99
|
-
})();
|
|
100
|
-
function matchesIgnorePattern(text, patterns) {
|
|
101
|
-
return patterns.some(pattern => {
|
|
102
|
-
try {
|
|
103
|
-
const regex = new RegExp(pattern, 'i');
|
|
104
|
-
return regex.test(text);
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
return text.toLowerCase().includes(pattern.toLowerCase());
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
function isNullLiteral(node) {
|
|
112
|
-
return node.type === 'Literal' && node.raw === 'null';
|
|
113
|
-
}
|
|
114
|
-
function checkBinaryExpression(node) {
|
|
115
|
-
if (isTestFile) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (isCodemodFile) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const secretKeywords = new Set([
|
|
122
|
-
'secret', 'secrets', 'token', 'tokens', 'password', 'passwd', 'pwd',
|
|
123
|
-
'apikey', 'api_key', 'secretkey', 'secret_key', 'privatekey', 'private_key',
|
|
124
|
-
'signature', 'hmac', 'digest', 'checksum', 'nonce', 'otp',
|
|
125
|
-
'passwordhash', 'password_hash', 'hashedpassword', 'hashed_password',
|
|
126
|
-
]);
|
|
127
|
-
const nameSegments = (name) => {
|
|
128
|
-
const parts = name
|
|
129
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
130
|
-
.split(/[^A-Za-z0-9]+/)
|
|
131
|
-
.filter(Boolean)
|
|
132
|
-
.map((p) => p.toLowerCase());
|
|
133
|
-
return [...parts, parts.join(''), parts.join('_'), name.toLowerCase()];
|
|
134
|
-
};
|
|
135
|
-
const namesIn = (expr) => {
|
|
136
|
-
const out = [];
|
|
137
|
-
const walk = (n) => {
|
|
138
|
-
if (n.type === 'Identifier')
|
|
139
|
-
out.push(n.name);
|
|
140
|
-
else if (n.type === 'MemberExpression') {
|
|
141
|
-
walk(n.object);
|
|
142
|
-
if (!n.computed && n.property.type === 'Identifier')
|
|
143
|
-
out.push(n.property.name);
|
|
144
|
-
else
|
|
145
|
-
walk(n.property);
|
|
146
|
-
}
|
|
147
|
-
else if (n.type === 'CallExpression') {
|
|
148
|
-
walk(n.callee);
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
walk(expr);
|
|
152
|
-
return out;
|
|
153
|
-
};
|
|
154
|
-
const isSecurityContext = (() => {
|
|
155
|
-
let current = node;
|
|
156
|
-
while (current) {
|
|
157
|
-
if ((current.type === 'FunctionDeclaration' ||
|
|
158
|
-
current.type === 'FunctionExpression' ||
|
|
159
|
-
current.type === 'ArrowFunctionExpression') &&
|
|
160
|
-
'id' in current && current.id?.name) {
|
|
161
|
-
if (/security|auth|crypto|hash|token|secret|insecure|verify|validate/i.test(current.id.name)) {
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (current.type === 'MethodDefinition' && current.key.type === 'Identifier') {
|
|
166
|
-
if (/security|auth|crypto|hash|token|secret|insecure|verify|validate/i.test(current.key.name)) {
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
current = current.parent;
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
})();
|
|
174
|
-
const isPotentialSecret = (expr) => {
|
|
175
|
-
const segments = namesIn(expr).flatMap(nameSegments);
|
|
176
|
-
if (segments.some(segment => secretKeywords.has(segment)))
|
|
177
|
-
return true;
|
|
178
|
-
if (isSecurityContext) {
|
|
179
|
-
const contextKeywords = new Set(['provided', 'expected', 'actual', 'input', 'value', 'data']);
|
|
180
|
-
return segments.some(segment => contextKeywords.has(segment));
|
|
181
|
-
}
|
|
182
|
-
return false;
|
|
183
|
-
};
|
|
184
|
-
if ((node.operator === '===' || node.operator === '!==') &&
|
|
185
|
-
(isPotentialSecret(node.left) || isPotentialSecret(node.right))) {
|
|
186
|
-
const isLengthComparison = (expr) => {
|
|
187
|
-
return expr.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
|
|
188
|
-
expr.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
189
|
-
expr.property.name === 'length';
|
|
190
|
-
};
|
|
191
|
-
if (isLengthComparison(node.left) || isLengthComparison(node.right)) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
const leftText = sourceCode.getText(node.left);
|
|
195
|
-
const rightText = sourceCode.getText(node.right);
|
|
196
|
-
const example = `crypto.timingSafeEqual(Buffer.from(${leftText}), Buffer.from(${rightText}))`;
|
|
197
|
-
context.report({
|
|
198
|
-
node,
|
|
199
|
-
messageId: 'timingUnsafeComparison',
|
|
200
|
-
data: {
|
|
201
|
-
operator: node.operator,
|
|
202
|
-
strictOperator: node.operator,
|
|
203
|
-
example: example,
|
|
204
|
-
},
|
|
205
|
-
suggest: [
|
|
206
|
-
{
|
|
207
|
-
messageId: 'useStrictEquality',
|
|
208
|
-
fix: (fixer) => fixer.replaceText(node, example),
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
});
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if (node.operator === '==' || node.operator === '!=') {
|
|
215
|
-
const text = sourceCode.getText(node);
|
|
216
|
-
if (matchesIgnorePattern(text, ignorePatterns)) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (isNullLiteral(node.left) || isNullLiteral(node.right)) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
const strictOperator = node.operator === '==' ? '===' : '!==';
|
|
223
|
-
const leftText = sourceCode.getText(node.left);
|
|
224
|
-
const rightText = sourceCode.getText(node.right);
|
|
225
|
-
const example = `${leftText} ${strictOperator} ${rightText}`;
|
|
226
|
-
context.report({
|
|
227
|
-
node: node,
|
|
228
|
-
messageId: 'insecureComparison',
|
|
229
|
-
data: {
|
|
230
|
-
operator: node.operator,
|
|
231
|
-
strictOperator,
|
|
232
|
-
example,
|
|
233
|
-
},
|
|
234
|
-
suggest: [
|
|
235
|
-
{
|
|
236
|
-
messageId: 'useStrictEquality',
|
|
237
|
-
fix: (fixer) => {
|
|
238
|
-
return fixer.replaceText(node, example);
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
],
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
BinaryExpression: checkBinaryExpression,
|
|
247
|
-
};
|
|
248
|
-
},
|
|
249
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noInsecureComparison=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noInsecureComparison=(0,eslint_devkit_2.createRule)({name:"no-insecure-comparison",meta:{type:"problem",deprecated:true,replacedBy:["node-security/no-timing-unsafe-compare"],docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-insecure-comparison.md",description:"Detects insecure comparison operators (==, !=) that can lead to type coercion vulnerabilities",cwe:"CWE-697",cvss:5.3},hasSuggestions:true,messages:{insecureComparison:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Insecure Comparison",cwe:"CWE-697",description:"Insecure comparison operator ({{operator}}) detected - can lead to type coercion vulnerabilities",severity:"HIGH",fix:"Use strict equality ({{strictOperator}}) instead: {{example}}",documentationLink:"https://cwe.mitre.org/data/definitions/697.html"}),useStrictEquality:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.INFO,issueName:"Use Strict Equality",description:"Use strict equality operator",severity:"LOW",fix:"Replace == with === and != with !==",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality"}),timingUnsafeComparison:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Timing Attack Risk",cwe:"CWE-208",description:"Secret comparison with {{operator}} can leak timing information",severity:"HIGH",fix:"Use crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b))",documentationLink:"https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false,description:"Allow insecure comparison in test files"},ignorePatterns:{type:"array",items:{type:"string"},default:[],description:"Additional patterns to ignore"}},additionalProperties:false}]},defaultOptions:[{allowInTests:false,ignorePatterns:[]}],create(context,[options={}]){const{allowInTests=false,ignorePatterns=[]}=options;const filename=context.filename;const isTestFile=allowInTests&&/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);const sourceCode=context.sourceCode;const AST_TOOL_PACKAGES=["@babel/types","@babel/traverse","@babel/generator","@babel/parser","recast","jscodeshift","estree-walker","unist-util-visit","@typescript-eslint/utils","@typescript-eslint/typescript-estree","typescript","ts-morph","eslint"];const isCodemodFile=(()=>{if(/\/codemod[s]?\//i.test(filename))return true;if(/codemod\.[mc]?[jt]sx?$/i.test(filename))return true;const program=sourceCode.ast;for(const stmt of program.body){if(stmt.type==="ImportDeclaration"){const source=stmt.source.value;if(typeof source==="string"&&AST_TOOL_PACKAGES.some(p=>source===p||source.startsWith(p+"/"))){return true}}}return false})();function matchesIgnorePattern(text,patterns){return patterns.some(pattern=>{try{const regex=new RegExp(pattern,"i");return regex.test(text)}catch{return text.toLowerCase().includes(pattern.toLowerCase())}})}function isNullLiteral(node){return node.type==="Literal"&&node.raw==="null"}function checkBinaryExpression(node){if(isTestFile){return}if(isCodemodFile){return}const secretKeywords=new Set(["secret","secrets","token","tokens","password","passwd","pwd","apikey","api_key","secretkey","secret_key","privatekey","private_key","signature","hmac","digest","checksum","nonce","otp","passwordhash","password_hash","hashedpassword","hashed_password"]);const nameSegments=name=>{const parts=name.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^A-Za-z0-9]+/).filter(Boolean).map(p=>p.toLowerCase());return[...parts,parts.join(""),parts.join("_"),name.toLowerCase()]};const namesIn=expr=>{const out=[];const walk=n=>{if(n.type==="Identifier")out.push(n.name);else if(n.type==="MemberExpression"){walk(n.object);if(!n.computed&&n.property.type==="Identifier")out.push(n.property.name);else walk(n.property)}else if(n.type==="CallExpression"){walk(n.callee)}};walk(expr);return out};const isSecurityContext=(()=>{let current=node;while(current){if((current.type==="FunctionDeclaration"||current.type==="FunctionExpression"||current.type==="ArrowFunctionExpression")&&"id"in current&¤t.id?.name){if(/security|auth|crypto|hash|token|secret|insecure|verify|validate/i.test(current.id.name)){return true}}if(current.type==="MethodDefinition"&¤t.key.type==="Identifier"){if(/security|auth|crypto|hash|token|secret|insecure|verify|validate/i.test(current.key.name)){return true}}current=current.parent}return false})();const isPotentialSecret=expr=>{const segments=namesIn(expr).flatMap(nameSegments);if(segments.some(segment=>secretKeywords.has(segment)))return true;if(isSecurityContext){const contextKeywords=new Set(["provided","expected","actual","input","value","data"]);return segments.some(segment=>contextKeywords.has(segment))}return false};if((node.operator==="==="||node.operator==="!==")&&(isPotentialSecret(node.left)||isPotentialSecret(node.right))){const isLengthComparison=expr=>{return expr.type===eslint_devkit_1.AST_NODE_TYPES.MemberExpression&&expr.property.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&expr.property.name==="length"};if(isLengthComparison(node.left)||isLengthComparison(node.right)){return}const leftText=sourceCode.getText(node.left);const rightText=sourceCode.getText(node.right);const example=`crypto.timingSafeEqual(Buffer.from(${leftText}), Buffer.from(${rightText}))`;context.report({node,messageId:"timingUnsafeComparison",data:{operator:node.operator,strictOperator:node.operator,example},suggest:[{messageId:"useStrictEquality",fix:fixer=>fixer.replaceText(node,example)}]});return}if(node.operator==="=="||node.operator==="!="){const text=sourceCode.getText(node);if(matchesIgnorePattern(text,ignorePatterns)){return}if(isNullLiteral(node.left)||isNullLiteral(node.right)){return}const strictOperator=node.operator==="=="?"===":"!==";const leftText=sourceCode.getText(node.left);const rightText=sourceCode.getText(node.right);const example=`${leftText} ${strictOperator} ${rightText}`;context.report({node,messageId:"insecureComparison",data:{operator:node.operator,strictOperator,example},suggest:[{messageId:"useStrictEquality",fix:fixer=>{return fixer.replaceText(node,example)}}]})}}return{BinaryExpression:checkBinaryExpression}}});
|