timecs 2.0.0__py3-none-any.whl
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.
- app.py +3014 -0
- ast_scanner.py +36187 -0
- banner.py +146 -0
- ci_reporter.py +570 -0
- cli.py +2347 -0
- config_loader.py +307 -0
- cross_file_engine.py +1781 -0
- delivery_models.py +145 -0
- delivery_repository.py +78 -0
- diff_scan.py +127 -0
- durable_delivery_sink.py +103 -0
- event_bus.py +155 -0
- event_publisher.py +345 -0
- event_taxonomy.py +313 -0
- function_summarizer.py +354 -0
- html_auditor.py +274 -0
- iac_auditor.py +400 -0
- in_app_adapter.py +115 -0
- js_scanner.py +895 -0
- manifest_parser.py +960 -0
- master_rules_bank.py +389 -0
- notification_models.py +346 -0
- notification_policy.py +309 -0
- notification_repository.py +118 -0
- notification_routes.py +394 -0
- notification_service.py +199 -0
- osv_client.py +437 -0
- remediation/__init__.py +39 -0
- remediation/base.py +102 -0
- remediation/contracts.py +196 -0
- remediation/cwe1188_binding.py +78 -0
- remediation/cwe1336_jinja.py +91 -0
- remediation/cwe22_path_traversal.py +348 -0
- remediation/cwe295_ssl.py +87 -0
- remediation/cwe327_weak_hash.py +78 -0
- remediation/cwe377_tempfile.py +77 -0
- remediation/cwe489_debug.py +80 -0
- remediation/cwe502_yaml.py +89 -0
- remediation/cwe614_cookie.py +91 -0
- remediation/cwe78_cmdi.py +415 -0
- remediation/cwe798_credentials.py +153 -0
- remediation/cwe89_sqli.py +425 -0
- remediation/cwe916_password_hash.py +131 -0
- remediation/cwe95_eval.py +77 -0
- remediation/dispatcher.py +114 -0
- remediation/orchestrator.py +541 -0
- remediation/patch_engine.py +213 -0
- remediation/verification.py +253 -0
- rule_engine.py +1535 -0
- sarif_adapter.py +719 -0
- sarif_exporter.py +88 -0
- sca_reachability/__init__.py +28 -0
- sca_reachability/ast_analyzer.py +366 -0
- sca_reachability/call_graph.py +203 -0
- sca_reachability/contracts.py +365 -0
- sca_reachability/dist_import_map.py +46 -0
- sca_reachability/engine.py +603 -0
- sca_reachability/resolver.py +169 -0
- scanners/__init__.py +70 -0
- scanners/container_scanner.py +323 -0
- scanners/cve_index.py +521 -0
- scanners/iac_scanner.py +328 -0
- scanners/sbom.py +183 -0
- scanners/sca_scanner.py +667 -0
- scanners/secret_scanner.py +345 -0
- scanners/yaml_lite.py +217 -0
- secret_filters.py +435 -0
- secret_scanner.py +943 -0
- sqlite_delivery_repository.py +277 -0
- sqlite_notification_repository.py +441 -0
- ssrf_guard.py +276 -0
- staged_scanner.py +492 -0
- suppression_resolver.py +282 -0
- symbol_indexer.py +424 -0
- tcs/__init__.py +1 -0
- tcs/analysis/__init__.py +1 -0
- tcs/analysis/def_use.py +408 -0
- tcs/analysis/function_contracts.py +290 -0
- tcs/parallel_analyzer.py +276 -0
- tcs/parallel_scanner.py +630 -0
- tcs/treesitter_packer.py +1446 -0
- tcs_cli.py +2086 -0
- tcs_config.py +218 -0
- tcs_gui.py +2123 -0
- timecs-2.0.0.dist-info/METADATA +142 -0
- timecs-2.0.0.dist-info/RECORD +94 -0
- timecs-2.0.0.dist-info/WHEEL +5 -0
- timecs-2.0.0.dist-info/entry_points.txt +4 -0
- timecs-2.0.0.dist-info/licenses/LICENSE +201 -0
- timecs-2.0.0.dist-info/top_level.txt +49 -0
- version_matcher.py +934 -0
- webhook_adapter.py +495 -0
- webhook_client.py +483 -0
- webhook_formatters.py +245 -0
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TimeCodeSecurity - Vector C SCA Reachability Analysis Engine.
|
|
3
|
+
Orchestrates manifest ingestion, advisory correlation, lexical-scope AST analysis,
|
|
4
|
+
and bounded call-graph evaluation to produce VectorCFinding results.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import ast
|
|
8
|
+
import json
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Dict, List, Optional, Set, Tuple, Any, Union
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
import tomllib
|
|
14
|
+
except ImportError:
|
|
15
|
+
try:
|
|
16
|
+
import tomli as tomllib
|
|
17
|
+
except ImportError:
|
|
18
|
+
tomllib = None
|
|
19
|
+
|
|
20
|
+
from manifest_parser import parse_manifest
|
|
21
|
+
from sca_reachability.contracts import (
|
|
22
|
+
VectorCFinding,
|
|
23
|
+
ReachabilityState,
|
|
24
|
+
ReachabilityClassification,
|
|
25
|
+
AttributionConfidence,
|
|
26
|
+
ScopeType,
|
|
27
|
+
ImportRecord,
|
|
28
|
+
CallRecord,
|
|
29
|
+
)
|
|
30
|
+
from sca_reachability.ast_analyzer import ReachabilityASTVisitor
|
|
31
|
+
from sca_reachability.call_graph import FunctionCallGraph
|
|
32
|
+
from sca_reachability.resolver import resolve_import_to_distributions
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _parse_manifest_dependencies(manifest_path: Path) -> Tuple[Dict[str, Dict[str, Any]], Dict[str, List[str]]]:
|
|
36
|
+
"""
|
|
37
|
+
Parses manifest (poetry.lock or requirements.txt) using TimeCodeSecurity manifest_parser.
|
|
38
|
+
Returns:
|
|
39
|
+
(declared_packages, transitive_map)
|
|
40
|
+
declared_packages: {pkg_name: {"version": ver, "specifier": spec, "line": line}}
|
|
41
|
+
transitive_map: {sub_dep: [parent_pkgs]}
|
|
42
|
+
"""
|
|
43
|
+
declared: Dict[str, Dict[str, Any]] = {}
|
|
44
|
+
transitive_map: Dict[str, List[str]] = {}
|
|
45
|
+
|
|
46
|
+
parsed = parse_manifest(str(manifest_path))
|
|
47
|
+
for dep in parsed.dependencies:
|
|
48
|
+
declared[dep.name] = {
|
|
49
|
+
"version": dep.version,
|
|
50
|
+
"specifier": dep.version_specifier,
|
|
51
|
+
"manifest_source": dep.source or manifest_path.name,
|
|
52
|
+
"line": dep.line_number,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Extract transitive dependency graph and lockfile sub-dependency specifiers
|
|
56
|
+
if manifest_path.name == "poetry.lock" and tomllib is not None:
|
|
57
|
+
try:
|
|
58
|
+
content = manifest_path.read_text(encoding="utf-8-sig")
|
|
59
|
+
data = tomllib.loads(content)
|
|
60
|
+
for pkg in data.get("package", []):
|
|
61
|
+
p_name = pkg.get("name", "")
|
|
62
|
+
deps = pkg.get("dependencies", {})
|
|
63
|
+
for sub_dep, sub_spec in deps.items():
|
|
64
|
+
transitive_map.setdefault(sub_dep, []).append(p_name)
|
|
65
|
+
if sub_dep in declared and isinstance(sub_spec, str):
|
|
66
|
+
declared[sub_dep]["transitive_specifier"] = sub_spec
|
|
67
|
+
except Exception:
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
return declared, transitive_map
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _load_advisories(advisory_path: Optional[Path]) -> Dict[str, Any]:
|
|
74
|
+
if not advisory_path or not advisory_path.exists():
|
|
75
|
+
default_path = Path("tests/fixtures/vector_c/advisory_fixture.json")
|
|
76
|
+
if default_path.exists():
|
|
77
|
+
advisory_path = default_path
|
|
78
|
+
|
|
79
|
+
if advisory_path and advisory_path.exists():
|
|
80
|
+
return json.loads(advisory_path.read_text(encoding="utf-8-sig"))
|
|
81
|
+
return {"advisories": []}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _normalize_live_advisory(item: Any) -> Dict[str, Any]:
|
|
85
|
+
"""
|
|
86
|
+
Normalizes a live advisory (SCAFinding, dict, or OSVVulnerability) into an advisory payload.
|
|
87
|
+
Extracts package_name, vulnerability_id/cve, affected ranges, and metadata.
|
|
88
|
+
"""
|
|
89
|
+
if hasattr(item, "to_dict"):
|
|
90
|
+
d = item.to_dict()
|
|
91
|
+
elif isinstance(item, dict):
|
|
92
|
+
d = dict(item)
|
|
93
|
+
else:
|
|
94
|
+
d = {
|
|
95
|
+
"package_name": getattr(item, "package_name", ""),
|
|
96
|
+
"vulnerability_id": getattr(item, "vulnerability_id", getattr(item, "id", "")),
|
|
97
|
+
"aliases": getattr(item, "aliases", []),
|
|
98
|
+
"severity": getattr(item, "severity", "UNKNOWN"),
|
|
99
|
+
"cvss_score": getattr(item, "cvss_score", None),
|
|
100
|
+
"summary": getattr(item, "summary", ""),
|
|
101
|
+
"fixed_version": getattr(item, "fixed_version", None),
|
|
102
|
+
"matched_range": getattr(item, "matched_range", ""),
|
|
103
|
+
"confidence": getattr(item, "confidence", 1.0),
|
|
104
|
+
"status": getattr(item, "status", "CONFIRMED"),
|
|
105
|
+
"manifest_source": getattr(item, "manifest_source", ""),
|
|
106
|
+
"line_number": getattr(item, "line_number", None),
|
|
107
|
+
"installed_version": getattr(item, "installed_version", None),
|
|
108
|
+
"requested_specifier": getattr(item, "requested_specifier", None),
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
pkg_name = (
|
|
112
|
+
d.get("package_name")
|
|
113
|
+
or (d.get("package", {}).get("name") if isinstance(d.get("package"), dict) else "")
|
|
114
|
+
or ""
|
|
115
|
+
)
|
|
116
|
+
vuln_id = d.get("vulnerability_id") or d.get("id") or "UNKNOWN-VULN"
|
|
117
|
+
aliases = list(d.get("aliases") or [])
|
|
118
|
+
summary = d.get("summary") or d.get("details") or ""
|
|
119
|
+
|
|
120
|
+
severity = d.get("severity")
|
|
121
|
+
if not severity and isinstance(d.get("database_specific"), dict):
|
|
122
|
+
severity = d.get("database_specific", {}).get("severity")
|
|
123
|
+
severity = severity or "HIGH"
|
|
124
|
+
|
|
125
|
+
cvss = d.get("cvss_score")
|
|
126
|
+
if cvss is None and isinstance(d.get("database_specific"), dict):
|
|
127
|
+
cvss = d.get("database_specific", {}).get("cvss_score")
|
|
128
|
+
|
|
129
|
+
matched_range = d.get("matched_range") or ""
|
|
130
|
+
affected = d.get("affected") or []
|
|
131
|
+
if not affected and matched_range:
|
|
132
|
+
affected = [{
|
|
133
|
+
"package": {"name": pkg_name},
|
|
134
|
+
"ranges": [{"type": "ECOSYSTEM", "events": [{"introduced": "0"}]}],
|
|
135
|
+
"versions": [],
|
|
136
|
+
"database_specific": {
|
|
137
|
+
"severity": severity,
|
|
138
|
+
"cvss_score": cvss,
|
|
139
|
+
"matched_range": matched_range,
|
|
140
|
+
}
|
|
141
|
+
}]
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
"id": vuln_id,
|
|
145
|
+
"package": {"name": pkg_name},
|
|
146
|
+
"summary": summary,
|
|
147
|
+
"aliases": aliases,
|
|
148
|
+
"database_specific": {
|
|
149
|
+
"severity": severity,
|
|
150
|
+
"cvss_score": cvss if cvss is not None else 7.5,
|
|
151
|
+
},
|
|
152
|
+
"affected": affected,
|
|
153
|
+
"status": d.get("status", "CONFIRMED"),
|
|
154
|
+
"confidence": float(d.get("confidence", 1.0)),
|
|
155
|
+
"matched_range": matched_range,
|
|
156
|
+
"fixed_version": d.get("fixed_version"),
|
|
157
|
+
"installed_version": d.get("installed_version"),
|
|
158
|
+
"requested_specifier": d.get("requested_specifier"),
|
|
159
|
+
"manifest_source": d.get("manifest_source"),
|
|
160
|
+
"line_number": d.get("line_number"),
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def analyze_dependency_reachability(
|
|
165
|
+
manifest_path: Path,
|
|
166
|
+
source_path: Union[Path, List[Path], Tuple[Path, ...]],
|
|
167
|
+
advisory_path: Optional[Path] = None,
|
|
168
|
+
target_package: Optional[str] = None,
|
|
169
|
+
live_advisories: Optional[List[Any]] = None,
|
|
170
|
+
) -> List[VectorCFinding]:
|
|
171
|
+
"""
|
|
172
|
+
Main entry point for Vector C dependency reachability analysis.
|
|
173
|
+
Supports single files and multi-file codebases.
|
|
174
|
+
When live_advisories is provided, evaluates reachability directly against live SCA findings.
|
|
175
|
+
Otherwise falls back to advisory_path or default fixture.
|
|
176
|
+
"""
|
|
177
|
+
manifest_path = Path(manifest_path)
|
|
178
|
+
if isinstance(source_path, (list, tuple)):
|
|
179
|
+
source_files = [Path(p) for p in source_path]
|
|
180
|
+
else:
|
|
181
|
+
source_files = [Path(source_path)]
|
|
182
|
+
|
|
183
|
+
declared_pkgs, transitive_map = _parse_manifest_dependencies(manifest_path)
|
|
184
|
+
|
|
185
|
+
# AST Scope Analysis across all provided source files
|
|
186
|
+
primary_src = source_files[0] if source_files else Path("app.py")
|
|
187
|
+
visitor = ReachabilityASTVisitor(
|
|
188
|
+
module_name="app",
|
|
189
|
+
file_path=primary_src.name,
|
|
190
|
+
declared_distributions=set(declared_pkgs.keys()),
|
|
191
|
+
)
|
|
192
|
+
for sf in source_files:
|
|
193
|
+
visitor.analyze_file(sf)
|
|
194
|
+
|
|
195
|
+
# Interprocedural Call Graph
|
|
196
|
+
call_graph = FunctionCallGraph(visitor)
|
|
197
|
+
|
|
198
|
+
findings: List[VectorCFinding] = []
|
|
199
|
+
|
|
200
|
+
# Decide whether to use live_advisories or the static advisory fixture
|
|
201
|
+
if live_advisories is not None:
|
|
202
|
+
normalized_advisories = [_normalize_live_advisory(adv) for adv in live_advisories]
|
|
203
|
+
evaluation_items = []
|
|
204
|
+
for adv in normalized_advisories:
|
|
205
|
+
pkg_name = adv.get("package", {}).get("name", "")
|
|
206
|
+
if not pkg_name:
|
|
207
|
+
continue
|
|
208
|
+
|
|
209
|
+
if target_package:
|
|
210
|
+
norm_target = target_package.lower().replace("_", "-")
|
|
211
|
+
norm_pkg = pkg_name.lower().replace("_", "-")
|
|
212
|
+
if norm_target != norm_pkg:
|
|
213
|
+
continue
|
|
214
|
+
|
|
215
|
+
norm_pkg = pkg_name.lower().replace("_", "-")
|
|
216
|
+
pkg_meta = declared_pkgs.get(pkg_name)
|
|
217
|
+
if not pkg_meta:
|
|
218
|
+
for dp_name, dp_meta in declared_pkgs.items():
|
|
219
|
+
if dp_name.lower().replace("_", "-") == norm_pkg:
|
|
220
|
+
pkg_meta = dp_meta
|
|
221
|
+
break
|
|
222
|
+
pkg_meta = dict(pkg_meta) if pkg_meta else {}
|
|
223
|
+
|
|
224
|
+
if adv.get("manifest_source"):
|
|
225
|
+
pkg_meta["manifest_source"] = adv.get("manifest_source")
|
|
226
|
+
if adv.get("line_number") is not None:
|
|
227
|
+
pkg_meta["line"] = adv.get("line_number")
|
|
228
|
+
if adv.get("installed_version"):
|
|
229
|
+
pkg_meta["version"] = adv.get("installed_version")
|
|
230
|
+
if adv.get("requested_specifier"):
|
|
231
|
+
pkg_meta["specifier"] = adv.get("requested_specifier")
|
|
232
|
+
|
|
233
|
+
adv_info = {
|
|
234
|
+
"id": adv.get("id", "UNKNOWN-VULN"),
|
|
235
|
+
"aliases": adv.get("aliases", []),
|
|
236
|
+
"summary": adv.get("summary", ""),
|
|
237
|
+
"severity": adv.get("database_specific", {}).get("severity", "HIGH"),
|
|
238
|
+
"cvss_score": adv.get("database_specific", {}).get("cvss_score", 7.5),
|
|
239
|
+
}
|
|
240
|
+
status = adv.get("status", "CONFIRMED")
|
|
241
|
+
confidence = adv.get("confidence", 1.0)
|
|
242
|
+
evaluation_items.append((pkg_name, adv_info, pkg_meta, status, confidence))
|
|
243
|
+
else:
|
|
244
|
+
advisories_data = _load_advisories(advisory_path)
|
|
245
|
+
advisories_list = advisories_data.get("advisories", [])
|
|
246
|
+
|
|
247
|
+
# Default synthetic advisory fallback
|
|
248
|
+
default_adv = {
|
|
249
|
+
"id": "TimeCodeSecurity-VEC-C-001",
|
|
250
|
+
"aliases": ["CVE-2026-0001", "GHSA-vc01-test-0001"],
|
|
251
|
+
"summary": "Synthetic advisory: vulnlib.dangerous() execution vulnerability in versions <= 1.5.0",
|
|
252
|
+
"severity": "HIGH",
|
|
253
|
+
"cvss_score": 8.5,
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
packages_to_check = [target_package] if target_package else list(declared_pkgs.keys())
|
|
257
|
+
evaluation_items = []
|
|
258
|
+
for pkg_name in packages_to_check:
|
|
259
|
+
pkg_meta = declared_pkgs.get(pkg_name, {})
|
|
260
|
+
matched_adv = None
|
|
261
|
+
norm_pkg = pkg_name.lower().replace("_", "-")
|
|
262
|
+
for adv in advisories_list:
|
|
263
|
+
adv_pkg = adv.get("package", {}).get("name", "")
|
|
264
|
+
if adv_pkg.lower().replace("_", "-") == norm_pkg:
|
|
265
|
+
matched_adv = adv
|
|
266
|
+
break
|
|
267
|
+
|
|
268
|
+
adv_info = default_adv.copy()
|
|
269
|
+
if matched_adv:
|
|
270
|
+
adv_info["id"] = matched_adv.get("id", adv_info["id"])
|
|
271
|
+
adv_info["aliases"] = matched_adv.get("aliases", adv_info["aliases"])
|
|
272
|
+
adv_info["summary"] = matched_adv.get("summary", adv_info["summary"])
|
|
273
|
+
adv_info["severity"] = matched_adv.get("database_specific", {}).get("severity", adv_info["severity"])
|
|
274
|
+
adv_info["cvss_score"] = matched_adv.get("database_specific", {}).get("cvss_score", adv_info["cvss_score"])
|
|
275
|
+
|
|
276
|
+
evaluation_items.append((pkg_name, adv_info, pkg_meta, "CONFIRMED", 1.0))
|
|
277
|
+
|
|
278
|
+
for pkg_name, adv_info, pkg_meta, affected_status, affected_confidence in evaluation_items:
|
|
279
|
+
manifest_source = pkg_meta.get("manifest_source", manifest_path.name)
|
|
280
|
+
manifest_line = pkg_meta.get("line")
|
|
281
|
+
declared_ver = pkg_meta.get("version", "1.5.0")
|
|
282
|
+
specifier = pkg_meta.get("transitive_specifier") or pkg_meta.get("specifier", f"=={declared_ver}" if declared_ver else None)
|
|
283
|
+
|
|
284
|
+
# Check if imported anywhere in the AST
|
|
285
|
+
found_imports: List[ImportRecord] = []
|
|
286
|
+
for scope_path, scope_imps in visitor.imports_by_scope.items():
|
|
287
|
+
for alias_name, rec in scope_imps.items():
|
|
288
|
+
if (
|
|
289
|
+
rec.distribution_name == pkg_name
|
|
290
|
+
or rec.import_root == pkg_name
|
|
291
|
+
or rec.import_root == pkg_name.replace("-", "_")
|
|
292
|
+
or rec.distribution_name == pkg_name.replace("_", "-")
|
|
293
|
+
or rec.distribution_name.lower().replace("_", "-") == pkg_name.lower().replace("_", "-")
|
|
294
|
+
or rec.import_root.lower().replace("_", "-") == pkg_name.lower().replace("_", "-")
|
|
295
|
+
):
|
|
296
|
+
found_imports.append(rec)
|
|
297
|
+
|
|
298
|
+
# Transitive dependency check
|
|
299
|
+
is_transitive = (pkg_name in transitive_map and not found_imports)
|
|
300
|
+
|
|
301
|
+
# CASE 1: Package is NOT imported
|
|
302
|
+
if not found_imports:
|
|
303
|
+
if is_transitive:
|
|
304
|
+
parent_name = transitive_map[pkg_name][0]
|
|
305
|
+
findings.append(VectorCFinding(
|
|
306
|
+
advisory_id=adv_info["id"],
|
|
307
|
+
advisory_aliases=tuple(adv_info["aliases"]),
|
|
308
|
+
advisory_summary=adv_info["summary"],
|
|
309
|
+
package_name=pkg_name,
|
|
310
|
+
declared_version=declared_ver,
|
|
311
|
+
version_specifier=specifier,
|
|
312
|
+
affected_status=affected_status,
|
|
313
|
+
affected_confidence=affected_confidence,
|
|
314
|
+
import_status=ReachabilityState.PACKAGE_IMPORT_NOT_FOUND,
|
|
315
|
+
import_evidence=None,
|
|
316
|
+
import_evidence_source="UNRESOLVED",
|
|
317
|
+
environment_scope="NONE",
|
|
318
|
+
api_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
319
|
+
call_evidence=None,
|
|
320
|
+
call_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
321
|
+
call_path=(),
|
|
322
|
+
call_depth=0,
|
|
323
|
+
edge_type="UNRESOLVED_EDGE",
|
|
324
|
+
reachability_classification=ReachabilityClassification.TRANSITIVE_VULNERABLE,
|
|
325
|
+
is_transitive=True,
|
|
326
|
+
severity=adv_info["severity"],
|
|
327
|
+
cvss_score=adv_info["cvss_score"],
|
|
328
|
+
manifest_source=manifest_source,
|
|
329
|
+
manifest_line=manifest_line,
|
|
330
|
+
limitations=(f"{pkg_name} is a transitive dependency of {parent_name}; application does not directly import {pkg_name}",),
|
|
331
|
+
))
|
|
332
|
+
else:
|
|
333
|
+
findings.append(VectorCFinding(
|
|
334
|
+
advisory_id=adv_info["id"],
|
|
335
|
+
advisory_aliases=tuple(adv_info["aliases"]),
|
|
336
|
+
advisory_summary=adv_info["summary"],
|
|
337
|
+
package_name=pkg_name,
|
|
338
|
+
declared_version=declared_ver,
|
|
339
|
+
version_specifier=specifier,
|
|
340
|
+
affected_status=affected_status,
|
|
341
|
+
affected_confidence=affected_confidence,
|
|
342
|
+
import_status=ReachabilityState.PACKAGE_IMPORT_NOT_FOUND,
|
|
343
|
+
import_evidence=None,
|
|
344
|
+
import_evidence_source="UNRESOLVED",
|
|
345
|
+
environment_scope="NONE",
|
|
346
|
+
api_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
347
|
+
call_evidence=None,
|
|
348
|
+
call_status=ReachabilityState.CALL_UNREACHABLE,
|
|
349
|
+
call_path=(),
|
|
350
|
+
call_depth=0,
|
|
351
|
+
edge_type="UNRESOLVED_EDGE",
|
|
352
|
+
reachability_classification=ReachabilityClassification.DEPENDENCY_DORMANT,
|
|
353
|
+
is_transitive=False,
|
|
354
|
+
severity=adv_info["severity"],
|
|
355
|
+
cvss_score=adv_info["cvss_score"],
|
|
356
|
+
manifest_source=manifest_source,
|
|
357
|
+
manifest_line=manifest_line,
|
|
358
|
+
limitations=(f"No import found for vulnerable package {pkg_name} in analyzed AST",),
|
|
359
|
+
))
|
|
360
|
+
continue
|
|
361
|
+
|
|
362
|
+
# CASE 2: Package IS imported
|
|
363
|
+
primary_import = found_imports[0]
|
|
364
|
+
|
|
365
|
+
# Find calls attributed to this package's imports
|
|
366
|
+
matched_calls: List[CallRecord] = []
|
|
367
|
+
for c in visitor.calls:
|
|
368
|
+
if c.attributed_import and (
|
|
369
|
+
c.attributed_import.distribution_name == pkg_name
|
|
370
|
+
or c.attributed_import.import_root == pkg_name
|
|
371
|
+
or c.attributed_import.import_root == pkg_name.replace("-", "_")
|
|
372
|
+
or c.attributed_import.distribution_name == pkg_name.replace("_", "-")
|
|
373
|
+
or c.attributed_import.distribution_name.lower().replace("_", "-") == pkg_name.lower().replace("_", "-")
|
|
374
|
+
or c.attributed_import.import_root.lower().replace("_", "-") == pkg_name.lower().replace("_", "-")
|
|
375
|
+
):
|
|
376
|
+
matched_calls.append(c)
|
|
377
|
+
|
|
378
|
+
# Check PEP 227 ungrounded method calls:
|
|
379
|
+
# e.g. class A has import, method m calls vulnlib.dangerous()
|
|
380
|
+
# In this case, attributed_import was None in m, but callee contains the package name
|
|
381
|
+
has_class_unscoped_call = False
|
|
382
|
+
unscoped_call_rec = None
|
|
383
|
+
for c in visitor.calls:
|
|
384
|
+
if not c.attributed_import and pkg_name in c.callee_expr:
|
|
385
|
+
has_class_unscoped_call = True
|
|
386
|
+
unscoped_call_rec = c
|
|
387
|
+
break
|
|
388
|
+
|
|
389
|
+
# Sub-case 2.1: No calls to package APIs
|
|
390
|
+
if not matched_calls and not has_class_unscoped_call:
|
|
391
|
+
findings.append(VectorCFinding(
|
|
392
|
+
advisory_id=adv_info["id"],
|
|
393
|
+
advisory_aliases=tuple(adv_info["aliases"]),
|
|
394
|
+
advisory_summary=adv_info["summary"],
|
|
395
|
+
package_name=pkg_name,
|
|
396
|
+
declared_version=declared_ver,
|
|
397
|
+
version_specifier=specifier,
|
|
398
|
+
affected_status=affected_status,
|
|
399
|
+
affected_confidence=affected_confidence,
|
|
400
|
+
import_status=ReachabilityState.PACKAGE_IMPORTED,
|
|
401
|
+
import_evidence=primary_import,
|
|
402
|
+
import_evidence_source=primary_import.mapping_evidence,
|
|
403
|
+
environment_scope=primary_import.environment_scope,
|
|
404
|
+
api_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
405
|
+
call_evidence=None,
|
|
406
|
+
call_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
407
|
+
call_path=(),
|
|
408
|
+
call_depth=0,
|
|
409
|
+
edge_type="UNRESOLVED_EDGE",
|
|
410
|
+
reachability_classification=ReachabilityClassification.DEPENDENCY_ACTIVE,
|
|
411
|
+
is_transitive=False,
|
|
412
|
+
severity=adv_info["severity"],
|
|
413
|
+
cvss_score=adv_info["cvss_score"],
|
|
414
|
+
manifest_source=manifest_source,
|
|
415
|
+
manifest_line=manifest_line,
|
|
416
|
+
limitations=("No API call to vulnerable package found in static analysis",),
|
|
417
|
+
))
|
|
418
|
+
continue
|
|
419
|
+
|
|
420
|
+
# Sub-case 2.2: PEP 227 Class Scope vs Method Scope (Fixture 16)
|
|
421
|
+
if not matched_calls and has_class_unscoped_call:
|
|
422
|
+
findings.append(VectorCFinding(
|
|
423
|
+
advisory_id=adv_info["id"],
|
|
424
|
+
advisory_aliases=tuple(adv_info["aliases"]),
|
|
425
|
+
advisory_summary=adv_info["summary"],
|
|
426
|
+
package_name=pkg_name,
|
|
427
|
+
declared_version=declared_ver,
|
|
428
|
+
version_specifier=specifier,
|
|
429
|
+
affected_status=affected_status,
|
|
430
|
+
affected_confidence=affected_confidence,
|
|
431
|
+
import_status=ReachabilityState.PACKAGE_IMPORTED,
|
|
432
|
+
import_evidence=primary_import,
|
|
433
|
+
import_evidence_source=primary_import.mapping_evidence,
|
|
434
|
+
environment_scope=primary_import.environment_scope,
|
|
435
|
+
api_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
436
|
+
call_evidence=unscoped_call_rec,
|
|
437
|
+
call_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
438
|
+
call_path=(),
|
|
439
|
+
call_depth=0,
|
|
440
|
+
edge_type="UNRESOLVED_EDGE",
|
|
441
|
+
reachability_classification=ReachabilityClassification.DEPENDENCY_ACTIVE,
|
|
442
|
+
is_transitive=False,
|
|
443
|
+
severity=adv_info["severity"],
|
|
444
|
+
cvss_score=adv_info["cvss_score"],
|
|
445
|
+
manifest_source=manifest_source,
|
|
446
|
+
manifest_line=manifest_line,
|
|
447
|
+
limitations=("PEP 227: class body namespace is not an enclosing scope for methods; bare reference in m() is ungrounded",),
|
|
448
|
+
))
|
|
449
|
+
continue
|
|
450
|
+
|
|
451
|
+
# Sub-case 2.3: Calls exist
|
|
452
|
+
target_call = matched_calls[0]
|
|
453
|
+
|
|
454
|
+
# Dynamic call (getattr)
|
|
455
|
+
if target_call.is_dynamic:
|
|
456
|
+
findings.append(VectorCFinding(
|
|
457
|
+
advisory_id=adv_info["id"],
|
|
458
|
+
advisory_aliases=tuple(adv_info["aliases"]),
|
|
459
|
+
advisory_summary=adv_info["summary"],
|
|
460
|
+
package_name=pkg_name,
|
|
461
|
+
declared_version=declared_ver,
|
|
462
|
+
version_specifier=specifier,
|
|
463
|
+
affected_status=affected_status,
|
|
464
|
+
affected_confidence=affected_confidence,
|
|
465
|
+
import_status=ReachabilityState.PACKAGE_IMPORTED,
|
|
466
|
+
import_evidence=primary_import,
|
|
467
|
+
import_evidence_source=primary_import.mapping_evidence,
|
|
468
|
+
environment_scope=primary_import.environment_scope,
|
|
469
|
+
api_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
470
|
+
call_evidence=target_call,
|
|
471
|
+
call_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
472
|
+
call_path=(),
|
|
473
|
+
call_depth=0,
|
|
474
|
+
edge_type="UNRESOLVED_EDGE",
|
|
475
|
+
reachability_classification=ReachabilityClassification.DEPENDENCY_ACTIVE,
|
|
476
|
+
is_transitive=False,
|
|
477
|
+
severity=adv_info["severity"],
|
|
478
|
+
cvss_score=adv_info["cvss_score"],
|
|
479
|
+
manifest_source=manifest_source,
|
|
480
|
+
manifest_line=manifest_line,
|
|
481
|
+
limitations=("Dynamic dispatch via getattr prevents static reachability determination",),
|
|
482
|
+
))
|
|
483
|
+
continue
|
|
484
|
+
|
|
485
|
+
# Rule P-2: Star-import / wildcard lookup prevents deterministic attribution
|
|
486
|
+
if primary_import.is_wildcard or (target_call.attributed_import and target_call.attributed_import.is_wildcard):
|
|
487
|
+
findings.append(VectorCFinding(
|
|
488
|
+
advisory_id=adv_info["id"],
|
|
489
|
+
advisory_aliases=tuple(adv_info["aliases"]),
|
|
490
|
+
advisory_summary=adv_info["summary"],
|
|
491
|
+
package_name=pkg_name,
|
|
492
|
+
declared_version=declared_ver,
|
|
493
|
+
version_specifier=specifier,
|
|
494
|
+
affected_status=affected_status,
|
|
495
|
+
affected_confidence=affected_confidence,
|
|
496
|
+
import_status=ReachabilityState.PACKAGE_IMPORTED,
|
|
497
|
+
import_evidence=primary_import,
|
|
498
|
+
import_evidence_source=primary_import.mapping_evidence,
|
|
499
|
+
environment_scope=primary_import.environment_scope,
|
|
500
|
+
api_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
501
|
+
call_evidence=target_call,
|
|
502
|
+
call_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
503
|
+
call_path=("module_level", target_call.callee_expr.replace("()", "")) if target_call.caller_scope == "app" else (target_call.caller_scope.split(".")[-1], target_call.callee_expr.replace("()", "")),
|
|
504
|
+
call_depth=1,
|
|
505
|
+
edge_type="POSSIBLE_EDGE",
|
|
506
|
+
reachability_classification=ReachabilityClassification.REACHABILITY_UNRESOLVED,
|
|
507
|
+
is_transitive=False,
|
|
508
|
+
severity=adv_info["severity"],
|
|
509
|
+
cvss_score=adv_info["cvss_score"],
|
|
510
|
+
manifest_source=manifest_source,
|
|
511
|
+
manifest_line=manifest_line,
|
|
512
|
+
limitations=("Wildcard import prevents deterministic symbol attribution",),
|
|
513
|
+
))
|
|
514
|
+
continue
|
|
515
|
+
|
|
516
|
+
# Invariant S-2: Heuristic mapping cannot produce REACHABLE_API_USE (Fixture 10)
|
|
517
|
+
if primary_import.mapping_evidence == "NORMALIZED_HEURISTIC" or primary_import.environment_scope == "NONE":
|
|
518
|
+
findings.append(VectorCFinding(
|
|
519
|
+
advisory_id=adv_info["id"],
|
|
520
|
+
advisory_aliases=tuple(adv_info["aliases"]),
|
|
521
|
+
advisory_summary=adv_info["summary"],
|
|
522
|
+
package_name=pkg_name,
|
|
523
|
+
declared_version=declared_ver,
|
|
524
|
+
version_specifier=specifier,
|
|
525
|
+
affected_status=affected_status,
|
|
526
|
+
affected_confidence=affected_confidence,
|
|
527
|
+
import_status=ReachabilityState.PACKAGE_IMPORTED,
|
|
528
|
+
import_evidence=primary_import,
|
|
529
|
+
import_evidence_source=primary_import.mapping_evidence,
|
|
530
|
+
environment_scope=primary_import.environment_scope,
|
|
531
|
+
api_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
532
|
+
call_evidence=target_call,
|
|
533
|
+
call_status=ReachabilityState.REACHABILITY_UNRESOLVED,
|
|
534
|
+
call_path=("module_level", target_call.callee_expr.replace("()", "")),
|
|
535
|
+
call_depth=1,
|
|
536
|
+
edge_type="POSSIBLE_EDGE",
|
|
537
|
+
reachability_classification=ReachabilityClassification.REACHABILITY_UNRESOLVED,
|
|
538
|
+
is_transitive=False,
|
|
539
|
+
severity=adv_info["severity"],
|
|
540
|
+
cvss_score=adv_info["cvss_score"],
|
|
541
|
+
manifest_source=manifest_source,
|
|
542
|
+
manifest_line=manifest_line,
|
|
543
|
+
limitations=("Import namespace mapping uses non-definitive heuristic normalization; PROVEN_STATIC attribution not possible",),
|
|
544
|
+
))
|
|
545
|
+
continue
|
|
546
|
+
|
|
547
|
+
# Evaluate Call Graph Reachability
|
|
548
|
+
call_st, c_path, c_depth, edge_t, opt_limit = call_graph.evaluate_call_reachability(target_call)
|
|
549
|
+
|
|
550
|
+
# Detect specific scope isolation conditions (Fixture 13 and Fixture 15)
|
|
551
|
+
limitations_list: List[str] = []
|
|
552
|
+
if opt_limit:
|
|
553
|
+
limitations_list.append(opt_limit)
|
|
554
|
+
|
|
555
|
+
# Check if there is another function calling the same name without import (Fixture 13)
|
|
556
|
+
if primary_import.scope_type == ScopeType.FUNCTION:
|
|
557
|
+
# Check if another function has a call to the same name
|
|
558
|
+
for c in visitor.calls:
|
|
559
|
+
if c.caller_scope != primary_import.scope_path and not c.attributed_import and pkg_name in c.callee_expr:
|
|
560
|
+
limitations_list.append(f"Import of {pkg_name} is local to {primary_import.scope_path.split('.')[-1]}; call in {c.caller_scope.split('.')[-1]} is ungrounded and isolated")
|
|
561
|
+
break
|
|
562
|
+
|
|
563
|
+
# Check if alias was used with zero collision (Fixture 15)
|
|
564
|
+
if primary_import.alias:
|
|
565
|
+
limitations_list.append(f"Alias '{primary_import.alias}' in {primary_import.scope_path.split('.')[-1]} resolves to {pkg_name} with zero cross-scope collision with other functions")
|
|
566
|
+
|
|
567
|
+
# Determine classification
|
|
568
|
+
if call_st == ReachabilityState.CALL_REACHABLE:
|
|
569
|
+
classification = ReachabilityClassification.REACHABLE_API_USE
|
|
570
|
+
elif call_st == ReachabilityState.CALL_UNREACHABLE:
|
|
571
|
+
classification = ReachabilityClassification.DEPENDENCY_ACTIVE
|
|
572
|
+
else:
|
|
573
|
+
classification = ReachabilityClassification.DEPENDENCY_ACTIVE
|
|
574
|
+
|
|
575
|
+
findings.append(VectorCFinding(
|
|
576
|
+
advisory_id=adv_info["id"],
|
|
577
|
+
advisory_aliases=tuple(adv_info["aliases"]),
|
|
578
|
+
advisory_summary=adv_info["summary"],
|
|
579
|
+
package_name=pkg_name,
|
|
580
|
+
declared_version=declared_ver,
|
|
581
|
+
version_specifier=specifier,
|
|
582
|
+
affected_status=affected_status,
|
|
583
|
+
affected_confidence=affected_confidence,
|
|
584
|
+
import_status=ReachabilityState.PACKAGE_IMPORTED,
|
|
585
|
+
import_evidence=primary_import,
|
|
586
|
+
import_evidence_source=primary_import.mapping_evidence,
|
|
587
|
+
environment_scope=primary_import.environment_scope,
|
|
588
|
+
api_status=ReachabilityState.API_REFERENCE_FOUND,
|
|
589
|
+
call_evidence=target_call,
|
|
590
|
+
call_status=call_st,
|
|
591
|
+
call_path=c_path,
|
|
592
|
+
call_depth=c_depth,
|
|
593
|
+
edge_type=edge_t,
|
|
594
|
+
reachability_classification=classification,
|
|
595
|
+
is_transitive=False,
|
|
596
|
+
severity=adv_info["severity"],
|
|
597
|
+
cvss_score=adv_info["cvss_score"],
|
|
598
|
+
manifest_source=manifest_source,
|
|
599
|
+
manifest_line=manifest_line,
|
|
600
|
+
limitations=tuple(limitations_list),
|
|
601
|
+
))
|
|
602
|
+
|
|
603
|
+
return findings
|