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.
Files changed (32) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +1 -107
  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 -555
  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,403 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noLdapInjection = void 0;
4
- exports.containsDangerousLdapFilter = containsDangerousLdapFilter;
5
- exports.containsLdapInterpolation = containsLdapInterpolation;
6
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
7
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
8
- const eslint_devkit_3 = require("@interlace/eslint-devkit");
9
- function containsDangerousLdapFilter(filterText) {
10
- const dangerousPatterns = [
11
- /\*\)$/,
12
- /\|\)$/,
13
- /&\)$/,
14
- /!\)$/,
15
- /\*\|\*/,
16
- /\*&\*/,
17
- /\*!/,
18
- ];
19
- return dangerousPatterns.some(pattern => pattern.test(filterText));
20
- }
21
- function containsLdapInterpolation(text) {
22
- return /\$\{[^}]+\}/.test(text) || /'[^']*\+[^+]*'/.test(text) || /"[^"]*\+[^+]*"/.test(text);
23
- }
24
- exports.noLdapInjection = (0, eslint_devkit_1.createRule)({
25
- name: 'no-ldap-injection',
26
- meta: {
27
- type: 'problem',
28
- docs: {
29
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-ldap-injection.md',
30
- description: 'Detects LDAP injection vulnerabilities',
31
- cwe: 'CWE-90',
32
- },
33
- hasSuggestions: true,
34
- messages: {
35
- ldapInjection: (0, eslint_devkit_2.formatLLMMessage)({
36
- icon: eslint_devkit_2.MessageIcons.SECURITY,
37
- issueName: 'LDAP Injection',
38
- cwe: 'CWE-90',
39
- description: 'LDAP injection vulnerability detected',
40
- severity: '{{severity}}',
41
- fix: '{{safeAlternative}}',
42
- documentationLink: 'https://cwe.mitre.org/data/definitions/90.html',
43
- }),
44
- unsafeLdapFilter: (0, eslint_devkit_2.formatLLMMessage)({
45
- icon: eslint_devkit_2.MessageIcons.SECURITY,
46
- issueName: 'Unsafe LDAP Filter',
47
- cwe: 'CWE-90',
48
- description: 'LDAP filter constructed with unsafe string operations',
49
- severity: 'HIGH',
50
- fix: 'Use ldap.escape.filterValue() to escape user input',
51
- documentationLink: 'https://ldap.com/ldap-filters/',
52
- }),
53
- unescapedLdapInput: (0, eslint_devkit_2.formatLLMMessage)({
54
- icon: eslint_devkit_2.MessageIcons.SECURITY,
55
- issueName: 'Unescaped LDAP Input',
56
- cwe: 'CWE-90',
57
- description: 'LDAP operation uses unescaped user input',
58
- severity: 'MEDIUM',
59
- fix: 'Escape all user input before LDAP operations',
60
- documentationLink: 'https://cwe.mitre.org/data/definitions/90.html',
61
- }),
62
- dangerousLdapOperation: (0, eslint_devkit_2.formatLLMMessage)({
63
- icon: eslint_devkit_2.MessageIcons.SECURITY,
64
- issueName: 'Dangerous LDAP Operation',
65
- cwe: 'CWE-90',
66
- description: 'LDAP operation allows dangerous filter patterns',
67
- severity: 'HIGH',
68
- fix: 'Validate LDAP filters and restrict allowed operations',
69
- documentationLink: 'https://ldap.com/ldap-filters/',
70
- }),
71
- useLdapEscaping: (0, eslint_devkit_2.formatLLMMessage)({
72
- icon: eslint_devkit_2.MessageIcons.INFO,
73
- issueName: 'Use LDAP Escaping',
74
- description: 'Use proper LDAP escaping functions',
75
- severity: 'LOW',
76
- fix: 'Use ldap.escape.filterValue() or equivalent',
77
- documentationLink: 'https://www.npmjs.com/package/ldap-escape',
78
- }),
79
- validateLdapInput: (0, eslint_devkit_2.formatLLMMessage)({
80
- icon: eslint_devkit_2.MessageIcons.INFO,
81
- issueName: 'Validate LDAP Input',
82
- description: 'Validate LDAP input before processing',
83
- severity: 'LOW',
84
- fix: 'Validate input against allowed patterns',
85
- documentationLink: 'https://cwe.mitre.org/data/definitions/90.html',
86
- }),
87
- useParameterizedLdap: (0, eslint_devkit_2.formatLLMMessage)({
88
- icon: eslint_devkit_2.MessageIcons.INFO,
89
- issueName: 'Use Parameterized LDAP',
90
- description: 'Use parameterized LDAP queries when possible',
91
- severity: 'LOW',
92
- fix: 'Use prepared LDAP statements or safe construction',
93
- documentationLink: 'https://ldap.com/ldap-filters/',
94
- }),
95
- strategyInputValidation: (0, eslint_devkit_2.formatLLMMessage)({
96
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
97
- issueName: 'Input Validation Strategy',
98
- description: 'Validate LDAP input at application boundary',
99
- severity: 'LOW',
100
- fix: 'Implement input validation and length limits',
101
- documentationLink: 'https://cwe.mitre.org/data/definitions/90.html',
102
- }),
103
- strategySafeLibraries: (0, eslint_devkit_2.formatLLMMessage)({
104
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
105
- issueName: 'Safe Libraries Strategy',
106
- description: 'Use LDAP libraries with built-in escaping',
107
- severity: 'LOW',
108
- fix: 'Use ldapjs or libraries with automatic escaping',
109
- documentationLink: 'https://www.npmjs.com/package/ldapjs',
110
- }),
111
- strategyFilterConstruction: (0, eslint_devkit_2.formatLLMMessage)({
112
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
113
- issueName: 'Filter Construction Strategy',
114
- description: 'Use safe LDAP filter construction methods',
115
- severity: 'LOW',
116
- fix: 'Build filters programmatically with escaped values',
117
- documentationLink: 'https://ldap.com/ldap-filters/',
118
- })
119
- },
120
- schema: [
121
- {
122
- type: 'object',
123
- properties: {
124
- ldapFunctions: {
125
- type: 'array',
126
- items: { type: 'string' },
127
- default: ['search', 'bind', 'modify', 'add', 'delete', 'compare', 'searchAsync'], description: 'LDAP client methods treated as query sinks'
128
- },
129
- ldapEscapeFunctions: {
130
- type: 'array',
131
- items: { type: 'string' },
132
- default: ['escape.filterValue', 'escape.dnValue', 'filterEscape', 'dnEscape'], description: 'Function names that escape LDAP filter or DN values'
133
- },
134
- ldapValidationFunctions: {
135
- type: 'array',
136
- items: { type: 'string' },
137
- default: ['validateLdapInput', 'sanitizeLdapFilter', 'cleanLdapValue', 'checkLdapFilter'], description: 'Function names that count as LDAP input validation'
138
- },
139
- trustedSanitizers: {
140
- type: 'array',
141
- items: { type: 'string' },
142
- default: [],
143
- description: 'Additional function names to consider as LDAP sanitizers',
144
- },
145
- trustedAnnotations: {
146
- type: 'array',
147
- items: { type: 'string' },
148
- default: [],
149
- description: 'Additional JSDoc annotations to consider as safe markers',
150
- },
151
- strictMode: {
152
- type: 'boolean',
153
- default: false,
154
- description: 'Disable all false positive detection (strict mode)',
155
- },
156
- },
157
- additionalProperties: false,
158
- },
159
- ],
160
- },
161
- defaultOptions: [
162
- {
163
- ldapFunctions: ['search', 'bind', 'modify', 'add', 'delete', 'compare', 'searchAsync'],
164
- ldapEscapeFunctions: ['escape.filterValue', 'escape.dnValue', 'filterEscape', 'dnEscape'],
165
- ldapValidationFunctions: ['validateLdapInput', 'sanitizeLdapFilter', 'cleanLdapValue', 'checkLdapFilter'],
166
- trustedSanitizers: [],
167
- trustedAnnotations: [],
168
- strictMode: false,
169
- },
170
- ],
171
- create(context) {
172
- const options = context.options[0] || {};
173
- const { ldapFunctions = ['search', 'bind', 'modify', 'add', 'delete', 'compare', 'searchAsync'], ldapEscapeFunctions = ['escape.filterValue', 'escape.dnValue', 'filterEscape', 'dnEscape'], ldapValidationFunctions = ['validateLdapInput', 'sanitizeLdapFilter', 'cleanLdapValue', 'checkLdapFilter'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
174
- const sourceCode = context.sourceCode;
175
- const filename = context.filename;
176
- const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
177
- trustedSanitizers,
178
- trustedAnnotations,
179
- trustedOrmPatterns: [],
180
- strictMode,
181
- });
182
- const isLdapOperation = (node) => {
183
- const callee = node.callee;
184
- if (callee.type === 'MemberExpression' &&
185
- callee.property.type === 'Identifier' &&
186
- ldapFunctions.includes(callee.property.name)) {
187
- return true;
188
- }
189
- return false;
190
- };
191
- const isUntrustedLdapInput = (inputNode) => {
192
- if (inputNode.type === 'MemberExpression') {
193
- const fullName = sourceCode.getText(inputNode).toLowerCase();
194
- return fullName.includes('req.') || fullName.includes('request.') ||
195
- fullName.includes('query.') || fullName.includes('params.') ||
196
- fullName.includes('body.');
197
- }
198
- if (inputNode.type === 'Identifier') {
199
- const varName = inputNode.name.toLowerCase();
200
- return ['userid', 'username', 'userinput', 'input', 'term', 'name', 'search', 'query', 'param', 'password', 'id', 'dn'].includes(varName) ||
201
- varName.startsWith('user') || varName.startsWith('input') || varName.endsWith('input') ||
202
- varName.includes('user') || varName.includes('input');
203
- }
204
- return false;
205
- };
206
- const isLdapInputEscaped = (inputNode) => {
207
- let current = inputNode;
208
- while (current) {
209
- if (current.type === 'CallExpression') {
210
- const callee = current.callee;
211
- if (callee.type === 'MemberExpression' &&
212
- callee.property.type === 'Identifier') {
213
- const propertyName = callee.property.name;
214
- if (ldapEscapeFunctions.some(escapeFunc => escapeFunc.includes(propertyName) ||
215
- propertyName.includes('escape'))) {
216
- return true;
217
- }
218
- }
219
- if (callee.type === 'Identifier' &&
220
- ldapValidationFunctions.includes(callee.name)) {
221
- return true;
222
- }
223
- }
224
- current = current.parent;
225
- }
226
- return false;
227
- };
228
- return {
229
- CallExpression(node) {
230
- if (!isLdapOperation(node)) {
231
- return;
232
- }
233
- const args = node.arguments;
234
- if (args.length < 2) {
235
- return;
236
- }
237
- const filterArg = args[1];
238
- if (isUntrustedLdapInput(filterArg)) {
239
- if (safetyChecker.isSafe(filterArg, context)) {
240
- return;
241
- }
242
- context.report({
243
- node: filterArg,
244
- messageId: 'unescapedLdapInput',
245
- data: {
246
- filePath: filename,
247
- line: String(node.loc?.start.line ?? 0),
248
- },
249
- suggest: [
250
- {
251
- messageId: 'useLdapEscaping',
252
- fix: () => null,
253
- },
254
- ],
255
- });
256
- }
257
- else if (filterArg.type === 'TemplateLiteral' && filterArg.expressions.length > 0) {
258
- if (safetyChecker.isSafe(filterArg, context)) {
259
- return;
260
- }
261
- context.report({
262
- node: filterArg,
263
- messageId: 'unescapedLdapInput',
264
- data: {
265
- filePath: filename,
266
- line: String(node.loc?.start.line ?? 0),
267
- },
268
- suggest: [
269
- {
270
- messageId: 'useLdapEscaping',
271
- fix: () => null,
272
- },
273
- ],
274
- });
275
- }
276
- },
277
- VariableDeclarator(node) {
278
- if (!node.init || node.id.type !== 'Identifier') {
279
- return;
280
- }
281
- const varName = node.id.name.toLowerCase();
282
- const isLdapRelated = varName.includes('filter') || varName.includes('ldap') ||
283
- varName.includes('query') || varName.includes('search') ||
284
- varName.includes('dn') || varName.includes('bind');
285
- if (!isLdapRelated && node.init) {
286
- const initText = sourceCode.getText(node.init);
287
- if (!initText.includes('(') || !initText.includes(')')) {
288
- return;
289
- }
290
- }
291
- if (node.init.type === 'Literal' && typeof node.init.value === 'string') {
292
- if (containsDangerousLdapFilter(node.init.value)) {
293
- if (safetyChecker.isSafe(node.init, context)) {
294
- return;
295
- }
296
- context.report({
297
- node: node.init,
298
- messageId: 'dangerousLdapOperation',
299
- data: {
300
- filePath: filename,
301
- line: String(node.loc?.start.line ?? 0),
302
- },
303
- });
304
- }
305
- }
306
- else if (node.init.type === 'TemplateLiteral') {
307
- const fullText = sourceCode.getText(node.init);
308
- if (containsLdapInterpolation(fullText)) {
309
- const hasUntrustedInterpolation = node.init.expressions.some((expr) => isUntrustedLdapInput(expr) && !isLdapInputEscaped(expr));
310
- if (hasUntrustedInterpolation) {
311
- if (safetyChecker.isSafe(node.init, context)) {
312
- return;
313
- }
314
- context.report({
315
- node: node.init,
316
- messageId: 'unsafeLdapFilter',
317
- data: {
318
- filePath: filename,
319
- line: String(node.loc?.start.line ?? 0),
320
- },
321
- suggest: [
322
- {
323
- messageId: 'useLdapEscaping',
324
- fix: () => null,
325
- },
326
- ],
327
- });
328
- }
329
- }
330
- if (containsDangerousLdapFilter(fullText)) {
331
- if (safetyChecker.isSafe(node.init, context)) {
332
- return;
333
- }
334
- context.report({
335
- node: node.init,
336
- messageId: 'dangerousLdapOperation',
337
- data: {
338
- filePath: filename,
339
- line: String(node.loc?.start.line ?? 0),
340
- },
341
- });
342
- }
343
- }
344
- else if (node.init.type === 'BinaryExpression' && node.init.operator === '+') {
345
- const fullText = sourceCode.getText(node.init);
346
- if (fullText.includes('(') && fullText.includes(')')) {
347
- const hasUntrustedInput = (expr) => {
348
- if (isUntrustedLdapInput(expr) && !isLdapInputEscaped(expr)) {
349
- return true;
350
- }
351
- if (expr.type === 'BinaryExpression' && expr.operator === '+') {
352
- return hasUntrustedInput(expr.left) || hasUntrustedInput(expr.right);
353
- }
354
- return false;
355
- };
356
- if (hasUntrustedInput(node.init.left) || hasUntrustedInput(node.init.right)) {
357
- if (safetyChecker.isSafe(node.init, context)) {
358
- return;
359
- }
360
- context.report({
361
- node: node.init,
362
- messageId: 'ldapInjection',
363
- data: {
364
- filePath: filename,
365
- line: String(node.loc?.start.line ?? 0),
366
- severity: 'HIGH',
367
- safeAlternative: 'Use ldap.escape.filterValue() or parameterized LDAP queries',
368
- },
369
- suggest: [
370
- {
371
- messageId: 'useLdapEscaping',
372
- fix: () => null,
373
- },
374
- ],
375
- });
376
- }
377
- }
378
- }
379
- else if (isUntrustedLdapInput(node.init) && !isLdapInputEscaped(node.init)) {
380
- if (safetyChecker.isSafe(node.init, context)) {
381
- return;
382
- }
383
- context.report({
384
- node: node.init,
385
- messageId: 'ldapInjection',
386
- data: {
387
- filePath: filename,
388
- line: String(node.loc?.start.line ?? 0),
389
- severity: 'MEDIUM',
390
- safeAlternative: 'Use proper LDAP escaping and validation',
391
- },
392
- suggest: [
393
- {
394
- messageId: 'useLdapEscaping',
395
- fix: () => null,
396
- },
397
- ],
398
- });
399
- }
400
- }
401
- };
402
- },
403
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noLdapInjection=void 0;exports.containsDangerousLdapFilter=containsDangerousLdapFilter;exports.containsLdapInterpolation=containsLdapInterpolation;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");const eslint_devkit_3=require("@interlace/eslint-devkit");function containsDangerousLdapFilter(filterText){const dangerousPatterns=[/\*\)$/,/\|\)$/,/&\)$/,/!\)$/,/\*\|\*/,/\*&\*/,/\*!/];return dangerousPatterns.some(pattern=>pattern.test(filterText))}function containsLdapInterpolation(text){return/\$\{[^}]+\}/.test(text)||/'[^']*\+[^+]*'/.test(text)||/"[^"]*\+[^+]*"/.test(text)}exports.noLdapInjection=(0,eslint_devkit_1.createRule)({name:"no-ldap-injection",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-ldap-injection.md",description:"Detects LDAP injection vulnerabilities",cwe:"CWE-90"},hasSuggestions:true,messages:{ldapInjection:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"LDAP Injection",cwe:"CWE-90",description:"LDAP injection vulnerability detected",severity:"{{severity}}",fix:"{{safeAlternative}}",documentationLink:"https://cwe.mitre.org/data/definitions/90.html"}),unsafeLdapFilter:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Unsafe LDAP Filter",cwe:"CWE-90",description:"LDAP filter constructed with unsafe string operations",severity:"HIGH",fix:"Use ldap.escape.filterValue() to escape user input",documentationLink:"https://ldap.com/ldap-filters/"}),unescapedLdapInput:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Unescaped LDAP Input",cwe:"CWE-90",description:"LDAP operation uses unescaped user input",severity:"MEDIUM",fix:"Escape all user input before LDAP operations",documentationLink:"https://cwe.mitre.org/data/definitions/90.html"}),dangerousLdapOperation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Dangerous LDAP Operation",cwe:"CWE-90",description:"LDAP operation allows dangerous filter patterns",severity:"HIGH",fix:"Validate LDAP filters and restrict allowed operations",documentationLink:"https://ldap.com/ldap-filters/"}),useLdapEscaping:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use LDAP Escaping",description:"Use proper LDAP escaping functions",severity:"LOW",fix:"Use ldap.escape.filterValue() or equivalent",documentationLink:"https://www.npmjs.com/package/ldap-escape"}),validateLdapInput:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Validate LDAP Input",description:"Validate LDAP input before processing",severity:"LOW",fix:"Validate input against allowed patterns",documentationLink:"https://cwe.mitre.org/data/definitions/90.html"}),useParameterizedLdap:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use Parameterized LDAP",description:"Use parameterized LDAP queries when possible",severity:"LOW",fix:"Use prepared LDAP statements or safe construction",documentationLink:"https://ldap.com/ldap-filters/"}),strategyInputValidation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Input Validation Strategy",description:"Validate LDAP input at application boundary",severity:"LOW",fix:"Implement input validation and length limits",documentationLink:"https://cwe.mitre.org/data/definitions/90.html"}),strategySafeLibraries:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Safe Libraries Strategy",description:"Use LDAP libraries with built-in escaping",severity:"LOW",fix:"Use ldapjs or libraries with automatic escaping",documentationLink:"https://www.npmjs.com/package/ldapjs"}),strategyFilterConstruction:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Filter Construction Strategy",description:"Use safe LDAP filter construction methods",severity:"LOW",fix:"Build filters programmatically with escaped values",documentationLink:"https://ldap.com/ldap-filters/"})},schema:[{type:"object",properties:{ldapFunctions:{type:"array",items:{type:"string"},default:["search","bind","modify","add","delete","compare","searchAsync"],description:"LDAP client methods treated as query sinks"},ldapEscapeFunctions:{type:"array",items:{type:"string"},default:["escape.filterValue","escape.dnValue","filterEscape","dnEscape"],description:"Function names that escape LDAP filter or DN values"},ldapValidationFunctions:{type:"array",items:{type:"string"},default:["validateLdapInput","sanitizeLdapFilter","cleanLdapValue","checkLdapFilter"],description:"Function names that count as LDAP input validation"},trustedSanitizers:{type:"array",items:{type:"string"},default:[],description:"Additional function names to consider as LDAP sanitizers"},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:[{ldapFunctions:["search","bind","modify","add","delete","compare","searchAsync"],ldapEscapeFunctions:["escape.filterValue","escape.dnValue","filterEscape","dnEscape"],ldapValidationFunctions:["validateLdapInput","sanitizeLdapFilter","cleanLdapValue","checkLdapFilter"],trustedSanitizers:[],trustedAnnotations:[],strictMode:false}],create(context){const options=context.options[0]||{};const{ldapFunctions=["search","bind","modify","add","delete","compare","searchAsync"],ldapEscapeFunctions=["escape.filterValue","escape.dnValue","filterEscape","dnEscape"],ldapValidationFunctions=["validateLdapInput","sanitizeLdapFilter","cleanLdapValue","checkLdapFilter"],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 isLdapOperation=node=>{const callee=node.callee;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"&&ldapFunctions.includes(callee.property.name)){return true}return false};const isUntrustedLdapInput=inputNode=>{if(inputNode.type==="MemberExpression"){const fullName=sourceCode.getText(inputNode).toLowerCase();return fullName.includes("req.")||fullName.includes("request.")||fullName.includes("query.")||fullName.includes("params.")||fullName.includes("body.")}if(inputNode.type==="Identifier"){const varName=inputNode.name.toLowerCase();return["userid","username","userinput","input","term","name","search","query","param","password","id","dn"].includes(varName)||varName.startsWith("user")||varName.startsWith("input")||varName.endsWith("input")||varName.includes("user")||varName.includes("input")}return false};const isLdapInputEscaped=inputNode=>{let current=inputNode;while(current){if(current.type==="CallExpression"){const callee=current.callee;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"){const propertyName=callee.property.name;if(ldapEscapeFunctions.some(escapeFunc=>escapeFunc.includes(propertyName)||propertyName.includes("escape"))){return true}}if(callee.type==="Identifier"&&ldapValidationFunctions.includes(callee.name)){return true}}current=current.parent}return false};return{CallExpression(node){if(!isLdapOperation(node)){return}const args=node.arguments;if(args.length<2){return}const filterArg=args[1];if(isUntrustedLdapInput(filterArg)){if(safetyChecker.isSafe(filterArg,context)){return}context.report({node:filterArg,messageId:"unescapedLdapInput",data:{filePath:filename,line:String(node.loc?.start.line??0)},suggest:[{messageId:"useLdapEscaping",fix:()=>null}]})}else if(filterArg.type==="TemplateLiteral"&&filterArg.expressions.length>0){if(safetyChecker.isSafe(filterArg,context)){return}context.report({node:filterArg,messageId:"unescapedLdapInput",data:{filePath:filename,line:String(node.loc?.start.line??0)},suggest:[{messageId:"useLdapEscaping",fix:()=>null}]})}},VariableDeclarator(node){if(!node.init||node.id.type!=="Identifier"){return}const varName=node.id.name.toLowerCase();const isLdapRelated=varName.includes("filter")||varName.includes("ldap")||varName.includes("query")||varName.includes("search")||varName.includes("dn")||varName.includes("bind");if(!isLdapRelated&&node.init){const initText=sourceCode.getText(node.init);if(!initText.includes("(")||!initText.includes(")")){return}}if(node.init.type==="Literal"&&typeof node.init.value==="string"){if(containsDangerousLdapFilter(node.init.value)){if(safetyChecker.isSafe(node.init,context)){return}context.report({node:node.init,messageId:"dangerousLdapOperation",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}else if(node.init.type==="TemplateLiteral"){const fullText=sourceCode.getText(node.init);if(containsLdapInterpolation(fullText)){const hasUntrustedInterpolation=node.init.expressions.some(expr=>isUntrustedLdapInput(expr)&&!isLdapInputEscaped(expr));if(hasUntrustedInterpolation){if(safetyChecker.isSafe(node.init,context)){return}context.report({node:node.init,messageId:"unsafeLdapFilter",data:{filePath:filename,line:String(node.loc?.start.line??0)},suggest:[{messageId:"useLdapEscaping",fix:()=>null}]})}}if(containsDangerousLdapFilter(fullText)){if(safetyChecker.isSafe(node.init,context)){return}context.report({node:node.init,messageId:"dangerousLdapOperation",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}else if(node.init.type==="BinaryExpression"&&node.init.operator==="+"){const fullText=sourceCode.getText(node.init);if(fullText.includes("(")&&fullText.includes(")")){const hasUntrustedInput=expr=>{if(isUntrustedLdapInput(expr)&&!isLdapInputEscaped(expr)){return true}if(expr.type==="BinaryExpression"&&expr.operator==="+"){return hasUntrustedInput(expr.left)||hasUntrustedInput(expr.right)}return false};if(hasUntrustedInput(node.init.left)||hasUntrustedInput(node.init.right)){if(safetyChecker.isSafe(node.init,context)){return}context.report({node:node.init,messageId:"ldapInjection",data:{filePath:filename,line:String(node.loc?.start.line??0),severity:"HIGH",safeAlternative:"Use ldap.escape.filterValue() or parameterized LDAP queries"},suggest:[{messageId:"useLdapEscaping",fix:()=>null}]})}}}else if(isUntrustedLdapInput(node.init)&&!isLdapInputEscaped(node.init)){if(safetyChecker.isSafe(node.init,context)){return}context.report({node:node.init,messageId:"ldapInjection",data:{filePath:filename,line:String(node.loc?.start.line??0),severity:"MEDIUM",safeAlternative:"Use proper LDAP escaping and validation"},suggest:[{messageId:"useLdapEscaping",fix:()=>null}]})}}}}});