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,365 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TimeCodeSecurity - Vector C SCA Reachability Analysis Contracts.
|
|
3
|
+
Defines typed, immutable data models, enums, and serialization contracts.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from dataclasses import dataclass, field, asdict
|
|
9
|
+
from typing import Optional, Tuple, Dict, Any, List
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ScopeType(str, Enum):
|
|
13
|
+
"""Lexical scope hierarchy for Python bindings."""
|
|
14
|
+
MODULE = "MODULE"
|
|
15
|
+
CLASS = "CLASS"
|
|
16
|
+
FUNCTION = "FUNCTION"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ReachabilityState(str, Enum):
|
|
20
|
+
"""Fine-grained atomic evidence states."""
|
|
21
|
+
PACKAGE_VULNERABLE = "PACKAGE_VULNERABLE"
|
|
22
|
+
PACKAGE_NOT_VULNERABLE = "PACKAGE_NOT_VULNERABLE"
|
|
23
|
+
PACKAGE_IMPORT_NOT_FOUND = "PACKAGE_IMPORT_NOT_FOUND"
|
|
24
|
+
PACKAGE_IMPORTED = "PACKAGE_IMPORTED"
|
|
25
|
+
API_REFERENCE_FOUND = "API_REFERENCE_FOUND"
|
|
26
|
+
CALL_REACHABLE = "CALL_REACHABLE"
|
|
27
|
+
CALL_UNREACHABLE = "CALL_UNREACHABLE"
|
|
28
|
+
REACHABILITY_UNRESOLVED = "REACHABILITY_UNRESOLVED"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ReachabilityClassification(str, Enum):
|
|
32
|
+
"""High-level conservative security classification."""
|
|
33
|
+
DEPENDENCY_ACTIVE = "DEPENDENCY_ACTIVE" # Vulnerable + imported
|
|
34
|
+
DEPENDENCY_DORMANT = "DEPENDENCY_DORMANT" # Vulnerable + NOT imported in static AST
|
|
35
|
+
REACHABLE_API_USE = "REACHABLE_API_USE" # Vulnerable + imported + call proven reachable from entrypoint
|
|
36
|
+
REACHABILITY_UNRESOLVED = "REACHABILITY_UNRESOLVED" # Vulnerable + imported + call path ambiguous/dynamic
|
|
37
|
+
TRANSITIVE_VULNERABLE = "TRANSITIVE_VULNERABLE" # Transitive dependency (unimported directly)
|
|
38
|
+
NOT_VULNERABLE = "NOT_VULNERABLE" # Advisory proven disjoint from declared version
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class AttributionConfidence(str, Enum):
|
|
42
|
+
"""Deterministic confidence level for symbol/call attribution."""
|
|
43
|
+
PROVEN_STATIC = "PROVEN_STATIC" # Full 5-link chain statically proven with definitive evidence
|
|
44
|
+
POSSIBLE = "POSSIBLE" # Plausible attribution but type inference or dynamic dispatch involved
|
|
45
|
+
UNRESOLVED = "UNRESOLVED" # Missing import link, cross-scope leakage, or dynamic ungrounded reference
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(frozen=True)
|
|
49
|
+
class ImportRecord:
|
|
50
|
+
"""
|
|
51
|
+
Immutable representation of an AST import statement, bound to its exact lexical scope.
|
|
52
|
+
|
|
53
|
+
Rule P-2 (Wildcard / Star-Import Contract):
|
|
54
|
+
If symbol == "*", any subsequent unresolvable symbol lookup in that scope must strictly
|
|
55
|
+
yield REACHABILITY_UNRESOLVED (reason: "Wildcard import prevents deterministic attribution"),
|
|
56
|
+
and MUST NEVER be silently dropped.
|
|
57
|
+
"""
|
|
58
|
+
import_style: str # "import" | "from_import" | "from_import_star"
|
|
59
|
+
distribution_name: str # Normalized distribution name (e.g. "urllib3")
|
|
60
|
+
import_root: str # First dotted component of imported namespace (e.g. "urllib3")
|
|
61
|
+
module: str # Full imported module path (e.g. "urllib3.poolmanager")
|
|
62
|
+
symbol: Optional[str] # Imported symbol name (e.g. "PoolManager"), None for bare import, "*" for star-import
|
|
63
|
+
alias: Optional[str] # Local binding name (e.g. "u3" or "PoolManager"), None if unaliased
|
|
64
|
+
file: str # Source file path
|
|
65
|
+
line: int # 1-based start line
|
|
66
|
+
column: int # 0-based column offset
|
|
67
|
+
scope_type: ScopeType # MODULE, CLASS, or FUNCTION
|
|
68
|
+
scope_path: str # Deterministic hierarchical path: e.g. "client", "client.make_req"
|
|
69
|
+
parent_scope_path: Optional[str] # Immediate enclosing scope path, None for MODULE
|
|
70
|
+
mapping_evidence: str # Evidence level (TARGET_ENVIRONMENT_METADATA, VERIFIED_STATIC_CURATED_MAPPING, etc.)
|
|
71
|
+
environment_scope: str # "TARGET_ENVIRONMENT" | "STATIC_METADATA" | "SCANNER_ENVIRONMENT" | "NONE"
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def is_wildcard(self) -> bool:
|
|
75
|
+
"""Rule P-2: True if this is a wildcard import (`from module import *`)."""
|
|
76
|
+
return self.symbol == "*" or self.import_style == "from_import_star"
|
|
77
|
+
|
|
78
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
79
|
+
return {
|
|
80
|
+
"import_style": self.import_style,
|
|
81
|
+
"distribution_name": self.distribution_name,
|
|
82
|
+
"import_root": self.import_root,
|
|
83
|
+
"module": self.module,
|
|
84
|
+
"symbol": self.symbol,
|
|
85
|
+
"alias": self.alias,
|
|
86
|
+
"file": self.file,
|
|
87
|
+
"line": self.line,
|
|
88
|
+
"column": self.column,
|
|
89
|
+
"scope_type": self.scope_type.value,
|
|
90
|
+
"scope_path": self.scope_path,
|
|
91
|
+
"parent_scope_path": self.parent_scope_path,
|
|
92
|
+
"mapping_evidence": self.mapping_evidence,
|
|
93
|
+
"environment_scope": self.environment_scope,
|
|
94
|
+
"is_wildcard": self.is_wildcard,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclass(frozen=True)
|
|
99
|
+
class LocalAssignmentBinding:
|
|
100
|
+
"""
|
|
101
|
+
Rule P-3: Tracks local variable instance assignments to maintain symbol attribution
|
|
102
|
+
back to an imported class or constructor.
|
|
103
|
+
Example: `manager = urllib3.PoolManager(); manager.request(...)`
|
|
104
|
+
"""
|
|
105
|
+
variable_name: str # Local variable name (e.g. "manager")
|
|
106
|
+
scope_path: str # Scope path where assignment occurred (e.g. "client.fetch")
|
|
107
|
+
source_expression: str # Expression string (e.g. "urllib3.PoolManager()")
|
|
108
|
+
attributed_type: str # Inferred dotted type (e.g. "urllib3.PoolManager")
|
|
109
|
+
attributed_import: Optional[ImportRecord] # Grounding import record
|
|
110
|
+
file: str
|
|
111
|
+
line: int
|
|
112
|
+
column: int
|
|
113
|
+
confidence: AttributionConfidence
|
|
114
|
+
|
|
115
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
116
|
+
return {
|
|
117
|
+
"variable_name": self.variable_name,
|
|
118
|
+
"scope_path": self.scope_path,
|
|
119
|
+
"source_expression": self.source_expression,
|
|
120
|
+
"attributed_type": self.attributed_type,
|
|
121
|
+
"attributed_import": self.attributed_import.to_dict() if self.attributed_import else None,
|
|
122
|
+
"file": self.file,
|
|
123
|
+
"line": self.line,
|
|
124
|
+
"column": self.column,
|
|
125
|
+
"confidence": self.confidence.value,
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@dataclass(frozen=True)
|
|
130
|
+
class CallRecord:
|
|
131
|
+
"""Represents a concrete AST call expression evaluated for dependency reachability."""
|
|
132
|
+
caller_scope: str # Scope path of caller (e.g. "app.make_req")
|
|
133
|
+
callee_expr: str # Raw expression (e.g. "u3.PoolManager().request")
|
|
134
|
+
attributed_import: Optional[ImportRecord] # Grounding import record
|
|
135
|
+
target_symbol: str # Resolved symbol (e.g. "PoolManager.request")
|
|
136
|
+
call_path: Tuple[str, ...] # Call graph hops from entrypoint (e.g. ("main", "make_req", "request"))
|
|
137
|
+
file: str
|
|
138
|
+
line: int
|
|
139
|
+
column: int
|
|
140
|
+
attribution_confidence: AttributionConfidence
|
|
141
|
+
is_dynamic: bool # True if getattr / __import__ / reflection
|
|
142
|
+
|
|
143
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
144
|
+
return {
|
|
145
|
+
"caller_scope": self.caller_scope,
|
|
146
|
+
"callee_expr": self.callee_expr,
|
|
147
|
+
"attributed_import": self.attributed_import.to_dict() if self.attributed_import else None,
|
|
148
|
+
"target_symbol": self.target_symbol,
|
|
149
|
+
"call_path": list(self.call_path),
|
|
150
|
+
"file": self.file,
|
|
151
|
+
"line": self.line,
|
|
152
|
+
"column": self.column,
|
|
153
|
+
"attribution_confidence": self.attribution_confidence.value,
|
|
154
|
+
"is_dynamic": self.is_dynamic,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@dataclass(frozen=True)
|
|
159
|
+
class ImportDistributionResult:
|
|
160
|
+
"""Reverse lookup result: maps import namespace root to distribution package name(s)."""
|
|
161
|
+
import_root: str
|
|
162
|
+
distribution_names: Tuple[str, ...] # Tuple because 1 import root can map to multiple distributions
|
|
163
|
+
evidence_source: str # Evidence hierarchy level
|
|
164
|
+
environment_scope: str # "TARGET_ENVIRONMENT" | "STATIC_METADATA" | "SCANNER_ENVIRONMENT" | "NONE"
|
|
165
|
+
is_definitive: bool # False if heuristic, scanner-only, or ambiguous
|
|
166
|
+
limitations: Tuple[str, ...] = ()
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def is_unique(self) -> bool:
|
|
170
|
+
"""True if exactly one distribution was identified."""
|
|
171
|
+
return len(self.distribution_names) == 1
|
|
172
|
+
|
|
173
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
174
|
+
return {
|
|
175
|
+
"import_root": self.import_root,
|
|
176
|
+
"distribution_names": list(self.distribution_names),
|
|
177
|
+
"evidence_source": self.evidence_source,
|
|
178
|
+
"environment_scope": self.environment_scope,
|
|
179
|
+
"is_definitive": self.is_definitive,
|
|
180
|
+
"is_unique": self.is_unique,
|
|
181
|
+
"limitations": list(self.limitations),
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@dataclass(frozen=True)
|
|
186
|
+
class ImportNamespaceResult:
|
|
187
|
+
"""Forward lookup result: maps distribution package name to import namespace root(s)."""
|
|
188
|
+
distribution_name: str
|
|
189
|
+
import_roots: Tuple[str, ...]
|
|
190
|
+
evidence_source: str
|
|
191
|
+
environment_scope: str
|
|
192
|
+
is_definitive: bool
|
|
193
|
+
limitations: Tuple[str, ...] = ()
|
|
194
|
+
|
|
195
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
196
|
+
return {
|
|
197
|
+
"distribution_name": self.distribution_name,
|
|
198
|
+
"import_roots": list(self.import_roots),
|
|
199
|
+
"evidence_source": self.evidence_source,
|
|
200
|
+
"environment_scope": self.environment_scope,
|
|
201
|
+
"is_definitive": self.is_definitive,
|
|
202
|
+
"limitations": list(self.limitations),
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
@dataclass(frozen=True)
|
|
207
|
+
class VectorCFinding:
|
|
208
|
+
"""
|
|
209
|
+
Unified Evidence Object for Vector C SCA Reachability Analysis.
|
|
210
|
+
Combines advisory affectedness with deterministic AST reachability proofs.
|
|
211
|
+
"""
|
|
212
|
+
# 1. Advisory Grounding (from OSV via version_matcher)
|
|
213
|
+
advisory_id: str
|
|
214
|
+
advisory_aliases: Tuple[str, ...] = ()
|
|
215
|
+
advisory_summary: str = ""
|
|
216
|
+
package_name: str = ""
|
|
217
|
+
declared_version: Optional[str] = None
|
|
218
|
+
version_specifier: Optional[str] = None
|
|
219
|
+
affected_status: str = "CONFIRMED" # CONFIRMED | POTENTIAL | UNRESOLVED
|
|
220
|
+
affected_confidence: float = 1.0
|
|
221
|
+
|
|
222
|
+
# 2. Import Grounding
|
|
223
|
+
import_status: ReachabilityState = ReachabilityState.PACKAGE_IMPORT_NOT_FOUND
|
|
224
|
+
import_evidence: Optional[ImportRecord] = None
|
|
225
|
+
import_evidence_source: str = "UNRESOLVED"
|
|
226
|
+
environment_scope: str = "NONE"
|
|
227
|
+
|
|
228
|
+
# 3. Call Grounding
|
|
229
|
+
api_status: ReachabilityState = ReachabilityState.REACHABILITY_UNRESOLVED
|
|
230
|
+
call_evidence: Optional[CallRecord] = None
|
|
231
|
+
|
|
232
|
+
# 4. Reachability & Call Graph
|
|
233
|
+
call_status: ReachabilityState = ReachabilityState.REACHABILITY_UNRESOLVED
|
|
234
|
+
call_path: Tuple[str, ...] = ()
|
|
235
|
+
call_depth: int = 0
|
|
236
|
+
edge_type: str = "UNRESOLVED_EDGE"
|
|
237
|
+
|
|
238
|
+
# 5. Final Classification & Advisory Severity
|
|
239
|
+
reachability_classification: ReachabilityClassification = ReachabilityClassification.REACHABILITY_UNRESOLVED
|
|
240
|
+
is_transitive: bool = False
|
|
241
|
+
severity: str = "UNKNOWN"
|
|
242
|
+
cvss_score: Optional[float] = None
|
|
243
|
+
manifest_source: str = ""
|
|
244
|
+
manifest_line: Optional[int] = None
|
|
245
|
+
|
|
246
|
+
# 6. Audit & Limitations
|
|
247
|
+
limitations: Tuple[str, ...] = ()
|
|
248
|
+
|
|
249
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
250
|
+
return {
|
|
251
|
+
"advisory_id": self.advisory_id,
|
|
252
|
+
"advisory_aliases": list(self.advisory_aliases),
|
|
253
|
+
"advisory_summary": self.advisory_summary,
|
|
254
|
+
"package_name": self.package_name,
|
|
255
|
+
"declared_version": self.declared_version,
|
|
256
|
+
"version_specifier": self.version_specifier,
|
|
257
|
+
"affected_status": self.affected_status,
|
|
258
|
+
"affected_confidence": self.affected_confidence,
|
|
259
|
+
"import_status": self.import_status.value if isinstance(self.import_status, ReachabilityState) else str(self.import_status),
|
|
260
|
+
"import_evidence": self.import_evidence.to_dict() if self.import_evidence else None,
|
|
261
|
+
"import_evidence_source": self.import_evidence_source,
|
|
262
|
+
"environment_scope": self.environment_scope,
|
|
263
|
+
"api_status": self.api_status.value if isinstance(self.api_status, ReachabilityState) else str(self.api_status),
|
|
264
|
+
"call_evidence": self.call_evidence.to_dict() if self.call_evidence else None,
|
|
265
|
+
"call_status": self.call_status.value if isinstance(self.call_status, ReachabilityState) else str(self.call_status),
|
|
266
|
+
"call_path": list(self.call_path),
|
|
267
|
+
"call_depth": self.call_depth,
|
|
268
|
+
"edge_type": self.edge_type,
|
|
269
|
+
"reachability_classification": self.reachability_classification.value if isinstance(self.reachability_classification, ReachabilityClassification) else str(self.reachability_classification),
|
|
270
|
+
"is_transitive": self.is_transitive,
|
|
271
|
+
"severity": self.severity,
|
|
272
|
+
"cvss_score": self.cvss_score,
|
|
273
|
+
"manifest_source": self.manifest_source,
|
|
274
|
+
"manifest_line": self.manifest_line,
|
|
275
|
+
"limitations": list(self.limitations),
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
@classmethod
|
|
279
|
+
def from_dict(cls, d: Dict[str, Any]) -> VectorCFinding:
|
|
280
|
+
"""Reconstitutes a typed VectorCFinding from a serialized dictionary."""
|
|
281
|
+
import_status_val = d.get("import_status", ReachabilityState.PACKAGE_IMPORT_NOT_FOUND.value)
|
|
282
|
+
if isinstance(import_status_val, str):
|
|
283
|
+
import_status_val = ReachabilityState(import_status_val)
|
|
284
|
+
|
|
285
|
+
api_status_val = d.get("api_status", ReachabilityState.REACHABILITY_UNRESOLVED.value)
|
|
286
|
+
if isinstance(api_status_val, str):
|
|
287
|
+
api_status_val = ReachabilityState(api_status_val)
|
|
288
|
+
|
|
289
|
+
call_status_val = d.get("call_status", ReachabilityState.REACHABILITY_UNRESOLVED.value)
|
|
290
|
+
if isinstance(call_status_val, str):
|
|
291
|
+
call_status_val = ReachabilityState(call_status_val)
|
|
292
|
+
|
|
293
|
+
class_val = d.get("reachability_classification", ReachabilityClassification.REACHABILITY_UNRESOLVED.value)
|
|
294
|
+
if isinstance(class_val, str):
|
|
295
|
+
class_val = ReachabilityClassification(class_val)
|
|
296
|
+
|
|
297
|
+
import_ev = None
|
|
298
|
+
if d.get("import_evidence"):
|
|
299
|
+
ie_d = d["import_evidence"]
|
|
300
|
+
scope_t = ie_d.get("scope_type", ScopeType.MODULE.value)
|
|
301
|
+
if isinstance(scope_t, str):
|
|
302
|
+
scope_t = ScopeType(scope_t)
|
|
303
|
+
import_ev = ImportRecord(
|
|
304
|
+
import_style=ie_d.get("import_style", "import"),
|
|
305
|
+
distribution_name=ie_d.get("distribution_name", ""),
|
|
306
|
+
import_root=ie_d.get("import_root", ""),
|
|
307
|
+
module=ie_d.get("module", ""),
|
|
308
|
+
symbol=ie_d.get("symbol"),
|
|
309
|
+
alias=ie_d.get("alias"),
|
|
310
|
+
file=ie_d.get("file", ""),
|
|
311
|
+
line=ie_d.get("line", 1),
|
|
312
|
+
column=ie_d.get("column", 0),
|
|
313
|
+
scope_type=scope_t,
|
|
314
|
+
scope_path=ie_d.get("scope_path", ""),
|
|
315
|
+
parent_scope_path=ie_d.get("parent_scope_path"),
|
|
316
|
+
mapping_evidence=ie_d.get("mapping_evidence", "UNRESOLVED"),
|
|
317
|
+
environment_scope=ie_d.get("environment_scope", "NONE"),
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
call_ev = None
|
|
321
|
+
if d.get("call_evidence"):
|
|
322
|
+
ce_d = d["call_evidence"]
|
|
323
|
+
conf = ce_d.get("attribution_confidence", AttributionConfidence.UNRESOLVED.value)
|
|
324
|
+
if isinstance(conf, str):
|
|
325
|
+
conf = AttributionConfidence(conf)
|
|
326
|
+
call_ev = CallRecord(
|
|
327
|
+
caller_scope=ce_d.get("caller_scope", ""),
|
|
328
|
+
callee_expr=ce_d.get("callee_expr", ""),
|
|
329
|
+
attributed_import=import_ev,
|
|
330
|
+
target_symbol=ce_d.get("target_symbol", ""),
|
|
331
|
+
call_path=tuple(ce_d.get("call_path", ())),
|
|
332
|
+
file=ce_d.get("file", ""),
|
|
333
|
+
line=ce_d.get("line", 1),
|
|
334
|
+
column=ce_d.get("column", 0),
|
|
335
|
+
attribution_confidence=conf,
|
|
336
|
+
is_dynamic=ce_d.get("is_dynamic", False),
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
return cls(
|
|
340
|
+
advisory_id=d.get("advisory_id", ""),
|
|
341
|
+
advisory_aliases=tuple(d.get("advisory_aliases", ())),
|
|
342
|
+
advisory_summary=d.get("advisory_summary", ""),
|
|
343
|
+
package_name=d.get("package_name", ""),
|
|
344
|
+
declared_version=d.get("declared_version"),
|
|
345
|
+
version_specifier=d.get("version_specifier"),
|
|
346
|
+
affected_status=d.get("affected_status", "CONFIRMED"),
|
|
347
|
+
affected_confidence=float(d.get("affected_confidence", 1.0)),
|
|
348
|
+
import_status=import_status_val,
|
|
349
|
+
import_evidence=import_ev,
|
|
350
|
+
import_evidence_source=d.get("import_evidence_source", "UNRESOLVED"),
|
|
351
|
+
environment_scope=d.get("environment_scope", "NONE"),
|
|
352
|
+
api_status=api_status_val,
|
|
353
|
+
call_evidence=call_ev,
|
|
354
|
+
call_status=call_status_val,
|
|
355
|
+
call_path=tuple(d.get("call_path", ())),
|
|
356
|
+
call_depth=int(d.get("call_depth", 0)),
|
|
357
|
+
edge_type=d.get("edge_type", "UNRESOLVED_EDGE"),
|
|
358
|
+
reachability_classification=class_val,
|
|
359
|
+
is_transitive=bool(d.get("is_transitive", False)),
|
|
360
|
+
severity=d.get("severity", "UNKNOWN"),
|
|
361
|
+
cvss_score=float(d["cvss_score"]) if d.get("cvss_score") is not None else None,
|
|
362
|
+
manifest_source=d.get("manifest_source", ""),
|
|
363
|
+
manifest_line=d.get("manifest_line"),
|
|
364
|
+
limitations=tuple(d.get("limitations", ())),
|
|
365
|
+
)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TimeCodeSecurity - Vector C Curated Distribution to Import Namespace Mappings.
|
|
3
|
+
Provides compile-time, zero-IO bidirectional lookup tables for well-known
|
|
4
|
+
Python distribution packages whose import namespaces differ from their PyPI distribution names.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Dict, Tuple, Optional
|
|
8
|
+
|
|
9
|
+
# Forward Mapping: Distribution Name (PEP 503 normalized) -> Tuple of provided import root(s)
|
|
10
|
+
CURATED_DIST_TO_IMPORTS: Dict[str, Tuple[str, ...]] = {
|
|
11
|
+
"python-dateutil": ("dateutil",),
|
|
12
|
+
"attrs": ("attr",),
|
|
13
|
+
"pillow": ("PIL",),
|
|
14
|
+
"scikit-learn": ("sklearn",),
|
|
15
|
+
"opencv-python": ("cv2",),
|
|
16
|
+
"beautifulsoup4": ("bs4",),
|
|
17
|
+
"pyyaml": ("yaml",),
|
|
18
|
+
"mysqlclient": ("MySQLdb",),
|
|
19
|
+
"pypdf2": ("PyPDF2",),
|
|
20
|
+
"protobuf": ("google.protobuf",),
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# Reverse Mapping: Import Root (First dotted identifier) -> Tuple of distribution name(s)
|
|
24
|
+
CURATED_IMPORT_TO_DISTS: Dict[str, Tuple[str, ...]] = {
|
|
25
|
+
"dateutil": ("python-dateutil",),
|
|
26
|
+
"attr": ("attrs",),
|
|
27
|
+
"PIL": ("pillow",),
|
|
28
|
+
"sklearn": ("scikit-learn",),
|
|
29
|
+
"cv2": ("opencv-python",),
|
|
30
|
+
"bs4": ("beautifulsoup4",),
|
|
31
|
+
"yaml": ("pyyaml",),
|
|
32
|
+
"MySQLdb": ("mysqlclient",),
|
|
33
|
+
"PyPDF2": ("pypdf2",),
|
|
34
|
+
"google.protobuf": ("protobuf",),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def get_curated_imports_for_dist(dist: str) -> Optional[Tuple[str, ...]]:
|
|
39
|
+
"""Returns the curated import roots for a given distribution name, or None."""
|
|
40
|
+
norm = dist.strip().lower().replace("_", "-")
|
|
41
|
+
return CURATED_DIST_TO_IMPORTS.get(norm)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_curated_dists_for_import(import_root: str) -> Optional[Tuple[str, ...]]:
|
|
45
|
+
"""Returns the curated distribution name(s) for a given import root, or None."""
|
|
46
|
+
return CURATED_IMPORT_TO_DISTS.get(import_root)
|