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.
- package/LICENSE +15 -0
- package/README.md +200 -0
- package/configs/sinks/code_injection.yaml +672 -0
- package/configs/sinks/command.yaml +917 -0
- package/configs/sinks/deserialization.yaml +105 -0
- package/configs/sinks/ldap.yaml +136 -0
- package/configs/sinks/nodejs.json +629 -0
- package/configs/sinks/path.yaml +715 -0
- package/configs/sinks/python.json +501 -0
- package/configs/sinks/rust.json +339 -0
- package/configs/sinks/sql.yaml +233 -0
- package/configs/sinks/ssrf.yaml +160 -0
- package/configs/sinks/xpath.yaml +121 -0
- package/configs/sinks/xss.yaml +727 -0
- package/configs/sources/db_sources.yaml +90 -0
- package/configs/sources/env_sources.yaml +94 -0
- package/configs/sources/express.json +197 -0
- package/configs/sources/file_sources.yaml +164 -0
- package/configs/sources/http_sources.yaml +379 -0
- package/configs/sources/io_sources.yaml +519 -0
- package/configs/sources/network_sources.yaml +99 -0
- package/configs/sources/python.json +230 -0
- package/configs/sources/rust.json +286 -0
- package/configs/sources/spring.yaml +70 -0
- package/dist/analysis/advisory-db.d.ts +86 -0
- package/dist/analysis/advisory-db.js +104 -0
- package/dist/analysis/advisory-db.js.map +1 -0
- package/dist/analysis/cargo-parser.d.ts +42 -0
- package/dist/analysis/cargo-parser.js +102 -0
- package/dist/analysis/cargo-parser.js.map +1 -0
- package/dist/analysis/config-loader.d.ts +37 -0
- package/dist/analysis/config-loader.js +1561 -0
- package/dist/analysis/config-loader.js.map +1 -0
- package/dist/analysis/constant-propagation/ast-utils.d.ts +25 -0
- package/dist/analysis/constant-propagation/ast-utils.js +34 -0
- package/dist/analysis/constant-propagation/ast-utils.js.map +1 -0
- package/dist/analysis/constant-propagation/evaluator.d.ts +32 -0
- package/dist/analysis/constant-propagation/evaluator.js +296 -0
- package/dist/analysis/constant-propagation/evaluator.js.map +1 -0
- package/dist/analysis/constant-propagation/index.d.ts +62 -0
- package/dist/analysis/constant-propagation/index.js +152 -0
- package/dist/analysis/constant-propagation/index.js.map +1 -0
- package/dist/analysis/constant-propagation/patterns.d.ts +8 -0
- package/dist/analysis/constant-propagation/patterns.js +126 -0
- package/dist/analysis/constant-propagation/patterns.js.map +1 -0
- package/dist/analysis/constant-propagation/propagator.d.ts +180 -0
- package/dist/analysis/constant-propagation/propagator.js +1985 -0
- package/dist/analysis/constant-propagation/propagator.js.map +1 -0
- package/dist/analysis/constant-propagation/types.d.ts +63 -0
- package/dist/analysis/constant-propagation/types.js +5 -0
- package/dist/analysis/constant-propagation/types.js.map +1 -0
- package/dist/analysis/constant-propagation.d.ts +9 -0
- package/dist/analysis/constant-propagation.js +18 -0
- package/dist/analysis/constant-propagation.js.map +1 -0
- package/dist/analysis/dependency-scanner.d.ts +79 -0
- package/dist/analysis/dependency-scanner.js +122 -0
- package/dist/analysis/dependency-scanner.js.map +1 -0
- package/dist/analysis/dfg-verifier.d.ts +116 -0
- package/dist/analysis/dfg-verifier.js +399 -0
- package/dist/analysis/dfg-verifier.js.map +1 -0
- package/dist/analysis/findings.d.ts +11 -0
- package/dist/analysis/findings.js +228 -0
- package/dist/analysis/findings.js.map +1 -0
- package/dist/analysis/index.d.ts +16 -0
- package/dist/analysis/index.js +18 -0
- package/dist/analysis/index.js.map +1 -0
- package/dist/analysis/interprocedural.d.ts +99 -0
- package/dist/analysis/interprocedural.js +526 -0
- package/dist/analysis/interprocedural.js.map +1 -0
- package/dist/analysis/path-finder.d.ts +133 -0
- package/dist/analysis/path-finder.js +354 -0
- package/dist/analysis/path-finder.js.map +1 -0
- package/dist/analysis/rules.d.ts +75 -0
- package/dist/analysis/rules.js +332 -0
- package/dist/analysis/rules.js.map +1 -0
- package/dist/analysis/semver.d.ts +27 -0
- package/dist/analysis/semver.js +127 -0
- package/dist/analysis/semver.js.map +1 -0
- package/dist/analysis/taint-matcher.d.ts +15 -0
- package/dist/analysis/taint-matcher.js +634 -0
- package/dist/analysis/taint-matcher.js.map +1 -0
- package/dist/analysis/taint-propagation.d.ts +67 -0
- package/dist/analysis/taint-propagation.js +298 -0
- package/dist/analysis/taint-propagation.js.map +1 -0
- package/dist/analysis/unresolved.d.ts +14 -0
- package/dist/analysis/unresolved.js +202 -0
- package/dist/analysis/unresolved.js.map +1 -0
- package/dist/analyzer.d.ts +43 -0
- package/dist/analyzer.js +1010 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/browser/circle-ir.js +16576 -0
- package/dist/browser.d.ts +38 -0
- package/dist/browser.js +38 -0
- package/dist/browser.js.map +1 -0
- package/dist/core/circle-ir-core.cjs +13626 -0
- package/dist/core/circle-ir-core.d.ts +59 -0
- package/dist/core/circle-ir-core.js +13591 -0
- package/dist/core/extractors/calls.d.ts +13 -0
- package/dist/core/extractors/calls.js +1429 -0
- package/dist/core/extractors/calls.js.map +1 -0
- package/dist/core/extractors/cfg.d.ts +9 -0
- package/dist/core/extractors/cfg.js +519 -0
- package/dist/core/extractors/cfg.js.map +1 -0
- package/dist/core/extractors/dfg.d.ts +12 -0
- package/dist/core/extractors/dfg.js +1081 -0
- package/dist/core/extractors/dfg.js.map +1 -0
- package/dist/core/extractors/exports.d.ts +14 -0
- package/dist/core/extractors/exports.js +80 -0
- package/dist/core/extractors/exports.js.map +1 -0
- package/dist/core/extractors/imports.d.ts +9 -0
- package/dist/core/extractors/imports.js +739 -0
- package/dist/core/extractors/imports.js.map +1 -0
- package/dist/core/extractors/index.d.ts +10 -0
- package/dist/core/extractors/index.js +11 -0
- package/dist/core/extractors/index.js.map +1 -0
- package/dist/core/extractors/meta.d.ts +10 -0
- package/dist/core/extractors/meta.js +109 -0
- package/dist/core/extractors/meta.js.map +1 -0
- package/dist/core/extractors/types.d.ts +10 -0
- package/dist/core/extractors/types.js +1479 -0
- package/dist/core/extractors/types.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +8 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/parser.d.ts +84 -0
- package/dist/core/parser.js +250 -0
- package/dist/core/parser.js.map +1 -0
- package/dist/core-lib.d.ts +59 -0
- package/dist/core-lib.js +62 -0
- package/dist/core-lib.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/languages/index.d.ts +11 -0
- package/dist/languages/index.js +14 -0
- package/dist/languages/index.js.map +1 -0
- package/dist/languages/plugins/base.d.ts +44 -0
- package/dist/languages/plugins/base.js +82 -0
- package/dist/languages/plugins/base.js.map +1 -0
- package/dist/languages/plugins/index.d.ts +14 -0
- package/dist/languages/plugins/index.js +25 -0
- package/dist/languages/plugins/index.js.map +1 -0
- package/dist/languages/plugins/java.d.ts +49 -0
- package/dist/languages/plugins/java.js +402 -0
- package/dist/languages/plugins/java.js.map +1 -0
- package/dist/languages/plugins/javascript.d.ts +48 -0
- package/dist/languages/plugins/javascript.js +445 -0
- package/dist/languages/plugins/javascript.js.map +1 -0
- package/dist/languages/plugins/python.d.ts +47 -0
- package/dist/languages/plugins/python.js +480 -0
- package/dist/languages/plugins/python.js.map +1 -0
- package/dist/languages/plugins/rust.d.ts +47 -0
- package/dist/languages/plugins/rust.js +405 -0
- package/dist/languages/plugins/rust.js.map +1 -0
- package/dist/languages/registry.d.ts +30 -0
- package/dist/languages/registry.js +80 -0
- package/dist/languages/registry.js.map +1 -0
- package/dist/languages/types.d.ts +184 -0
- package/dist/languages/types.js +8 -0
- package/dist/languages/types.js.map +1 -0
- package/dist/resolution/cross-file.d.ts +146 -0
- package/dist/resolution/cross-file.js +439 -0
- package/dist/resolution/cross-file.js.map +1 -0
- package/dist/resolution/index.d.ts +12 -0
- package/dist/resolution/index.js +10 -0
- package/dist/resolution/index.js.map +1 -0
- package/dist/resolution/symbol-table.d.ts +136 -0
- package/dist/resolution/symbol-table.js +336 -0
- package/dist/resolution/symbol-table.js.map +1 -0
- package/dist/resolution/type-hierarchy.d.ts +124 -0
- package/dist/resolution/type-hierarchy.js +515 -0
- package/dist/resolution/type-hierarchy.js.map +1 -0
- package/dist/types/config.d.ts +45 -0
- package/dist/types/config.js +5 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +392 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +85 -0
- package/dist/utils/logger.js +198 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/wasm/tree-sitter-java.wasm +0 -0
- package/dist/wasm/tree-sitter-javascript.wasm +0 -0
- package/dist/wasm/tree-sitter-python.wasm +0 -0
- package/dist/wasm/tree-sitter-rust.wasm +0 -0
- package/dist/wasm/web-tree-sitter.wasm +0 -0
- package/docs/SPEC.md +1021 -0
- package/examples/browser-example.html +610 -0
- package/examples/node-example.ts +215 -0
- package/package.json +107 -0
- package/wasm/tree-sitter-java.wasm +0 -0
- package/wasm/tree-sitter-javascript.wasm +0 -0
- package/wasm/tree-sitter-python.wasm +0 -0
- package/wasm/tree-sitter-rust.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Cognium Labs
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# circle-ir
|
|
2
|
+
|
|
3
|
+
A high-performance Static Application Security Testing (SAST) library for detecting security vulnerabilities through taint analysis. Works in Node.js, browsers, and Cloudflare Workers.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Taint Analysis**: Track data flow from sources (user input) to sinks (dangerous operations)
|
|
8
|
+
- **Multi-language Support**: Java, JavaScript/TypeScript, Python, Rust
|
|
9
|
+
- **High Accuracy**: 100% on OWASP Benchmark, 100% on Juliet Test Suite, 98.1% TPR on SecuriBench Micro
|
|
10
|
+
- **Universal**: Works in Node.js, browsers, and Cloudflare Workers
|
|
11
|
+
- **Zero External Dependencies**: Core analysis runs without network calls or external services
|
|
12
|
+
- **Browser Compatible**: Tree-sitter WASM for universal parsing
|
|
13
|
+
- **Configuration-Driven**: YAML/JSON patterns for sources, sinks, and sanitizers
|
|
14
|
+
|
|
15
|
+
## Related Packages
|
|
16
|
+
|
|
17
|
+
- **[circle-ir-ai](https://github.com/cogniumhq/circle-ir-ai)**: LLM-enhanced analysis with CLI
|
|
18
|
+
- **[circle-pack](https://github.com/cogniumhq/circle-pack)**: Cloudflare Workers API deployment
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install circle-ir
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Node.js
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { initAnalyzer, analyze } from 'circle-ir';
|
|
32
|
+
|
|
33
|
+
// Initialize the analyzer
|
|
34
|
+
await initAnalyzer();
|
|
35
|
+
|
|
36
|
+
// Analyze Java code
|
|
37
|
+
const result = await analyze(code, 'MyClass.java', 'java');
|
|
38
|
+
|
|
39
|
+
// Check for vulnerabilities
|
|
40
|
+
for (const flow of result.taint.flows || []) {
|
|
41
|
+
console.log(`Found ${flow.sink_type} vulnerability`);
|
|
42
|
+
console.log(` Source: line ${flow.source_line}`);
|
|
43
|
+
console.log(` Sink: line ${flow.sink_line}`);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Browser
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<script type="module">
|
|
51
|
+
import { initAnalyzer, analyze } from './dist/browser/circle-ir.js';
|
|
52
|
+
|
|
53
|
+
await initAnalyzer({
|
|
54
|
+
wasmPath: './wasm/web-tree-sitter.wasm',
|
|
55
|
+
languagePaths: {
|
|
56
|
+
java: './wasm/tree-sitter-java.wasm'
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const result = await analyze(code, 'Test.java', 'java');
|
|
61
|
+
console.log(result);
|
|
62
|
+
</script>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API Reference
|
|
66
|
+
|
|
67
|
+
### `initAnalyzer(options?)`
|
|
68
|
+
|
|
69
|
+
Initialize the analyzer. Must be called before `analyze()`.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
interface AnalyzerOptions {
|
|
73
|
+
wasmPath?: string; // Path to web-tree-sitter.wasm
|
|
74
|
+
languagePaths?: { // Paths to language WASM files
|
|
75
|
+
java?: string;
|
|
76
|
+
javascript?: string;
|
|
77
|
+
python?: string;
|
|
78
|
+
rust?: string;
|
|
79
|
+
};
|
|
80
|
+
taintConfig?: TaintConfig; // Custom taint configuration
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### `analyze(code, filePath, language, options?)`
|
|
85
|
+
|
|
86
|
+
Analyze source code and return Circle-IR output.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const result = await analyze(code, 'File.java', 'java');
|
|
90
|
+
|
|
91
|
+
// Result contains:
|
|
92
|
+
result.meta // File metadata
|
|
93
|
+
result.types // Classes, methods, fields
|
|
94
|
+
result.calls // Method invocations
|
|
95
|
+
result.cfg // Control flow graph
|
|
96
|
+
result.dfg // Data flow graph
|
|
97
|
+
result.taint // Taint sources, sinks, flows
|
|
98
|
+
result.imports // Import statements
|
|
99
|
+
result.exports // Exported symbols
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `analyzeForAPI(code, filePath, language, options?)`
|
|
103
|
+
|
|
104
|
+
Simplified API response format suitable for REST APIs.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const response = await analyzeForAPI(code, 'File.java', 'java');
|
|
108
|
+
|
|
109
|
+
// Response format:
|
|
110
|
+
{
|
|
111
|
+
success: true,
|
|
112
|
+
analysis: {
|
|
113
|
+
sources: [...],
|
|
114
|
+
sinks: [...],
|
|
115
|
+
vulnerabilities: [...]
|
|
116
|
+
},
|
|
117
|
+
meta: {
|
|
118
|
+
parseTimeMs: 15,
|
|
119
|
+
analysisTimeMs: 42,
|
|
120
|
+
totalTimeMs: 57
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Supported Languages
|
|
126
|
+
|
|
127
|
+
| Language | Parser | Frameworks |
|
|
128
|
+
|----------|--------|------------|
|
|
129
|
+
| **Java** | tree-sitter-java | Spring, JAX-RS, Servlet API |
|
|
130
|
+
| **JavaScript/TypeScript** | tree-sitter-javascript | Express, Fastify, Node.js |
|
|
131
|
+
| **Python** | tree-sitter-python | Flask, Django, FastAPI |
|
|
132
|
+
| **Rust** | tree-sitter-rust | Actix-web, Rocket, Axum |
|
|
133
|
+
|
|
134
|
+
### Multi-Language Examples
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// Analyze JavaScript
|
|
138
|
+
const jsResult = await analyze(jsCode, 'server.js', 'javascript');
|
|
139
|
+
|
|
140
|
+
// Analyze Python
|
|
141
|
+
const pyResult = await analyze(pyCode, 'app.py', 'python');
|
|
142
|
+
|
|
143
|
+
// Analyze Rust
|
|
144
|
+
const rsResult = await analyze(rsCode, 'main.rs', 'rust');
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Detected Vulnerabilities
|
|
148
|
+
|
|
149
|
+
| Type | CWE | Description |
|
|
150
|
+
|------|-----|-------------|
|
|
151
|
+
| SQL Injection | CWE-89 | User input in SQL queries |
|
|
152
|
+
| Command Injection | CWE-78 | User input in system commands |
|
|
153
|
+
| XSS | CWE-79 | User input in HTML output |
|
|
154
|
+
| Path Traversal | CWE-22 | User input in file paths |
|
|
155
|
+
| LDAP Injection | CWE-90 | User input in LDAP queries |
|
|
156
|
+
| XPath Injection | CWE-643 | User input in XPath queries |
|
|
157
|
+
| Deserialization | CWE-502 | Untrusted deserialization |
|
|
158
|
+
| SSRF | CWE-918 | Server-side request forgery |
|
|
159
|
+
| Code Injection | CWE-94 | Dynamic code execution |
|
|
160
|
+
| XXE | CWE-611 | XML external entity injection |
|
|
161
|
+
|
|
162
|
+
## Configuration
|
|
163
|
+
|
|
164
|
+
Custom taint sources, sinks, and sanitizers can be configured via YAML:
|
|
165
|
+
|
|
166
|
+
```yaml
|
|
167
|
+
# configs/sources/custom.yaml
|
|
168
|
+
sources:
|
|
169
|
+
- method: getUserInput
|
|
170
|
+
class: CustomInputHandler
|
|
171
|
+
type: http_param
|
|
172
|
+
severity: high
|
|
173
|
+
tainted_args: [return]
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Key Analysis Features
|
|
177
|
+
|
|
178
|
+
- **Constant Propagation**: Eliminates false positives by tracking variable values and detecting dead code
|
|
179
|
+
- **DFG-Based Verification**: Uses data flow graphs to verify end-to-end taint flows
|
|
180
|
+
- **Inter-Procedural Analysis**: Tracks taint across method boundaries
|
|
181
|
+
- **Sanitizer Recognition**: Detects PreparedStatement, ESAPI, escapeHtml, and other sanitizers
|
|
182
|
+
- **Collection Tracking**: Precise taint tracking through List/Map operations with index shifting
|
|
183
|
+
|
|
184
|
+
## Benchmark Results
|
|
185
|
+
|
|
186
|
+
| Benchmark | Score | Details |
|
|
187
|
+
|-----------|-------|---------|
|
|
188
|
+
| **OWASP Benchmark** | +100% | TPR 100%, FPR 0% (1415 test cases) |
|
|
189
|
+
| **Juliet Test Suite** | +100% | 156/156 test cases, 9 CWEs |
|
|
190
|
+
| **SecuriBench Micro** | 98.1% TPR | 106/108 vulns detected, 6.7% FPR |
|
|
191
|
+
| **CWE-Bench-Java** | 65.5% | 509/777 real-world CVEs |
|
|
192
|
+
|
|
193
|
+
## Documentation
|
|
194
|
+
|
|
195
|
+
- [Circle-IR Specification](docs/SPEC.md) - IR format specification
|
|
196
|
+
- [Architecture Guide](docs/ARCHITECTURE.md) - Detailed system architecture
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
ISC
|