eslint-plugin-secure-coding 3.4.3 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/src/index.js +1 -107
  4. package/src/oxlint.js +1 -3
  5. package/src/rules/detect-non-literal-regexp/index.js +1 -329
  6. package/src/rules/detect-object-injection/index.js +1 -691
  7. package/src/rules/detect-weak-password-validation/index.js +1 -54
  8. package/src/rules/no-directive-injection/index.js +1 -416
  9. package/src/rules/no-electron-security-issues/index.js +1 -385
  10. package/src/rules/no-format-string-injection/index.js +1 -565
  11. package/src/rules/no-graphql-injection/index.js +1 -612
  12. package/src/rules/no-hardcoded-credentials/index.js +1 -658
  13. package/src/rules/no-hardcoded-session-tokens/index.js +1 -56
  14. package/src/rules/no-improper-sanitization/index.js +1 -391
  15. package/src/rules/no-improper-type-validation/index.js +1 -422
  16. package/src/rules/no-insecure-comparison/index.js +1 -249
  17. package/src/rules/no-ldap-injection/index.js +1 -403
  18. package/src/rules/no-missing-authentication/index.js +1 -282
  19. package/src/rules/no-pii-in-logs/index.js +1 -63
  20. package/src/rules/no-privilege-escalation/index.js +1 -282
  21. package/src/rules/no-redos-vulnerable-regex/index.js +0 -0
  22. package/src/rules/no-sensitive-data-exposure/index.js +1 -249
  23. package/src/rules/no-template-injection/index.js +1 -84
  24. package/src/rules/no-unchecked-loop-condition/index.js +1 -541
  25. package/src/rules/no-unlimited-resource-allocation/index.js +1 -555
  26. package/src/rules/no-unsafe-deserialization/index.js +1 -497
  27. package/src/rules/no-unsafe-regex-construction/index.js +1 -275
  28. package/src/rules/no-weak-password-recovery/index.js +1 -382
  29. package/src/rules/no-xpath-injection/index.js +1 -431
  30. package/src/rules/no-xxe-injection/index.js +1 -230
  31. package/src/rules/require-backend-authorization/index.js +1 -58
  32. package/src/rules/require-secure-defaults/index.js +1 -41
  33. package/src/types/index.js +1 -2
@@ -1,54 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectWeakPasswordValidation = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.detectWeakPasswordValidation = (0, eslint_devkit_1.createRule)({
6
- name: 'detect-weak-password-validation',
7
- meta: {
8
- type: 'suggestion',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/detect-weak-password-validation.md',
11
- description: 'Identify weak password requirements',
12
- cwe: 'CWE-521',
13
- cvss: 5.3,
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Weak Password Validation',
19
- cwe: 'CWE-521',
20
- description: 'Password length requirement is too weak (less than 8 characters)',
21
- severity: 'CRITICAL',
22
- fix: 'Require at least 12 characters with complexity requirements',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/521.html',
24
- })
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- function report(node) {
31
- context.report({ node, messageId: 'violationDetected' });
32
- }
33
- return {
34
- BinaryExpression(node) {
35
- if (['>=', '>', '==', '==='].includes(node.operator)) {
36
- if (node.left.type === 'MemberExpression' &&
37
- node.left.property.type === 'Identifier' &&
38
- node.left.property.name === 'length') {
39
- if (node.right.type === 'Literal' &&
40
- typeof node.right.value === 'number' &&
41
- node.right.value < 8) {
42
- if (node.left.object.type === 'Identifier') {
43
- const varName = node.left.object.name.toLowerCase();
44
- if (varName.includes('password') || varName.includes('pwd') || varName.includes('pass')) {
45
- report(node);
46
- }
47
- }
48
- }
49
- }
50
- }
51
- },
52
- };
53
- },
54
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.detectWeakPasswordValidation=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.detectWeakPasswordValidation=(0,eslint_devkit_1.createRule)({name:"detect-weak-password-validation",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/detect-weak-password-validation.md",description:"Identify weak password requirements",cwe:"CWE-521",cvss:5.3},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Weak Password Validation",cwe:"CWE-521",description:"Password length requirement is too weak (less than 8 characters)",severity:"CRITICAL",fix:"Require at least 12 characters with complexity requirements",documentationLink:"https://cwe.mitre.org/data/definitions/521.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}return{BinaryExpression(node){if([">=",">","==","==="].includes(node.operator)){if(node.left.type==="MemberExpression"&&node.left.property.type==="Identifier"&&node.left.property.name==="length"){if(node.right.type==="Literal"&&typeof node.right.value==="number"&&node.right.value<8){if(node.left.object.type==="Identifier"){const varName=node.left.object.name.toLowerCase();if(varName.includes("password")||varName.includes("pwd")||varName.includes("pass")){report(node)}}}}}}}}});
@@ -1,416 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDirectiveInjection = 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.noDirectiveInjection = (0, eslint_devkit_1.createRule)({
8
- name: 'no-directive-injection',
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-directive-injection.md',
13
- description: 'Detects directive injection vulnerabilities in templates',
14
- cwe: 'CWE-96',
15
- },
16
- hasSuggestions: true,
17
- messages: {
18
- directiveInjection: (0, eslint_devkit_2.formatLLMMessage)({
19
- icon: eslint_devkit_2.MessageIcons.SECURITY,
20
- issueName: 'Directive Injection',
21
- cwe: 'CWE-96',
22
- description: 'User input injected into directive or template',
23
- severity: '{{severity}}',
24
- fix: '{{safeAlternative}}',
25
- documentationLink: 'https://cwe.mitre.org/data/definitions/96.html',
26
- }),
27
- unsafeDirectiveName: (0, eslint_devkit_2.formatLLMMessage)({
28
- icon: eslint_devkit_2.MessageIcons.SECURITY,
29
- issueName: 'Unsafe Directive Name',
30
- cwe: 'CWE-96',
31
- description: 'Directive name controlled by user input',
32
- severity: 'CRITICAL',
33
- fix: 'Use hardcoded directive names or validate against whitelist',
34
- documentationLink: 'https://cwe.mitre.org/data/definitions/96.html',
35
- }),
36
- dynamicDirectiveCreation: (0, eslint_devkit_2.formatLLMMessage)({
37
- icon: eslint_devkit_2.MessageIcons.SECURITY,
38
- issueName: 'Dynamic Directive Creation',
39
- cwe: 'CWE-96',
40
- description: 'Dynamic creation of directives from user input',
41
- severity: 'HIGH',
42
- fix: 'Validate directive names against trusted list',
43
- documentationLink: 'https://cwe.mitre.org/data/definitions/96.html',
44
- }),
45
- templateInjection: (0, eslint_devkit_2.formatLLMMessage)({
46
- icon: eslint_devkit_2.MessageIcons.SECURITY,
47
- issueName: 'Template Injection',
48
- cwe: 'CWE-96',
49
- description: 'User input injected into template content',
50
- severity: 'HIGH',
51
- fix: 'Sanitize template input or use safe rendering',
52
- documentationLink: 'https://cwe.mitre.org/data/definitions/96.html',
53
- }),
54
- unsafeComponentBinding: (0, eslint_devkit_2.formatLLMMessage)({
55
- icon: eslint_devkit_2.MessageIcons.SECURITY,
56
- issueName: 'Unsafe Component Binding',
57
- cwe: 'CWE-96',
58
- description: 'Dynamic component binding with user input',
59
- severity: 'HIGH',
60
- fix: 'Use component whitelist or validate component names',
61
- documentationLink: 'https://cwe.mitre.org/data/definitions/96.html',
62
- }),
63
- userControlledTemplate: (0, eslint_devkit_2.formatLLMMessage)({
64
- icon: eslint_devkit_2.MessageIcons.SECURITY,
65
- issueName: 'User Controlled Template',
66
- cwe: 'CWE-96',
67
- description: 'Template content controlled by user input',
68
- severity: 'CRITICAL',
69
- fix: 'Sanitize template input before compilation',
70
- documentationLink: 'https://cwe.mitre.org/data/definitions/96.html',
71
- }),
72
- dangerousInnerHTML: (0, eslint_devkit_2.formatLLMMessage)({
73
- icon: eslint_devkit_2.MessageIcons.SECURITY,
74
- issueName: 'Dangerous innerHTML',
75
- cwe: 'CWE-96',
76
- description: 'innerHTML set with user-controlled content',
77
- severity: 'HIGH',
78
- fix: 'Use textContent or sanitize HTML content',
79
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML',
80
- }),
81
- untrustedDirectiveSource: (0, eslint_devkit_2.formatLLMMessage)({
82
- icon: eslint_devkit_2.MessageIcons.SECURITY,
83
- issueName: 'Untrusted Directive Source',
84
- cwe: 'CWE-96',
85
- description: 'Directive loaded from untrusted source',
86
- severity: 'MEDIUM',
87
- fix: 'Load directives from trusted, verified sources',
88
- documentationLink: 'https://cwe.mitre.org/data/definitions/96.html',
89
- }),
90
- useTrustedDirectives: (0, eslint_devkit_2.formatLLMMessage)({
91
- icon: eslint_devkit_2.MessageIcons.INFO,
92
- issueName: 'Use Trusted Directives',
93
- description: 'Use only trusted, verified directives',
94
- severity: 'LOW',
95
- fix: 'Maintain whitelist of allowed directives',
96
- documentationLink: 'https://cwe.mitre.org/data/definitions/96.html',
97
- }),
98
- sanitizeTemplateInput: (0, eslint_devkit_2.formatLLMMessage)({
99
- icon: eslint_devkit_2.MessageIcons.INFO,
100
- issueName: 'Sanitize Template Input',
101
- description: 'Sanitize user input before template processing',
102
- severity: 'LOW',
103
- fix: 'Use DOMPurify or equivalent sanitization',
104
- documentationLink: 'https://github.com/cure53/DOMPurify',
105
- }),
106
- validateDirectiveNames: (0, eslint_devkit_2.formatLLMMessage)({
107
- icon: eslint_devkit_2.MessageIcons.INFO,
108
- issueName: 'Validate Directive Names',
109
- description: 'Validate directive names against whitelist',
110
- severity: 'LOW',
111
- fix: 'Check directive names before dynamic creation',
112
- documentationLink: 'https://cwe.mitre.org/data/definitions/96.html',
113
- }),
114
- strategyTemplateSanitization: (0, eslint_devkit_2.formatLLMMessage)({
115
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
116
- issueName: 'Template Sanitization Strategy',
117
- description: 'Implement template input sanitization',
118
- severity: 'LOW',
119
- fix: 'Sanitize all user input before template processing',
120
- documentationLink: 'https://owasp.org/www-community/xss-filter-evasion-cheatsheet',
121
- }),
122
- strategyContentSecurity: (0, eslint_devkit_2.formatLLMMessage)({
123
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
124
- issueName: 'Content Security Strategy',
125
- description: 'Use CSP to restrict directive execution',
126
- severity: 'LOW',
127
- fix: 'Implement strict CSP with script-src restrictions',
128
- documentationLink: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP',
129
- }),
130
- strategyInputValidation: (0, eslint_devkit_2.formatLLMMessage)({
131
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
132
- issueName: 'Input Validation Strategy',
133
- description: 'Validate all template inputs',
134
- severity: 'LOW',
135
- fix: 'Use schema validation for template inputs',
136
- documentationLink: 'https://joi.dev/',
137
- })
138
- },
139
- schema: [
140
- {
141
- type: 'object',
142
- properties: {
143
- trustedDirectives: {
144
- type: 'array',
145
- items: { type: 'string' },
146
- default: ['ngIf', 'ngFor', 'ngClass', 'v-if', 'v-for', 'v-bind', 'v-on'], description: 'Template directives treated as safe'
147
- },
148
- userInputVariables: {
149
- type: 'array',
150
- items: { type: 'string' },
151
- default: ['req', 'request', 'body', 'query', 'params', 'input', 'data', 'userInput'], description: 'Variable names treated as user-controlled input'
152
- },
153
- frameworks: {
154
- type: 'array',
155
- items: { type: 'string' },
156
- default: ['angular', 'vue', 'react', 'svelte'], description: 'Template frameworks to analyse'
157
- },
158
- allowDynamicInComponents: {
159
- type: 'boolean',
160
- default: false, description: 'Allow dynamic directives inside component code'
161
- },
162
- trustedSanitizers: {
163
- type: 'array',
164
- items: { type: 'string' },
165
- default: [],
166
- description: 'Additional function names to consider as template sanitizers',
167
- },
168
- trustedAnnotations: {
169
- type: 'array',
170
- items: { type: 'string' },
171
- default: [],
172
- description: 'Additional JSDoc annotations to consider as safe markers',
173
- },
174
- strictMode: {
175
- type: 'boolean',
176
- default: false,
177
- description: 'Disable all false positive detection (strict mode)',
178
- },
179
- },
180
- additionalProperties: false,
181
- },
182
- ],
183
- },
184
- defaultOptions: [
185
- {
186
- trustedDirectives: ['ngIf', 'ngFor', 'ngClass', 'v-if', 'v-for', 'v-bind', 'v-on'],
187
- userInputVariables: ['req', 'request', 'body', 'query', 'params', 'input', 'data', 'userInput'],
188
- frameworks: ['angular', 'vue', 'react', 'svelte'],
189
- allowDynamicInComponents: false,
190
- trustedSanitizers: [],
191
- trustedAnnotations: [],
192
- strictMode: false,
193
- },
194
- ],
195
- create(context) {
196
- const options = context.options[0] || {};
197
- const { userInputVariables = ['req', 'request', 'body', 'query', 'params', 'input', 'data', 'userInput'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
198
- const sourceCode = context.sourceCode;
199
- const filename = context.filename;
200
- const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
201
- trustedSanitizers,
202
- trustedAnnotations,
203
- trustedOrmPatterns: [],
204
- strictMode,
205
- });
206
- const isUserInput = (varName) => {
207
- return userInputVariables.some(input => varName.includes(input)) ||
208
- varName.startsWith('user');
209
- };
210
- return {
211
- JSXAttribute(node) {
212
- const attrName = node.name;
213
- const attrValue = node.value;
214
- if (attrName.type === 'JSXIdentifier' && attrName.name === 'dangerouslySetInnerHTML') {
215
- if (attrValue && attrValue.type === 'JSXExpressionContainer') {
216
- const expression = attrValue.expression;
217
- const expressionText = sourceCode.getText(expression);
218
- if (userInputVariables.some(input => expressionText.includes(input))) {
219
- if (safetyChecker.isSafe(node, context)) {
220
- return;
221
- }
222
- context.report({
223
- node: attrValue,
224
- messageId: 'dangerousInnerHTML',
225
- data: {
226
- filePath: filename,
227
- line: String(node.loc?.start.line ?? 0),
228
- },
229
- });
230
- }
231
- }
232
- }
233
- const isNamespaceDirective = ((attrName.type === 'JSXNamespacedName' && (attrName.namespace.name === 'v' || attrName.namespace.name === 'ng')) ||
234
- (attrName.type === 'JSXIdentifier' && (attrName.name.startsWith('ng:') || attrName.name.startsWith('v:'))));
235
- if (isNamespaceDirective && attrValue) {
236
- if (attrValue.type === 'JSXExpressionContainer') {
237
- const expression = attrValue.expression;
238
- if (expression.type === 'Identifier' && isUserInput(expression.name)) {
239
- if (safetyChecker.isSafe(node, context)) {
240
- return;
241
- }
242
- context.report({
243
- node: attrValue,
244
- messageId: 'directiveInjection',
245
- data: {
246
- filePath: filename,
247
- line: String(node.loc?.start.line ?? 0),
248
- severity: 'HIGH',
249
- safeAlternative: 'Use hardcoded directive values or validate user input',
250
- },
251
- });
252
- }
253
- }
254
- }
255
- if (attrName.type === 'JSXIdentifier') {
256
- const attrNameStr = attrName.name;
257
- if (attrNameStr === 'is' && attrValue) {
258
- if (attrValue.type === 'JSXExpressionContainer') {
259
- const expression = attrValue.expression;
260
- if (expression.type === 'Identifier' && isUserInput(expression.name)) {
261
- if (safetyChecker.isSafe(node, context)) {
262
- return;
263
- }
264
- context.report({
265
- node: attrValue,
266
- messageId: 'unsafeComponentBinding',
267
- data: {
268
- filePath: filename,
269
- line: String(node.loc?.start.line ?? 0),
270
- },
271
- });
272
- }
273
- }
274
- }
275
- }
276
- },
277
- AssignmentExpression(node) {
278
- const left = node.left;
279
- const right = node.right;
280
- if (left.type === 'MemberExpression' &&
281
- left.property.type === 'Identifier' &&
282
- left.property.name === 'innerHTML') {
283
- const rightText = sourceCode.getText(right);
284
- if (userInputVariables.some(input => rightText.includes(input))) {
285
- if (safetyChecker.isSafe(node, context)) {
286
- return;
287
- }
288
- context.report({
289
- node: right,
290
- messageId: 'dangerousInnerHTML',
291
- data: {
292
- filePath: filename,
293
- line: String(node.loc?.start.line ?? 0),
294
- },
295
- });
296
- }
297
- }
298
- },
299
- CallExpression(node) {
300
- const callee = node.callee;
301
- if (callee.type === 'MemberExpression' &&
302
- callee.property.type === 'Identifier') {
303
- const methodName = callee.property.name;
304
- const objectName = callee.object.type === 'Identifier' ? callee.object.name : '';
305
- if (['compile', 'template', '$compile', '$interpolate'].includes(methodName) ||
306
- (objectName === 'Handlebars' && methodName === 'compile') ||
307
- (objectName === '_' && methodName === 'template') ||
308
- (objectName === 'ejs' && methodName === 'render') ||
309
- (objectName === 'pug' && methodName === 'render') ||
310
- (objectName === 'mustache' && methodName === 'render')) {
311
- const args = node.arguments;
312
- if (args.length > 0) {
313
- const templateArg = args[0];
314
- if (templateArg.type === 'Identifier' && isUserInput(templateArg.name)) {
315
- if (safetyChecker.isSafe(node, context)) {
316
- return;
317
- }
318
- context.report({
319
- node: templateArg,
320
- messageId: 'userControlledTemplate',
321
- data: {
322
- filePath: filename,
323
- line: String(node.loc?.start.line ?? 0),
324
- },
325
- });
326
- }
327
- }
328
- }
329
- if (objectName === 'Vue' && methodName === 'directive') {
330
- const args = node.arguments;
331
- if (args.length >= 2) {
332
- const directiveName = args[0];
333
- if (directiveName.type === 'Identifier' && isUserInput(directiveName.name)) {
334
- if (safetyChecker.isSafe(node, context)) {
335
- return;
336
- }
337
- context.report({
338
- node: directiveName,
339
- messageId: 'unsafeDirectiveName',
340
- data: {
341
- filePath: filename,
342
- line: String(node.loc?.start.line ?? 0),
343
- },
344
- });
345
- }
346
- }
347
- }
348
- }
349
- if (callee.type === 'Identifier' && callee.name === 'directive') {
350
- const args = node.arguments;
351
- if (args.length >= 2) {
352
- const directiveName = args[0];
353
- if (directiveName.type === 'Identifier' && isUserInput(directiveName.name)) {
354
- if (safetyChecker.isSafe(node, context)) {
355
- return;
356
- }
357
- context.report({
358
- node: directiveName,
359
- messageId: 'dynamicDirectiveCreation',
360
- data: {
361
- filePath: filename,
362
- line: String(node.loc?.start.line ?? 0),
363
- },
364
- });
365
- }
366
- }
367
- }
368
- },
369
- TemplateLiteral(node) {
370
- let current = node;
371
- let isInDangerousContext = false;
372
- while (current) {
373
- if (current.type === 'JSXExpressionContainer') {
374
- if (current.parent?.type === 'JSXAttribute' &&
375
- current.parent.name.type === 'JSXIdentifier' &&
376
- current.parent.name.name === 'dangerouslySetInnerHTML') {
377
- isInDangerousContext = true;
378
- break;
379
- }
380
- }
381
- else if (current.type === 'AssignmentExpression') {
382
- const left = current.left;
383
- if (left.type === 'MemberExpression' &&
384
- left.property.type === 'Identifier' &&
385
- left.property.name === 'innerHTML') {
386
- isInDangerousContext = true;
387
- break;
388
- }
389
- }
390
- current = current.parent;
391
- }
392
- if (isInDangerousContext) {
393
- const hasUserInput = node.expressions.some((expr) => (expr.type === 'Identifier' && isUserInput(expr.name)) ||
394
- (expr.type === 'MemberExpression' &&
395
- expr.object.type === 'Identifier' &&
396
- isUserInput(expr.object.name)));
397
- if (hasUserInput) {
398
- if (safetyChecker.isSafe(node, context)) {
399
- return;
400
- }
401
- context.report({
402
- node,
403
- messageId: 'templateInjection',
404
- data: {
405
- filePath: filename,
406
- line: String(node.loc?.start.line ?? 0),
407
- severity: 'HIGH',
408
- safeAlternative: 'Sanitize template input before insertion',
409
- },
410
- });
411
- }
412
- }
413
- }
414
- };
415
- },
416
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDirectiveInjection=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.noDirectiveInjection=(0,eslint_devkit_1.createRule)({name:"no-directive-injection",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-directive-injection.md",description:"Detects directive injection vulnerabilities in templates",cwe:"CWE-96"},messages:{directiveInjection:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Directive Injection",cwe:"CWE-96",description:"User input injected into directive or template",severity:"{{severity}}",fix:"{{safeAlternative}}",documentationLink:"https://cwe.mitre.org/data/definitions/96.html"}),unsafeDirectiveName:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Unsafe Directive Name",cwe:"CWE-96",description:"Directive name controlled by user input",severity:"CRITICAL",fix:"Use hardcoded directive names or validate against whitelist",documentationLink:"https://cwe.mitre.org/data/definitions/96.html"}),dynamicDirectiveCreation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Dynamic Directive Creation",cwe:"CWE-96",description:"Dynamic creation of directives from user input",severity:"HIGH",fix:"Validate directive names against trusted list",documentationLink:"https://cwe.mitre.org/data/definitions/96.html"}),templateInjection:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Template Injection",cwe:"CWE-96",description:"User input injected into template content",severity:"HIGH",fix:"Sanitize template input or use safe rendering",documentationLink:"https://cwe.mitre.org/data/definitions/96.html"}),unsafeComponentBinding:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Unsafe Component Binding",cwe:"CWE-96",description:"Dynamic component binding with user input",severity:"HIGH",fix:"Use component whitelist or validate component names",documentationLink:"https://cwe.mitre.org/data/definitions/96.html"}),userControlledTemplate:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"User Controlled Template",cwe:"CWE-96",description:"Template content controlled by user input",severity:"CRITICAL",fix:"Sanitize template input before compilation",documentationLink:"https://cwe.mitre.org/data/definitions/96.html"}),dangerousInnerHTML:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Dangerous innerHTML",cwe:"CWE-96",description:"innerHTML set with user-controlled content",severity:"HIGH",fix:"Use textContent or sanitize HTML content",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML"}),untrustedDirectiveSource:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Untrusted Directive Source",cwe:"CWE-96",description:"Directive loaded from untrusted source",severity:"MEDIUM",fix:"Load directives from trusted, verified sources",documentationLink:"https://cwe.mitre.org/data/definitions/96.html"}),useTrustedDirectives:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use Trusted Directives",description:"Use only trusted, verified directives",severity:"LOW",fix:"Maintain whitelist of allowed directives",documentationLink:"https://cwe.mitre.org/data/definitions/96.html"}),sanitizeTemplateInput:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Sanitize Template Input",description:"Sanitize user input before template processing",severity:"LOW",fix:"Use DOMPurify or equivalent sanitization",documentationLink:"https://github.com/cure53/DOMPurify"}),validateDirectiveNames:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Validate Directive Names",description:"Validate directive names against whitelist",severity:"LOW",fix:"Check directive names before dynamic creation",documentationLink:"https://cwe.mitre.org/data/definitions/96.html"}),strategyTemplateSanitization:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Template Sanitization Strategy",description:"Implement template input sanitization",severity:"LOW",fix:"Sanitize all user input before template processing",documentationLink:"https://owasp.org/www-community/xss-filter-evasion-cheatsheet"}),strategyContentSecurity:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Content Security Strategy",description:"Use CSP to restrict directive execution",severity:"LOW",fix:"Implement strict CSP with script-src restrictions",documentationLink:"https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP"}),strategyInputValidation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Input Validation Strategy",description:"Validate all template inputs",severity:"LOW",fix:"Use schema validation for template inputs",documentationLink:"https://joi.dev/"})},schema:[{type:"object",properties:{trustedDirectives:{type:"array",items:{type:"string"},default:["ngIf","ngFor","ngClass","v-if","v-for","v-bind","v-on"],description:"Template directives treated as safe"},userInputVariables:{type:"array",items:{type:"string"},default:["req","request","body","query","params","input","data","userInput"],description:"Variable names treated as user-controlled input"},frameworks:{type:"array",items:{type:"string"},default:["angular","vue","react","svelte"],description:"Template frameworks to analyse"},allowDynamicInComponents:{type:"boolean",default:false,description:"Allow dynamic directives inside component code"},trustedSanitizers:{type:"array",items:{type:"string"},default:[],description:"Additional function names to consider as template 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:[{trustedDirectives:["ngIf","ngFor","ngClass","v-if","v-for","v-bind","v-on"],userInputVariables:["req","request","body","query","params","input","data","userInput"],frameworks:["angular","vue","react","svelte"],allowDynamicInComponents:false,trustedSanitizers:[],trustedAnnotations:[],strictMode:false}],create(context){const options=context.options[0]||{};const{userInputVariables=["req","request","body","query","params","input","data","userInput"],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))||varName.startsWith("user")};return{JSXAttribute(node){const attrName=node.name;const attrValue=node.value;if(attrName.type==="JSXIdentifier"&&attrName.name==="dangerouslySetInnerHTML"){if(attrValue&&attrValue.type==="JSXExpressionContainer"){const expression=attrValue.expression;const expressionText=sourceCode.getText(expression);if(userInputVariables.some(input=>expressionText.includes(input))){if(safetyChecker.isSafe(node,context)){return}context.report({node:attrValue,messageId:"dangerousInnerHTML",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}const isNamespaceDirective=attrName.type==="JSXNamespacedName"&&(attrName.namespace.name==="v"||attrName.namespace.name==="ng")||attrName.type==="JSXIdentifier"&&(attrName.name.startsWith("ng:")||attrName.name.startsWith("v:"));if(isNamespaceDirective&&attrValue){if(attrValue.type==="JSXExpressionContainer"){const expression=attrValue.expression;if(expression.type==="Identifier"&&isUserInput(expression.name)){if(safetyChecker.isSafe(node,context)){return}context.report({node:attrValue,messageId:"directiveInjection",data:{filePath:filename,line:String(node.loc?.start.line??0),severity:"HIGH",safeAlternative:"Use hardcoded directive values or validate user input"}})}}}if(attrName.type==="JSXIdentifier"){const attrNameStr=attrName.name;if(attrNameStr==="is"&&attrValue){if(attrValue.type==="JSXExpressionContainer"){const expression=attrValue.expression;if(expression.type==="Identifier"&&isUserInput(expression.name)){if(safetyChecker.isSafe(node,context)){return}context.report({node:attrValue,messageId:"unsafeComponentBinding",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}}},AssignmentExpression(node){const left=node.left;const right=node.right;if(left.type==="MemberExpression"&&left.property.type==="Identifier"&&left.property.name==="innerHTML"){const rightText=sourceCode.getText(right);if(userInputVariables.some(input=>rightText.includes(input))){if(safetyChecker.isSafe(node,context)){return}context.report({node:right,messageId:"dangerousInnerHTML",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(["compile","template","$compile","$interpolate"].includes(methodName)||objectName==="Handlebars"&&methodName==="compile"||objectName==="_"&&methodName==="template"||objectName==="ejs"&&methodName==="render"||objectName==="pug"&&methodName==="render"||objectName==="mustache"&&methodName==="render"){const args=node.arguments;if(args.length>0){const templateArg=args[0];if(templateArg.type==="Identifier"&&isUserInput(templateArg.name)){if(safetyChecker.isSafe(node,context)){return}context.report({node:templateArg,messageId:"userControlledTemplate",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}if(objectName==="Vue"&&methodName==="directive"){const args=node.arguments;if(args.length>=2){const directiveName=args[0];if(directiveName.type==="Identifier"&&isUserInput(directiveName.name)){if(safetyChecker.isSafe(node,context)){return}context.report({node:directiveName,messageId:"unsafeDirectiveName",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}}if(callee.type==="Identifier"&&callee.name==="directive"){const args=node.arguments;if(args.length>=2){const directiveName=args[0];if(directiveName.type==="Identifier"&&isUserInput(directiveName.name)){if(safetyChecker.isSafe(node,context)){return}context.report({node:directiveName,messageId:"dynamicDirectiveCreation",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}},TemplateLiteral(node){let current=node;let isInDangerousContext=false;while(current){if(current.type==="JSXExpressionContainer"){if(current.parent?.type==="JSXAttribute"&&current.parent.name.type==="JSXIdentifier"&&current.parent.name.name==="dangerouslySetInnerHTML"){isInDangerousContext=true;break}}else if(current.type==="AssignmentExpression"){const left=current.left;if(left.type==="MemberExpression"&&left.property.type==="Identifier"&&left.property.name==="innerHTML"){isInDangerousContext=true;break}}current=current.parent}if(isInDangerousContext){const hasUserInput=node.expressions.some(expr=>expr.type==="Identifier"&&isUserInput(expr.name)||expr.type==="MemberExpression"&&expr.object.type==="Identifier"&&isUserInput(expr.object.name));if(hasUserInput){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"templateInjection",data:{filePath:filename,line:String(node.loc?.start.line??0),severity:"HIGH",safeAlternative:"Sanitize template input before insertion"}})}}}}}});