eslint-plugin-node-security 4.8.0 → 4.8.1

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 (41) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +1 -95
  3. package/src/oxlint.js +1 -3
  4. package/src/rules/detect-child-process/index.js +1 -625
  5. package/src/rules/detect-eval-with-expression/index.js +1 -364
  6. package/src/rules/detect-non-literal-fs-filename/index.js +1 -516
  7. package/src/rules/detect-suspicious-dependencies/index.js +1 -69
  8. package/src/rules/lock-file/index.js +1 -92
  9. package/src/rules/no-arbitrary-file-access/index.js +1 -152
  10. package/src/rules/no-buffer-overread/index.js +1 -543
  11. package/src/rules/no-cryptojs/index.js +1 -99
  12. package/src/rules/no-cryptojs-weak-random/index.js +1 -103
  13. package/src/rules/no-data-in-temp-storage/index.js +1 -85
  14. package/src/rules/no-deprecated-buffer/index.js +1 -84
  15. package/src/rules/no-deprecated-cipher-method/index.js +1 -112
  16. package/src/rules/no-dynamic-algorithm-selection/index.js +1 -72
  17. package/src/rules/no-dynamic-command-string/index.js +1 -201
  18. package/src/rules/no-dynamic-dependency-loading/index.js +1 -45
  19. package/src/rules/no-dynamic-require/index.js +1 -96
  20. package/src/rules/no-ecb-mode/index.js +1 -108
  21. package/src/rules/no-insecure-key-derivation/index.js +1 -109
  22. package/src/rules/no-insecure-rsa-padding/index.js +1 -104
  23. package/src/rules/no-math-random-crypto/index.js +1 -192
  24. package/src/rules/no-self-signed-certs/index.js +1 -110
  25. package/src/rules/no-sha1-hash/index.js +1 -121
  26. package/src/rules/no-shell-injection/index.js +1 -68
  27. package/src/rules/no-ssrf/index.js +1 -221
  28. package/src/rules/no-static-iv/index.js +1 -129
  29. package/src/rules/no-timing-unsafe-compare/index.js +1 -106
  30. package/src/rules/no-toctou-vulnerability/index.js +1 -195
  31. package/src/rules/no-unsafe-buffer-alloc/index.js +1 -87
  32. package/src/rules/no-unsafe-dynamic-require/index.js +1 -93
  33. package/src/rules/no-weak-cipher-algorithm/index.js +1 -174
  34. package/src/rules/no-weak-hash-algorithm/index.js +1 -199
  35. package/src/rules/no-zip-slip/index.js +1 -410
  36. package/src/rules/prefer-native-crypto/index.js +1 -119
  37. package/src/rules/require-dependency-integrity/index.js +1 -62
  38. package/src/rules/require-secure-credential-storage/index.js +1 -45
  39. package/src/rules/require-secure-deletion/index.js +1 -82
  40. package/src/rules/require-storage-encryption/index.js +1 -45
  41. package/src/types/index.js +1 -2
@@ -1,364 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectEvalWithExpression = exports.generateRefactoringSteps = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- const EVAL_PATTERNS = [
7
- {
8
- pattern: 'JSON\\.parse|parse\\(.*\\)',
9
- category: 'json',
10
- safeAlternative: 'JSON.parse()',
11
- example: {
12
- bad: 'eval(\'{"key": "\' + value + \'"}"\')',
13
- good: 'JSON.parse(\'{"key": "\' + value + \'"}"\')'
14
- },
15
- effort: '2 minutes'
16
- },
17
- {
18
- pattern: 'Math\\.|parseInt|parseFloat',
19
- category: 'math',
20
- safeAlternative: 'Math functions or parseInt/parseFloat',
21
- example: {
22
- bad: 'eval(\'Math.\' + method + \'(\' + arg + \')\')',
23
- good: 'const mathMethods = {sin: Math.sin, cos: Math.cos}; mathMethods[method](arg)'
24
- },
25
- effort: '5 minutes'
26
- },
27
- {
28
- pattern: '\\$\\{|template|interpolat',
29
- category: 'template',
30
- safeAlternative: 'Template literals or template engine',
31
- example: {
32
- bad: 'eval(\'Hello \' + userName + \'!\')',
33
- good: 'const template = `Hello ${userName}!`;'
34
- },
35
- effort: '3 minutes'
36
- },
37
- {
38
- pattern: '\\[.*\\]|object\\[|obj\\.|\\.',
39
- category: 'object',
40
- safeAlternative: 'Direct property access or Map',
41
- example: {
42
- bad: 'eval(\'obj.\' + property)',
43
- good: 'const allowedProps = {name: true, age: true}; if (allowedProps[property]) obj[property]'
44
- },
45
- effort: '8 minutes'
46
- }
47
- ];
48
- const generateRefactoringSteps = (pattern) => {
49
- if (!pattern) {
50
- return [
51
- ' 1. Remove eval() usage entirely',
52
- ' 2. Identify what the code is trying to achieve',
53
- ' 3. Use appropriate safe alternative (JSON.parse, Map, etc.)',
54
- ' 4. Add input validation if dynamic behavior needed',
55
- ' 5. Test thoroughly for edge cases'
56
- ].join('\n');
57
- }
58
- switch (pattern.category) {
59
- case 'json':
60
- return [
61
- ' 1. Replace eval() with JSON.parse()',
62
- ' 2. Ensure input is valid JSON string',
63
- ' 3. Add try/catch for JSON parsing errors',
64
- ' 4. Consider using a JSON schema validator'
65
- ].join('\n');
66
- case 'math':
67
- return [
68
- ' 1. Create whitelist of allowed Math functions',
69
- ' 2. Use direct function calls: Math.sin(x)',
70
- ' 3. Validate inputs are numbers',
71
- ' 4. Consider using a math expression parser library'
72
- ].join('\n');
73
- case 'template':
74
- return [
75
- ' 1. Use template literals: `Hello ${name}`',
76
- ' 2. Sanitize variables before interpolation',
77
- ' 3. Use a template engine like Handlebars if complex',
78
- ' 4. Validate template structure'
79
- ].join('\n');
80
- case 'object':
81
- return [
82
- ' 1. Use Map or plain object for key-value access',
83
- ' 2. Whitelist allowed property names',
84
- ' 3. Use hasOwnProperty() check',
85
- ' 4. Consider Object.create(null) for clean objects'
86
- ].join('\n');
87
- default:
88
- return [
89
- ' 1. Identify the specific use case',
90
- ' 2. Find a safer alternative approach',
91
- ' 3. Add comprehensive input validation',
92
- ' 4. Use static analysis if possible'
93
- ].join('\n');
94
- }
95
- };
96
- exports.generateRefactoringSteps = generateRefactoringSteps;
97
- exports.detectEvalWithExpression = (0, eslint_devkit_2.createRule)({
98
- name: 'detect-eval-with-expression',
99
- meta: {
100
- type: 'problem',
101
- docs: {
102
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-node-security/docs/rules/detect-eval-with-expression.md',
103
- description: 'Detects eval(variable) which can allow an attacker to run arbitrary code',
104
- cwe: 'CWE-95',
105
- cvss: 9.8,
106
- confidence: 'high',
107
- },
108
- messages: {
109
- evalWithExpression: (0, eslint_devkit_1.formatLLMMessage)({
110
- icon: eslint_devkit_1.MessageIcons.SECURITY,
111
- issueName: 'eval() with dynamic code',
112
- cwe: 'CWE-95',
113
- description: 'eval() with dynamic code',
114
- severity: 'CRITICAL',
115
- fix: '{{safeAlternative}}',
116
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
117
- }),
118
- useJsonParse: (0, eslint_devkit_1.formatLLMMessage)({
119
- icon: eslint_devkit_1.MessageIcons.SECURITY,
120
- issueName: 'Unsafe eval() for JSON parsing',
121
- cwe: 'CWE-95',
122
- description: 'Use JSON.parse() instead of eval() for JSON string parsing',
123
- severity: 'HIGH',
124
- fix: 'Replace eval() with JSON.parse()',
125
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
126
- }),
127
- useObjectAccess: (0, eslint_devkit_1.formatLLMMessage)({
128
- icon: eslint_devkit_1.MessageIcons.SECURITY,
129
- issueName: 'Unsafe eval() for property access',
130
- cwe: 'CWE-95',
131
- description: 'Use direct property access instead of eval() for dynamic property access',
132
- severity: 'HIGH',
133
- fix: 'Use obj[key] or Map.get(key) instead of eval()',
134
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
135
- }),
136
- useTemplateLiteral: (0, eslint_devkit_1.formatLLMMessage)({
137
- icon: eslint_devkit_1.MessageIcons.SECURITY,
138
- issueName: 'Unsafe eval() for string interpolation',
139
- cwe: 'CWE-95',
140
- description: 'Use template literals instead of eval() for string interpolation',
141
- severity: 'HIGH',
142
- fix: 'Replace eval() with template literals: `Hello ${name}`',
143
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
144
- }),
145
- useFunctionConstructor: (0, eslint_devkit_1.formatLLMMessage)({
146
- icon: eslint_devkit_1.MessageIcons.SECURITY,
147
- issueName: 'Unsafe eval() for function creation',
148
- cwe: 'CWE-95',
149
- description: 'Use Function constructor with validation instead of eval()',
150
- severity: 'HIGH',
151
- fix: 'Replace eval() with validated Function constructor',
152
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
153
- }),
154
- useSaferAlternative: (0, eslint_devkit_1.formatLLMMessage)({
155
- icon: eslint_devkit_1.MessageIcons.SECURITY,
156
- issueName: 'Unsafe eval() usage detected',
157
- cwe: 'CWE-95',
158
- description: 'eval() with dynamic code execution detected',
159
- severity: 'HIGH',
160
- fix: '{{alternative}}',
161
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
162
- }),
163
- strategyRemove: (0, eslint_devkit_1.formatLLMMessage)({
164
- icon: eslint_devkit_1.MessageIcons.SECURITY,
165
- issueName: 'Critical eval() security vulnerability',
166
- cwe: 'CWE-95',
167
- description: 'eval() usage poses severe security risk',
168
- severity: 'CRITICAL',
169
- fix: 'Remove eval() entirely - security risk too high',
170
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
171
- }),
172
- strategyRefactor: (0, eslint_devkit_1.formatLLMMessage)({
173
- icon: eslint_devkit_1.MessageIcons.SECURITY,
174
- issueName: 'eval() refactoring required',
175
- cwe: 'CWE-95',
176
- description: 'eval() can be refactored to safer alternative',
177
- severity: 'HIGH',
178
- fix: '{{safeAlternative}}',
179
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
180
- }),
181
- strategyValidate: (0, eslint_devkit_1.formatLLMMessage)({
182
- icon: eslint_devkit_1.MessageIcons.SECURITY,
183
- issueName: 'eval() input validation needed',
184
- cwe: 'CWE-95',
185
- description: 'eval() requires input validation for security',
186
- severity: 'MEDIUM',
187
- fix: 'Add input validation before using eval()',
188
- documentationLink: 'https://owasp.org/www-community/attacks/Code_Injection',
189
- })
190
- },
191
- schema: [
192
- {
193
- type: 'object',
194
- properties: {
195
- allowLiteralStrings: {
196
- type: 'boolean',
197
- default: false,
198
- description: 'Allow eval with literal strings (false = stricter)'
199
- },
200
- additionalEvalFunctions: {
201
- type: 'array',
202
- items: { type: 'string' },
203
- default: [],
204
- description: 'Additional functions to treat as eval-like'
205
- },
206
- strategy: {
207
- type: 'string',
208
- enum: ['remove', 'refactor', 'validate', 'auto'],
209
- default: 'auto',
210
- description: 'Strategy for fixing eval usage (auto = smart detection)'
211
- }
212
- },
213
- additionalProperties: false,
214
- },
215
- ],
216
- },
217
- defaultOptions: [
218
- {
219
- allowLiteralStrings: false,
220
- additionalEvalFunctions: [],
221
- strategy: 'auto'
222
- },
223
- ],
224
- create(context) {
225
- const options = context.options[0] || {};
226
- const { allowLiteralStrings = false, additionalEvalFunctions = [], strategy = 'auto' } = options;
227
- const evalFunctions = new Set([
228
- 'eval',
229
- 'Function',
230
- ...additionalEvalFunctions
231
- ]);
232
- const isLiteralString = (node) => {
233
- return node.type === 'Literal' && typeof node.value === 'string';
234
- };
235
- const selectStrategyMessage = (pattern) => {
236
- switch (strategy) {
237
- case 'remove':
238
- return 'strategyRemove';
239
- case 'refactor':
240
- return 'strategyRefactor';
241
- case 'validate':
242
- return 'strategyValidate';
243
- case 'auto':
244
- default:
245
- if (pattern && pattern.category === 'json') {
246
- return 'useJsonParse';
247
- }
248
- if (pattern && pattern.category === 'object') {
249
- return 'useObjectAccess';
250
- }
251
- if (pattern && pattern.category === 'template') {
252
- return 'useTemplateLiteral';
253
- }
254
- return 'strategyRefactor';
255
- }
256
- };
257
- const detectPattern = (expression) => {
258
- for (const pattern of EVAL_PATTERNS) {
259
- if (new RegExp(pattern.pattern, 'i').test(expression)) {
260
- return pattern;
261
- }
262
- }
263
- return null;
264
- };
265
- const extractExpression = (node) => {
266
- const sourceCode = context.sourceCode;
267
- if (node.arguments.length > 0) {
268
- return sourceCode.getText(node.arguments[0]);
269
- }
270
- return 'dynamic expression';
271
- };
272
- const checkCallExpression = (node) => {
273
- if (node.callee.type === 'Identifier' &&
274
- evalFunctions.has(node.callee.name)) {
275
- if (allowLiteralStrings &&
276
- node.arguments.length > 0 &&
277
- isLiteralString(node.arguments[0])) {
278
- return;
279
- }
280
- if (node.arguments.length > 0 &&
281
- node.callee.name === 'eval' &&
282
- isLiteralString(node.arguments[0])) {
283
- return;
284
- }
285
- const expression = extractExpression(node);
286
- const pattern = detectPattern(expression);
287
- const steps = (0, exports.generateRefactoringSteps)(pattern);
288
- const strategyMessageId = selectStrategyMessage(pattern);
289
- context.report({
290
- node,
291
- messageId: strategyMessageId,
292
- data: {
293
- expression,
294
- patternCategory: pattern?.category || 'dynamic code execution',
295
- safeAlternative: pattern?.safeAlternative || 'Remove eval entirely',
296
- steps,
297
- effort: pattern?.effort || '15-30 minutes'
298
- },
299
- suggest: pattern ? [
300
- {
301
- messageId: strategyMessageId,
302
- data: {
303
- safeAlternative: pattern.safeAlternative,
304
- alternative: pattern.safeAlternative
305
- },
306
- fix: () => null
307
- }
308
- ] : undefined
309
- });
310
- }
311
- if (node.callee.type === 'NewExpression' &&
312
- node.callee.callee.type === 'Identifier' &&
313
- node.callee.callee.name === 'Function') {
314
- const expression = extractExpression(node);
315
- const pattern = detectPattern(expression);
316
- const strategyMessageId = selectStrategyMessage(pattern);
317
- context.report({
318
- node,
319
- messageId: strategyMessageId,
320
- data: {
321
- expression: `new Function(${expression})`,
322
- patternCategory: 'function constructor',
323
- safeAlternative: 'Arrow function or regular function',
324
- steps: [
325
- ' 1. Replace Function constructor with arrow function',
326
- ' 2. Use regular function declaration',
327
- ' 3. Validate any dynamic parts',
328
- ' 4. Consider module imports instead'
329
- ].join('\n'),
330
- effort: '10 minutes'
331
- }
332
- });
333
- }
334
- };
335
- const checkNewExpression = (node) => {
336
- if (node.callee.type === 'Identifier' && node.callee.name === 'Function') {
337
- const sourceCode = context.sourceCode;
338
- const expression = node.arguments.map((arg) => sourceCode.getText(arg)).join(', ');
339
- const pattern = detectPattern(expression);
340
- const strategyMessageId = selectStrategyMessage(pattern);
341
- context.report({
342
- node,
343
- messageId: strategyMessageId,
344
- data: {
345
- expression: `new Function(${expression})`,
346
- patternCategory: 'function constructor',
347
- safeAlternative: 'Arrow function or regular function',
348
- steps: [
349
- ' 1. Replace Function constructor with arrow function',
350
- ' 2. Use regular function declaration',
351
- ' 3. Validate any dynamic parts',
352
- ' 4. Consider module imports instead'
353
- ].join('\n'),
354
- effort: '10 minutes'
355
- }
356
- });
357
- }
358
- };
359
- return {
360
- CallExpression: checkCallExpression,
361
- NewExpression: checkNewExpression
362
- };
363
- },
364
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.detectEvalWithExpression=exports.generateRefactoringSteps=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const EVAL_PATTERNS=[{pattern:"JSON\\.parse|parse\\(.*\\)",category:"json",safeAlternative:"JSON.parse()",example:{bad:`eval('{"key": "' + value + '"}"')`,good:`JSON.parse('{"key": "' + value + '"}"')`},effort:"2 minutes"},{pattern:"Math\\.|parseInt|parseFloat",category:"math",safeAlternative:"Math functions or parseInt/parseFloat",example:{bad:"eval('Math.' + method + '(' + arg + ')')",good:"const mathMethods = {sin: Math.sin, cos: Math.cos}; mathMethods[method](arg)"},effort:"5 minutes"},{pattern:"\\$\\{|template|interpolat",category:"template",safeAlternative:"Template literals or template engine",example:{bad:"eval('Hello ' + userName + '!')",good:"const template = `Hello ${userName}!`;"},effort:"3 minutes"},{pattern:"\\[.*\\]|object\\[|obj\\.|\\.",category:"object",safeAlternative:"Direct property access or Map",example:{bad:"eval('obj.' + property)",good:"const allowedProps = {name: true, age: true}; if (allowedProps[property]) obj[property]"},effort:"8 minutes"}];const generateRefactoringSteps=pattern=>{if(!pattern){return[" 1. Remove eval() usage entirely"," 2. Identify what the code is trying to achieve"," 3. Use appropriate safe alternative (JSON.parse, Map, etc.)"," 4. Add input validation if dynamic behavior needed"," 5. Test thoroughly for edge cases"].join("\n")}switch(pattern.category){case"json":return[" 1. Replace eval() with JSON.parse()"," 2. Ensure input is valid JSON string"," 3. Add try/catch for JSON parsing errors"," 4. Consider using a JSON schema validator"].join("\n");case"math":return[" 1. Create whitelist of allowed Math functions"," 2. Use direct function calls: Math.sin(x)"," 3. Validate inputs are numbers"," 4. Consider using a math expression parser library"].join("\n");case"template":return[" 1. Use template literals: `Hello ${name}`"," 2. Sanitize variables before interpolation"," 3. Use a template engine like Handlebars if complex"," 4. Validate template structure"].join("\n");case"object":return[" 1. Use Map or plain object for key-value access"," 2. Whitelist allowed property names"," 3. Use hasOwnProperty() check"," 4. Consider Object.create(null) for clean objects"].join("\n");default:return[" 1. Identify the specific use case"," 2. Find a safer alternative approach"," 3. Add comprehensive input validation"," 4. Use static analysis if possible"].join("\n")}};exports.generateRefactoringSteps=generateRefactoringSteps;exports.detectEvalWithExpression=(0,eslint_devkit_2.createRule)({name:"detect-eval-with-expression",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-node-security/docs/rules/detect-eval-with-expression.md",description:"Detects eval(variable) which can allow an attacker to run arbitrary code",cwe:"CWE-95",cvss:9.8,confidence:"high"},messages:{evalWithExpression:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"eval() with dynamic code",cwe:"CWE-95",description:"eval() with dynamic code",severity:"CRITICAL",fix:"{{safeAlternative}}",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"}),useJsonParse:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unsafe eval() for JSON parsing",cwe:"CWE-95",description:"Use JSON.parse() instead of eval() for JSON string parsing",severity:"HIGH",fix:"Replace eval() with JSON.parse()",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"}),useObjectAccess:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unsafe eval() for property access",cwe:"CWE-95",description:"Use direct property access instead of eval() for dynamic property access",severity:"HIGH",fix:"Use obj[key] or Map.get(key) instead of eval()",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"}),useTemplateLiteral:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unsafe eval() for string interpolation",cwe:"CWE-95",description:"Use template literals instead of eval() for string interpolation",severity:"HIGH",fix:"Replace eval() with template literals: `Hello ${name}`",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"}),useFunctionConstructor:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unsafe eval() for function creation",cwe:"CWE-95",description:"Use Function constructor with validation instead of eval()",severity:"HIGH",fix:"Replace eval() with validated Function constructor",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"}),useSaferAlternative:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Unsafe eval() usage detected",cwe:"CWE-95",description:"eval() with dynamic code execution detected",severity:"HIGH",fix:"{{alternative}}",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"}),strategyRemove:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Critical eval() security vulnerability",cwe:"CWE-95",description:"eval() usage poses severe security risk",severity:"CRITICAL",fix:"Remove eval() entirely - security risk too high",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"}),strategyRefactor:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"eval() refactoring required",cwe:"CWE-95",description:"eval() can be refactored to safer alternative",severity:"HIGH",fix:"{{safeAlternative}}",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"}),strategyValidate:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"eval() input validation needed",cwe:"CWE-95",description:"eval() requires input validation for security",severity:"MEDIUM",fix:"Add input validation before using eval()",documentationLink:"https://owasp.org/www-community/attacks/Code_Injection"})},schema:[{type:"object",properties:{allowLiteralStrings:{type:"boolean",default:false,description:"Allow eval with literal strings (false = stricter)"},additionalEvalFunctions:{type:"array",items:{type:"string"},default:[],description:"Additional functions to treat as eval-like"},strategy:{type:"string",enum:["remove","refactor","validate","auto"],default:"auto",description:"Strategy for fixing eval usage (auto = smart detection)"}},additionalProperties:false}]},defaultOptions:[{allowLiteralStrings:false,additionalEvalFunctions:[],strategy:"auto"}],create(context){const options=context.options[0]||{};const{allowLiteralStrings=false,additionalEvalFunctions=[],strategy="auto"}=options;const evalFunctions=new Set(["eval","Function",...additionalEvalFunctions]);const isLiteralString=node=>{return node.type==="Literal"&&typeof node.value==="string"};const selectStrategyMessage=pattern=>{switch(strategy){case"remove":return"strategyRemove";case"refactor":return"strategyRefactor";case"validate":return"strategyValidate";case"auto":default:if(pattern&&pattern.category==="json"){return"useJsonParse"}if(pattern&&pattern.category==="object"){return"useObjectAccess"}if(pattern&&pattern.category==="template"){return"useTemplateLiteral"}return"strategyRefactor"}};const detectPattern=expression=>{for(const pattern of EVAL_PATTERNS){if(new RegExp(pattern.pattern,"i").test(expression)){return pattern}}return null};const extractExpression=node=>{const sourceCode=context.sourceCode;if(node.arguments.length>0){return sourceCode.getText(node.arguments[0])}return"dynamic expression"};const checkCallExpression=node=>{if(node.callee.type==="Identifier"&&evalFunctions.has(node.callee.name)){if(allowLiteralStrings&&node.arguments.length>0&&isLiteralString(node.arguments[0])){return}if(node.arguments.length>0&&node.callee.name==="eval"&&isLiteralString(node.arguments[0])){return}const expression=extractExpression(node);const pattern=detectPattern(expression);const steps=(0,exports.generateRefactoringSteps)(pattern);const strategyMessageId=selectStrategyMessage(pattern);context.report({node,messageId:strategyMessageId,data:{expression,patternCategory:pattern?.category||"dynamic code execution",safeAlternative:pattern?.safeAlternative||"Remove eval entirely",steps,effort:pattern?.effort||"15-30 minutes"},suggest:pattern?[{messageId:strategyMessageId,data:{safeAlternative:pattern.safeAlternative,alternative:pattern.safeAlternative},fix:()=>null}]:void 0})}if(node.callee.type==="NewExpression"&&node.callee.callee.type==="Identifier"&&node.callee.callee.name==="Function"){const expression=extractExpression(node);const pattern=detectPattern(expression);const strategyMessageId=selectStrategyMessage(pattern);context.report({node,messageId:strategyMessageId,data:{expression:`new Function(${expression})`,patternCategory:"function constructor",safeAlternative:"Arrow function or regular function",steps:[" 1. Replace Function constructor with arrow function"," 2. Use regular function declaration"," 3. Validate any dynamic parts"," 4. Consider module imports instead"].join("\n"),effort:"10 minutes"}})}};const checkNewExpression=node=>{if(node.callee.type==="Identifier"&&node.callee.name==="Function"){const sourceCode=context.sourceCode;const expression=node.arguments.map(arg=>sourceCode.getText(arg)).join(", ");const pattern=detectPattern(expression);const strategyMessageId=selectStrategyMessage(pattern);context.report({node,messageId:strategyMessageId,data:{expression:`new Function(${expression})`,patternCategory:"function constructor",safeAlternative:"Arrow function or regular function",steps:[" 1. Replace Function constructor with arrow function"," 2. Use regular function declaration"," 3. Validate any dynamic parts"," 4. Consider module imports instead"].join("\n"),effort:"10 minutes"}})}};return{CallExpression:checkCallExpression,NewExpression:checkNewExpression}}});