eslint-plugin-secure-coding 3.4.2 → 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.
Files changed (32) hide show
  1. package/package.json +2 -3
  2. package/src/index.js +1 -134
  3. package/src/oxlint.js +1 -3
  4. package/src/rules/detect-non-literal-regexp/index.js +1 -329
  5. package/src/rules/detect-object-injection/index.js +1 -691
  6. package/src/rules/detect-weak-password-validation/index.js +1 -54
  7. package/src/rules/no-directive-injection/index.js +1 -416
  8. package/src/rules/no-electron-security-issues/index.js +1 -385
  9. package/src/rules/no-format-string-injection/index.js +1 -565
  10. package/src/rules/no-graphql-injection/index.js +1 -612
  11. package/src/rules/no-hardcoded-credentials/index.js +1 -658
  12. package/src/rules/no-hardcoded-session-tokens/index.js +1 -56
  13. package/src/rules/no-improper-sanitization/index.js +1 -391
  14. package/src/rules/no-improper-type-validation/index.js +1 -422
  15. package/src/rules/no-insecure-comparison/index.js +1 -249
  16. package/src/rules/no-ldap-injection/index.js +1 -403
  17. package/src/rules/no-missing-authentication/index.js +1 -282
  18. package/src/rules/no-pii-in-logs/index.js +1 -63
  19. package/src/rules/no-privilege-escalation/index.js +1 -282
  20. package/src/rules/no-redos-vulnerable-regex/index.js +0 -0
  21. package/src/rules/no-sensitive-data-exposure/index.js +1 -249
  22. package/src/rules/no-template-injection/index.js +1 -84
  23. package/src/rules/no-unchecked-loop-condition/index.js +1 -541
  24. package/src/rules/no-unlimited-resource-allocation/index.js +1 -554
  25. package/src/rules/no-unsafe-deserialization/index.js +1 -497
  26. package/src/rules/no-unsafe-regex-construction/index.js +1 -275
  27. package/src/rules/no-weak-password-recovery/index.js +1 -382
  28. package/src/rules/no-xpath-injection/index.js +1 -431
  29. package/src/rules/no-xxe-injection/index.js +1 -230
  30. package/src/rules/require-backend-authorization/index.js +1 -58
  31. package/src/rules/require-secure-defaults/index.js +1 -41
  32. package/src/types/index.js +1 -2
@@ -1,422 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noImproperTypeValidation = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- const eslint_devkit_3 = require("@interlace/eslint-devkit");
7
- exports.noImproperTypeValidation = (0, eslint_devkit_1.createRule)({
8
- name: 'no-improper-type-validation',
9
- meta: {
10
- type: 'problem',
11
- docs: {
12
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-improper-type-validation.md',
13
- description: 'Detects improper type validation in user input handling',
14
- cwe: 'CWE-1287',
15
- },
16
- hasSuggestions: true,
17
- messages: {
18
- improperTypeValidation: (0, eslint_devkit_2.formatLLMMessage)({
19
- icon: eslint_devkit_2.MessageIcons.SECURITY,
20
- issueName: 'Improper Type Validation',
21
- cwe: 'CWE-1287',
22
- description: 'Type validation may be bypassed or incomplete',
23
- severity: '{{severity}}',
24
- fix: '{{safeAlternative}}',
25
- documentationLink: 'https://cwe.mitre.org/data/definitions/1287.html',
26
- }),
27
- unsafeTypeofCheck: (0, eslint_devkit_2.formatLLMMessage)({
28
- icon: eslint_devkit_2.MessageIcons.WARNING,
29
- issueName: 'Unsafe typeof Check',
30
- cwe: 'CWE-1287',
31
- description: 'typeof check misses null values',
32
- severity: 'MEDIUM',
33
- fix: 'Use value != null && typeof value === "object"',
34
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof',
35
- }),
36
- unsafeInstanceofUsage: (0, eslint_devkit_2.formatLLMMessage)({
37
- icon: eslint_devkit_2.MessageIcons.WARNING,
38
- issueName: 'Unsafe instanceof Usage',
39
- cwe: 'CWE-1287',
40
- description: 'instanceof may fail across contexts',
41
- severity: 'LOW',
42
- fix: 'Use Array.isArray() or typeof checks',
43
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof',
44
- }),
45
- looseEqualityTypeCheck: (0, eslint_devkit_2.formatLLMMessage)({
46
- icon: eslint_devkit_2.MessageIcons.WARNING,
47
- issueName: 'Loose Equality Type Check',
48
- cwe: 'CWE-1287',
49
- description: 'Loose equality may cause type confusion',
50
- severity: 'LOW',
51
- fix: 'Use strict equality (===) for type checking',
52
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality',
53
- }),
54
- missingNullCheck: (0, eslint_devkit_2.formatLLMMessage)({
55
- icon: eslint_devkit_2.MessageIcons.WARNING,
56
- issueName: 'Missing Null Check',
57
- cwe: 'CWE-1287',
58
- description: 'Type check doesn\'t handle null values',
59
- severity: 'MEDIUM',
60
- fix: 'Check for both null and undefined',
61
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof',
62
- }),
63
- unreliableConstructorCheck: (0, eslint_devkit_2.formatLLMMessage)({
64
- icon: eslint_devkit_2.MessageIcons.WARNING,
65
- issueName: 'Unreliable Constructor Check',
66
- cwe: 'CWE-1287',
67
- description: 'constructor.name can be spoofed',
68
- severity: 'MEDIUM',
69
- fix: 'Use Object.prototype.toString.call() or duck typing',
70
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor',
71
- }),
72
- incompleteTypeValidation: (0, eslint_devkit_2.formatLLMMessage)({
73
- icon: eslint_devkit_2.MessageIcons.WARNING,
74
- issueName: 'Incomplete Type Validation',
75
- cwe: 'CWE-1287',
76
- description: 'Type validation is incomplete',
77
- severity: 'LOW',
78
- fix: 'Use comprehensive type checking',
79
- documentationLink: 'https://cwe.mitre.org/data/definitions/1287.html',
80
- }),
81
- useTypeofCorrectly: (0, eslint_devkit_2.formatLLMMessage)({
82
- icon: eslint_devkit_2.MessageIcons.INFO,
83
- issueName: 'Use typeof Correctly',
84
- description: 'Use typeof with null checks for objects',
85
- severity: 'LOW',
86
- fix: 'if (value != null && typeof value === "object")',
87
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof',
88
- }),
89
- useProperTypeGuards: (0, eslint_devkit_2.formatLLMMessage)({
90
- icon: eslint_devkit_2.MessageIcons.INFO,
91
- issueName: 'Use Proper Type Guards',
92
- description: 'Use proper type guard functions',
93
- severity: 'LOW',
94
- fix: 'Array.isArray(), Number.isNaN(), etc.',
95
- documentationLink: 'https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types',
96
- }),
97
- validateUserInput: (0, eslint_devkit_2.formatLLMMessage)({
98
- icon: eslint_devkit_2.MessageIcons.INFO,
99
- issueName: 'Validate User Input',
100
- description: 'Validate user input before processing',
101
- severity: 'LOW',
102
- fix: 'Use schema validation libraries',
103
- documentationLink: 'https://joi.dev/',
104
- }),
105
- strategyTypeGuards: (0, eslint_devkit_2.formatLLMMessage)({
106
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
107
- issueName: 'Type Guards Strategy',
108
- description: 'Use type guards for runtime type checking',
109
- severity: 'LOW',
110
- fix: 'Implement custom type guard functions',
111
- documentationLink: 'https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types',
112
- }),
113
- strategySchemaValidation: (0, eslint_devkit_2.formatLLMMessage)({
114
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
115
- issueName: 'Schema Validation Strategy',
116
- description: 'Use schema validation for complex inputs',
117
- severity: 'LOW',
118
- fix: 'Use Joi, Yup, or Zod for input validation',
119
- documentationLink: 'https://joi.dev/',
120
- }),
121
- strategyDefensiveProgramming: (0, eslint_devkit_2.formatLLMMessage)({
122
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
123
- issueName: 'Defensive Programming Strategy',
124
- description: 'Use defensive programming techniques',
125
- severity: 'LOW',
126
- fix: 'Check types and handle edge cases explicitly',
127
- documentationLink: 'https://en.wikipedia.org/wiki/Defensive_programming',
128
- })
129
- },
130
- schema: [
131
- {
132
- type: 'object',
133
- properties: {
134
- userInputVariables: {
135
- type: 'array',
136
- items: { type: 'string' },
137
- default: ['req', 'request', 'body', 'query', 'params', 'input', 'data', 'userInput'],
138
- },
139
- safeTypeCheckFunctions: {
140
- type: 'array',
141
- items: { type: 'string' },
142
- default: ['isArray', 'isString', 'isNumber', 'isObject', 'validateType', 'checkType'],
143
- },
144
- allowInstanceofSameRealm: {
145
- type: 'boolean',
146
- default: true,
147
- description: 'Allow instanceof for same-realm objects'
148
- },
149
- trustedSanitizers: {
150
- type: 'array',
151
- items: { type: 'string' },
152
- default: [],
153
- description: 'Additional function names to consider as type validators',
154
- },
155
- trustedAnnotations: {
156
- type: 'array',
157
- items: { type: 'string' },
158
- default: [],
159
- description: 'Additional JSDoc annotations to consider as safe markers',
160
- },
161
- strictMode: {
162
- type: 'boolean',
163
- default: false,
164
- description: 'Disable all false positive detection (strict mode)',
165
- },
166
- },
167
- additionalProperties: false,
168
- },
169
- ],
170
- },
171
- defaultOptions: [
172
- {
173
- userInputVariables: ['req', 'request', 'body', 'query', 'params', 'input', 'data', 'userInput'],
174
- safeTypeCheckFunctions: ['isArray', 'isString', 'isNumber', 'isObject', 'validateType', 'checkType'],
175
- allowInstanceofSameRealm: true,
176
- trustedSanitizers: [],
177
- trustedAnnotations: [],
178
- strictMode: false,
179
- },
180
- ],
181
- create(context) {
182
- const options = context.options[0] || {};
183
- const { userInputVariables = ['req', 'request', 'body', 'query', 'params', 'input', 'data', 'userInput'], allowInstanceofSameRealm = true, trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
184
- const sourceCode = context.sourceCode;
185
- const filename = context.filename;
186
- const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
187
- trustedSanitizers,
188
- trustedAnnotations,
189
- trustedOrmPatterns: [],
190
- strictMode,
191
- });
192
- const isUserInput = (varName) => {
193
- return userInputVariables.some(input => varName.includes(input));
194
- };
195
- const isUnsafeTypeof = (node) => {
196
- if (node.operator !== '===' && node.operator !== '!==') {
197
- return false;
198
- }
199
- const left = node.left;
200
- const right = node.right;
201
- if (left.type === 'UnaryExpression' &&
202
- left.operator === 'typeof' &&
203
- right.type === 'Literal' &&
204
- right.value === 'object') {
205
- let varName = '';
206
- if (left.argument.type === 'Identifier') {
207
- varName = left.argument.name;
208
- }
209
- if (varName) {
210
- let current = node.parent;
211
- let child = node;
212
- while (current) {
213
- if (current.type === 'LogicalExpression' && current.operator === '&&') {
214
- if (current.right === child) {
215
- const leftText = sourceCode.getText(current.left);
216
- if (leftText.includes(`${varName} !== null`) ||
217
- leftText.includes(`${varName} != null`)) {
218
- return false;
219
- }
220
- }
221
- }
222
- if (current.type.includes('Statement') || current.type.includes('Declaration')) {
223
- break;
224
- }
225
- child = current;
226
- current = current.parent;
227
- }
228
- }
229
- return true;
230
- }
231
- return false;
232
- };
233
- const isUnsafeInstanceof = (node) => {
234
- if (node.operator !== 'instanceof') {
235
- return false;
236
- }
237
- if (!allowInstanceofSameRealm) {
238
- return true;
239
- }
240
- return false;
241
- };
242
- const isLooseEqualityTypeCheck = (node) => {
243
- if (node.operator !== '==' && node.operator !== '!=') {
244
- return false;
245
- }
246
- const leftText = sourceCode.getText(node.left).toLowerCase();
247
- const rightText = sourceCode.getText(node.right).toLowerCase();
248
- return (leftText.includes('null') || rightText.includes('null') ||
249
- leftText.includes('undefined') || rightText.includes('undefined'));
250
- };
251
- const isUnreliableConstructorCheck = (node) => {
252
- return node.property.type === 'Identifier' &&
253
- node.property.name === 'name' &&
254
- node.object.type === 'MemberExpression' &&
255
- node.object.property.type === 'Identifier' &&
256
- node.object.property.name === 'constructor';
257
- };
258
- return {
259
- BinaryExpression(node) {
260
- if (isUnsafeTypeof(node)) {
261
- const left = node.left;
262
- let matchesUserInput = false;
263
- if (left.argument.type === 'Identifier' && isUserInput(left.argument.name)) {
264
- matchesUserInput = true;
265
- }
266
- else if (left.argument.type === 'MemberExpression' &&
267
- left.argument.object.type === 'Identifier' &&
268
- isUserInput(left.argument.object.name)) {
269
- matchesUserInput = true;
270
- }
271
- if (matchesUserInput) {
272
- if (safetyChecker.isSafe(node, context)) {
273
- return;
274
- }
275
- context.report({
276
- node: left,
277
- messageId: 'unsafeTypeofCheck',
278
- data: {
279
- filePath: filename,
280
- line: String(node.loc?.start.line ?? 0),
281
- },
282
- suggest: [
283
- {
284
- messageId: 'useTypeofCorrectly',
285
- fix: () => null
286
- },
287
- ],
288
- });
289
- }
290
- }
291
- if (isUnsafeInstanceof(node)) {
292
- const left = node.left;
293
- if (left.type === 'Identifier' && isUserInput(left.name)) {
294
- context.report({
295
- node,
296
- messageId: 'unsafeInstanceofUsage',
297
- data: {
298
- filePath: filename,
299
- line: String(node.loc?.start.line ?? 0),
300
- },
301
- });
302
- }
303
- }
304
- if (isLooseEqualityTypeCheck(node)) {
305
- const left = node.left;
306
- const right = node.right;
307
- const leftText = sourceCode.getText(left);
308
- const rightText = sourceCode.getText(right);
309
- if ((left.type === 'Identifier' && isUserInput(left.name)) ||
310
- (right.type === 'Identifier' && isUserInput(right.name)) ||
311
- leftText.includes('null') || rightText.includes('null')) {
312
- if (safetyChecker.isSafe(node, context)) {
313
- return;
314
- }
315
- context.report({
316
- node: node,
317
- messageId: 'looseEqualityTypeCheck',
318
- data: {
319
- filePath: filename,
320
- line: String(node.loc?.start.line ?? 0),
321
- },
322
- });
323
- }
324
- }
325
- },
326
- MemberExpression(node) {
327
- if (isUnreliableConstructorCheck(node)) {
328
- let current = node;
329
- let involvesUserInput = false;
330
- while (current?.parent) {
331
- current = current.parent;
332
- if (current.type === 'VariableDeclarator' &&
333
- current.init === node) {
334
- involvesUserInput = true;
335
- break;
336
- }
337
- if (current.type === 'BinaryExpression' &&
338
- (current.left === node || current.right === node)) {
339
- involvesUserInput = true;
340
- break;
341
- }
342
- }
343
- if (involvesUserInput) {
344
- if (safetyChecker.isSafe(node, context)) {
345
- return;
346
- }
347
- context.report({
348
- node,
349
- messageId: 'unreliableConstructorCheck',
350
- data: {
351
- filePath: filename,
352
- line: String(node.loc?.start.line ?? 0),
353
- },
354
- });
355
- }
356
- }
357
- },
358
- CallExpression(node) {
359
- const callee = node.callee;
360
- if (callee.type === 'MemberExpression' &&
361
- callee.property.type === 'Identifier') {
362
- const methodName = callee.property.name;
363
- const objectName = callee.object.type === 'Identifier' ? callee.object.name : '';
364
- if (['isArray', 'isString', 'isNumber', 'isObject'].includes(methodName) &&
365
- objectName && ['Array', 'Number', 'String', 'Object'].includes(objectName)) {
366
- return;
367
- }
368
- }
369
- if (callee.type === 'Identifier' && callee.name === 'typeof') {
370
- context.report({
371
- node,
372
- messageId: 'improperTypeValidation',
373
- data: {
374
- filePath: filename,
375
- line: String(node.loc?.start.line ?? 0),
376
- severity: 'LOW',
377
- safeAlternative: 'Use typeof as unary operator: typeof value',
378
- },
379
- });
380
- }
381
- },
382
- IfStatement(node) {
383
- const test = node.test;
384
- if (test.type === 'Identifier' && isUserInput(test.name)) {
385
- if (safetyChecker.isSafe(node, context)) {
386
- return;
387
- }
388
- context.report({
389
- node: test,
390
- messageId: 'improperTypeValidation',
391
- data: {
392
- filePath: filename,
393
- line: String(node.loc?.start.line ?? 0),
394
- severity: 'LOW',
395
- safeAlternative: 'Explicitly check for null/undefined or type',
396
- }
397
- });
398
- }
399
- if (test.type === 'BinaryExpression') {
400
- const testText = sourceCode.getText(test).toLowerCase();
401
- if ((testText.includes('!= null') || testText.includes('== null')) &&
402
- !testText.includes('!== undefined') && !testText.includes('=== undefined')) {
403
- if ((test.left.type === 'Identifier' && isUserInput(test.left.name)) ||
404
- (test.right.type === 'Identifier' && isUserInput(test.right.name))) {
405
- if (safetyChecker.isSafe(node, context)) {
406
- return;
407
- }
408
- context.report({
409
- node: test,
410
- messageId: 'missingNullCheck',
411
- data: {
412
- filePath: filename,
413
- line: String(node.loc?.start.line ?? 0),
414
- },
415
- });
416
- }
417
- }
418
- }
419
- }
420
- };
421
- },
422
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noImproperTypeValidation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const eslint_devkit_3=require("@interlace/eslint-devkit");exports.noImproperTypeValidation=(0,eslint_devkit_1.createRule)({name:"no-improper-type-validation",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-improper-type-validation.md",description:"Detects improper type validation in user input handling",cwe:"CWE-1287"},hasSuggestions:true,messages:{improperTypeValidation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Improper Type Validation",cwe:"CWE-1287",description:"Type validation may be bypassed or incomplete",severity:"{{severity}}",fix:"{{safeAlternative}}",documentationLink:"https://cwe.mitre.org/data/definitions/1287.html"}),unsafeTypeofCheck:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Unsafe typeof Check",cwe:"CWE-1287",description:"typeof check misses null values",severity:"MEDIUM",fix:'Use value != null && typeof value === "object"',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof"}),unsafeInstanceofUsage:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Unsafe instanceof Usage",cwe:"CWE-1287",description:"instanceof may fail across contexts",severity:"LOW",fix:"Use Array.isArray() or typeof checks",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof"}),looseEqualityTypeCheck:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Loose Equality Type Check",cwe:"CWE-1287",description:"Loose equality may cause type confusion",severity:"LOW",fix:"Use strict equality (===) for type checking",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality"}),missingNullCheck:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Missing Null Check",cwe:"CWE-1287",description:"Type check doesn't handle null values",severity:"MEDIUM",fix:"Check for both null and undefined",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof"}),unreliableConstructorCheck:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Unreliable Constructor Check",cwe:"CWE-1287",description:"constructor.name can be spoofed",severity:"MEDIUM",fix:"Use Object.prototype.toString.call() or duck typing",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor"}),incompleteTypeValidation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Incomplete Type Validation",cwe:"CWE-1287",description:"Type validation is incomplete",severity:"LOW",fix:"Use comprehensive type checking",documentationLink:"https://cwe.mitre.org/data/definitions/1287.html"}),useTypeofCorrectly:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use typeof Correctly",description:"Use typeof with null checks for objects",severity:"LOW",fix:'if (value != null && typeof value === "object")',documentationLink:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof"}),useProperTypeGuards:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use Proper Type Guards",description:"Use proper type guard functions",severity:"LOW",fix:"Array.isArray(), Number.isNaN(), etc.",documentationLink:"https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types"}),validateUserInput:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Validate User Input",description:"Validate user input before processing",severity:"LOW",fix:"Use schema validation libraries",documentationLink:"https://joi.dev/"}),strategyTypeGuards:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Type Guards Strategy",description:"Use type guards for runtime type checking",severity:"LOW",fix:"Implement custom type guard functions",documentationLink:"https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types"}),strategySchemaValidation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Schema Validation Strategy",description:"Use schema validation for complex inputs",severity:"LOW",fix:"Use Joi, Yup, or Zod for input validation",documentationLink:"https://joi.dev/"}),strategyDefensiveProgramming:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Defensive Programming Strategy",description:"Use defensive programming techniques",severity:"LOW",fix:"Check types and handle edge cases explicitly",documentationLink:"https://en.wikipedia.org/wiki/Defensive_programming"})},schema:[{type:"object",properties:{userInputVariables:{type:"array",items:{type:"string"},default:["req","request","body","query","params","input","data","userInput"],description:"Variable names treated as user-controlled input"},safeTypeCheckFunctions:{type:"array",items:{type:"string"},default:["isArray","isString","isNumber","isObject","validateType","checkType"],description:"Function names that count as a type check"},allowInstanceofSameRealm:{type:"boolean",default:true,description:"Allow instanceof for same-realm objects"},trustedSanitizers:{type:"array",items:{type:"string"},default:[],description:"Additional function names to consider as type validators"},trustedAnnotations:{type:"array",items:{type:"string"},default:[],description:"Additional JSDoc annotations to consider as safe markers"},strictMode:{type:"boolean",default:false,description:"Disable all false positive detection (strict mode)"}},additionalProperties:false}]},defaultOptions:[{userInputVariables:["req","request","body","query","params","input","data","userInput"],safeTypeCheckFunctions:["isArray","isString","isNumber","isObject","validateType","checkType"],allowInstanceofSameRealm:true,trustedSanitizers:[],trustedAnnotations:[],strictMode:false}],create(context){const options=context.options[0]||{};const{userInputVariables=["req","request","body","query","params","input","data","userInput"],allowInstanceofSameRealm=true,trustedSanitizers=[],trustedAnnotations=[],strictMode=false}=options;const sourceCode=context.sourceCode;const filename=context.filename;const safetyChecker=(0,eslint_devkit_3.createSafetyChecker)({trustedSanitizers,trustedAnnotations,trustedOrmPatterns:[],strictMode});const isUserInput=varName=>{return userInputVariables.some(input=>varName.includes(input))};const isUnsafeTypeof=node=>{if(node.operator!=="==="&&node.operator!=="!=="){return false}const left=node.left;const right=node.right;if(left.type==="UnaryExpression"&&left.operator==="typeof"&&right.type==="Literal"&&right.value==="object"){let varName="";if(left.argument.type==="Identifier"){varName=left.argument.name}if(varName){let current=node.parent;let child=node;while(current){if(current.type==="LogicalExpression"&&current.operator==="&&"){if(current.right===child){const leftText=sourceCode.getText(current.left);if(leftText.includes(`${varName} !== null`)||leftText.includes(`${varName} != null`)){return false}}}if(current.type.includes("Statement")||current.type.includes("Declaration")){break}child=current;current=current.parent}}return true}return false};const isUnsafeInstanceof=node=>{if(node.operator!=="instanceof"){return false}if(!allowInstanceofSameRealm){return true}return false};const isLooseEqualityTypeCheck=node=>{if(node.operator!=="=="&&node.operator!=="!="){return false}const leftText=sourceCode.getText(node.left).toLowerCase();const rightText=sourceCode.getText(node.right).toLowerCase();return leftText.includes("null")||rightText.includes("null")||leftText.includes("undefined")||rightText.includes("undefined")};const isUnreliableConstructorCheck=node=>{return node.property.type==="Identifier"&&node.property.name==="name"&&node.object.type==="MemberExpression"&&node.object.property.type==="Identifier"&&node.object.property.name==="constructor"};return{BinaryExpression(node){if(isUnsafeTypeof(node)){const left=node.left;let matchesUserInput=false;if(left.argument.type==="Identifier"&&isUserInput(left.argument.name)){matchesUserInput=true}else if(left.argument.type==="MemberExpression"&&left.argument.object.type==="Identifier"&&isUserInput(left.argument.object.name)){matchesUserInput=true}if(matchesUserInput){if(safetyChecker.isSafe(node,context)){return}context.report({node:left,messageId:"unsafeTypeofCheck",data:{filePath:filename,line:String(node.loc?.start.line??0)},suggest:[{messageId:"useTypeofCorrectly",fix:()=>null}]})}}if(isUnsafeInstanceof(node)){const left=node.left;if(left.type==="Identifier"&&isUserInput(left.name)){context.report({node,messageId:"unsafeInstanceofUsage",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}if(isLooseEqualityTypeCheck(node)){const left=node.left;const right=node.right;const leftText=sourceCode.getText(left);const rightText=sourceCode.getText(right);if(left.type==="Identifier"&&isUserInput(left.name)||right.type==="Identifier"&&isUserInput(right.name)||leftText.includes("null")||rightText.includes("null")){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"looseEqualityTypeCheck",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}},MemberExpression(node){if(isUnreliableConstructorCheck(node)){let current=node;let involvesUserInput=false;while(current?.parent){current=current.parent;if(current.type==="VariableDeclarator"&&current.init===node){involvesUserInput=true;break}if(current.type==="BinaryExpression"&&(current.left===node||current.right===node)){involvesUserInput=true;break}}if(involvesUserInput){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"unreliableConstructorCheck",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}},CallExpression(node){const callee=node.callee;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"){const methodName=callee.property.name;const objectName=callee.object.type==="Identifier"?callee.object.name:"";if(["isArray","isString","isNumber","isObject"].includes(methodName)&&objectName&&["Array","Number","String","Object"].includes(objectName)){return}}if(callee.type==="Identifier"&&callee.name==="typeof"){context.report({node,messageId:"improperTypeValidation",data:{filePath:filename,line:String(node.loc?.start.line??0),severity:"LOW",safeAlternative:"Use typeof as unary operator: typeof value"}})}},IfStatement(node){const test=node.test;if(test.type==="Identifier"&&isUserInput(test.name)){if(safetyChecker.isSafe(node,context)){return}context.report({node:test,messageId:"improperTypeValidation",data:{filePath:filename,line:String(node.loc?.start.line??0),severity:"LOW",safeAlternative:"Explicitly check for null/undefined or type"}})}if(test.type==="BinaryExpression"){const testText=sourceCode.getText(test).toLowerCase();if((testText.includes("!= null")||testText.includes("== null"))&&!testText.includes("!== undefined")&&!testText.includes("=== undefined")){if(test.left.type==="Identifier"&&isUserInput(test.left.name)||test.right.type==="Identifier"&&isUserInput(test.right.name)){if(safetyChecker.isSafe(node,context)){return}context.report({node:test,messageId:"missingNullCheck",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}}}}});