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,56 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noHardcodedSessionTokens = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noHardcodedSessionTokens = (0, eslint_devkit_1.createRule)({
6
- name: 'no-hardcoded-session-tokens',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-hardcoded-session-tokens.md',
11
- description: 'Detect hardcoded session/JWT tokens',
12
- cwe: 'CWE-798',
13
- cvss: 9.8,
14
- },
15
- messages: {
16
- violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.SECURITY,
18
- issueName: 'Hardcoded Token',
19
- cwe: 'CWE-798',
20
- description: 'Hardcoded session or JWT token detected - credentials at risk',
21
- severity: 'CRITICAL',
22
- fix: 'Use environment variables or secure credential management',
23
- documentationLink: 'https://cwe.mitre.org/data/definitions/798.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
- Literal(node) {
35
- if (typeof node.value !== 'string')
36
- return;
37
- if (node.value.startsWith('eyJ') && node.value.length > 50 &&
38
- (node.value.match(/\./g) || []).length >= 2) {
39
- report(node);
40
- }
41
- if (node.value.startsWith('Bearer ') && node.value.length > 20) {
42
- report(node);
43
- }
44
- const parent = node.parent;
45
- if (parent?.type === 'VariableDeclarator' &&
46
- parent.id.type === 'Identifier') {
47
- const varName = parent.id.name.toLowerCase();
48
- if ((varName.includes('session') || varName.includes('token')) &&
49
- node.value.length >= 16 && /^[a-zA-Z0-9]+$/.test(node.value)) {
50
- report(node);
51
- }
52
- }
53
- },
54
- };
55
- },
56
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noHardcodedSessionTokens=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noHardcodedSessionTokens=(0,eslint_devkit_1.createRule)({name:"no-hardcoded-session-tokens",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-hardcoded-session-tokens.md",description:"Detect hardcoded session/JWT tokens",cwe:"CWE-798",cvss:9.8},messages:{violationDetected:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.SECURITY,issueName:"Hardcoded Token",cwe:"CWE-798",description:"Hardcoded session or JWT token detected - credentials at risk",severity:"CRITICAL",fix:"Use environment variables or secure credential management",documentationLink:"https://cwe.mitre.org/data/definitions/798.html"})},schema:[]},defaultOptions:[],create(context){function report(node){context.report({node,messageId:"violationDetected"})}return{Literal(node){if(typeof node.value!=="string")return;if(node.value.startsWith("eyJ")&&node.value.length>50&&(node.value.match(/\./g)||[]).length>=2){report(node)}if(node.value.startsWith("Bearer ")&&node.value.length>20){report(node)}const parent=node.parent;if(parent?.type==="VariableDeclarator"&&parent.id.type==="Identifier"){const varName=parent.id.name.toLowerCase();if((varName.includes("session")||varName.includes("token"))&&node.value.length>=16&&/^[a-zA-Z0-9]+$/.test(node.value)){report(node)}}}}}});
@@ -1,391 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noImproperSanitization = 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.noImproperSanitization = (0, eslint_devkit_1.createRule)({
8
- name: 'no-improper-sanitization',
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-sanitization.md',
13
- description: 'Detects improper sanitization of user input',
14
- cwe: 'CWE-116',
15
- },
16
- hasSuggestions: true,
17
- messages: {
18
- improperSanitization: (0, eslint_devkit_2.formatLLMMessage)({
19
- icon: eslint_devkit_2.MessageIcons.SECURITY,
20
- issueName: 'Improper Sanitization',
21
- cwe: 'CWE-116',
22
- description: 'User input sanitization is insufficient or incorrect',
23
- severity: '{{severity}}',
24
- fix: '{{safeAlternative}}',
25
- documentationLink: 'https://cwe.mitre.org/data/definitions/116.html',
26
- }),
27
- insufficientXssProtection: (0, eslint_devkit_2.formatLLMMessage)({
28
- icon: eslint_devkit_2.MessageIcons.SECURITY,
29
- issueName: 'Insufficient XSS Protection',
30
- cwe: 'CWE-79',
31
- description: 'XSS protection is incomplete or missing',
32
- severity: 'HIGH',
33
- fix: 'Use comprehensive XSS prevention or trusted sanitization library',
34
- documentationLink: 'https://owasp.org/www-community/attacks/xss/',
35
- }),
36
- incompleteHtmlEscaping: (0, eslint_devkit_2.formatLLMMessage)({
37
- icon: eslint_devkit_2.MessageIcons.SECURITY,
38
- issueName: 'Incomplete HTML Escaping',
39
- cwe: 'CWE-116',
40
- description: 'HTML escaping misses dangerous characters',
41
- severity: 'MEDIUM',
42
- fix: 'Escape all HTML special characters: & < > " \'',
43
- documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html',
44
- }),
45
- unsafeReplaceSanitization: (0, eslint_devkit_2.formatLLMMessage)({
46
- icon: eslint_devkit_2.MessageIcons.SECURITY,
47
- issueName: 'Unsafe Replace Sanitization',
48
- cwe: 'CWE-116',
49
- description: 'Simple replace() calls are insufficient for sanitization',
50
- severity: 'MEDIUM',
51
- fix: 'Use comprehensive sanitization libraries',
52
- documentationLink: 'https://cwe.mitre.org/data/definitions/116.html',
53
- }),
54
- missingContextEncoding: (0, eslint_devkit_2.formatLLMMessage)({
55
- icon: eslint_devkit_2.MessageIcons.SECURITY,
56
- issueName: 'Missing Context Encoding',
57
- cwe: 'CWE-116',
58
- description: 'Output encoding missing for specific context',
59
- severity: 'MEDIUM',
60
- fix: 'Encode output according to usage context (HTML, URL, SQL, etc.)',
61
- documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html',
62
- }),
63
- dangerousSanitizerUsage: (0, eslint_devkit_2.formatLLMMessage)({
64
- icon: eslint_devkit_2.MessageIcons.SECURITY,
65
- issueName: 'Dangerous Sanitizer Usage',
66
- cwe: 'CWE-94',
67
- description: 'Custom sanitizer may be incomplete or bypassable',
68
- severity: 'LOW',
69
- fix: 'Use well-tested sanitization libraries',
70
- documentationLink: 'https://cwe.mitre.org/data/definitions/94.html',
71
- }),
72
- sqlInjectionSanitization: (0, eslint_devkit_2.formatLLMMessage)({
73
- icon: eslint_devkit_2.MessageIcons.SECURITY,
74
- issueName: 'SQL Injection Sanitization',
75
- cwe: 'CWE-89',
76
- description: 'SQL input sanitization is insufficient',
77
- severity: 'HIGH',
78
- fix: 'Use parameterized queries instead of sanitization',
79
- documentationLink: 'https://owasp.org/www-community/attacks/SQL_Injection',
80
- }),
81
- commandInjectionSanitization: (0, eslint_devkit_2.formatLLMMessage)({
82
- icon: eslint_devkit_2.MessageIcons.SECURITY,
83
- issueName: 'Command Injection Sanitization',
84
- cwe: 'CWE-78',
85
- description: 'Command input sanitization is insufficient',
86
- severity: 'CRITICAL',
87
- fix: 'Avoid shell commands with user input, use safe APIs',
88
- documentationLink: 'https://owasp.org/www-community/attacks/Command_Injection',
89
- }),
90
- useProperSanitization: (0, eslint_devkit_2.formatLLMMessage)({
91
- icon: eslint_devkit_2.MessageIcons.INFO,
92
- issueName: 'Use Proper Sanitization',
93
- description: 'Use proper sanitization methods for each context',
94
- severity: 'LOW',
95
- fix: 'HTML: DOMPurify, URL: encodeURIComponent, SQL: parameterized queries',
96
- documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html',
97
- }),
98
- validateSanitization: (0, eslint_devkit_2.formatLLMMessage)({
99
- icon: eslint_devkit_2.MessageIcons.INFO,
100
- issueName: 'Validate Sanitization',
101
- description: 'Validate that sanitization is effective',
102
- severity: 'LOW',
103
- fix: 'Test sanitization with malicious inputs',
104
- documentationLink: 'https://cwe.mitre.org/data/definitions/116.html',
105
- }),
106
- implementContextAware: (0, eslint_devkit_2.formatLLMMessage)({
107
- icon: eslint_devkit_2.MessageIcons.INFO,
108
- issueName: 'Implement Context Aware Sanitization',
109
- description: 'Use different sanitization for different contexts',
110
- severity: 'LOW',
111
- fix: 'HTML context: escape <>&"\' , URL context: encodeURIComponent',
112
- documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html',
113
- }),
114
- strategyDefenseInDepth: (0, eslint_devkit_2.formatLLMMessage)({
115
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
116
- issueName: 'Defense in Depth Strategy',
117
- description: 'Implement multiple layers of input validation',
118
- severity: 'LOW',
119
- fix: 'Validate input, sanitize output, use CSP, implement rate limiting',
120
- documentationLink: 'https://owasp.org/www-community/controls/Defense_in_depth',
121
- }),
122
- strategyInputValidation: (0, eslint_devkit_2.formatLLMMessage)({
123
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
124
- issueName: 'Input Validation Strategy',
125
- description: 'Validate input at multiple layers',
126
- severity: 'LOW',
127
- fix: 'Client-side, server-side, and database-level validation',
128
- documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html',
129
- }),
130
- strategyOutputEncoding: (0, eslint_devkit_2.formatLLMMessage)({
131
- icon: eslint_devkit_2.MessageIcons.STRATEGY,
132
- issueName: 'Output Encoding Strategy',
133
- description: 'Encode output according to context',
134
- severity: 'LOW',
135
- fix: 'Use appropriate encoding for HTML, JavaScript, CSS, URL contexts',
136
- documentationLink: 'https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html',
137
- })
138
- },
139
- schema: [
140
- {
141
- type: 'object',
142
- properties: {
143
- safeSanitizers: {
144
- type: 'array',
145
- items: { type: 'string' },
146
- default: ['DOMPurify.sanitize', 'he.encode', 'encodeURIComponent', 'encodeURI', 'escape'], description: 'Sanitizer calls treated as sufficient'
147
- },
148
- dangerousChars: {
149
- type: 'array',
150
- items: { type: 'string' },
151
- default: ['<', '>', '"', "'", '&', '`', '$', '{', '}', '|', ';', '(', ')'], description: 'Characters a sanitizer is expected to handle'
152
- },
153
- contexts: {
154
- type: 'array',
155
- items: { type: 'string' },
156
- default: ['html', 'url', 'sql', 'command', 'javascript', 'css'], description: 'Output contexts checked for a context-appropriate sanitizer'
157
- },
158
- trustedLibraries: {
159
- type: 'array',
160
- items: { type: 'string' },
161
- default: ['DOMPurify', 'he', 'validator', 'express-validator'], description: 'Libraries whose sanitizers are trusted'
162
- },
163
- trustedSanitizers: {
164
- type: 'array',
165
- items: { type: 'string' },
166
- default: [],
167
- description: 'Additional function names to consider as sanitizers',
168
- },
169
- trustedAnnotations: {
170
- type: 'array',
171
- items: { type: 'string' },
172
- default: [],
173
- description: 'Additional JSDoc annotations to consider as safe markers',
174
- },
175
- strictMode: {
176
- type: 'boolean',
177
- default: false,
178
- description: 'Disable all false positive detection (strict mode)',
179
- },
180
- },
181
- additionalProperties: false,
182
- },
183
- ],
184
- },
185
- defaultOptions: [
186
- {
187
- safeSanitizers: ['DOMPurify.sanitize', 'he.encode', 'encodeURIComponent', 'encodeURI', 'escape'],
188
- dangerousChars: ['<', '>', '"', "'", '&', '`', '$', '{', '}', '|', ';', '(', ')'],
189
- contexts: ['html', 'url', 'sql', 'command', 'javascript', 'css'],
190
- trustedLibraries: ['DOMPurify', 'he', 'validator', 'express-validator'],
191
- trustedSanitizers: [],
192
- trustedAnnotations: [],
193
- strictMode: false,
194
- },
195
- ],
196
- create(context) {
197
- const options = context.options[0] || {};
198
- const { safeSanitizers = ['DOMPurify.sanitize', 'he.encode', 'encodeURIComponent', 'encodeURI', 'escape'], dangerousChars = ['<', '>', '"', "'", '&', '`', '$', '{', '}', '|', ';', '(', ')'], trustedSanitizers = [], trustedAnnotations = [], strictMode = false, } = options;
199
- const sourceCode = context.sourceCode;
200
- const filename = context.filename;
201
- const safetyChecker = (0, eslint_devkit_3.createSafetyChecker)({
202
- trustedSanitizers,
203
- trustedAnnotations,
204
- trustedOrmPatterns: [],
205
- strictMode,
206
- });
207
- const isSafeSanitizer = (callText) => {
208
- return safeSanitizers.some(sanitizer => callText.includes(sanitizer));
209
- };
210
- const isIncompleteReplaceSanitization = (callExpression) => {
211
- const callText = sourceCode.getText(callExpression);
212
- const escapesOnlyTags = /replace\(\s*\/[<>]/.test(callText);
213
- if (escapesOnlyTags) {
214
- const hasQuoteEscaping = /&quot;|&#x27;|&#039;/.test(callText);
215
- const hasAmpersandEscaping = /&amp;/.test(callText);
216
- return !(hasQuoteEscaping && hasAmpersandEscaping);
217
- }
218
- return false;
219
- };
220
- const needsContextEncoding = (outputNode) => {
221
- let current = outputNode;
222
- while (current) {
223
- const text = sourceCode.getText(current).toLowerCase();
224
- if (text.includes('innerhtml') || text.includes('outerhtml')) {
225
- return 'html';
226
- }
227
- if (text.includes('href') || text.includes('src') || text.includes('url')) {
228
- return 'url';
229
- }
230
- if (text.includes('sql') || text.includes('query') || text.includes('execute')) {
231
- return 'sql';
232
- }
233
- if (text.includes('exec') || text.includes('spawn') || text.includes('command')) {
234
- return 'command';
235
- }
236
- current = current.parent;
237
- }
238
- return null;
239
- };
240
- return {
241
- CallExpression(node) {
242
- const callee = node.callee;
243
- if (callee.type === 'MemberExpression' &&
244
- callee.property.type === 'Identifier' &&
245
- callee.property.name === 'replace') {
246
- if (isIncompleteReplaceSanitization(node)) {
247
- if (safetyChecker.isSafe(node, context)) {
248
- return;
249
- }
250
- context.report({
251
- node,
252
- messageId: 'incompleteHtmlEscaping',
253
- data: {
254
- filePath: filename,
255
- line: String(node.loc?.start.line ?? 0),
256
- },
257
- });
258
- }
259
- }
260
- if (callee.type === 'Identifier') {
261
- const functionName = callee.name;
262
- if (functionName.toLowerCase().includes('sanitize') ||
263
- functionName.toLowerCase().includes('escape') ||
264
- functionName.toLowerCase().includes('clean')) {
265
- if (!safeSanitizers.some(safe => functionName.includes(safe))) {
266
- const args = node.arguments;
267
- let hasUserInput = false;
268
- for (const arg of args) {
269
- const argText = sourceCode.getText(arg).toLowerCase();
270
- if (argText.includes('req.') || argText.includes('body') ||
271
- argText.includes('query') || argText.includes('params') ||
272
- argText.includes('input') || argText.includes('data')) {
273
- hasUserInput = true;
274
- break;
275
- }
276
- }
277
- if (hasUserInput) {
278
- if (safetyChecker.isSafe(node, context)) {
279
- return;
280
- }
281
- context.report({
282
- node,
283
- messageId: 'dangerousSanitizerUsage',
284
- data: {
285
- filePath: filename,
286
- line: String(node.loc?.start.line ?? 0),
287
- },
288
- });
289
- }
290
- }
291
- }
292
- }
293
- },
294
- AssignmentExpression(node) {
295
- const left = node.left;
296
- const right = node.right;
297
- if (left.type === 'MemberExpression' &&
298
- left.property.type === 'Identifier') {
299
- const propertyName = left.property.name.toLowerCase();
300
- if (['innerhtml', 'outerhtml', 'innertext', 'textcontent'].includes(propertyName)) {
301
- const encodingContext = needsContextEncoding(node);
302
- if (encodingContext === 'html' && propertyName === 'innerhtml') {
303
- const rightText = sourceCode.getText(right);
304
- if (!isSafeSanitizer(rightText)) {
305
- const hasUserInput = rightText.includes('req.') ||
306
- rightText.includes('body') ||
307
- rightText.includes('query') ||
308
- rightText.includes('input');
309
- if (hasUserInput) {
310
- if (safetyChecker.isSafe(node, context)) {
311
- return;
312
- }
313
- context.report({
314
- node: right,
315
- messageId: 'insufficientXssProtection',
316
- data: {
317
- filePath: filename,
318
- line: String(node.loc?.start.line ?? 0),
319
- },
320
- });
321
- }
322
- }
323
- }
324
- }
325
- }
326
- },
327
- Literal(node) {
328
- if (typeof node.value !== 'string') {
329
- return;
330
- }
331
- const directParent = node.parent;
332
- if (directParent?.type === 'AssignmentExpression' &&
333
- directParent.right === node &&
334
- directParent.left.type === 'MemberExpression') {
335
- const left = directParent.left;
336
- if (left.property.type === 'Identifier' &&
337
- ['innerHTML', 'outerHTML'].includes(left.property.name)) {
338
- const literalValue = node.value;
339
- const hasDangerousMarkup = /<script[\s>]|<\/script>|\son\w+\s*=|javascript:/i.test(literalValue);
340
- if (!hasDangerousMarkup) {
341
- return;
342
- }
343
- }
344
- }
345
- const text = node.value;
346
- let current = node;
347
- let isInDangerousContext = false;
348
- while (current) {
349
- if (current.type === 'AssignmentExpression') {
350
- const left = current.left;
351
- if (left.type === 'MemberExpression' &&
352
- left.property.type === 'Identifier' &&
353
- ['innerHTML', 'outerHTML'].includes(left.property.name)) {
354
- isInDangerousContext = true;
355
- break;
356
- }
357
- }
358
- else if (current.type === 'CallExpression') {
359
- const callee = current.callee;
360
- if (callee.type === 'MemberExpression' &&
361
- callee.property.type === 'Identifier' &&
362
- ['write', 'send', 'json'].includes(callee.property.name)) {
363
- isInDangerousContext = true;
364
- break;
365
- }
366
- }
367
- current = current.parent;
368
- }
369
- if (isInDangerousContext) {
370
- const hasDangerousChars = dangerousChars.some(char => text.includes(char));
371
- const hasEscaping = text.includes('&lt;') || text.includes('&gt;') ||
372
- text.includes('&quot;') || text.includes('&#x27;') ||
373
- text.includes('&amp;');
374
- if (hasDangerousChars && !hasEscaping) {
375
- if (safetyChecker.isSafe(node, context)) {
376
- return;
377
- }
378
- context.report({
379
- node,
380
- messageId: 'unsafeReplaceSanitization',
381
- data: {
382
- filePath: filename,
383
- line: String(node.loc?.start.line ?? 0),
384
- },
385
- });
386
- }
387
- }
388
- }
389
- };
390
- },
391
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noImproperSanitization=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.noImproperSanitization=(0,eslint_devkit_1.createRule)({name:"no-improper-sanitization",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-secure-coding/docs/rules/no-improper-sanitization.md",description:"Detects improper sanitization of user input",cwe:"CWE-116"},hasSuggestions:true,messages:{improperSanitization:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Improper Sanitization",cwe:"CWE-116",description:"User input sanitization is insufficient or incorrect",severity:"{{severity}}",fix:"{{safeAlternative}}",documentationLink:"https://cwe.mitre.org/data/definitions/116.html"}),insufficientXssProtection:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Insufficient XSS Protection",cwe:"CWE-79",description:"XSS protection is incomplete or missing",severity:"HIGH",fix:"Use comprehensive XSS prevention or trusted sanitization library",documentationLink:"https://owasp.org/www-community/attacks/xss/"}),incompleteHtmlEscaping:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Incomplete HTML Escaping",cwe:"CWE-116",description:"HTML escaping misses dangerous characters",severity:"MEDIUM",fix:`Escape all HTML special characters: & < > " '`,documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html"}),unsafeReplaceSanitization:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Unsafe Replace Sanitization",cwe:"CWE-116",description:"Simple replace() calls are insufficient for sanitization",severity:"MEDIUM",fix:"Use comprehensive sanitization libraries",documentationLink:"https://cwe.mitre.org/data/definitions/116.html"}),missingContextEncoding:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Missing Context Encoding",cwe:"CWE-116",description:"Output encoding missing for specific context",severity:"MEDIUM",fix:"Encode output according to usage context (HTML, URL, SQL, etc.)",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html"}),dangerousSanitizerUsage:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Dangerous Sanitizer Usage",cwe:"CWE-94",description:"Custom sanitizer may be incomplete or bypassable",severity:"LOW",fix:"Use well-tested sanitization libraries",documentationLink:"https://cwe.mitre.org/data/definitions/94.html"}),sqlInjectionSanitization:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"SQL Injection Sanitization",cwe:"CWE-89",description:"SQL input sanitization is insufficient",severity:"HIGH",fix:"Use parameterized queries instead of sanitization",documentationLink:"https://owasp.org/www-community/attacks/SQL_Injection"}),commandInjectionSanitization:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.SECURITY,issueName:"Command Injection Sanitization",cwe:"CWE-78",description:"Command input sanitization is insufficient",severity:"CRITICAL",fix:"Avoid shell commands with user input, use safe APIs",documentationLink:"https://owasp.org/www-community/attacks/Command_Injection"}),useProperSanitization:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Use Proper Sanitization",description:"Use proper sanitization methods for each context",severity:"LOW",fix:"HTML: DOMPurify, URL: encodeURIComponent, SQL: parameterized queries",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html"}),validateSanitization:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Validate Sanitization",description:"Validate that sanitization is effective",severity:"LOW",fix:"Test sanitization with malicious inputs",documentationLink:"https://cwe.mitre.org/data/definitions/116.html"}),implementContextAware:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.INFO,issueName:"Implement Context Aware Sanitization",description:"Use different sanitization for different contexts",severity:"LOW",fix:`HTML context: escape <>&"' , URL context: encodeURIComponent`,documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html"}),strategyDefenseInDepth:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Defense in Depth Strategy",description:"Implement multiple layers of input validation",severity:"LOW",fix:"Validate input, sanitize output, use CSP, implement rate limiting",documentationLink:"https://owasp.org/www-community/controls/Defense_in_depth"}),strategyInputValidation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Input Validation Strategy",description:"Validate input at multiple layers",severity:"LOW",fix:"Client-side, server-side, and database-level validation",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html"}),strategyOutputEncoding:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.STRATEGY,issueName:"Output Encoding Strategy",description:"Encode output according to context",severity:"LOW",fix:"Use appropriate encoding for HTML, JavaScript, CSS, URL contexts",documentationLink:"https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html"})},schema:[{type:"object",properties:{safeSanitizers:{type:"array",items:{type:"string"},default:["DOMPurify.sanitize","he.encode","encodeURIComponent","encodeURI","escape"],description:"Sanitizer calls treated as sufficient"},dangerousChars:{type:"array",items:{type:"string"},default:["<",">",'"',"'","&","`","$","{","}","|",";","(",")"],description:"Characters a sanitizer is expected to handle"},contexts:{type:"array",items:{type:"string"},default:["html","url","sql","command","javascript","css"],description:"Output contexts checked for a context-appropriate sanitizer"},trustedLibraries:{type:"array",items:{type:"string"},default:["DOMPurify","he","validator","express-validator"],description:"Libraries whose sanitizers are trusted"},trustedSanitizers:{type:"array",items:{type:"string"},default:[],description:"Additional function names to consider as 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:[{safeSanitizers:["DOMPurify.sanitize","he.encode","encodeURIComponent","encodeURI","escape"],dangerousChars:["<",">",'"',"'","&","`","$","{","}","|",";","(",")"],contexts:["html","url","sql","command","javascript","css"],trustedLibraries:["DOMPurify","he","validator","express-validator"],trustedSanitizers:[],trustedAnnotations:[],strictMode:false}],create(context){const options=context.options[0]||{};const{safeSanitizers=["DOMPurify.sanitize","he.encode","encodeURIComponent","encodeURI","escape"],dangerousChars=["<",">",'"',"'","&","`","$","{","}","|",";","(",")"],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 isSafeSanitizer=callText=>{return safeSanitizers.some(sanitizer=>callText.includes(sanitizer))};const isIncompleteReplaceSanitization=callExpression=>{const callText=sourceCode.getText(callExpression);const escapesOnlyTags=/replace\(\s*\/[<>]/.test(callText);if(escapesOnlyTags){const hasQuoteEscaping=/&quot;|&#x27;|&#039;/.test(callText);const hasAmpersandEscaping=/&amp;/.test(callText);return!(hasQuoteEscaping&&hasAmpersandEscaping)}return false};const needsContextEncoding=outputNode=>{let current=outputNode;while(current){const text=sourceCode.getText(current).toLowerCase();if(text.includes("innerhtml")||text.includes("outerhtml")){return"html"}if(text.includes("href")||text.includes("src")||text.includes("url")){return"url"}if(text.includes("sql")||text.includes("query")||text.includes("execute")){return"sql"}if(text.includes("exec")||text.includes("spawn")||text.includes("command")){return"command"}current=current.parent}return null};return{CallExpression(node){const callee=node.callee;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"&&callee.property.name==="replace"){if(isIncompleteReplaceSanitization(node)){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"incompleteHtmlEscaping",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}if(callee.type==="Identifier"){const functionName=callee.name;if(functionName.toLowerCase().includes("sanitize")||functionName.toLowerCase().includes("escape")||functionName.toLowerCase().includes("clean")){if(!safeSanitizers.some(safe=>functionName.includes(safe))){const args=node.arguments;let hasUserInput=false;for(const arg of args){const argText=sourceCode.getText(arg).toLowerCase();if(argText.includes("req.")||argText.includes("body")||argText.includes("query")||argText.includes("params")||argText.includes("input")||argText.includes("data")){hasUserInput=true;break}}if(hasUserInput){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"dangerousSanitizerUsage",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"){const propertyName=left.property.name.toLowerCase();if(["innerhtml","outerhtml","innertext","textcontent"].includes(propertyName)){const encodingContext=needsContextEncoding(node);if(encodingContext==="html"&&propertyName==="innerhtml"){const rightText=sourceCode.getText(right);if(!isSafeSanitizer(rightText)){const hasUserInput=rightText.includes("req.")||rightText.includes("body")||rightText.includes("query")||rightText.includes("input");if(hasUserInput){if(safetyChecker.isSafe(node,context)){return}context.report({node:right,messageId:"insufficientXssProtection",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}}}},Literal(node){if(typeof node.value!=="string"){return}const directParent=node.parent;if(directParent?.type==="AssignmentExpression"&&directParent.right===node&&directParent.left.type==="MemberExpression"){const left=directParent.left;if(left.property.type==="Identifier"&&["innerHTML","outerHTML"].includes(left.property.name)){const literalValue=node.value;const hasDangerousMarkup=/<script[\s>]|<\/script>|\son\w+\s*=|javascript:/i.test(literalValue);if(!hasDangerousMarkup){return}}}const text=node.value;let current=node;let isInDangerousContext=false;while(current){if(current.type==="AssignmentExpression"){const left=current.left;if(left.type==="MemberExpression"&&left.property.type==="Identifier"&&["innerHTML","outerHTML"].includes(left.property.name)){isInDangerousContext=true;break}}else if(current.type==="CallExpression"){const callee=current.callee;if(callee.type==="MemberExpression"&&callee.property.type==="Identifier"&&["write","send","json"].includes(callee.property.name)){isInDangerousContext=true;break}}current=current.parent}if(isInDangerousContext){const hasDangerousChars=dangerousChars.some(char=>text.includes(char));const hasEscaping=text.includes("&lt;")||text.includes("&gt;")||text.includes("&quot;")||text.includes("&#x27;")||text.includes("&amp;");if(hasDangerousChars&&!hasEscaping){if(safetyChecker.isSafe(node,context)){return}context.report({node,messageId:"unsafeReplaceSanitization",data:{filePath:filename,line:String(node.loc?.start.line??0)}})}}}}}});