@interlace/eslint-devkit 1.0.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 (77) hide show
  1. package/AGENTS.md +352 -0
  2. package/CHANGELOG.md +88 -0
  3. package/LICENSE +22 -0
  4. package/README.md +528 -0
  5. package/package.json +88 -0
  6. package/src/aria-definitions.d.ts +9 -0
  7. package/src/aria-definitions.js +973 -0
  8. package/src/aria-definitions.js.map +1 -0
  9. package/src/ast/ast-utils.d.ts +81 -0
  10. package/src/ast/ast-utils.js +201 -0
  11. package/src/ast/ast-utils.js.map +1 -0
  12. package/src/ast/index.d.ts +1 -0
  13. package/src/ast/index.js +6 -0
  14. package/src/ast/index.js.map +1 -0
  15. package/src/index.d.ts +30 -0
  16. package/src/index.js +54 -0
  17. package/src/index.js.map +1 -0
  18. package/src/messaging/constants.d.ts +120 -0
  19. package/src/messaging/constants.js +744 -0
  20. package/src/messaging/constants.js.map +1 -0
  21. package/src/messaging/formatters.d.ts +124 -0
  22. package/src/messaging/formatters.js +330 -0
  23. package/src/messaging/formatters.js.map +1 -0
  24. package/src/messaging/index.d.ts +3 -0
  25. package/src/messaging/index.js +8 -0
  26. package/src/messaging/index.js.map +1 -0
  27. package/src/messaging/types.d.ts +122 -0
  28. package/src/messaging/types.js +8 -0
  29. package/src/messaging/types.js.map +1 -0
  30. package/src/node/fs.d.ts +65 -0
  31. package/src/node/fs.js +129 -0
  32. package/src/node/fs.js.map +1 -0
  33. package/src/node/index.d.ts +3 -0
  34. package/src/node/index.js +8 -0
  35. package/src/node/index.js.map +1 -0
  36. package/src/node/os.d.ts +24 -0
  37. package/src/node/os.js +49 -0
  38. package/src/node/os.js.map +1 -0
  39. package/src/node/path.d.ts +121 -0
  40. package/src/node/path.js +209 -0
  41. package/src/node/path.js.map +1 -0
  42. package/src/resolver/dependency-analysis.d.ts +421 -0
  43. package/src/resolver/dependency-analysis.js +934 -0
  44. package/src/resolver/dependency-analysis.js.map +1 -0
  45. package/src/resolver/index.d.ts +4 -0
  46. package/src/resolver/index.js +9 -0
  47. package/src/resolver/index.js.map +1 -0
  48. package/src/resolver/resolver-adapter.d.ts +53 -0
  49. package/src/resolver/resolver-adapter.js +126 -0
  50. package/src/resolver/resolver-adapter.js.map +1 -0
  51. package/src/resolver/resolver-detection.d.ts +36 -0
  52. package/src/resolver/resolver-detection.js +219 -0
  53. package/src/resolver/resolver-detection.js.map +1 -0
  54. package/src/resolver/resolver.d.ts +52 -0
  55. package/src/resolver/resolver.js +294 -0
  56. package/src/resolver/resolver.js.map +1 -0
  57. package/src/resolver.d.ts +1 -0
  58. package/src/resolver.js +5 -0
  59. package/src/resolver.js.map +1 -0
  60. package/src/rule-creation/index.d.ts +1 -0
  61. package/src/rule-creation/index.js +6 -0
  62. package/src/rule-creation/index.js.map +1 -0
  63. package/src/rule-creation/rule-creator.d.ts +42 -0
  64. package/src/rule-creation/rule-creator.js +42 -0
  65. package/src/rule-creation/rule-creator.js.map +1 -0
  66. package/src/security/index.d.ts +1 -0
  67. package/src/security/index.js +6 -0
  68. package/src/security/index.js.map +1 -0
  69. package/src/security/security-utils.d.ts +303 -0
  70. package/src/security/security-utils.js +607 -0
  71. package/src/security/security-utils.js.map +1 -0
  72. package/src/types/index.d.ts +1 -0
  73. package/src/types/index.js +6 -0
  74. package/src/types/index.js.map +1 -0
  75. package/src/types/type-utils.d.ts +146 -0
  76. package/src/types/type-utils.js +329 -0
  77. package/src/types/type-utils.js.map +1 -0
@@ -0,0 +1,303 @@
1
+ /**
2
+ * Security Utilities - Shared helpers for reducing false positives in security rules
3
+ *
4
+ * This module provides common detection for:
5
+ * 1. Sanitization/validation function calls
6
+ * 2. Safe patterns (ORMs, parameterized queries)
7
+ * 3. JSDoc annotations (@safe, @validated, @sanitized)
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import {
12
+ * isSanitizedInput,
13
+ * hasSafeAnnotation,
14
+ * isOrmMethodCall
15
+ * } from '../../utils/security-utils';
16
+ *
17
+ * // Skip reporting if input is sanitized
18
+ * if (isSanitizedInput(node, context)) {
19
+ * return; // Not a vulnerability - input was sanitized
20
+ * }
21
+ * ```
22
+ */
23
+ import type { TSESTree, TSESLint } from '@typescript-eslint/utils';
24
+ /**
25
+ * Common sanitization function names
26
+ * These functions are typically used to sanitize/escape user input
27
+ */
28
+ export declare const SANITIZATION_FUNCTIONS: string[];
29
+ /**
30
+ * Common validation library method patterns
31
+ * Format: objectName.methodName
32
+ */
33
+ export declare const VALIDATION_PATTERNS: string[];
34
+ /**
35
+ * Safe JSDoc annotations that indicate the value has been validated/sanitized
36
+ */
37
+ export declare const SAFE_ANNOTATIONS: string[];
38
+ /**
39
+ * ORM method patterns that are considered safe (use parameterized queries internally)
40
+ */
41
+ export declare const SAFE_ORM_PATTERNS: string[];
42
+ /**
43
+ * Check if a node represents a call to a sanitization function
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // Returns true for:
48
+ * sanitize(userInput)
49
+ * escape(userInput)
50
+ * DOMPurify.sanitize(html)
51
+ * validator.escape(input)
52
+ * ```
53
+ */
54
+ export declare function isSanitizationCall(node: TSESTree.Node, customFunctions?: string[]): boolean;
55
+ /**
56
+ * Check if a variable was assigned from a sanitization call
57
+ * Traces back through variable assignments to find sanitization
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const clean = sanitize(userInput);
62
+ * db.query(`SELECT * FROM users WHERE name = '${clean}'`);
63
+ * // ^ This should NOT be flagged - clean was sanitized
64
+ * ```
65
+ */
66
+ export declare function isSanitizedInput(node: TSESTree.Node, context: TSESLint.RuleContext<string, unknown[]>, customFunctions?: string[]): boolean;
67
+ /**
68
+ * Check if a node or its parent function has a safe JSDoc annotation
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * /** @safe - Input validated by middleware *\/
73
+ * function processInput(input) {
74
+ * db.query(`SELECT * FROM users WHERE name = '${input}'`);
75
+ * }
76
+ * ```
77
+ */
78
+ export declare function hasSafeAnnotation(node: TSESTree.Node, context: TSESLint.RuleContext<string, unknown[]>, customAnnotations?: string[]): boolean;
79
+ /**
80
+ * Check if a call expression is using an ORM's safe methods
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * // Returns true - ORM handles parameterization
85
+ * prisma.user.findMany({ where: { name: userInput } });
86
+ * userRepository.createQueryBuilder().where('name = :name', { name: userInput });
87
+ * ```
88
+ */
89
+ export declare function isOrmMethodCall(node: TSESTree.Node, context: TSESLint.RuleContext<string, unknown[]>, customPatterns?: string[]): boolean;
90
+ /**
91
+ * Check if a query uses parameterized placeholders
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * // Returns true - parameterized
96
+ * db.query('SELECT * FROM users WHERE id = ?', [userId]);
97
+ * db.query('SELECT * FROM users WHERE id = $1', [userId]);
98
+ * db.query('SELECT * FROM users WHERE id = :id', { id: userId });
99
+ * ```
100
+ */
101
+ export declare function isParameterizedQuery(queryText: string): boolean;
102
+ /**
103
+ * Combined check: is the input safe from injection?
104
+ *
105
+ * This function combines all safety checks:
106
+ * 1. Sanitization function calls
107
+ * 2. Safe JSDoc annotations
108
+ * 3. ORM method calls
109
+ * 4. Type-constrained values (when available)
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * if (isInputSafe(node, context)) {
114
+ * return; // Don't report - input is safe
115
+ * }
116
+ * ```
117
+ */
118
+ export declare function isInputSafe(node: TSESTree.Node, context: TSESLint.RuleContext<string, unknown[]>, options?: {
119
+ customSanitizers?: string[];
120
+ customAnnotations?: string[];
121
+ customOrmPatterns?: string[];
122
+ }): boolean;
123
+ /**
124
+ * Options interface for security rules that want to use these utilities
125
+ */
126
+ /**
127
+ * Compliance framework identifiers
128
+ */
129
+ export type ComplianceFramework = 'SOC2' | 'HIPAA' | 'PCI-DSS' | 'GDPR' | 'ISO27001' | 'NIST-CSF' | 'OWASP-ASVS' | 'FEDRAMP' | string;
130
+ /**
131
+ * Severity level override options
132
+ */
133
+ export type SeverityLevel = 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW' | 'INFO';
134
+ /**
135
+ * Severity override configuration
136
+ */
137
+ export interface SeverityOverride {
138
+ /**
139
+ * Override the default severity level for this rule
140
+ * @example 'CRITICAL'
141
+ */
142
+ level?: SeverityLevel;
143
+ /**
144
+ * Override based on pattern matching
145
+ * @example { 'user-input': 'CRITICAL', 'internal-api': 'MEDIUM' }
146
+ */
147
+ patterns?: Record<string, SeverityLevel>;
148
+ /**
149
+ * Minimum severity to report (filters out lower severity issues)
150
+ * @example 'MEDIUM' - only report MEDIUM, HIGH, CRITICAL
151
+ */
152
+ minSeverity?: SeverityLevel;
153
+ }
154
+ /**
155
+ * Compliance context for security rules
156
+ */
157
+ export interface ComplianceContext {
158
+ /**
159
+ * Additional compliance frameworks this rule applies to
160
+ * These are added to the auto-detected frameworks
161
+ * @example ['COMPANY-SEC-001', 'TEAM-POLICY-A']
162
+ */
163
+ frameworks?: ComplianceFramework[];
164
+ /**
165
+ * Ticket/issue tracking integration
166
+ * When violations are found, include link to create ticket
167
+ */
168
+ ticketTemplate?: {
169
+ /** Template URL with placeholders */
170
+ url: string;
171
+ /** Template for ticket summary */
172
+ summary?: string;
173
+ /** Default priority for tickets */
174
+ priority?: 'Critical' | 'High' | 'Medium' | 'Low';
175
+ /** Additional labels to apply */
176
+ labels?: string[];
177
+ };
178
+ /**
179
+ * Documentation link override for organization-specific docs
180
+ */
181
+ documentationUrl?: string;
182
+ /**
183
+ * Risk owner or team responsible for this category
184
+ */
185
+ riskOwner?: string;
186
+ /**
187
+ * Custom metadata for enterprise integration
188
+ */
189
+ metadata?: Record<string, string>;
190
+ }
191
+ export interface SecurityRuleOptions {
192
+ /** Additional function names to consider as sanitizers */
193
+ trustedSanitizers?: string[];
194
+ /** Additional JSDoc annotations to consider as safe markers */
195
+ trustedAnnotations?: string[];
196
+ /** Additional ORM patterns to consider safe */
197
+ trustedOrmPatterns?: string[];
198
+ /** Disable all false positive detection (strict mode) */
199
+ strictMode?: boolean;
200
+ /**
201
+ * Override the default severity for this rule
202
+ *
203
+ * @example
204
+ * ```javascript
205
+ * // Simple override
206
+ * { severity: { level: 'CRITICAL' } }
207
+ *
208
+ * // Pattern-based override
209
+ * { severity: { patterns: { 'user-input': 'CRITICAL', 'admin-api': 'HIGH' } } }
210
+ *
211
+ * // Filter low severity
212
+ * { severity: { minSeverity: 'MEDIUM' } }
213
+ * ```
214
+ */
215
+ severity?: SeverityOverride;
216
+ /**
217
+ * Compliance context for enterprise security reporting
218
+ *
219
+ * @example
220
+ * ```javascript
221
+ * {
222
+ * compliance: {
223
+ * frameworks: ['HIPAA', 'SOC2', 'COMPANY-SEC-001'],
224
+ * ticketTemplate: {
225
+ * url: 'https://jira.company.com/create?summary={{summary}}&priority={{priority}}',
226
+ * priority: 'Critical',
227
+ * labels: ['security', 'automated'],
228
+ * },
229
+ * documentationUrl: 'https://wiki.company.com/security/sql-injection',
230
+ * riskOwner: 'security-team@company.com',
231
+ * }
232
+ * }
233
+ * ```
234
+ */
235
+ compliance?: ComplianceContext;
236
+ }
237
+ /**
238
+ * Apply security rule options to configure safety checking
239
+ */
240
+ export declare function createSafetyChecker(options?: SecurityRuleOptions): {
241
+ /**
242
+ * Check if input should be considered safe (skip reporting)
243
+ */
244
+ isSafe(node: TSESTree.Node, context: TSESLint.RuleContext<string, unknown[]>): boolean;
245
+ /**
246
+ * Check specifically for sanitization
247
+ */
248
+ isSanitized(node: TSESTree.Node, context: TSESLint.RuleContext<string, unknown[]>): boolean;
249
+ /**
250
+ * Check specifically for safe annotations
251
+ */
252
+ hasAnnotation(node: TSESTree.Node, context: TSESLint.RuleContext<string, unknown[]>): boolean;
253
+ };
254
+ /**
255
+ * Check if a severity level meets or exceeds a minimum threshold
256
+ */
257
+ export declare function meetsSeverityThreshold(severity: SeverityLevel, minSeverity: SeverityLevel): boolean;
258
+ /**
259
+ * Get the effective severity level based on options and context
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * const effectiveSeverity = getEffectiveSeverity('HIGH', options.severity, {
264
+ * pattern: 'user-input', // optional context for pattern matching
265
+ * });
266
+ * ```
267
+ */
268
+ export declare function getEffectiveSeverity(defaultSeverity: SeverityLevel, override?: SeverityOverride, context?: {
269
+ pattern?: string;
270
+ }): SeverityLevel;
271
+ /**
272
+ * Check if an issue should be reported based on severity threshold
273
+ */
274
+ export declare function shouldReportSeverity(severity: SeverityLevel, override?: SeverityOverride): boolean;
275
+ /**
276
+ * Build compliance tags string for error messages
277
+ */
278
+ export declare function formatComplianceTags(defaultFrameworks: ComplianceFramework[], complianceContext?: ComplianceContext): string;
279
+ /**
280
+ * Build ticket URL from template
281
+ */
282
+ export declare function buildTicketUrl(template: ComplianceContext['ticketTemplate'], data: {
283
+ summary: string;
284
+ description?: string;
285
+ cwe?: string;
286
+ file?: string;
287
+ line?: number;
288
+ }): string | undefined;
289
+ /**
290
+ * Get documentation URL with fallback to organization-specific docs
291
+ */
292
+ export declare function getDocumentationUrl(defaultUrl: string, complianceContext?: ComplianceContext): string;
293
+ /**
294
+ * Create enhanced message data with compliance context
295
+ */
296
+ export declare function enhanceMessageData(baseData: Record<string, unknown>, options: SecurityRuleOptions, context: {
297
+ defaultFrameworks?: ComplianceFramework[];
298
+ summary?: string;
299
+ description?: string;
300
+ cwe?: string;
301
+ file?: string;
302
+ line?: number;
303
+ }): Record<string, unknown>;