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
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Security Rule Definitions
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for vulnerability types, severity levels,
|
|
5
|
+
* descriptions, and remediation advice used across the codebase.
|
|
6
|
+
*/
|
|
7
|
+
// =============================================================================
|
|
8
|
+
// Sink Categories
|
|
9
|
+
// =============================================================================
|
|
10
|
+
/** Sinks that warrant critical severity when exploitable. */
|
|
11
|
+
export const CRITICAL_SINKS = [
|
|
12
|
+
'sql_injection',
|
|
13
|
+
'command_injection',
|
|
14
|
+
'deserialization',
|
|
15
|
+
'code_injection',
|
|
16
|
+
];
|
|
17
|
+
/** Sinks that warrant high severity. */
|
|
18
|
+
export const HIGH_SINKS = [
|
|
19
|
+
'xss',
|
|
20
|
+
'path_traversal',
|
|
21
|
+
'xxe',
|
|
22
|
+
'ssrf',
|
|
23
|
+
'ldap_injection',
|
|
24
|
+
'xpath_injection',
|
|
25
|
+
];
|
|
26
|
+
/** Source types that represent direct HTTP user input. */
|
|
27
|
+
export const HIGH_SEVERITY_SOURCES = [
|
|
28
|
+
'http_param',
|
|
29
|
+
'http_body',
|
|
30
|
+
'http_header',
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Complete rule definitions for all supported vulnerability types.
|
|
34
|
+
*/
|
|
35
|
+
export const RULE_DEFINITIONS = {
|
|
36
|
+
sql_injection: {
|
|
37
|
+
name: 'SQL Injection',
|
|
38
|
+
shortDescription: 'User input used in SQL query without sanitization',
|
|
39
|
+
fullDescription: 'The application constructs SQL queries using user-controlled input without proper sanitization or parameterization, allowing attackers to manipulate database queries.',
|
|
40
|
+
remediation: 'Use parameterized queries or prepared statements. Never concatenate user input directly into SQL strings.',
|
|
41
|
+
cvssScore: '9.8',
|
|
42
|
+
severityLevel: 'critical',
|
|
43
|
+
cwe: 'CWE-89',
|
|
44
|
+
},
|
|
45
|
+
nosql_injection: {
|
|
46
|
+
name: 'NoSQL Injection',
|
|
47
|
+
shortDescription: 'User input used in NoSQL query without sanitization',
|
|
48
|
+
fullDescription: 'The application constructs NoSQL queries using user-controlled input, allowing attackers to manipulate database queries in MongoDB, CouchDB, or similar databases.',
|
|
49
|
+
remediation: 'Validate and sanitize user input. Use parameterized queries. Avoid using $where with user input.',
|
|
50
|
+
cvssScore: '9.8',
|
|
51
|
+
severityLevel: 'critical',
|
|
52
|
+
cwe: 'CWE-943',
|
|
53
|
+
},
|
|
54
|
+
command_injection: {
|
|
55
|
+
name: 'Command Injection',
|
|
56
|
+
shortDescription: 'User input used in system command without sanitization',
|
|
57
|
+
fullDescription: 'The application executes system commands using user-controlled input, allowing attackers to execute arbitrary commands on the server.',
|
|
58
|
+
remediation: 'Avoid executing system commands with user input. If necessary, use strict input validation and avoid shell interpreters.',
|
|
59
|
+
cvssScore: '9.8',
|
|
60
|
+
severityLevel: 'critical',
|
|
61
|
+
cwe: 'CWE-78',
|
|
62
|
+
},
|
|
63
|
+
xss: {
|
|
64
|
+
name: 'Cross-Site Scripting (XSS)',
|
|
65
|
+
shortDescription: 'User input rendered in HTML without encoding',
|
|
66
|
+
fullDescription: 'The application includes user-controlled input in HTML output without proper encoding, allowing attackers to inject malicious scripts.',
|
|
67
|
+
remediation: 'Encode all user input before rendering in HTML. Use context-appropriate encoding (HTML, JavaScript, URL, CSS).',
|
|
68
|
+
cvssScore: '6.1',
|
|
69
|
+
severityLevel: 'medium',
|
|
70
|
+
cwe: 'CWE-79',
|
|
71
|
+
},
|
|
72
|
+
path_traversal: {
|
|
73
|
+
name: 'Path Traversal',
|
|
74
|
+
shortDescription: 'User input used in file path without validation',
|
|
75
|
+
fullDescription: 'The application uses user-controlled input to construct file paths, allowing attackers to access files outside the intended directory.',
|
|
76
|
+
remediation: 'Validate and sanitize file paths. Use allowlists for permitted directories. Resolve and verify canonical paths.',
|
|
77
|
+
cvssScore: '7.5',
|
|
78
|
+
severityLevel: 'high',
|
|
79
|
+
cwe: 'CWE-22',
|
|
80
|
+
},
|
|
81
|
+
deserialization: {
|
|
82
|
+
name: 'Unsafe Deserialization',
|
|
83
|
+
shortDescription: 'Untrusted data deserialized without validation',
|
|
84
|
+
fullDescription: 'The application deserializes data from untrusted sources, potentially allowing attackers to execute arbitrary code.',
|
|
85
|
+
remediation: 'Avoid deserializing untrusted data. Use safe serialization formats like JSON. Implement integrity checks.',
|
|
86
|
+
cvssScore: '9.8',
|
|
87
|
+
severityLevel: 'critical',
|
|
88
|
+
cwe: 'CWE-502',
|
|
89
|
+
},
|
|
90
|
+
xxe: {
|
|
91
|
+
name: 'XML External Entity (XXE)',
|
|
92
|
+
shortDescription: 'XML parser processes external entities from untrusted input',
|
|
93
|
+
fullDescription: 'The application parses XML with external entity processing enabled, allowing attackers to read local files or make server-side requests.',
|
|
94
|
+
remediation: 'Disable external entity processing in XML parsers. Use less complex data formats when possible.',
|
|
95
|
+
cvssScore: '7.5',
|
|
96
|
+
severityLevel: 'high',
|
|
97
|
+
cwe: 'CWE-611',
|
|
98
|
+
},
|
|
99
|
+
ldap_injection: {
|
|
100
|
+
name: 'LDAP Injection',
|
|
101
|
+
shortDescription: 'User input used in LDAP query without sanitization',
|
|
102
|
+
fullDescription: 'The application constructs LDAP queries using user-controlled input without proper sanitization.',
|
|
103
|
+
remediation: 'Use parameterized LDAP queries. Escape special characters in user input.',
|
|
104
|
+
cvssScore: '8.1',
|
|
105
|
+
severityLevel: 'high',
|
|
106
|
+
cwe: 'CWE-90',
|
|
107
|
+
},
|
|
108
|
+
xpath_injection: {
|
|
109
|
+
name: 'XPath Injection',
|
|
110
|
+
shortDescription: 'User input used in XPath query without sanitization',
|
|
111
|
+
fullDescription: 'The application constructs XPath queries using user-controlled input without proper sanitization.',
|
|
112
|
+
remediation: 'Use parameterized XPath queries. Compile expressions with variables instead of concatenation.',
|
|
113
|
+
cvssScore: '7.5',
|
|
114
|
+
severityLevel: 'high',
|
|
115
|
+
cwe: 'CWE-643',
|
|
116
|
+
},
|
|
117
|
+
ssrf: {
|
|
118
|
+
name: 'Server-Side Request Forgery (SSRF)',
|
|
119
|
+
shortDescription: 'User input used in server-side URL request',
|
|
120
|
+
fullDescription: 'The application makes HTTP requests to URLs controlled by user input, allowing attackers to access internal services.',
|
|
121
|
+
remediation: 'Validate and allowlist URLs. Block private IP ranges and internal hostnames.',
|
|
122
|
+
cvssScore: '8.6',
|
|
123
|
+
severityLevel: 'high',
|
|
124
|
+
cwe: 'CWE-918',
|
|
125
|
+
},
|
|
126
|
+
open_redirect: {
|
|
127
|
+
name: 'Open Redirect',
|
|
128
|
+
shortDescription: 'User input used in redirect URL',
|
|
129
|
+
fullDescription: 'The application redirects to URLs controlled by user input, allowing attackers to redirect users to malicious sites.',
|
|
130
|
+
remediation: 'Validate redirect URLs against an allowlist. Use relative URLs or validate the host component.',
|
|
131
|
+
cvssScore: '6.1',
|
|
132
|
+
severityLevel: 'medium',
|
|
133
|
+
cwe: 'CWE-601',
|
|
134
|
+
},
|
|
135
|
+
log_injection: {
|
|
136
|
+
name: 'Log Injection',
|
|
137
|
+
shortDescription: 'User input written to logs without sanitization',
|
|
138
|
+
fullDescription: 'The application writes user-controlled input directly to logs without sanitization, allowing attackers to forge log entries or inject malicious content.',
|
|
139
|
+
remediation: 'Sanitize log messages by removing or escaping newlines and control characters.',
|
|
140
|
+
cvssScore: '5.3',
|
|
141
|
+
severityLevel: 'low',
|
|
142
|
+
cwe: 'CWE-117',
|
|
143
|
+
},
|
|
144
|
+
code_injection: {
|
|
145
|
+
name: 'Code Injection',
|
|
146
|
+
shortDescription: 'User input executed as code',
|
|
147
|
+
fullDescription: 'The application evaluates user-controlled input as code, allowing attackers to execute arbitrary code.',
|
|
148
|
+
remediation: 'Avoid dynamic code evaluation. If necessary, use strict sandboxing and input validation.',
|
|
149
|
+
cvssScore: '9.8',
|
|
150
|
+
severityLevel: 'critical',
|
|
151
|
+
cwe: 'CWE-94',
|
|
152
|
+
},
|
|
153
|
+
weak_random: {
|
|
154
|
+
name: 'Weak Random Number Generator',
|
|
155
|
+
shortDescription: 'Cryptographically weak random number generator used',
|
|
156
|
+
fullDescription: 'The application uses a weak random number generator for security-sensitive operations.',
|
|
157
|
+
remediation: 'Use java.security.SecureRandom instead of java.util.Random for security-sensitive operations.',
|
|
158
|
+
cvssScore: '5.3',
|
|
159
|
+
severityLevel: 'medium',
|
|
160
|
+
cwe: 'CWE-330',
|
|
161
|
+
},
|
|
162
|
+
weak_hash: {
|
|
163
|
+
name: 'Weak Hash Algorithm',
|
|
164
|
+
shortDescription: 'Cryptographically weak hash algorithm used',
|
|
165
|
+
fullDescription: 'The application uses a weak hash algorithm (MD5, SHA-1) for security-sensitive operations.',
|
|
166
|
+
remediation: 'Use strong hash algorithms like SHA-256 or SHA-3. Avoid MD5 and SHA-1.',
|
|
167
|
+
cvssScore: '5.3',
|
|
168
|
+
severityLevel: 'medium',
|
|
169
|
+
cwe: 'CWE-328',
|
|
170
|
+
},
|
|
171
|
+
weak_crypto: {
|
|
172
|
+
name: 'Weak Cipher Algorithm',
|
|
173
|
+
shortDescription: 'Cryptographically weak encryption algorithm used',
|
|
174
|
+
fullDescription: 'The application uses a weak encryption algorithm that may be vulnerable to attacks.',
|
|
175
|
+
remediation: 'Use strong encryption algorithms like AES. Avoid DES, 3DES, RC4, and Blowfish.',
|
|
176
|
+
cvssScore: '5.3',
|
|
177
|
+
severityLevel: 'medium',
|
|
178
|
+
cwe: 'CWE-327',
|
|
179
|
+
},
|
|
180
|
+
insecure_cookie: {
|
|
181
|
+
name: 'Insecure Cookie',
|
|
182
|
+
shortDescription: 'Cookie set without security flags',
|
|
183
|
+
fullDescription: 'The application sets cookies without Secure, HttpOnly, or SameSite flags.',
|
|
184
|
+
remediation: 'Set Secure and HttpOnly flags on cookies. Use SameSite attribute.',
|
|
185
|
+
cvssScore: '4.3',
|
|
186
|
+
severityLevel: 'low',
|
|
187
|
+
cwe: 'CWE-614',
|
|
188
|
+
},
|
|
189
|
+
trust_boundary: {
|
|
190
|
+
name: 'Trust Boundary Violation',
|
|
191
|
+
shortDescription: 'Untrusted data crosses trust boundary',
|
|
192
|
+
fullDescription: 'The application stores untrusted user input in a trusted context (e.g., session).',
|
|
193
|
+
remediation: 'Validate and sanitize data before storing in session. Do not trust user input.',
|
|
194
|
+
cvssScore: '5.3',
|
|
195
|
+
severityLevel: 'medium',
|
|
196
|
+
cwe: 'CWE-501',
|
|
197
|
+
},
|
|
198
|
+
external_taint_escape: {
|
|
199
|
+
name: 'Tainted Data Passed to External Method',
|
|
200
|
+
shortDescription: 'User-controlled data passed to external method call',
|
|
201
|
+
fullDescription: 'The application passes user-controlled data to an external method that cannot be analyzed. This may result in security vulnerabilities if the external method does not properly sanitize the data.',
|
|
202
|
+
remediation: 'Sanitize user input before passing to external methods. Review external method documentation for security requirements.',
|
|
203
|
+
cvssScore: '5.0',
|
|
204
|
+
severityLevel: 'medium',
|
|
205
|
+
cwe: 'CWE-668',
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
// =============================================================================
|
|
209
|
+
// Lookup Functions
|
|
210
|
+
// =============================================================================
|
|
211
|
+
/**
|
|
212
|
+
* Get complete rule information for a sink type.
|
|
213
|
+
*/
|
|
214
|
+
export function getRuleInfo(sinkType) {
|
|
215
|
+
const rule = RULE_DEFINITIONS[sinkType];
|
|
216
|
+
if (rule) {
|
|
217
|
+
return rule;
|
|
218
|
+
}
|
|
219
|
+
// Fallback for unknown types
|
|
220
|
+
return {
|
|
221
|
+
name: sinkType,
|
|
222
|
+
shortDescription: `Potential security issue: ${sinkType}`,
|
|
223
|
+
fullDescription: `The application may be vulnerable to ${sinkType} attacks.`,
|
|
224
|
+
remediation: 'Review and sanitize user input before use.',
|
|
225
|
+
cvssScore: '5.0',
|
|
226
|
+
severityLevel: 'medium',
|
|
227
|
+
cwe: 'CWE-20',
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get remediation advice for a sink type.
|
|
232
|
+
*/
|
|
233
|
+
export function getRemediation(sinkType) {
|
|
234
|
+
return getRuleInfo(sinkType).remediation;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get severity level for a sink type.
|
|
238
|
+
*/
|
|
239
|
+
export function getSeverityLevel(sinkType) {
|
|
240
|
+
return getRuleInfo(sinkType).severityLevel;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get CWE identifier for a sink type.
|
|
244
|
+
*/
|
|
245
|
+
export function getCwe(sinkType) {
|
|
246
|
+
return getRuleInfo(sinkType).cwe;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Check if a sink type is critical severity.
|
|
250
|
+
*/
|
|
251
|
+
export function isCriticalSink(sinkType) {
|
|
252
|
+
return CRITICAL_SINKS.includes(sinkType);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Check if a sink type is high severity.
|
|
256
|
+
*/
|
|
257
|
+
export function isHighSink(sinkType) {
|
|
258
|
+
return HIGH_SINKS.includes(sinkType);
|
|
259
|
+
}
|
|
260
|
+
// =============================================================================
|
|
261
|
+
// Source Descriptions
|
|
262
|
+
// =============================================================================
|
|
263
|
+
const SOURCE_DESCRIPTIONS = {
|
|
264
|
+
http_param: 'User-controlled HTTP parameter',
|
|
265
|
+
http_body: 'User-controlled request body',
|
|
266
|
+
http_header: 'User-controlled HTTP header',
|
|
267
|
+
http_cookie: 'User-controlled cookie value',
|
|
268
|
+
http_path: 'User-controlled URL path',
|
|
269
|
+
http_query: 'User-controlled query string',
|
|
270
|
+
io_input: 'External file/console input',
|
|
271
|
+
env_input: 'Environment variable',
|
|
272
|
+
db_input: 'Database-sourced data',
|
|
273
|
+
file_input: 'File content',
|
|
274
|
+
network_input: 'Network input',
|
|
275
|
+
config_param: 'Servlet configuration parameter',
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Get human-readable description for a source type.
|
|
279
|
+
*/
|
|
280
|
+
export function getSourceDescription(sourceType) {
|
|
281
|
+
return SOURCE_DESCRIPTIONS[sourceType] ?? 'Tainted data';
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get human-readable description for a sink type.
|
|
285
|
+
*/
|
|
286
|
+
export function getSinkDescription(sinkType) {
|
|
287
|
+
const rule = RULE_DEFINITIONS[sinkType];
|
|
288
|
+
if (rule) {
|
|
289
|
+
// Convert name to lowercase description
|
|
290
|
+
return rule.name.toLowerCase();
|
|
291
|
+
}
|
|
292
|
+
return 'dangerous operation';
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Calculate severity based on source, sink, and path information.
|
|
296
|
+
*/
|
|
297
|
+
export function calculateSeverity(context) {
|
|
298
|
+
const { sourceType, sinkType, pathExists, confidence = 0.5 } = context;
|
|
299
|
+
const isCritical = isCriticalSink(sinkType);
|
|
300
|
+
const isHigh = isHighSink(sinkType);
|
|
301
|
+
const isHttpSource = sourceType ? HIGH_SEVERITY_SOURCES.includes(sourceType) : false;
|
|
302
|
+
// Critical: Direct path from HTTP to critical sink
|
|
303
|
+
if (pathExists && isCritical && isHttpSource) {
|
|
304
|
+
return 'critical';
|
|
305
|
+
}
|
|
306
|
+
// Critical: High confidence path to critical sink
|
|
307
|
+
if (pathExists && isCritical && confidence > 0.8) {
|
|
308
|
+
return 'critical';
|
|
309
|
+
}
|
|
310
|
+
// High: HTTP source to critical sink (even without confirmed path)
|
|
311
|
+
if (isHttpSource && isCritical) {
|
|
312
|
+
return 'high';
|
|
313
|
+
}
|
|
314
|
+
// High: Confirmed path to critical sink
|
|
315
|
+
if (pathExists && isCritical) {
|
|
316
|
+
return 'high';
|
|
317
|
+
}
|
|
318
|
+
// High: High confidence path to high-severity sink
|
|
319
|
+
if (pathExists && isHigh && confidence > 0.8) {
|
|
320
|
+
return 'high';
|
|
321
|
+
}
|
|
322
|
+
// Medium: Path exists but not critical
|
|
323
|
+
if (pathExists) {
|
|
324
|
+
return 'medium';
|
|
325
|
+
}
|
|
326
|
+
// Medium: Proximity to critical/high sink
|
|
327
|
+
if (isCritical || isHigh) {
|
|
328
|
+
return 'medium';
|
|
329
|
+
}
|
|
330
|
+
return 'low';
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/analysis/rules.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,cAAc,GAAe;IACxC,eAAe;IACf,mBAAmB;IACnB,iBAAiB;IACjB,gBAAgB;CACjB,CAAC;AAEF,wCAAwC;AACxC,MAAM,CAAC,MAAM,UAAU,GAAe;IACpC,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,MAAM;IACN,gBAAgB;IAChB,iBAAiB;CAClB,CAAC;AAEF,0DAA0D;AAC1D,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,YAAY;IACZ,WAAW;IACX,aAAa;CACd,CAAC;AA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mDAAmD;IACnD,IAAI,UAAU,IAAI,UAAU,IAAI,YAAY,EAAE,CAAC;QAC7C,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,kDAAkD;IAClD,IAAI,UAAU,IAAI,UAAU,IAAI,UAAU,GAAG,GAAG,EAAE,CAAC;QACjD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,mEAAmE;IACnE,IAAI,YAAY,IAAI,UAAU,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,wCAAwC;IACxC,IAAI,UAAU,IAAI,UAAU,EAAE,CAAC;QAC7B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,mDAAmD;IACnD,IAAI,UAAU,IAAI,MAAM,IAAI,UAAU,GAAG,GAAG,EAAE,CAAC;QAC7C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,uCAAuC;IACvC,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,0CAA0C;IAC1C,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semver version matching for RustSec advisory version constraints
|
|
3
|
+
* Supports: "1.0.0", "^1.0.0", ">=1.0.0", "<2.0.0", etc.
|
|
4
|
+
*/
|
|
5
|
+
export interface ParsedVersion {
|
|
6
|
+
major: number;
|
|
7
|
+
minor: number;
|
|
8
|
+
patch: number;
|
|
9
|
+
prerelease?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse a version string into components
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseVersion(version: string): ParsedVersion;
|
|
15
|
+
/**
|
|
16
|
+
* Compare two versions
|
|
17
|
+
* Returns: -1 if a < b, 0 if a == b, 1 if a > b
|
|
18
|
+
*/
|
|
19
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a version satisfies a semver specification
|
|
22
|
+
*/
|
|
23
|
+
export declare function semverSatisfies(version: string, spec: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a version is in a vulnerable range based on patched/unaffected specs
|
|
26
|
+
*/
|
|
27
|
+
export declare function isVersionVulnerable(version: string, patched?: string[], unaffected?: string[]): boolean;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semver version matching for RustSec advisory version constraints
|
|
3
|
+
* Supports: "1.0.0", "^1.0.0", ">=1.0.0", "<2.0.0", etc.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Parse a version string into components
|
|
7
|
+
*/
|
|
8
|
+
export function parseVersion(version) {
|
|
9
|
+
// Remove leading 'v' if present
|
|
10
|
+
const v = version.replace(/^v/, '').trim();
|
|
11
|
+
// Handle prerelease versions
|
|
12
|
+
const [mainPart, prerelease] = v.split('-');
|
|
13
|
+
const parts = mainPart.split('.');
|
|
14
|
+
return {
|
|
15
|
+
major: parseInt(parts[0] ?? '0', 10) || 0,
|
|
16
|
+
minor: parseInt(parts[1] ?? '0', 10) || 0,
|
|
17
|
+
patch: parseInt(parts[2] ?? '0', 10) || 0,
|
|
18
|
+
prerelease,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Compare two versions
|
|
23
|
+
* Returns: -1 if a < b, 0 if a == b, 1 if a > b
|
|
24
|
+
*/
|
|
25
|
+
export function compareVersions(a, b) {
|
|
26
|
+
const va = parseVersion(a);
|
|
27
|
+
const vb = parseVersion(b);
|
|
28
|
+
if (va.major !== vb.major)
|
|
29
|
+
return va.major < vb.major ? -1 : 1;
|
|
30
|
+
if (va.minor !== vb.minor)
|
|
31
|
+
return va.minor < vb.minor ? -1 : 1;
|
|
32
|
+
if (va.patch !== vb.patch)
|
|
33
|
+
return va.patch < vb.patch ? -1 : 1;
|
|
34
|
+
// Prerelease versions are lower than release
|
|
35
|
+
if (va.prerelease && !vb.prerelease)
|
|
36
|
+
return -1;
|
|
37
|
+
if (!va.prerelease && vb.prerelease)
|
|
38
|
+
return 1;
|
|
39
|
+
if (va.prerelease && vb.prerelease) {
|
|
40
|
+
return va.prerelease.localeCompare(vb.prerelease);
|
|
41
|
+
}
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if a version satisfies a semver specification
|
|
46
|
+
*/
|
|
47
|
+
export function semverSatisfies(version, spec) {
|
|
48
|
+
const trimmedSpec = spec.trim();
|
|
49
|
+
// Handle caret range: ^1.2.3 means >=1.2.3 and <2.0.0
|
|
50
|
+
if (trimmedSpec.startsWith('^')) {
|
|
51
|
+
const specParts = parseVersion(trimmedSpec.slice(1));
|
|
52
|
+
const vParts = parseVersion(version);
|
|
53
|
+
// Major must match (or be higher minor/patch)
|
|
54
|
+
if (vParts.major !== specParts.major)
|
|
55
|
+
return false;
|
|
56
|
+
if (vParts.minor < specParts.minor)
|
|
57
|
+
return false;
|
|
58
|
+
if (vParts.minor === specParts.minor && vParts.patch < specParts.patch)
|
|
59
|
+
return false;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
// Handle tilde range: ~1.2.3 means >=1.2.3 and <1.3.0
|
|
63
|
+
if (trimmedSpec.startsWith('~')) {
|
|
64
|
+
const specParts = parseVersion(trimmedSpec.slice(1));
|
|
65
|
+
const vParts = parseVersion(version);
|
|
66
|
+
if (vParts.major !== specParts.major)
|
|
67
|
+
return false;
|
|
68
|
+
if (vParts.minor !== specParts.minor)
|
|
69
|
+
return false;
|
|
70
|
+
return vParts.patch >= specParts.patch;
|
|
71
|
+
}
|
|
72
|
+
// Handle >= comparison
|
|
73
|
+
if (trimmedSpec.startsWith('>=')) {
|
|
74
|
+
return compareVersions(version, trimmedSpec.slice(2).trim()) >= 0;
|
|
75
|
+
}
|
|
76
|
+
// Handle > comparison
|
|
77
|
+
if (trimmedSpec.startsWith('>') && !trimmedSpec.startsWith('>=')) {
|
|
78
|
+
return compareVersions(version, trimmedSpec.slice(1).trim()) > 0;
|
|
79
|
+
}
|
|
80
|
+
// Handle <= comparison
|
|
81
|
+
if (trimmedSpec.startsWith('<=')) {
|
|
82
|
+
return compareVersions(version, trimmedSpec.slice(2).trim()) <= 0;
|
|
83
|
+
}
|
|
84
|
+
// Handle < comparison
|
|
85
|
+
if (trimmedSpec.startsWith('<') && !trimmedSpec.startsWith('<=')) {
|
|
86
|
+
return compareVersions(version, trimmedSpec.slice(1).trim()) < 0;
|
|
87
|
+
}
|
|
88
|
+
// Handle = comparison (explicit)
|
|
89
|
+
if (trimmedSpec.startsWith('=')) {
|
|
90
|
+
return compareVersions(version, trimmedSpec.slice(1).trim()) === 0;
|
|
91
|
+
}
|
|
92
|
+
// Handle range: "1.0.0 - 2.0.0"
|
|
93
|
+
if (trimmedSpec.includes(' - ')) {
|
|
94
|
+
const [min, max] = trimmedSpec.split(' - ').map((s) => s.trim());
|
|
95
|
+
return (compareVersions(version, min) >= 0 && compareVersions(version, max) <= 0);
|
|
96
|
+
}
|
|
97
|
+
// Handle wildcard: "*" or "x"
|
|
98
|
+
if (trimmedSpec === '*' || trimmedSpec === 'x') {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
// Exact match
|
|
102
|
+
return compareVersions(version, trimmedSpec) === 0;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if a version is in a vulnerable range based on patched/unaffected specs
|
|
106
|
+
*/
|
|
107
|
+
export function isVersionVulnerable(version, patched, unaffected) {
|
|
108
|
+
// Check if version is unaffected
|
|
109
|
+
if (unaffected) {
|
|
110
|
+
for (const spec of unaffected) {
|
|
111
|
+
if (semverSatisfies(version, spec)) {
|
|
112
|
+
return false; // Not vulnerable - in unaffected range
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Check if version is patched
|
|
117
|
+
if (patched) {
|
|
118
|
+
for (const spec of patched) {
|
|
119
|
+
if (semverSatisfies(version, spec)) {
|
|
120
|
+
return false; // Not vulnerable - patched version
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// If not in unaffected or patched ranges, it's vulnerable
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=semver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semver.js","sourceRoot":"","sources":["../../src/analysis/semver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,gCAAgC;IAChC,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAE3C,6BAA6B;IAC7B,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAElC,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC;QACzC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC;QACzC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC;QACzC,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,CAAS,EAAE,CAAS;IAClD,MAAM,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAE3B,IAAI,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,KAAK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qB;IAErB,iCAAiC;IACjC,IAAI,UAAU,EAAE,CAAC;QACf,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC9B,IAAI,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;gBACnC,OAAO,KAAK,CAAC,CAAC,uCAAuC;YACvD,CAAC;QACH,CAAC;IACH,CAAC;IAED,8BAA8B;IAC9B,IAAI,OAAO,EAAE,CAAC;QACZ,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAC3B,IAAI,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;gBACnC,OAAO,KAAK,CAAC,CAAC,mCAAmC;YACnD,CAAC;QACH,CAAC;IACH,CAAC;IAED,0DAA0D;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Taint source/sink matcher
|
|
3
|
+
*
|
|
4
|
+
* Matches method calls and annotations against taint configurations.
|
|
5
|
+
*/
|
|
6
|
+
import type { CallInfo, TypeInfo, Taint } from '../types/index.js';
|
|
7
|
+
import type { TaintConfig, SinkPattern } from '../types/config.js';
|
|
8
|
+
/**
|
|
9
|
+
* Analyze code for taint sources, sinks, and sanitizers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function analyzeTaint(calls: CallInfo[], types: TypeInfo[], config?: TaintConfig): Taint;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a variable at a given position flows to a dangerous sink argument.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isInDangerousPosition(argPosition: number, pattern: SinkPattern): boolean;
|