circle-ir 3.1.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 (194) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +200 -0
  3. package/configs/sinks/code_injection.yaml +672 -0
  4. package/configs/sinks/command.yaml +917 -0
  5. package/configs/sinks/deserialization.yaml +105 -0
  6. package/configs/sinks/ldap.yaml +136 -0
  7. package/configs/sinks/nodejs.json +629 -0
  8. package/configs/sinks/path.yaml +715 -0
  9. package/configs/sinks/python.json +501 -0
  10. package/configs/sinks/rust.json +339 -0
  11. package/configs/sinks/sql.yaml +233 -0
  12. package/configs/sinks/ssrf.yaml +160 -0
  13. package/configs/sinks/xpath.yaml +121 -0
  14. package/configs/sinks/xss.yaml +727 -0
  15. package/configs/sources/db_sources.yaml +90 -0
  16. package/configs/sources/env_sources.yaml +94 -0
  17. package/configs/sources/express.json +197 -0
  18. package/configs/sources/file_sources.yaml +164 -0
  19. package/configs/sources/http_sources.yaml +379 -0
  20. package/configs/sources/io_sources.yaml +519 -0
  21. package/configs/sources/network_sources.yaml +99 -0
  22. package/configs/sources/python.json +230 -0
  23. package/configs/sources/rust.json +286 -0
  24. package/configs/sources/spring.yaml +70 -0
  25. package/dist/analysis/advisory-db.d.ts +86 -0
  26. package/dist/analysis/advisory-db.js +104 -0
  27. package/dist/analysis/advisory-db.js.map +1 -0
  28. package/dist/analysis/cargo-parser.d.ts +42 -0
  29. package/dist/analysis/cargo-parser.js +102 -0
  30. package/dist/analysis/cargo-parser.js.map +1 -0
  31. package/dist/analysis/config-loader.d.ts +37 -0
  32. package/dist/analysis/config-loader.js +1561 -0
  33. package/dist/analysis/config-loader.js.map +1 -0
  34. package/dist/analysis/constant-propagation/ast-utils.d.ts +25 -0
  35. package/dist/analysis/constant-propagation/ast-utils.js +34 -0
  36. package/dist/analysis/constant-propagation/ast-utils.js.map +1 -0
  37. package/dist/analysis/constant-propagation/evaluator.d.ts +32 -0
  38. package/dist/analysis/constant-propagation/evaluator.js +296 -0
  39. package/dist/analysis/constant-propagation/evaluator.js.map +1 -0
  40. package/dist/analysis/constant-propagation/index.d.ts +62 -0
  41. package/dist/analysis/constant-propagation/index.js +152 -0
  42. package/dist/analysis/constant-propagation/index.js.map +1 -0
  43. package/dist/analysis/constant-propagation/patterns.d.ts +8 -0
  44. package/dist/analysis/constant-propagation/patterns.js +126 -0
  45. package/dist/analysis/constant-propagation/patterns.js.map +1 -0
  46. package/dist/analysis/constant-propagation/propagator.d.ts +180 -0
  47. package/dist/analysis/constant-propagation/propagator.js +1985 -0
  48. package/dist/analysis/constant-propagation/propagator.js.map +1 -0
  49. package/dist/analysis/constant-propagation/types.d.ts +63 -0
  50. package/dist/analysis/constant-propagation/types.js +5 -0
  51. package/dist/analysis/constant-propagation/types.js.map +1 -0
  52. package/dist/analysis/constant-propagation.d.ts +9 -0
  53. package/dist/analysis/constant-propagation.js +18 -0
  54. package/dist/analysis/constant-propagation.js.map +1 -0
  55. package/dist/analysis/dependency-scanner.d.ts +79 -0
  56. package/dist/analysis/dependency-scanner.js +122 -0
  57. package/dist/analysis/dependency-scanner.js.map +1 -0
  58. package/dist/analysis/dfg-verifier.d.ts +116 -0
  59. package/dist/analysis/dfg-verifier.js +399 -0
  60. package/dist/analysis/dfg-verifier.js.map +1 -0
  61. package/dist/analysis/findings.d.ts +11 -0
  62. package/dist/analysis/findings.js +228 -0
  63. package/dist/analysis/findings.js.map +1 -0
  64. package/dist/analysis/index.d.ts +16 -0
  65. package/dist/analysis/index.js +18 -0
  66. package/dist/analysis/index.js.map +1 -0
  67. package/dist/analysis/interprocedural.d.ts +99 -0
  68. package/dist/analysis/interprocedural.js +526 -0
  69. package/dist/analysis/interprocedural.js.map +1 -0
  70. package/dist/analysis/path-finder.d.ts +133 -0
  71. package/dist/analysis/path-finder.js +354 -0
  72. package/dist/analysis/path-finder.js.map +1 -0
  73. package/dist/analysis/rules.d.ts +75 -0
  74. package/dist/analysis/rules.js +332 -0
  75. package/dist/analysis/rules.js.map +1 -0
  76. package/dist/analysis/semver.d.ts +27 -0
  77. package/dist/analysis/semver.js +127 -0
  78. package/dist/analysis/semver.js.map +1 -0
  79. package/dist/analysis/taint-matcher.d.ts +15 -0
  80. package/dist/analysis/taint-matcher.js +634 -0
  81. package/dist/analysis/taint-matcher.js.map +1 -0
  82. package/dist/analysis/taint-propagation.d.ts +67 -0
  83. package/dist/analysis/taint-propagation.js +298 -0
  84. package/dist/analysis/taint-propagation.js.map +1 -0
  85. package/dist/analysis/unresolved.d.ts +14 -0
  86. package/dist/analysis/unresolved.js +202 -0
  87. package/dist/analysis/unresolved.js.map +1 -0
  88. package/dist/analyzer.d.ts +43 -0
  89. package/dist/analyzer.js +1010 -0
  90. package/dist/analyzer.js.map +1 -0
  91. package/dist/browser/circle-ir.js +16576 -0
  92. package/dist/browser.d.ts +38 -0
  93. package/dist/browser.js +38 -0
  94. package/dist/browser.js.map +1 -0
  95. package/dist/core/circle-ir-core.cjs +13626 -0
  96. package/dist/core/circle-ir-core.d.ts +59 -0
  97. package/dist/core/circle-ir-core.js +13591 -0
  98. package/dist/core/extractors/calls.d.ts +13 -0
  99. package/dist/core/extractors/calls.js +1429 -0
  100. package/dist/core/extractors/calls.js.map +1 -0
  101. package/dist/core/extractors/cfg.d.ts +9 -0
  102. package/dist/core/extractors/cfg.js +519 -0
  103. package/dist/core/extractors/cfg.js.map +1 -0
  104. package/dist/core/extractors/dfg.d.ts +12 -0
  105. package/dist/core/extractors/dfg.js +1081 -0
  106. package/dist/core/extractors/dfg.js.map +1 -0
  107. package/dist/core/extractors/exports.d.ts +14 -0
  108. package/dist/core/extractors/exports.js +80 -0
  109. package/dist/core/extractors/exports.js.map +1 -0
  110. package/dist/core/extractors/imports.d.ts +9 -0
  111. package/dist/core/extractors/imports.js +739 -0
  112. package/dist/core/extractors/imports.js.map +1 -0
  113. package/dist/core/extractors/index.d.ts +10 -0
  114. package/dist/core/extractors/index.js +11 -0
  115. package/dist/core/extractors/index.js.map +1 -0
  116. package/dist/core/extractors/meta.d.ts +10 -0
  117. package/dist/core/extractors/meta.js +109 -0
  118. package/dist/core/extractors/meta.js.map +1 -0
  119. package/dist/core/extractors/types.d.ts +10 -0
  120. package/dist/core/extractors/types.js +1479 -0
  121. package/dist/core/extractors/types.js.map +1 -0
  122. package/dist/core/index.d.ts +5 -0
  123. package/dist/core/index.js +8 -0
  124. package/dist/core/index.js.map +1 -0
  125. package/dist/core/parser.d.ts +84 -0
  126. package/dist/core/parser.js +250 -0
  127. package/dist/core/parser.js.map +1 -0
  128. package/dist/core-lib.d.ts +59 -0
  129. package/dist/core-lib.js +62 -0
  130. package/dist/core-lib.js.map +1 -0
  131. package/dist/index.d.ts +15 -0
  132. package/dist/index.js +20 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/languages/index.d.ts +11 -0
  135. package/dist/languages/index.js +14 -0
  136. package/dist/languages/index.js.map +1 -0
  137. package/dist/languages/plugins/base.d.ts +44 -0
  138. package/dist/languages/plugins/base.js +82 -0
  139. package/dist/languages/plugins/base.js.map +1 -0
  140. package/dist/languages/plugins/index.d.ts +14 -0
  141. package/dist/languages/plugins/index.js +25 -0
  142. package/dist/languages/plugins/index.js.map +1 -0
  143. package/dist/languages/plugins/java.d.ts +49 -0
  144. package/dist/languages/plugins/java.js +402 -0
  145. package/dist/languages/plugins/java.js.map +1 -0
  146. package/dist/languages/plugins/javascript.d.ts +48 -0
  147. package/dist/languages/plugins/javascript.js +445 -0
  148. package/dist/languages/plugins/javascript.js.map +1 -0
  149. package/dist/languages/plugins/python.d.ts +47 -0
  150. package/dist/languages/plugins/python.js +480 -0
  151. package/dist/languages/plugins/python.js.map +1 -0
  152. package/dist/languages/plugins/rust.d.ts +47 -0
  153. package/dist/languages/plugins/rust.js +405 -0
  154. package/dist/languages/plugins/rust.js.map +1 -0
  155. package/dist/languages/registry.d.ts +30 -0
  156. package/dist/languages/registry.js +80 -0
  157. package/dist/languages/registry.js.map +1 -0
  158. package/dist/languages/types.d.ts +184 -0
  159. package/dist/languages/types.js +8 -0
  160. package/dist/languages/types.js.map +1 -0
  161. package/dist/resolution/cross-file.d.ts +146 -0
  162. package/dist/resolution/cross-file.js +439 -0
  163. package/dist/resolution/cross-file.js.map +1 -0
  164. package/dist/resolution/index.d.ts +12 -0
  165. package/dist/resolution/index.js +10 -0
  166. package/dist/resolution/index.js.map +1 -0
  167. package/dist/resolution/symbol-table.d.ts +136 -0
  168. package/dist/resolution/symbol-table.js +336 -0
  169. package/dist/resolution/symbol-table.js.map +1 -0
  170. package/dist/resolution/type-hierarchy.d.ts +124 -0
  171. package/dist/resolution/type-hierarchy.js +515 -0
  172. package/dist/resolution/type-hierarchy.js.map +1 -0
  173. package/dist/types/config.d.ts +45 -0
  174. package/dist/types/config.js +5 -0
  175. package/dist/types/config.js.map +1 -0
  176. package/dist/types/index.d.ts +392 -0
  177. package/dist/types/index.js +7 -0
  178. package/dist/types/index.js.map +1 -0
  179. package/dist/utils/logger.d.ts +85 -0
  180. package/dist/utils/logger.js +198 -0
  181. package/dist/utils/logger.js.map +1 -0
  182. package/dist/wasm/tree-sitter-java.wasm +0 -0
  183. package/dist/wasm/tree-sitter-javascript.wasm +0 -0
  184. package/dist/wasm/tree-sitter-python.wasm +0 -0
  185. package/dist/wasm/tree-sitter-rust.wasm +0 -0
  186. package/dist/wasm/web-tree-sitter.wasm +0 -0
  187. package/docs/SPEC.md +1021 -0
  188. package/examples/browser-example.html +610 -0
  189. package/examples/node-example.ts +215 -0
  190. package/package.json +107 -0
  191. package/wasm/tree-sitter-java.wasm +0 -0
  192. package/wasm/tree-sitter-javascript.wasm +0 -0
  193. package/wasm/tree-sitter-python.wasm +0 -0
  194. package/wasm/tree-sitter-rust.wasm +0 -0
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Language Plugin System
3
+ *
4
+ * Defines the interface for language-specific analysis plugins.
5
+ * Each language (Java, JavaScript, Python, Rust) implements this interface.
6
+ */
7
+ import type { Parser, Node as SyntaxNode, Tree } from 'web-tree-sitter';
8
+ import type { TypeInfo, CallInfo, ImportInfo } from '../types/index.js';
9
+ /**
10
+ * Supported languages for analysis
11
+ */
12
+ export type SupportedLanguage = 'java' | 'javascript' | 'typescript' | 'python' | 'rust';
13
+ /**
14
+ * AST node type mappings for a language
15
+ */
16
+ export interface LanguageNodeTypes {
17
+ classDeclaration: string[];
18
+ interfaceDeclaration: string[];
19
+ enumDeclaration: string[];
20
+ functionDeclaration: string[];
21
+ methodDeclaration: string[];
22
+ methodCall: string[];
23
+ functionCall: string[];
24
+ assignment: string[];
25
+ variableDeclaration: string[];
26
+ parameter: string[];
27
+ argument: string[];
28
+ annotation: string[];
29
+ decorator: string[];
30
+ importStatement: string[];
31
+ ifStatement: string[];
32
+ forStatement: string[];
33
+ whileStatement: string[];
34
+ tryStatement: string[];
35
+ returnStatement: string[];
36
+ }
37
+ /**
38
+ * Framework detection result
39
+ */
40
+ export interface FrameworkInfo {
41
+ name: string;
42
+ version?: string;
43
+ confidence: number;
44
+ indicators: string[];
45
+ }
46
+ /**
47
+ * Language-specific extraction context
48
+ */
49
+ export interface ExtractionContext {
50
+ filePath: string;
51
+ sourceCode: string;
52
+ tree: Tree;
53
+ package?: string;
54
+ imports: ImportInfo[];
55
+ framework?: FrameworkInfo;
56
+ }
57
+ /**
58
+ * Language Plugin Interface
59
+ *
60
+ * Each supported language must implement this interface.
61
+ */
62
+ export interface LanguagePlugin {
63
+ /**
64
+ * Language identifier
65
+ */
66
+ readonly id: SupportedLanguage;
67
+ /**
68
+ * Human-readable name
69
+ */
70
+ readonly name: string;
71
+ /**
72
+ * File extensions handled by this plugin
73
+ */
74
+ readonly extensions: string[];
75
+ /**
76
+ * Path to tree-sitter WASM grammar
77
+ */
78
+ readonly wasmPath: string;
79
+ /**
80
+ * AST node type mappings for this language
81
+ */
82
+ readonly nodeTypes: LanguageNodeTypes;
83
+ /**
84
+ * Initialize the plugin (load WASM, etc.)
85
+ */
86
+ initialize(parser: Parser): Promise<void>;
87
+ /**
88
+ * Check if a file path is handled by this plugin
89
+ */
90
+ canHandle(filePath: string): boolean;
91
+ /**
92
+ * Detect framework from imports and code patterns
93
+ */
94
+ detectFramework(context: ExtractionContext): FrameworkInfo | undefined;
95
+ /**
96
+ * Extract type definitions (classes, interfaces, etc.)
97
+ */
98
+ extractTypes(context: ExtractionContext): TypeInfo[];
99
+ /**
100
+ * Extract method/function calls
101
+ */
102
+ extractCalls(context: ExtractionContext): CallInfo[];
103
+ /**
104
+ * Extract import statements
105
+ */
106
+ extractImports(context: ExtractionContext): ImportInfo[];
107
+ /**
108
+ * Get the package/module name from the file
109
+ */
110
+ extractPackage(context: ExtractionContext): string | undefined;
111
+ /**
112
+ * Language-specific taint source patterns
113
+ * Returns additional sources beyond YAML config
114
+ */
115
+ getBuiltinSources(): TaintSourcePattern[];
116
+ /**
117
+ * Language-specific taint sink patterns
118
+ * Returns additional sinks beyond YAML config
119
+ */
120
+ getBuiltinSinks(): TaintSinkPattern[];
121
+ /**
122
+ * Get receiver type from a method call node
123
+ */
124
+ getReceiverType(node: SyntaxNode, context: ExtractionContext): string | undefined;
125
+ /**
126
+ * Check if a node represents a string literal
127
+ */
128
+ isStringLiteral(node: SyntaxNode): boolean;
129
+ /**
130
+ * Get string value from a literal node
131
+ */
132
+ getStringValue(node: SyntaxNode): string | undefined;
133
+ }
134
+ /**
135
+ * Taint source pattern definition
136
+ */
137
+ export interface TaintSourcePattern {
138
+ method?: string;
139
+ class?: string;
140
+ annotation?: string;
141
+ parameterPattern?: RegExp;
142
+ type: string;
143
+ severity: 'critical' | 'high' | 'medium' | 'low';
144
+ confidence: number;
145
+ returnTainted?: boolean;
146
+ paramPositions?: number[];
147
+ }
148
+ /**
149
+ * Taint sink pattern definition
150
+ */
151
+ export interface TaintSinkPattern {
152
+ method: string;
153
+ class?: string;
154
+ type: string;
155
+ cwe: string;
156
+ severity: 'critical' | 'high' | 'medium' | 'low';
157
+ argPositions: number[];
158
+ sanitizes?: string[];
159
+ }
160
+ /**
161
+ * Language plugin registry
162
+ */
163
+ export interface LanguageRegistry {
164
+ /**
165
+ * Register a language plugin
166
+ */
167
+ register(plugin: LanguagePlugin): void;
168
+ /**
169
+ * Get plugin for a language
170
+ */
171
+ get(language: SupportedLanguage): LanguagePlugin | undefined;
172
+ /**
173
+ * Get plugin for a file path
174
+ */
175
+ getForFile(filePath: string): LanguagePlugin | undefined;
176
+ /**
177
+ * Get all registered plugins
178
+ */
179
+ getAll(): LanguagePlugin[];
180
+ /**
181
+ * Get all supported languages
182
+ */
183
+ getSupportedLanguages(): SupportedLanguage[];
184
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Language Plugin System
3
+ *
4
+ * Defines the interface for language-specific analysis plugins.
5
+ * Each language (Java, JavaScript, Python, Rust) implements this interface.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/languages/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Cross-File Call Resolution
3
+ *
4
+ * Resolves method calls to their definitions across file boundaries,
5
+ * enabling cross-file taint tracking.
6
+ */
7
+ import type { CallInfo, CircleIR } from '../types/index.js';
8
+ import { SymbolTable } from './symbol-table.js';
9
+ import { TypeHierarchyResolver } from './type-hierarchy.js';
10
+ /**
11
+ * Resolved call with target information
12
+ */
13
+ export interface ResolvedCall {
14
+ call: CallInfo;
15
+ sourceFile: string;
16
+ targetFile: string;
17
+ targetMethod: string;
18
+ targetClass: string;
19
+ resolution: 'exact' | 'polymorphic' | 'inferred';
20
+ candidates?: string[];
21
+ }
22
+ /**
23
+ * Taint propagation information for a method
24
+ */
25
+ export interface MethodTaintInfo {
26
+ methodFqn: string;
27
+ file: string;
28
+ taintedParams: number[];
29
+ returnsSource: boolean;
30
+ sourceType?: string;
31
+ sanitizes: boolean;
32
+ sanitizedTypes?: string[];
33
+ }
34
+ /**
35
+ * Cross-file taint flow
36
+ */
37
+ export interface CrossFileTaintFlow {
38
+ sourceFile: string;
39
+ sourceLine: number;
40
+ sourceType: string;
41
+ targetFile: string;
42
+ targetLine: number;
43
+ targetMethod: string;
44
+ flowType: 'call_arg' | 'return_value' | 'field_access';
45
+ taintedArgPositions?: number[];
46
+ }
47
+ /**
48
+ * CrossFileResolver - Resolves calls and tracks taint across files
49
+ */
50
+ export declare class CrossFileResolver {
51
+ private symbolTable;
52
+ private typeHierarchy;
53
+ private fileIRs;
54
+ private methodTaintInfo;
55
+ private resolvedCalls;
56
+ constructor(symbolTable: SymbolTable, typeHierarchy: TypeHierarchyResolver);
57
+ /**
58
+ * Add a file's IR for analysis
59
+ */
60
+ addFile(filePath: string, ir: CircleIR): void;
61
+ /**
62
+ * Resolve a call to its target method(s)
63
+ */
64
+ resolveCall(call: CallInfo, fromFile: string): ResolvedCall | undefined;
65
+ /**
66
+ * Resolve call with a receiver (instance method call)
67
+ */
68
+ private resolveWithReceiver;
69
+ /**
70
+ * Resolve static or local method call
71
+ */
72
+ private resolveStaticOrLocal;
73
+ /**
74
+ * Resolve by searching all known methods
75
+ */
76
+ private resolveByMethodName;
77
+ /**
78
+ * Infer the type of a receiver variable
79
+ */
80
+ private inferReceiverType;
81
+ /**
82
+ * Find polymorphic candidates (implementations/subclasses)
83
+ */
84
+ private findPolymorphicCandidates;
85
+ /**
86
+ * Analyze methods for taint propagation characteristics
87
+ */
88
+ private analyzeMethodTaint;
89
+ /**
90
+ * Check if method is a taint source
91
+ */
92
+ private isMethodTaintSource;
93
+ /**
94
+ * Get source type for a method
95
+ */
96
+ private getSourceType;
97
+ /**
98
+ * Find which parameters propagate taint to return value
99
+ */
100
+ private findTaintedParams;
101
+ /**
102
+ * Check if method name suggests sanitization
103
+ */
104
+ private isSanitizerMethod;
105
+ /**
106
+ * Get types sanitized by a method
107
+ */
108
+ private getSanitizedTypes;
109
+ /**
110
+ * Find all callers of a method across the project
111
+ */
112
+ findCallers(methodFqn: string): ResolvedCall[];
113
+ /**
114
+ * Find cross-file taint flows
115
+ */
116
+ findCrossFileTaintFlows(): CrossFileTaintFlow[];
117
+ /**
118
+ * Get taint info for a method
119
+ */
120
+ getMethodTaintInfo(methodFqn: string): MethodTaintInfo | undefined;
121
+ /**
122
+ * Get all resolved calls from a file
123
+ */
124
+ getResolvedCallsFromFile(filePath: string): ResolvedCall[];
125
+ /**
126
+ * Get statistics
127
+ */
128
+ getStats(): {
129
+ totalFiles: number;
130
+ totalCalls: number;
131
+ resolvedCalls: number;
132
+ crossFileCalls: number;
133
+ methodsWithTaintInfo: number;
134
+ };
135
+ /**
136
+ * Clear all caches
137
+ */
138
+ clear(): void;
139
+ }
140
+ /**
141
+ * Build a cross-file resolver from multiple IR results
142
+ */
143
+ export declare function buildCrossFileResolver(files: Array<{
144
+ ir: CircleIR;
145
+ path: string;
146
+ }>, symbolTable?: SymbolTable, typeHierarchy?: TypeHierarchyResolver): CrossFileResolver;