@interlace/eslint-devkit 1.9.0 → 1.11.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 (46) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -2
  3. package/src/aria-definitions.js +1 -990
  4. package/src/ast/ast-utils.js +1 -133
  5. package/src/ast/index.js +1 -17
  6. package/src/ast-node-types.js +1 -174
  7. package/src/index.js +1 -43
  8. package/src/messaging/config.js +1 -98
  9. package/src/messaging/constants.js +1 -678
  10. package/src/messaging/formatters-ai.js +2 -176
  11. package/src/messaging/formatters-v2.js +10 -212
  12. package/src/messaging/formatters.js +3 -186
  13. package/src/messaging/index.js +1 -21
  14. package/src/messaging/types-v2.js +1 -2
  15. package/src/messaging/types.js +1 -2
  16. package/src/node/fs.js +1 -104
  17. package/src/node/index.js +1 -19
  18. package/src/node/os.js +1 -52
  19. package/src/node/path.js +1 -143
  20. package/src/resolver/dependency-analysis.js +1 -740
  21. package/src/resolver/index.js +1 -20
  22. package/src/resolver/resolver-adapter.js +1 -92
  23. package/src/resolver/resolver-detection.js +1 -189
  24. package/src/resolver/resolver.js +1 -206
  25. package/src/resolver.js +1 -17
  26. package/src/rule-creation/browser-escape-hatch-rule.js +1 -100
  27. package/src/rule-creation/hardcoded-credentials-rule.js +1 -143
  28. package/src/rule-creation/index.d.ts +2 -0
  29. package/src/rule-creation/index.js +1 -26
  30. package/src/rule-creation/mass-assignment-rule.js +1 -121
  31. package/src/rule-creation/message-source.d.ts +95 -0
  32. package/src/rule-creation/message-source.js +1 -0
  33. package/src/rule-creation/mock-context.js +1 -39
  34. package/src/rule-creation/raw-identifier-rule.js +1 -140
  35. package/src/rule-creation/require-tls-rule.js +1 -190
  36. package/src/rule-creation/rule-creator.js +1 -70
  37. package/src/rule-creation/sdk-api-key-rule.js +1 -121
  38. package/src/rule-creation/sql-injection-rule.js +1 -207
  39. package/src/rule-creation/system-prompt-injection-rule.d.ts +78 -0
  40. package/src/rule-creation/system-prompt-injection-rule.js +1 -0
  41. package/src/rule-creation/unscoped-mutation-rule.js +1 -234
  42. package/src/security/index.js +1 -17
  43. package/src/security/security-utils.js +1 -461
  44. package/src/types/index.js +1 -18
  45. package/src/types/meta-augmentation.js +1 -2
  46. package/src/types/type-utils.js +1 -222
@@ -1,461 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_USER_INPUT_PATTERNS = exports.SAFE_ORM_PATTERNS = exports.SAFE_ANNOTATIONS = exports.VALIDATION_PATTERNS = exports.SANITIZATION_FUNCTIONS = void 0;
4
- exports.isSanitizationCall = isSanitizationCall;
5
- exports.isSanitizedInput = isSanitizedInput;
6
- exports.hasSafeAnnotation = hasSafeAnnotation;
7
- exports.isOrmMethodCall = isOrmMethodCall;
8
- exports.isParameterizedQuery = isParameterizedQuery;
9
- exports.isInputSafe = isInputSafe;
10
- exports.createSafetyChecker = createSafetyChecker;
11
- exports.shouldSkipForSafety = shouldSkipForSafety;
12
- exports.findAncestor = findAncestor;
13
- exports.isInsideLoop = isInsideLoop;
14
- exports.isInsideFunction = isInsideFunction;
15
- exports.getContainingFunction = getContainingFunction;
16
- exports.isUserInputIdentifier = isUserInputIdentifier;
17
- exports.isUserInputExpression = isUserInputExpression;
18
- exports.meetsSeverityThreshold = meetsSeverityThreshold;
19
- exports.getEffectiveSeverity = getEffectiveSeverity;
20
- exports.shouldReportSeverity = shouldReportSeverity;
21
- exports.formatComplianceTags = formatComplianceTags;
22
- exports.buildTicketUrl = buildTicketUrl;
23
- exports.getDocumentationUrl = getDocumentationUrl;
24
- exports.enhanceMessageData = enhanceMessageData;
25
- exports.SANITIZATION_FUNCTIONS = [
26
- 'sanitize',
27
- 'sanitizeInput',
28
- 'sanitizeHtml',
29
- 'sanitizeString',
30
- 'sanitizeUrl',
31
- 'sanitizeEmail',
32
- 'sanitizePath',
33
- 'sanitizeQuery',
34
- 'sanitizeOutput',
35
- 'clean',
36
- 'cleanInput',
37
- 'purify',
38
- 'DOMPurify',
39
- 'escape',
40
- 'escapeHtml',
41
- 'escapeString',
42
- 'escapeSql',
43
- 'escapeRegExp',
44
- 'escapeShell',
45
- 'htmlEscape',
46
- 'sqlEscape',
47
- 'encode',
48
- 'encodeURIComponent',
49
- 'encodeURI',
50
- 'htmlEncode',
51
- 'urlEncode',
52
- 'base64Encode',
53
- 'validate',
54
- 'validateInput',
55
- 'validateEmail',
56
- 'validateUrl',
57
- 'validateId',
58
- 'validateUuid',
59
- 'isValid',
60
- 'isValidEmail',
61
- 'isValidUrl',
62
- 'assertValid',
63
- 'parseInt',
64
- 'parseFloat',
65
- 'Number',
66
- 'Boolean',
67
- 'String',
68
- 'BigInt',
69
- 'xss',
70
- 'filterXSS',
71
- 'strip_tags',
72
- 'stripTags',
73
- 'bleach',
74
- 'validator',
75
- ];
76
- exports.VALIDATION_PATTERNS = [
77
- 'validator.escape',
78
- 'validator.isEmail',
79
- 'validator.isURL',
80
- 'validator.isUUID',
81
- 'validator.isAlphanumeric',
82
- 'validator.isInt',
83
- 'validator.isFloat',
84
- 'validator.trim',
85
- 'validator.normalizeEmail',
86
- 'validator.whitelist',
87
- 'validator.blacklist',
88
- 'z.string',
89
- 'z.number',
90
- 'z.boolean',
91
- 'z.array',
92
- 'z.object',
93
- 'schema.parse',
94
- 'schema.safeParse',
95
- 'yup.string',
96
- 'yup.number',
97
- 'string().email',
98
- 'string().url',
99
- 'string().uuid',
100
- 'Joi.string',
101
- 'Joi.number',
102
- 'joi.string',
103
- 'joi.number',
104
- 'IsEmail',
105
- 'IsUrl',
106
- 'IsUUID',
107
- 'IsString',
108
- 'IsNumber',
109
- 'IsNotEmpty',
110
- 'DOMPurify.sanitize',
111
- 'purify.sanitize',
112
- 'body().escape',
113
- 'body().trim',
114
- 'body().isEmail',
115
- 'param().escape',
116
- 'query().escape',
117
- 'check().escape',
118
- 'validationResult',
119
- 'matchedData',
120
- ];
121
- exports.SAFE_ANNOTATIONS = [
122
- '@safe',
123
- '@safe-loop',
124
- '@validated',
125
- '@sanitized',
126
- '@trusted',
127
- '@escaped',
128
- '@clean',
129
- '@verified',
130
- '@timing-safe',
131
- ];
132
- exports.SAFE_ORM_PATTERNS = [
133
- 'prisma.',
134
- '.findUnique(',
135
- '.findFirst(',
136
- '.findMany(',
137
- '.create(',
138
- '.createMany(',
139
- '.update(',
140
- '.updateMany(',
141
- '.upsert(',
142
- '.delete(',
143
- '.deleteMany(',
144
- '.aggregate(',
145
- '.groupBy(',
146
- '.count(',
147
- '.createQueryBuilder(',
148
- '.getRepository(',
149
- '.find(',
150
- '.findOne(',
151
- '.findOneBy(',
152
- '.save(',
153
- '.remove(',
154
- '.softDelete(',
155
- 'Model.findAll',
156
- 'Model.findOne',
157
- 'Model.findByPk',
158
- 'Model.create',
159
- 'Model.update',
160
- 'Model.destroy',
161
- '.where(',
162
- '.andWhere(',
163
- '.orWhere(',
164
- '.whereIn(',
165
- '.whereNotIn(',
166
- '.whereBetween(',
167
- '.insert(',
168
- '.returning(',
169
- '.findById(',
170
- '.findByIdAndUpdate(',
171
- '.findByIdAndDelete(',
172
- '.find({',
173
- '.findOne({',
174
- '.updateOne({',
175
- '.updateMany({',
176
- '.deleteOne({',
177
- '.deleteMany({',
178
- ];
179
- function isSanitizationCall(node, customFunctions = []) {
180
- const allFunctions = new Set([...exports.SANITIZATION_FUNCTIONS, ...customFunctions]);
181
- if (node.type === 'CallExpression') {
182
- const callee = node.callee;
183
- if (callee.type === 'Identifier') {
184
- return allFunctions.has(callee.name);
185
- }
186
- if (callee.type === 'MemberExpression') {
187
- const methodPath = getMemberExpressionPath(callee);
188
- if (exports.VALIDATION_PATTERNS.some((pattern) => methodPath.includes(pattern))) {
189
- return true;
190
- }
191
- if (callee.property.type === 'Identifier') {
192
- return allFunctions.has(callee.property.name);
193
- }
194
- }
195
- }
196
- return false;
197
- }
198
- function getMemberExpressionPath(node) {
199
- const parts = [];
200
- let current = node;
201
- while (current.type === 'MemberExpression') {
202
- if (current.property.type === 'Identifier') {
203
- parts.unshift(current.property.name);
204
- }
205
- current = current.object;
206
- }
207
- if (current.type === 'Identifier') {
208
- parts.unshift(current.name);
209
- }
210
- return parts.join('.');
211
- }
212
- function isSanitizedInput(node, context, customFunctions = []) {
213
- if (isSanitizationCall(node, customFunctions)) {
214
- return true;
215
- }
216
- if (node.type === 'Identifier') {
217
- const scope = context.sourceCode.getScope?.(node) ??
218
- (context.getScope ? context.getScope() : null);
219
- if (scope) {
220
- const variable = scope.variables.find((v) => v.name === node.name);
221
- if (variable) {
222
- for (const def of variable.defs) {
223
- if (def.node.type === 'VariableDeclarator' && def.node.init) {
224
- if (isSanitizationCall(def.node.init, customFunctions)) {
225
- return true;
226
- }
227
- }
228
- }
229
- }
230
- }
231
- }
232
- return false;
233
- }
234
- function hasSafeAnnotation(node, context, customAnnotations = []) {
235
- const allAnnotations = [...exports.SAFE_ANNOTATIONS, ...customAnnotations];
236
- const sourceCode = context.sourceCode;
237
- let current = node;
238
- while (current) {
239
- const comments = sourceCode.getCommentsBefore(current);
240
- for (const comment of comments) {
241
- const commentText = comment.value.toLowerCase();
242
- if (allAnnotations.some((ann) => commentText.includes(ann.toLowerCase()))) {
243
- return true;
244
- }
245
- }
246
- if (current.type === 'FunctionDeclaration' ||
247
- current.type === 'FunctionExpression' ||
248
- current.type === 'ArrowFunctionExpression' ||
249
- current.type === 'MethodDefinition') {
250
- break;
251
- }
252
- current = current.parent;
253
- }
254
- return false;
255
- }
256
- function isOrmMethodCall(node, context, customPatterns = []) {
257
- const allPatterns = [...exports.SAFE_ORM_PATTERNS, ...customPatterns];
258
- const sourceCode = context.sourceCode;
259
- if (node.type === 'CallExpression') {
260
- const callText = sourceCode.getText(node);
261
- if (allPatterns.some((pattern) => callText.includes(pattern))) {
262
- return true;
263
- }
264
- if (node.callee.type === 'MemberExpression') {
265
- const methodPath = getMemberExpressionPath(node.callee);
266
- const ormNames = [
267
- 'prisma',
268
- 'sequelize',
269
- 'knex',
270
- 'db',
271
- 'repository',
272
- 'model',
273
- ];
274
- if (ormNames.some((orm) => methodPath.toLowerCase().startsWith(orm))) {
275
- return true;
276
- }
277
- }
278
- }
279
- return false;
280
- }
281
- function isParameterizedQuery(queryText) {
282
- const placeholderPatterns = [
283
- /\?/,
284
- /\$\d+/,
285
- /:\w+/,
286
- /@\w+/,
287
- ];
288
- return placeholderPatterns.some((pattern) => pattern.test(queryText));
289
- }
290
- function isInputSafe(node, context, options = {}) {
291
- const { customSanitizers = [], customAnnotations = [], customOrmPatterns = [], } = options;
292
- if (isSanitizedInput(node, context, customSanitizers)) {
293
- return true;
294
- }
295
- if (node.type === 'BinaryExpression') {
296
- if (isSanitizedInput(node.left, context, customSanitizers) ||
297
- isSanitizedInput(node.right, context, customSanitizers)) {
298
- return true;
299
- }
300
- }
301
- if (hasSafeAnnotation(node, context, customAnnotations)) {
302
- return true;
303
- }
304
- let current = node;
305
- while (current) {
306
- if (current.type === 'CallExpression') {
307
- if (isOrmMethodCall(current, context, customOrmPatterns)) {
308
- return true;
309
- }
310
- }
311
- current = current.parent;
312
- }
313
- return false;
314
- }
315
- function createSafetyChecker(options = {}) {
316
- const { trustedSanitizers = [], trustedAnnotations = [], trustedOrmPatterns = [], strictMode = false, } = options;
317
- return {
318
- isSafe(node, context) {
319
- if (strictMode) {
320
- return false;
321
- }
322
- return isInputSafe(node, context, {
323
- customSanitizers: trustedSanitizers,
324
- customAnnotations: trustedAnnotations,
325
- customOrmPatterns: trustedOrmPatterns,
326
- });
327
- },
328
- isSanitized(node, context) {
329
- if (strictMode)
330
- return false;
331
- return isSanitizedInput(node, context, trustedSanitizers);
332
- },
333
- hasAnnotation(node, context) {
334
- if (strictMode)
335
- return false;
336
- return hasSafeAnnotation(node, context, trustedAnnotations);
337
- },
338
- };
339
- }
340
- function shouldSkipForSafety(safetyChecker, node, context) {
341
- return safetyChecker.isSafe(node, context);
342
- }
343
- const LOOP_NODE_TYPES = new Set([
344
- 'ForStatement',
345
- 'WhileStatement',
346
- 'DoWhileStatement',
347
- 'ForInStatement',
348
- 'ForOfStatement',
349
- ]);
350
- const FUNCTION_NODE_TYPES = new Set([
351
- 'FunctionDeclaration',
352
- 'FunctionExpression',
353
- 'ArrowFunctionExpression',
354
- 'MethodDefinition',
355
- ]);
356
- function findAncestor(node, predicate, maxDepth = 20) {
357
- let current = node.parent;
358
- let depth = 0;
359
- while (current && depth < maxDepth) {
360
- if (predicate(current)) {
361
- return current;
362
- }
363
- current = current.parent;
364
- depth++;
365
- }
366
- return null;
367
- }
368
- function isInsideLoop(node) {
369
- return findAncestor(node, n => LOOP_NODE_TYPES.has(n.type)) !== null;
370
- }
371
- function isInsideFunction(node) {
372
- return findAncestor(node, n => FUNCTION_NODE_TYPES.has(n.type)) !== null;
373
- }
374
- function getContainingFunction(node) {
375
- return findAncestor(node, n => FUNCTION_NODE_TYPES.has(n.type));
376
- }
377
- exports.DEFAULT_USER_INPUT_PATTERNS = [
378
- 'req', 'request', 'body', 'query', 'params',
379
- 'input', 'data', 'userInput', 'userData',
380
- 'args', 'argv', 'env', 'process.env',
381
- ];
382
- function isUserInputIdentifier(name, patterns = exports.DEFAULT_USER_INPUT_PATTERNS) {
383
- const lowerName = name.toLowerCase();
384
- return patterns.some(pattern => lowerName.includes(pattern.toLowerCase()));
385
- }
386
- function isUserInputExpression(expression, sourceCode, patterns = exports.DEFAULT_USER_INPUT_PATTERNS) {
387
- const exprText = sourceCode.getText(expression);
388
- return patterns.some(pattern => exprText.includes(pattern));
389
- }
390
- const SEVERITY_ORDER = {
391
- CRITICAL: 5,
392
- HIGH: 4,
393
- MEDIUM: 3,
394
- LOW: 2,
395
- INFO: 1,
396
- };
397
- function meetsSeverityThreshold(severity, minSeverity) {
398
- return SEVERITY_ORDER[severity] >= SEVERITY_ORDER[minSeverity];
399
- }
400
- function getEffectiveSeverity(defaultSeverity, override, context) {
401
- if (!override) {
402
- return defaultSeverity;
403
- }
404
- if (context?.pattern && override.patterns?.[context.pattern]) {
405
- return override.patterns[context.pattern];
406
- }
407
- if (override.level) {
408
- return override.level;
409
- }
410
- return defaultSeverity;
411
- }
412
- function shouldReportSeverity(severity, override) {
413
- if (!override?.minSeverity) {
414
- return true;
415
- }
416
- return meetsSeverityThreshold(severity, override.minSeverity);
417
- }
418
- function formatComplianceTags(defaultFrameworks, complianceContext) {
419
- const allFrameworks = [
420
- ...defaultFrameworks,
421
- ...(complianceContext?.frameworks ?? []),
422
- ];
423
- if (allFrameworks.length === 0) {
424
- return '';
425
- }
426
- const display = allFrameworks.slice(0, 4);
427
- return `[${display.join(',')}]`;
428
- }
429
- function buildTicketUrl(template, data) {
430
- if (!template?.url) {
431
- return undefined;
432
- }
433
- let url = template.url;
434
- url = url.replace(/\{\{summary\}\}/g, encodeURIComponent(data.summary));
435
- url = url.replace(/\{\{description\}\}/g, encodeURIComponent(data.description ?? ''));
436
- url = url.replace(/\{\{priority\}\}/g, template.priority ?? 'Medium');
437
- url = url.replace(/\{\{labels\}\}/g, (template.labels ?? []).join(','));
438
- url = url.replace(/\{\{cwe\}\}/g, data.cwe ?? '');
439
- url = url.replace(/\{\{file\}\}/g, encodeURIComponent(data.file ?? ''));
440
- url = url.replace(/\{\{line\}\}/g, String(data.line ?? 0));
441
- return url;
442
- }
443
- function getDocumentationUrl(defaultUrl, complianceContext) {
444
- return complianceContext?.documentationUrl ?? defaultUrl;
445
- }
446
- function enhanceMessageData(baseData, options, context) {
447
- const complianceContext = options.compliance;
448
- return {
449
- ...baseData,
450
- complianceTags: formatComplianceTags(context.defaultFrameworks ?? [], complianceContext),
451
- ticketUrl: buildTicketUrl(complianceContext?.ticketTemplate, {
452
- summary: context.summary ?? String(baseData['description'] ?? ''),
453
- description: context.description,
454
- cwe: context.cwe,
455
- file: context.file,
456
- line: context.line,
457
- }),
458
- riskOwner: complianceContext?.riskOwner ?? '',
459
- ...complianceContext?.metadata,
460
- };
461
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.DEFAULT_USER_INPUT_PATTERNS=exports.SAFE_ORM_PATTERNS=exports.SAFE_ANNOTATIONS=exports.VALIDATION_PATTERNS=exports.SANITIZATION_FUNCTIONS=void 0;exports.isSanitizationCall=isSanitizationCall;exports.isSanitizedInput=isSanitizedInput;exports.hasSafeAnnotation=hasSafeAnnotation;exports.isOrmMethodCall=isOrmMethodCall;exports.isParameterizedQuery=isParameterizedQuery;exports.isInputSafe=isInputSafe;exports.createSafetyChecker=createSafetyChecker;exports.shouldSkipForSafety=shouldSkipForSafety;exports.findAncestor=findAncestor;exports.isInsideLoop=isInsideLoop;exports.isInsideFunction=isInsideFunction;exports.getContainingFunction=getContainingFunction;exports.isUserInputIdentifier=isUserInputIdentifier;exports.isUserInputExpression=isUserInputExpression;exports.meetsSeverityThreshold=meetsSeverityThreshold;exports.getEffectiveSeverity=getEffectiveSeverity;exports.shouldReportSeverity=shouldReportSeverity;exports.formatComplianceTags=formatComplianceTags;exports.buildTicketUrl=buildTicketUrl;exports.getDocumentationUrl=getDocumentationUrl;exports.enhanceMessageData=enhanceMessageData;exports.SANITIZATION_FUNCTIONS=["sanitize","sanitizeInput","sanitizeHtml","sanitizeString","sanitizeUrl","sanitizeEmail","sanitizePath","sanitizeQuery","sanitizeOutput","clean","cleanInput","purify","DOMPurify","escape","escapeHtml","escapeString","escapeSql","escapeRegExp","escapeShell","htmlEscape","sqlEscape","encode","encodeURIComponent","encodeURI","htmlEncode","urlEncode","base64Encode","validate","validateInput","validateEmail","validateUrl","validateId","validateUuid","isValid","isValidEmail","isValidUrl","assertValid","parseInt","parseFloat","Number","Boolean","String","BigInt","xss","filterXSS","strip_tags","stripTags","bleach","validator"];exports.VALIDATION_PATTERNS=["validator.escape","validator.isEmail","validator.isURL","validator.isUUID","validator.isAlphanumeric","validator.isInt","validator.isFloat","validator.trim","validator.normalizeEmail","validator.whitelist","validator.blacklist","z.string","z.number","z.boolean","z.array","z.object","schema.parse","schema.safeParse","yup.string","yup.number","string().email","string().url","string().uuid","Joi.string","Joi.number","joi.string","joi.number","IsEmail","IsUrl","IsUUID","IsString","IsNumber","IsNotEmpty","DOMPurify.sanitize","purify.sanitize","body().escape","body().trim","body().isEmail","param().escape","query().escape","check().escape","validationResult","matchedData"];exports.SAFE_ANNOTATIONS=["@safe","@safe-loop","@validated","@sanitized","@trusted","@escaped","@clean","@verified","@timing-safe"];exports.SAFE_ORM_PATTERNS=["prisma.",".findUnique(",".findFirst(",".findMany(",".create(",".createMany(",".update(",".updateMany(",".upsert(",".delete(",".deleteMany(",".aggregate(",".groupBy(",".count(",".createQueryBuilder(",".getRepository(",".find(",".findOne(",".findOneBy(",".save(",".remove(",".softDelete(","Model.findAll","Model.findOne","Model.findByPk","Model.create","Model.update","Model.destroy",".where(",".andWhere(",".orWhere(",".whereIn(",".whereNotIn(",".whereBetween(",".insert(",".returning(",".findById(",".findByIdAndUpdate(",".findByIdAndDelete(",".find({",".findOne({",".updateOne({",".updateMany({",".deleteOne({",".deleteMany({"];function isSanitizationCall(node,customFunctions=[]){const allFunctions=new Set([...exports.SANITIZATION_FUNCTIONS,...customFunctions]);if(node.type==="CallExpression"){const callee=node.callee;if(callee.type==="Identifier"){return allFunctions.has(callee.name)}if(callee.type==="MemberExpression"){const methodPath=getMemberExpressionPath(callee);if(exports.VALIDATION_PATTERNS.some(pattern=>methodPath.includes(pattern))){return true}if(callee.property.type==="Identifier"){return allFunctions.has(callee.property.name)}}}return false}function getMemberExpressionPath(node){const parts=[];let current=node;while(current.type==="MemberExpression"){if(current.property.type==="Identifier"){parts.unshift(current.property.name)}current=current.object}if(current.type==="Identifier"){parts.unshift(current.name)}return parts.join(".")}function isSanitizedInput(node,context,customFunctions=[]){if(isSanitizationCall(node,customFunctions)){return true}if(node.type==="Identifier"){const scope=context.sourceCode.getScope?.(node)??(context.getScope?context.getScope():null);if(scope){const variable=scope.variables.find(v=>v.name===node.name);if(variable){for(const def of variable.defs){if(def.node.type==="VariableDeclarator"&&def.node.init){if(isSanitizationCall(def.node.init,customFunctions)){return true}}}}}}return false}function hasSafeAnnotation(node,context,customAnnotations=[]){const allAnnotations=[...exports.SAFE_ANNOTATIONS,...customAnnotations];const sourceCode=context.sourceCode;let current=node;while(current){const comments=sourceCode.getCommentsBefore(current);for(const comment of comments){const commentText=comment.value.toLowerCase();if(allAnnotations.some(ann=>commentText.includes(ann.toLowerCase()))){return true}}if(current.type==="FunctionDeclaration"||current.type==="FunctionExpression"||current.type==="ArrowFunctionExpression"||current.type==="MethodDefinition"){break}current=current.parent}return false}function isOrmMethodCall(node,context,customPatterns=[]){const allPatterns=[...exports.SAFE_ORM_PATTERNS,...customPatterns];const sourceCode=context.sourceCode;if(node.type==="CallExpression"){const callText=sourceCode.getText(node);if(allPatterns.some(pattern=>callText.includes(pattern))){return true}if(node.callee.type==="MemberExpression"){const methodPath=getMemberExpressionPath(node.callee);const ormNames=["prisma","sequelize","knex","db","repository","model"];if(ormNames.some(orm=>methodPath.toLowerCase().startsWith(orm))){return true}}}return false}function isParameterizedQuery(queryText){const placeholderPatterns=[/\?/,/\$\d+/,/:\w+/,/@\w+/];return placeholderPatterns.some(pattern=>pattern.test(queryText))}function isInputSafe(node,context,options={}){const{customSanitizers=[],customAnnotations=[],customOrmPatterns=[]}=options;if(isSanitizedInput(node,context,customSanitizers)){return true}if(node.type==="BinaryExpression"){if(isSanitizedInput(node.left,context,customSanitizers)||isSanitizedInput(node.right,context,customSanitizers)){return true}}if(hasSafeAnnotation(node,context,customAnnotations)){return true}let current=node;while(current){if(current.type==="CallExpression"){if(isOrmMethodCall(current,context,customOrmPatterns)){return true}}current=current.parent}return false}function createSafetyChecker(options={}){const{trustedSanitizers=[],trustedAnnotations=[],trustedOrmPatterns=[],strictMode=false}=options;return{isSafe(node,context){if(strictMode){return false}return isInputSafe(node,context,{customSanitizers:trustedSanitizers,customAnnotations:trustedAnnotations,customOrmPatterns:trustedOrmPatterns})},isSanitized(node,context){if(strictMode)return false;return isSanitizedInput(node,context,trustedSanitizers)},hasAnnotation(node,context){if(strictMode)return false;return hasSafeAnnotation(node,context,trustedAnnotations)}}}function shouldSkipForSafety(safetyChecker,node,context){return safetyChecker.isSafe(node,context)}const LOOP_NODE_TYPES=new Set(["ForStatement","WhileStatement","DoWhileStatement","ForInStatement","ForOfStatement"]);const FUNCTION_NODE_TYPES=new Set(["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","MethodDefinition"]);function findAncestor(node,predicate,maxDepth=20){let current=node.parent;let depth=0;while(current&&depth<maxDepth){if(predicate(current)){return current}current=current.parent;depth++}return null}function isInsideLoop(node){return findAncestor(node,n=>LOOP_NODE_TYPES.has(n.type))!==null}function isInsideFunction(node){return findAncestor(node,n=>FUNCTION_NODE_TYPES.has(n.type))!==null}function getContainingFunction(node){return findAncestor(node,n=>FUNCTION_NODE_TYPES.has(n.type))}exports.DEFAULT_USER_INPUT_PATTERNS=["req","request","body","query","params","input","data","userInput","userData","args","argv","env","process.env"];function isUserInputIdentifier(name,patterns=exports.DEFAULT_USER_INPUT_PATTERNS){const lowerName=name.toLowerCase();return patterns.some(pattern=>lowerName.includes(pattern.toLowerCase()))}function isUserInputExpression(expression,sourceCode,patterns=exports.DEFAULT_USER_INPUT_PATTERNS){const exprText=sourceCode.getText(expression);return patterns.some(pattern=>exprText.includes(pattern))}const SEVERITY_ORDER={CRITICAL:5,HIGH:4,MEDIUM:3,LOW:2,INFO:1};function meetsSeverityThreshold(severity,minSeverity){return SEVERITY_ORDER[severity]>=SEVERITY_ORDER[minSeverity]}function getEffectiveSeverity(defaultSeverity,override,context){if(!override){return defaultSeverity}if(context?.pattern&&override.patterns?.[context.pattern]){return override.patterns[context.pattern]}if(override.level){return override.level}return defaultSeverity}function shouldReportSeverity(severity,override){if(!override?.minSeverity){return true}return meetsSeverityThreshold(severity,override.minSeverity)}function formatComplianceTags(defaultFrameworks,complianceContext){const allFrameworks=[...defaultFrameworks,...complianceContext?.frameworks??[]];if(allFrameworks.length===0){return""}const display=allFrameworks.slice(0,4);return`[${display.join(",")}]`}function buildTicketUrl(template,data){if(!template?.url){return void 0}let url=template.url;url=url.replace(/\{\{summary\}\}/g,encodeURIComponent(data.summary));url=url.replace(/\{\{description\}\}/g,encodeURIComponent(data.description??""));url=url.replace(/\{\{priority\}\}/g,template.priority??"Medium");url=url.replace(/\{\{labels\}\}/g,(template.labels??[]).join(","));url=url.replace(/\{\{cwe\}\}/g,data.cwe??"");url=url.replace(/\{\{file\}\}/g,encodeURIComponent(data.file??""));url=url.replace(/\{\{line\}\}/g,String(data.line??0));return url}function getDocumentationUrl(defaultUrl,complianceContext){return complianceContext?.documentationUrl??defaultUrl}function enhanceMessageData(baseData,options,context){const complianceContext=options.compliance;return{...baseData,complianceTags:formatComplianceTags(context.defaultFrameworks??[],complianceContext),ticketUrl:buildTicketUrl(complianceContext?.ticketTemplate,{summary:context.summary??String(baseData["description"]??""),description:context.description,cwe:context.cwe,file:context.file,line:context.line}),riskOwner:complianceContext?.riskOwner??"",...complianceContext?.metadata}}
@@ -1,18 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./type-utils"), exports);
18
- require("./meta-augmentation");
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __exportStar=this&&this.__exportStar||function(m,exports2){for(var p in m)if(p!=="default"&&!Object.prototype.hasOwnProperty.call(exports2,p))__createBinding(exports2,m,p)};Object.defineProperty(exports,"__esModule",{value:true});__exportStar(require("./type-utils"),exports);require("./meta-augmentation");
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});