stackparity 1.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.
- stackparity/__init__.py +17 -0
- stackparity/_engine/agents/investigator.py +294 -0
- stackparity/_engine/agents/memory_agent.py +37 -0
- stackparity/_engine/agents/pipeline_agent.py +152 -0
- stackparity/_engine/agents/remediation_agent.py +248 -0
- stackparity/_engine/agents/runtime.py +177 -0
- stackparity/_engine/agents/specialists.py +709 -0
- stackparity/_engine/agents/suspicious_change_agent.py +1275 -0
- stackparity/_engine/cli/__init__.py +2 -0
- stackparity/_engine/cli/main.py +1252 -0
- stackparity/_engine/cli/remediate.py +461 -0
- stackparity/_engine/cli/term.py +44 -0
- stackparity/_engine/config/__init__.py +0 -0
- stackparity/_engine/config/constants.py +88 -0
- stackparity/_engine/config/loader.py +155 -0
- stackparity/_engine/config/settings.py +108 -0
- stackparity/_engine/containers/__init__.py +12 -0
- stackparity/_engine/containers/discovery.py +143 -0
- stackparity/_engine/containers/models.py +72 -0
- stackparity/_engine/containers/trivy_image_scanner.py +165 -0
- stackparity/_engine/core/__init__.py +0 -0
- stackparity/_engine/core/capabilities.py +107 -0
- stackparity/_engine/core/finding_schema.py +305 -0
- stackparity/_engine/core/git_manager.py +206 -0
- stackparity/_engine/core/http.py +64 -0
- stackparity/_engine/core/models.py +109 -0
- stackparity/_engine/core/netpolicy.py +242 -0
- stackparity/_engine/core/plugins.py +43 -0
- stackparity/_engine/core/repository_inspector.py +243 -0
- stackparity/_engine/core/safe_env.py +48 -0
- stackparity/_engine/core/scan_orchestrator.py +289 -0
- stackparity/_engine/core/scan_state.py +58 -0
- stackparity/_engine/core/url_validator.py +135 -0
- stackparity/_engine/ecosystems/__init__.py +1 -0
- stackparity/_engine/ecosystems/registry.py +138 -0
- stackparity/_engine/evidence/__init__.py +1 -0
- stackparity/_engine/evidence/store.py +65 -0
- stackparity/_engine/explainability/__init__.py +0 -0
- stackparity/_engine/explainability/evidence_formatter.py +30 -0
- stackparity/_engine/explainability/explanation_engine.py +132 -0
- stackparity/_engine/explainability/explanation_validator.py +54 -0
- stackparity/_engine/explainability/prompt_templates.py +18 -0
- stackparity/_engine/graph/__init__.py +0 -0
- stackparity/_engine/graph/dependency_tracer.py +86 -0
- stackparity/_engine/graph/graph_builder.py +165 -0
- stackparity/_engine/graph/graph_diff.py +57 -0
- stackparity/_engine/graph/graph_exporter.py +194 -0
- stackparity/_engine/graph/graph_validator.py +46 -0
- stackparity/_engine/graph/impact_analyzer.py +23 -0
- stackparity/_engine/graph/tree_view.py +185 -0
- stackparity/_engine/intel/__init__.py +0 -0
- stackparity/_engine/intel/epss.py +53 -0
- stackparity/_engine/llm/__init__.py +1 -0
- stackparity/_engine/llm/client.py +138 -0
- stackparity/_engine/monitor/__init__.py +0 -0
- stackparity/_engine/monitor/watch.py +171 -0
- stackparity/_engine/non_cve/__init__.py +7 -0
- stackparity/_engine/non_cve/base.py +62 -0
- stackparity/_engine/non_cve/iac.py +144 -0
- stackparity/_engine/non_cve/sast.py +272 -0
- stackparity/_engine/non_cve/supply_chain.py +147 -0
- stackparity/_engine/orchestration/__init__.py +1 -0
- stackparity/_engine/orchestration/pipeline.py +279 -0
- stackparity/_engine/orchestration/supervisor.py +167 -0
- stackparity/_engine/pipeline_analysis/__init__.py +0 -0
- stackparity/_engine/pipeline_analysis/analyzer.py +90 -0
- stackparity/_engine/pipeline_analysis/ci.py +189 -0
- stackparity/_engine/pipeline_analysis/ci_adapters/__init__.py +24 -0
- stackparity/_engine/pipeline_analysis/ci_adapters/azure_pipelines.py +221 -0
- stackparity/_engine/pipeline_analysis/ci_adapters/base.py +239 -0
- stackparity/_engine/pipeline_analysis/ci_adapters/circleci.py +176 -0
- stackparity/_engine/pipeline_analysis/ci_adapters/github_actions.py +356 -0
- stackparity/_engine/pipeline_analysis/ci_adapters/gitlab_ci.py +268 -0
- stackparity/_engine/pipeline_analysis/ci_adapters/jenkins.py +180 -0
- stackparity/_engine/pipeline_analysis/ci_adapters/registry.py +80 -0
- stackparity/_engine/pipeline_analysis/ci_models.py +72 -0
- stackparity/_engine/pipeline_analysis/dockerfile.py +235 -0
- stackparity/_engine/pipeline_analysis/eol.py +62 -0
- stackparity/_engine/pipeline_analysis/models.py +37 -0
- stackparity/_engine/policy/__init__.py +0 -0
- stackparity/_engine/policy/engine.py +216 -0
- stackparity/_engine/policy/resources/default.yaml +56 -0
- stackparity/_engine/policy/resources/strict.yaml +35 -0
- stackparity/_engine/reachability/__init__.py +0 -0
- stackparity/_engine/reachability/app_reachability.py +186 -0
- stackparity/_engine/reachability/scanners.py +215 -0
- stackparity/_engine/remediation/__init__.py +0 -0
- stackparity/_engine/remediation/adapters.py +198 -0
- stackparity/_engine/remediation/apply_local.py +309 -0
- stackparity/_engine/remediation/code_fixes.py +383 -0
- stackparity/_engine/remediation/compat.py +156 -0
- stackparity/_engine/remediation/container_plan.py +127 -0
- stackparity/_engine/remediation/delivery.py +31 -0
- stackparity/_engine/remediation/export.py +44 -0
- stackparity/_engine/remediation/lifecycle.py +623 -0
- stackparity/_engine/remediation/local_trial.py +358 -0
- stackparity/_engine/remediation/patchers.py +215 -0
- stackparity/_engine/remediation/planner.py +285 -0
- stackparity/_engine/remediation/pr_template_engine.py +234 -0
- stackparity/_engine/remediation/reachability_impact.py +147 -0
- stackparity/_engine/remediation/versions.py +92 -0
- stackparity/_engine/remediation/whatif.py +64 -0
- stackparity/_engine/remediation/worktree_pr.py +434 -0
- stackparity/_engine/reporting/__init__.py +0 -0
- stackparity/_engine/reporting/counts.py +63 -0
- stackparity/_engine/reporting/fix_pdf.py +343 -0
- stackparity/_engine/reporting/fix_report.py +135 -0
- stackparity/_engine/reporting/json_exporter.py +61 -0
- stackparity/_engine/reporting/report_generator.py +200 -0
- stackparity/_engine/reporting/sarif.py +71 -0
- stackparity/_engine/reporting/vex.py +57 -0
- stackparity/_engine/reporting/view.py +166 -0
- stackparity/_engine/risk_analysis/__init__.py +0 -0
- stackparity/_engine/risk_analysis/contextual_scorer.py +253 -0
- stackparity/_engine/risk_analysis/evidence_collector.py +62 -0
- stackparity/_engine/risk_analysis/evidence_normalizer.py +37 -0
- stackparity/_engine/risk_analysis/finding_correlator.py +90 -0
- stackparity/_engine/risk_analysis/function_impact.py +184 -0
- stackparity/_engine/risk_analysis/production_context.py +252 -0
- stackparity/_engine/risk_analysis/risk_rules.py +81 -0
- stackparity/_engine/risk_analysis/risk_scorer.py +390 -0
- stackparity/_engine/sandbox/__init__.py +0 -0
- stackparity/_engine/sandbox/runner.py +142 -0
- stackparity/_engine/sbom/__init__.py +0 -0
- stackparity/_engine/sbom/adapters/__init__.py +19 -0
- stackparity/_engine/sbom/adapters/builtin.py +29 -0
- stackparity/_engine/sbom/adapters/syft.py +26 -0
- stackparity/_engine/sbom/adapters/trivy.py +76 -0
- stackparity/_engine/sbom/builtin_generator.py +227 -0
- stackparity/_engine/sbom/cyclonedx_validator.py +166 -0
- stackparity/_engine/sbom/exporters.py +153 -0
- stackparity/_engine/sbom/fusion/__init__.py +5 -0
- stackparity/_engine/sbom/fusion/engine.py +315 -0
- stackparity/_engine/sbom/fusion/hashes.py +47 -0
- stackparity/_engine/sbom/fusion/ledger.py +96 -0
- stackparity/_engine/sbom/fusion/registries.py +271 -0
- stackparity/_engine/sbom/fusion/resolver.py +143 -0
- stackparity/_engine/sbom/fusion/writer.py +114 -0
- stackparity/_engine/sbom/lockfile_analyzer.py +114 -0
- stackparity/_engine/sbom/merge.py +71 -0
- stackparity/_engine/sbom/package_extractors/common.py +104 -0
- stackparity/_engine/sbom/package_extractors/manifests.py +101 -0
- stackparity/_engine/sbom/package_extractors/npm.py +206 -0
- stackparity/_engine/sbom/package_extractors/others.py +267 -0
- stackparity/_engine/sbom/package_extractors/python.py +143 -0
- stackparity/_engine/sbom/quality_analyzer.py +191 -0
- stackparity/_engine/sbom/scanner_engine.py +98 -0
- stackparity/_engine/sbom/syft_runner.py +100 -0
- stackparity/_engine/sbom/tool_locator.py +69 -0
- stackparity/_engine/sbom/trivy_runner.py +82 -0
- stackparity/_engine/storage/__init__.py +0 -0
- stackparity/_engine/storage/cache.py +56 -0
- stackparity/_engine/storage/database.py +295 -0
- stackparity/_engine/storage/memory.py +146 -0
- stackparity/_engine/suspicious_changes/__init__.py +12 -0
- stackparity/_engine/suspicious_changes/analyzer.py +1022 -0
- stackparity/_engine/suspicious_changes/change_correlation.py +861 -0
- stackparity/_engine/suspicious_changes/lifecycle_script_detector.py +263 -0
- stackparity/_engine/suspicious_changes/lockfile_change_detector.py +316 -0
- stackparity/_engine/suspicious_changes/manifest_diff_detector.py +251 -0
- stackparity/_engine/suspicious_changes/package_risk.py +78 -0
- stackparity/_engine/suspicious_changes/popular_packages.py +94 -0
- stackparity/_engine/suspicious_changes/registry_detector.py +354 -0
- stackparity/_engine/suspicious_changes/suspicious_models.py +57 -0
- stackparity/_engine/suspicious_changes/typosquatting_detector.py +298 -0
- stackparity/_engine/tools/__init__.py +1 -0
- stackparity/_engine/tools/builtin.py +93 -0
- stackparity/_engine/tools/registry.py +66 -0
- stackparity/_engine/ui/__init__.py +0 -0
- stackparity/_engine/ui/components/__init__.py +0 -0
- stackparity/_engine/ui/components/common.py +238 -0
- stackparity/_engine/ui/components/live_progress.py +157 -0
- stackparity/_engine/ui/components/memory_panel.py +82 -0
- stackparity/_engine/ui/pages/__init__.py +0 -0
- stackparity/_engine/ui/pages/agents_page.py +76 -0
- stackparity/_engine/ui/pages/architecture_page.py +44 -0
- stackparity/_engine/ui/pages/fixes_page.py +98 -0
- stackparity/_engine/ui/pages/graph_page.py +203 -0
- stackparity/_engine/ui/pages/health_page.py +117 -0
- stackparity/_engine/ui/pages/monitor_page.py +67 -0
- stackparity/_engine/ui/pages/pipeline_page.py +219 -0
- stackparity/_engine/ui/pages/remediation_page.py +409 -0
- stackparity/_engine/ui/pages/reports_page.py +54 -0
- stackparity/_engine/ui/pages/sbom_page.py +210 -0
- stackparity/_engine/ui/pages/scan_page.py +131 -0
- stackparity/_engine/ui/pages/suspicious_page.py +551 -0
- stackparity/_engine/ui/pages/vulns_page.py +201 -0
- stackparity/_engine/ui/state.py +116 -0
- stackparity/_engine/ui/theme.py +201 -0
- stackparity/_engine/ui/visualizations/__init__.py +0 -0
- stackparity/_engine/ui/visualizations/graphs.py +373 -0
- stackparity/_engine/vulnerability/__init__.py +0 -0
- stackparity/_engine/vulnerability/cvss.py +58 -0
- stackparity/_engine/vulnerability/kev_client.py +47 -0
- stackparity/_engine/vulnerability/nvd_client.py +74 -0
- stackparity/_engine/vulnerability/osv_client.py +139 -0
- stackparity/_engine/vulnerability/remediation_engine.py +50 -0
- stackparity/_engine/vulnerability/verification.py +94 -0
- stackparity/_engine/vulnerability/version_matcher.py +299 -0
- stackparity/_engine/vulnerability/vulnerability_correlator.py +303 -0
- stackparity/_engine/vulnerability/vulnerability_models.py +64 -0
- stackparity/cli.py +30 -0
- stackparity/dashboard_app.py +95 -0
- stackparity/web_dist/assets/index-DRJYw2Du.css +1 -0
- stackparity/web_dist/assets/index-Q6LLpbEi.js +495 -0
- stackparity/web_dist/index.html +13 -0
- stackparity/web_server.py +533 -0
- stackparity-1.0.0.dist-info/METADATA +204 -0
- stackparity-1.0.0.dist-info/RECORD +212 -0
- stackparity-1.0.0.dist-info/WHEEL +4 -0
- stackparity-1.0.0.dist-info/entry_points.txt +2 -0
- stackparity-1.0.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"""Go, Rust, PHP, .NET and Java/Maven extractors."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
import xml.etree.ElementTree as ET
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
from core.models import LockDependency
|
|
10
|
+
from sbom.package_extractors.common import classify_source, make_purl
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
import tomllib
|
|
14
|
+
except ImportError: # pragma: no cover
|
|
15
|
+
import tomli as tomllib # type: ignore
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _mk(eco, name, version, lockfile, service_dir, **kw) -> LockDependency:
|
|
19
|
+
return LockDependency(name=name, version=version, ecosystem=eco, purl=make_purl(eco, name, version),
|
|
20
|
+
lockfile=lockfile, service_dir=service_dir, **kw)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# ---------------------------------------------------------------- Go
|
|
24
|
+
def parse_go_mod(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
25
|
+
out = []
|
|
26
|
+
in_block = False
|
|
27
|
+
for i, line in enumerate(text.splitlines(), 1):
|
|
28
|
+
s = line.strip()
|
|
29
|
+
if s.startswith("require ("):
|
|
30
|
+
in_block = True
|
|
31
|
+
continue
|
|
32
|
+
if in_block and s == ")":
|
|
33
|
+
in_block = False
|
|
34
|
+
continue
|
|
35
|
+
body = None
|
|
36
|
+
if in_block:
|
|
37
|
+
body = s
|
|
38
|
+
elif s.startswith("require ") and "(" not in s:
|
|
39
|
+
body = s[len("require "):].strip()
|
|
40
|
+
if not body or body.startswith("//"):
|
|
41
|
+
continue
|
|
42
|
+
indirect = "// indirect" in body
|
|
43
|
+
body = body.split("//", 1)[0].strip()
|
|
44
|
+
parts = body.split()
|
|
45
|
+
if len(parts) >= 2:
|
|
46
|
+
out.append(_mk("Go", parts[0], parts[1], lockfile, service_dir, direct=not indirect, record=f"line {i}",
|
|
47
|
+
source_type="registry"))
|
|
48
|
+
return out
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def parse_go_sum(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
52
|
+
seen: dict[tuple[str, str], LockDependency] = {}
|
|
53
|
+
for i, line in enumerate(text.splitlines(), 1):
|
|
54
|
+
parts = line.split()
|
|
55
|
+
if len(parts) != 3:
|
|
56
|
+
continue
|
|
57
|
+
mod, ver, h = parts
|
|
58
|
+
is_mod_only = ver.endswith("/go.mod")
|
|
59
|
+
ver = ver.removesuffix("/go.mod")
|
|
60
|
+
key = (mod, ver)
|
|
61
|
+
if key not in seen or (not is_mod_only):
|
|
62
|
+
if is_mod_only and key in seen:
|
|
63
|
+
continue
|
|
64
|
+
seen[key] = _mk("Go", mod, ver, lockfile, service_dir, direct=None, record=f"line {i}", integrity=h,
|
|
65
|
+
source_type="registry")
|
|
66
|
+
return list(seen.values())
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# ---------------------------------------------------------------- Rust
|
|
70
|
+
def parse_cargo_lock(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
71
|
+
data = tomllib.loads(text)
|
|
72
|
+
pkgs = data.get("package", [])
|
|
73
|
+
members = [p for p in pkgs if not p.get("source")]
|
|
74
|
+
|
|
75
|
+
def depname(entry: str) -> str:
|
|
76
|
+
return entry.split(" ")[0]
|
|
77
|
+
|
|
78
|
+
direct = {depname(d) for m in members for d in (m.get("dependencies") or [])}
|
|
79
|
+
member_names = {m["name"] for m in members}
|
|
80
|
+
out = []
|
|
81
|
+
for p in pkgs:
|
|
82
|
+
if not p.get("source"):
|
|
83
|
+
continue
|
|
84
|
+
src = p["source"]
|
|
85
|
+
out.append(_mk("crates.io", p["name"], p.get("version"), lockfile, service_dir,
|
|
86
|
+
direct=(p["name"] in direct) if members else None,
|
|
87
|
+
requires=sorted({depname(d) for d in (p.get("dependencies") or [])} - member_names),
|
|
88
|
+
record=f"package[{p['name']}]", integrity=p.get("checksum"), resolved=src,
|
|
89
|
+
source_type="git" if src.startswith("git+") else "registry" if src.startswith("registry+") else classify_source(src)))
|
|
90
|
+
return out
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# ---------------------------------------------------------------- PHP
|
|
94
|
+
def parse_composer_lock(text: str, lockfile: str, service_dir: str, composer_json: Optional[str] = None, **_) -> list[LockDependency]:
|
|
95
|
+
data = json.loads(text)
|
|
96
|
+
direct: Optional[set[str]] = None
|
|
97
|
+
if composer_json:
|
|
98
|
+
try:
|
|
99
|
+
cj = json.loads(composer_json)
|
|
100
|
+
direct = {k.lower() for k in (cj.get("require") or {})} | {k.lower() for k in (cj.get("require-dev") or {})}
|
|
101
|
+
except Exception:
|
|
102
|
+
direct = None
|
|
103
|
+
out = []
|
|
104
|
+
for section, dev in (("packages", False), ("packages-dev", True)):
|
|
105
|
+
for p in data.get(section) or []:
|
|
106
|
+
name = p.get("name")
|
|
107
|
+
if not name:
|
|
108
|
+
continue
|
|
109
|
+
ver = (p.get("version") or "").lstrip("v") or None
|
|
110
|
+
dist = p.get("dist") or {}
|
|
111
|
+
src = p.get("source") or {}
|
|
112
|
+
out.append(_mk("Packagist", name.lower(), ver, lockfile, service_dir,
|
|
113
|
+
direct=(name.lower() in direct) if direct is not None else None, dev=True if dev else None,
|
|
114
|
+
requires=sorted(k.lower() for k in (p.get("require") or {}) if "/" in k),
|
|
115
|
+
record=f"{section}[{name}]", integrity=dist.get("shasum") or None,
|
|
116
|
+
resolved=dist.get("url") or src.get("url"),
|
|
117
|
+
license=" OR ".join(p.get("license") or []) or None,
|
|
118
|
+
meta={k: v for k, v in (("homepage", p.get("homepage")), ("description", p.get("description")), ("published", p.get("time")),
|
|
119
|
+
("authors", [a.get("name") for a in p.get("authors", []) if a.get("name")]),
|
|
120
|
+
("vcs", src.get("url")), ("vcs_ref", src.get("reference")), ("abandoned", p.get("abandoned") or None)) if v},
|
|
121
|
+
source_type=classify_source(dist.get("url") or src.get("url"))))
|
|
122
|
+
return out
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# ---------------------------------------------------------------- .NET
|
|
126
|
+
def parse_nuget_lock(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
127
|
+
data = json.loads(text)
|
|
128
|
+
out: dict[tuple[str, str], LockDependency] = {}
|
|
129
|
+
for fw, pkgs in (data.get("dependencies") or {}).items():
|
|
130
|
+
for name, meta in pkgs.items():
|
|
131
|
+
if meta.get("type") == "Project":
|
|
132
|
+
continue
|
|
133
|
+
ver = meta.get("resolved")
|
|
134
|
+
key = (name.lower(), ver or "")
|
|
135
|
+
dep = out.get(key)
|
|
136
|
+
is_direct = meta.get("type") == "Direct"
|
|
137
|
+
if dep:
|
|
138
|
+
dep.direct = bool(dep.direct or is_direct)
|
|
139
|
+
continue
|
|
140
|
+
out[key] = _mk("NuGet", name, ver, lockfile, service_dir, direct=is_direct,
|
|
141
|
+
requires=sorted((meta.get("dependencies") or {}).keys()), record=f"{fw}[{name}]",
|
|
142
|
+
integrity=meta.get("contentHash"), source_type="registry", meta={"hash_alg": "sha512"} if meta.get("contentHash") else {})
|
|
143
|
+
return list(out.values())
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def parse_csproj(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
147
|
+
out = []
|
|
148
|
+
try:
|
|
149
|
+
root = ET.fromstring(text)
|
|
150
|
+
except ET.ParseError:
|
|
151
|
+
return out
|
|
152
|
+
for el in root.iter():
|
|
153
|
+
if el.tag.split("}")[-1] == "PackageReference":
|
|
154
|
+
name = el.attrib.get("Include") or el.attrib.get("Update")
|
|
155
|
+
ver = el.attrib.get("Version")
|
|
156
|
+
if ver is None:
|
|
157
|
+
for ch in el:
|
|
158
|
+
if ch.tag.split("}")[-1] == "Version":
|
|
159
|
+
ver = (ch.text or "").strip()
|
|
160
|
+
if name:
|
|
161
|
+
if ver and ver.startswith("$("):
|
|
162
|
+
ver = None
|
|
163
|
+
out.append(_mk("NuGet", name, ver, lockfile, service_dir, direct=True, record="PackageReference",
|
|
164
|
+
source_type="registry"))
|
|
165
|
+
return out
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# ---------------------------------------------------------------- Java
|
|
169
|
+
def parse_pom(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
170
|
+
out = []
|
|
171
|
+
text = re.sub(r"<\?xml[^>]*\?>", "", text, count=1)
|
|
172
|
+
try:
|
|
173
|
+
root = ET.fromstring(text)
|
|
174
|
+
except ET.ParseError:
|
|
175
|
+
return out
|
|
176
|
+
|
|
177
|
+
def local(tag):
|
|
178
|
+
return tag.split("}")[-1]
|
|
179
|
+
|
|
180
|
+
props: dict[str, str] = {}
|
|
181
|
+
for el in root:
|
|
182
|
+
if local(el.tag) == "properties":
|
|
183
|
+
for p in el:
|
|
184
|
+
props[local(p.tag)] = (p.text or "").strip()
|
|
185
|
+
for el in root:
|
|
186
|
+
if local(el.tag) in ("groupId", "version"):
|
|
187
|
+
props[f"project.{local(el.tag)}"] = (el.text or "").strip()
|
|
188
|
+
props[f"pom.{local(el.tag)}"] = (el.text or "").strip()
|
|
189
|
+
|
|
190
|
+
def resolve(v: Optional[str]) -> Optional[str]:
|
|
191
|
+
if v is None:
|
|
192
|
+
return None
|
|
193
|
+
v = v.strip()
|
|
194
|
+
for _ in range(5):
|
|
195
|
+
m = re.search(r"\$\{([^}]+)\}", v)
|
|
196
|
+
if not m:
|
|
197
|
+
break
|
|
198
|
+
repl = props.get(m.group(1))
|
|
199
|
+
if repl is None:
|
|
200
|
+
return None
|
|
201
|
+
v = v.replace(m.group(0), repl)
|
|
202
|
+
return v or None
|
|
203
|
+
|
|
204
|
+
managed: dict[str, str] = {}
|
|
205
|
+
for dm in root.iter():
|
|
206
|
+
if local(dm.tag) == "dependencyManagement":
|
|
207
|
+
for dep in dm.iter():
|
|
208
|
+
if local(dep.tag) == "dependency":
|
|
209
|
+
g = a = v = None
|
|
210
|
+
for ch in dep:
|
|
211
|
+
t = local(ch.tag)
|
|
212
|
+
if t == "groupId":
|
|
213
|
+
g = ch.text
|
|
214
|
+
elif t == "artifactId":
|
|
215
|
+
a = ch.text
|
|
216
|
+
elif t == "version":
|
|
217
|
+
v = ch.text
|
|
218
|
+
if g and a and v:
|
|
219
|
+
managed[f"{g.strip()}:{a.strip()}"] = resolve(v) or ""
|
|
220
|
+
in_mgmt = {id(d) for dm in root.iter() if local(dm.tag) == "dependencyManagement" for d in dm.iter()}
|
|
221
|
+
for dep in root.iter():
|
|
222
|
+
if local(dep.tag) != "dependency" or id(dep) in in_mgmt:
|
|
223
|
+
continue
|
|
224
|
+
g = a = v = scope = None
|
|
225
|
+
for ch in dep:
|
|
226
|
+
t = local(ch.tag)
|
|
227
|
+
if t == "groupId":
|
|
228
|
+
g = (ch.text or "").strip()
|
|
229
|
+
elif t == "artifactId":
|
|
230
|
+
a = (ch.text or "").strip()
|
|
231
|
+
elif t == "version":
|
|
232
|
+
v = ch.text
|
|
233
|
+
elif t == "scope":
|
|
234
|
+
scope = (ch.text or "").strip()
|
|
235
|
+
if not (g and a):
|
|
236
|
+
continue
|
|
237
|
+
g = resolve(g) or g
|
|
238
|
+
name = f"{g}:{a}"
|
|
239
|
+
ver = resolve(v) if v else (managed.get(name) or None)
|
|
240
|
+
out.append(_mk("Maven", name, ver, lockfile, service_dir, direct=True, dev=True if scope == "test" else None,
|
|
241
|
+
record=f"dependency[{name}]", source_type="registry"))
|
|
242
|
+
return out
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
_GRADLE = re.compile(r"""(?:implementation|api|compile|runtimeOnly|compileOnly|testImplementation|testCompile|annotationProcessor)\s*\(?\s*['"]([\w.\-]+):([\w.\-]+):([\w.\-${}]+)['"]""")
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def parse_gradle(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
249
|
+
out = []
|
|
250
|
+
for m in _GRADLE.finditer(text):
|
|
251
|
+
g, a, v = m.groups()
|
|
252
|
+
out.append(_mk("Maven", f"{g}:{a}", None if "$" in v else v, lockfile, service_dir, direct=True,
|
|
253
|
+
dev=True if "test" in m.group(0).lower() else None, record=m.group(0)[:80], source_type="registry"))
|
|
254
|
+
return out
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def parse_gradle_lockfile(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
258
|
+
out = []
|
|
259
|
+
for i, line in enumerate(text.splitlines(), 1):
|
|
260
|
+
line = line.strip()
|
|
261
|
+
if not line or line.startswith("#") or line.startswith("empty="):
|
|
262
|
+
continue
|
|
263
|
+
coords = line.split("=", 1)[0].split(":")
|
|
264
|
+
if len(coords) == 3:
|
|
265
|
+
out.append(_mk("Maven", f"{coords[0]}:{coords[1]}", coords[2], lockfile, service_dir, direct=None,
|
|
266
|
+
record=f"line {i}", source_type="registry"))
|
|
267
|
+
return out
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""PyPI ecosystem: requirements*.txt, poetry.lock, uv.lock, Pipfile.lock."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from core.models import LockDependency
|
|
9
|
+
from sbom.package_extractors.common import classify_source, make_purl, normalize_name
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
import tomllib
|
|
13
|
+
except ImportError: # pragma: no cover
|
|
14
|
+
import tomli as tomllib # type: ignore
|
|
15
|
+
|
|
16
|
+
ECO = "PyPI"
|
|
17
|
+
_REQ = re.compile(r"^\s*([A-Za-z0-9][A-Za-z0-9._-]*)\s*(\[[^\]]*\])?\s*(.*)$")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _mk(name, version, lockfile, service_dir, **kw) -> LockDependency:
|
|
21
|
+
return LockDependency(name=normalize_name(ECO, name), version=version, ecosystem=ECO,
|
|
22
|
+
purl=make_purl(ECO, name, version), lockfile=lockfile, service_dir=service_dir, **kw)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def parse_requirements(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
26
|
+
out: list[LockDependency] = []
|
|
27
|
+
# join continuation lines
|
|
28
|
+
joined: list[str] = []
|
|
29
|
+
buf = ""
|
|
30
|
+
for line in text.splitlines():
|
|
31
|
+
if line.rstrip().endswith("\\"):
|
|
32
|
+
buf += line.rstrip()[:-1] + " "
|
|
33
|
+
continue
|
|
34
|
+
joined.append(buf + line)
|
|
35
|
+
buf = ""
|
|
36
|
+
if buf:
|
|
37
|
+
joined.append(buf)
|
|
38
|
+
for i, line in enumerate(joined, 1):
|
|
39
|
+
line = re.sub(r"(^|\s)#.*$", "", line).strip()
|
|
40
|
+
if not line or line.startswith(("-", "git+", "http://", "https://", ".", "/")):
|
|
41
|
+
continue
|
|
42
|
+
spec = line.split(";", 1)[0]
|
|
43
|
+
hashes = re.findall(r"--hash=(\S+)", spec)
|
|
44
|
+
spec = re.sub(r"--hash=\S+", "", spec)
|
|
45
|
+
m = _REQ.match(spec)
|
|
46
|
+
if not m:
|
|
47
|
+
continue
|
|
48
|
+
name, rest = m.group(1), m.group(3).strip()
|
|
49
|
+
pm = re.match(r"^(?:==|===)\s*([A-Za-z0-9.!+_*-]+)\s*$", rest.split(",")[0].strip()) if "," not in rest else None
|
|
50
|
+
version = pm.group(1) if pm and "*" not in pm.group(1) else None
|
|
51
|
+
out.append(_mk(name, version, lockfile, service_dir, direct=None, record=f"line {i}",
|
|
52
|
+
integrity=hashes[0] if hashes else None, source_type="registry", meta={"hashes": hashes} if hashes else {}))
|
|
53
|
+
return out
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _poetry_direct(pyproject: Optional[str]) -> Optional[set[str]]:
|
|
57
|
+
if not pyproject:
|
|
58
|
+
return None
|
|
59
|
+
try:
|
|
60
|
+
d = tomllib.loads(pyproject)
|
|
61
|
+
except Exception:
|
|
62
|
+
return None
|
|
63
|
+
names: set[str] = set()
|
|
64
|
+
for dep in (d.get("project", {}).get("dependencies") or []):
|
|
65
|
+
names.add(normalize_name(ECO, re.split(r"[<>=!~\[; ]", dep, 1)[0]))
|
|
66
|
+
poetry = d.get("tool", {}).get("poetry", {})
|
|
67
|
+
names |= {normalize_name(ECO, n) for n in (poetry.get("dependencies") or {}) if n.lower() != "python"}
|
|
68
|
+
names |= {normalize_name(ECO, n) for n in (poetry.get("dev-dependencies") or {})}
|
|
69
|
+
for grp in (poetry.get("group") or {}).values():
|
|
70
|
+
names |= {normalize_name(ECO, n) for n in (grp.get("dependencies") or {})}
|
|
71
|
+
for grp in (d.get("dependency-groups") or {}).values():
|
|
72
|
+
for dep in grp:
|
|
73
|
+
if isinstance(dep, str):
|
|
74
|
+
names.add(normalize_name(ECO, re.split(r"[<>=!~\[; ]", dep, 1)[0]))
|
|
75
|
+
return names or None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def parse_poetry_lock(text: str, lockfile: str, service_dir: str, pyproject: Optional[str] = None, **_) -> list[LockDependency]:
|
|
79
|
+
data = tomllib.loads(text)
|
|
80
|
+
direct = _poetry_direct(pyproject)
|
|
81
|
+
out = []
|
|
82
|
+
for i, p in enumerate(data.get("package", [])):
|
|
83
|
+
name, version = p.get("name"), p.get("version")
|
|
84
|
+
if not name:
|
|
85
|
+
continue
|
|
86
|
+
src = p.get("source") or {}
|
|
87
|
+
nn = normalize_name(ECO, name)
|
|
88
|
+
out.append(_mk(name, version, lockfile, service_dir, direct=(nn in direct) if direct is not None else None,
|
|
89
|
+
dev=True if p.get("category") == "dev" or (p.get("groups") and "main" not in p.get("groups")) else None,
|
|
90
|
+
requires=sorted(normalize_name(ECO, k) for k in (p.get("dependencies") or {})),
|
|
91
|
+
record=f"package[{name}]", resolved=src.get("url") or src.get("reference"),
|
|
92
|
+
integrity=((p.get("files") or [{}])[0].get("hash") if p.get("files") else None),
|
|
93
|
+
meta={k: v for k, v in (("hashes", [f.get("hash") for f in p.get("files", []) if f.get("hash")]), ("description", p.get("description")),
|
|
94
|
+
("optional", True if p.get("optional") else None)) if v},
|
|
95
|
+
source_type=("git" if src.get("type") == "git" else "path" if src.get("type") in ("directory", "file") else "registry")))
|
|
96
|
+
return out
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def parse_uv_lock(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
100
|
+
data = tomllib.loads(text)
|
|
101
|
+
pkgs = data.get("package", [])
|
|
102
|
+
roots = [p for p in pkgs if (p.get("source") or {}).get("virtual") or (p.get("source") or {}).get("editable")]
|
|
103
|
+
direct: set[str] = set()
|
|
104
|
+
for r in roots:
|
|
105
|
+
for d in (r.get("dependencies") or []):
|
|
106
|
+
direct.add(normalize_name(ECO, d.get("name", "")))
|
|
107
|
+
for grp in (r.get("dev-dependencies") or {}).values():
|
|
108
|
+
for d in grp:
|
|
109
|
+
direct.add(normalize_name(ECO, d.get("name", "")))
|
|
110
|
+
for grp in (r.get("optional-dependencies") or {}).values():
|
|
111
|
+
for d in grp:
|
|
112
|
+
direct.add(normalize_name(ECO, d.get("name", "")))
|
|
113
|
+
out = []
|
|
114
|
+
for p in pkgs:
|
|
115
|
+
src = p.get("source") or {}
|
|
116
|
+
if src.get("virtual") or src.get("editable"):
|
|
117
|
+
continue
|
|
118
|
+
name = p.get("name")
|
|
119
|
+
nn = normalize_name(ECO, name or "")
|
|
120
|
+
sdist = p.get("sdist") or {}
|
|
121
|
+
stype = "git" if "git" in src else "path" if "directory" in src or "path" in src else "registry" if "registry" in src else "unknown"
|
|
122
|
+
out.append(_mk(name, p.get("version"), lockfile, service_dir, direct=(nn in direct) if roots else None,
|
|
123
|
+
requires=sorted(normalize_name(ECO, d.get("name", "")) for d in (p.get("dependencies") or [])),
|
|
124
|
+
record=f"package[{name}]", integrity=sdist.get("hash") or ((p.get("wheels") or [{}])[0].get("hash") if p.get("wheels") else None),
|
|
125
|
+
resolved=src.get("registry") or src.get("git"),
|
|
126
|
+
meta={"hashes": [x for x in [sdist.get("hash")] + [w.get("hash") for w in p.get("wheels", [])] if x]},
|
|
127
|
+
source_type=stype))
|
|
128
|
+
return out
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def parse_pipfile_lock(text: str, lockfile: str, service_dir: str, **_) -> list[LockDependency]:
|
|
132
|
+
data = json.loads(text)
|
|
133
|
+
out = []
|
|
134
|
+
for section, dev in (("default", False), ("develop", True)):
|
|
135
|
+
for name, meta in (data.get(section) or {}).items():
|
|
136
|
+
ver = (meta.get("version") or "").lstrip("=") or None
|
|
137
|
+
hashes = meta.get("hashes") or []
|
|
138
|
+
out.append(_mk(name, ver, lockfile, service_dir, direct=None, dev=True if dev else None,
|
|
139
|
+
record=f"{section}[{name}]", integrity=hashes[0] if hashes else None,
|
|
140
|
+
meta={"hashes": hashes} if hashes else {},
|
|
141
|
+
resolved=meta.get("git") or meta.get("file") or meta.get("path"),
|
|
142
|
+
source_type="git" if meta.get("git") else "path" if (meta.get("file") or meta.get("path")) else "registry"))
|
|
143
|
+
return out
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""SBOM quality assessment: compares lockfile evidence, Syft components and SBOM relationships.
|
|
2
|
+
|
|
3
|
+
Comparisons are scoped by (ecosystem, service directory); components from another scope are never called "missing".
|
|
4
|
+
The report never declares an SBOM *complete*; the best status is "consistent_with_lockfiles".
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections import Counter, defaultdict
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
from core.models import Component, InspectionResult, LockDependency
|
|
12
|
+
from sbom.package_extractors.common import normalize_name
|
|
13
|
+
|
|
14
|
+
EXAMPLE_LIMIT = 15
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def key_of(eco: str, name: str, version: Optional[str]) -> tuple[str, str, str]:
|
|
18
|
+
return (eco, normalize_name(eco, name), version or "")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def analyze_quality(components: list[Component], sbom_doc: dict, lock_deps: list[LockDependency],
|
|
22
|
+
inspection: InspectionResult, syft_ok: bool = True, lock_errors: list[dict] | None = None) -> dict:
|
|
23
|
+
lock_errors = lock_errors or []
|
|
24
|
+
lock_deps = [d for d in lock_deps if not d.derived] # registry-resolved records are not repository evidence
|
|
25
|
+
limitations: list[str] = []
|
|
26
|
+
pkgs = [c for c in components if c.type not in ("file", "container") and c.purl_type not in ("docker", "github") and not c.is_self]
|
|
27
|
+
|
|
28
|
+
# ---- metadata gaps
|
|
29
|
+
miss = {"version": [], "purl": [], "license": [], "supplier": [], "hashes": []}
|
|
30
|
+
for c in pkgs:
|
|
31
|
+
if not c.version:
|
|
32
|
+
miss["version"].append(c.bom_ref)
|
|
33
|
+
if not c.purl:
|
|
34
|
+
miss["purl"].append(c.bom_ref)
|
|
35
|
+
if not c.licenses:
|
|
36
|
+
miss["license"].append(c.bom_ref)
|
|
37
|
+
if not c.supplier:
|
|
38
|
+
miss["supplier"].append(c.bom_ref)
|
|
39
|
+
if not c.hashes:
|
|
40
|
+
miss["hashes"].append(c.bom_ref)
|
|
41
|
+
|
|
42
|
+
# ---- duplicates / conflicts
|
|
43
|
+
ref_counts = Counter(c.bom_ref for c in components)
|
|
44
|
+
dup_refs = [r for r, n in ref_counts.items() if n > 1]
|
|
45
|
+
by_key: dict[tuple, list[Component]] = defaultdict(list)
|
|
46
|
+
for c in pkgs:
|
|
47
|
+
if c.ecosystem and c.version:
|
|
48
|
+
by_key[key_of(c.ecosystem, c.name, c.version) + (c.service_dir or "?",)].append(c)
|
|
49
|
+
dup_records = [{"package": f"{k[1]}@{k[2]}", "ecosystem": k[0], "service": k[3], "count": len(v),
|
|
50
|
+
"bom_refs": [x.bom_ref for x in v][:5]} for k, v in by_key.items() if len(v) > 1]
|
|
51
|
+
multi_version: dict[tuple, set] = defaultdict(set)
|
|
52
|
+
for c in pkgs:
|
|
53
|
+
if c.ecosystem and c.version:
|
|
54
|
+
multi_version[(c.ecosystem, normalize_name(c.ecosystem, c.name), c.service_dir)].add(c.version)
|
|
55
|
+
multiple_versions = [{"package": k[1], "ecosystem": k[0], "service": k[2], "versions": sorted(v)}
|
|
56
|
+
for k, v in multi_version.items() if len(v) > 1]
|
|
57
|
+
|
|
58
|
+
# ---- relationships
|
|
59
|
+
deps = [d for d in (sbom_doc.get("dependencies") or []) if isinstance(d, dict)]
|
|
60
|
+
with_edges = {d["ref"] for d in deps if d.get("dependsOn")}
|
|
61
|
+
referenced = {t for d in deps for t in (d.get("dependsOn") or [])}
|
|
62
|
+
in_graph = with_edges | referenced
|
|
63
|
+
no_rel = [c.bom_ref for c in pkgs if c.bom_ref not in in_graph]
|
|
64
|
+
edge_count = sum(len(d.get("dependsOn") or []) for d in deps)
|
|
65
|
+
if not pkgs:
|
|
66
|
+
rel_status = "none"
|
|
67
|
+
elif not edge_count:
|
|
68
|
+
rel_status = "absent"
|
|
69
|
+
elif len(no_rel) / max(len(pkgs), 1) > 0.5:
|
|
70
|
+
rel_status = "partial"
|
|
71
|
+
else:
|
|
72
|
+
rel_status = "mostly_present" if no_rel else "present"
|
|
73
|
+
|
|
74
|
+
# ---- lockfile vs SBOM (same ecosystem + service scope only)
|
|
75
|
+
lock_keys: dict[tuple, LockDependency] = {}
|
|
76
|
+
unpinned: list[dict] = []
|
|
77
|
+
for d in lock_deps:
|
|
78
|
+
if not d.version:
|
|
79
|
+
unpinned.append({"name": d.name, "ecosystem": d.ecosystem, "lockfile": d.lockfile})
|
|
80
|
+
continue
|
|
81
|
+
lock_keys.setdefault(key_of(d.ecosystem, d.name, d.version) + (d.service_dir,), d)
|
|
82
|
+
sbom_by_scope: dict[tuple, set] = defaultdict(set)
|
|
83
|
+
for c in pkgs:
|
|
84
|
+
if c.ecosystem and c.version:
|
|
85
|
+
sbom_by_scope[(c.ecosystem, c.service_dir)].add(key_of(c.ecosystem, c.name, c.version))
|
|
86
|
+
sbom_global = {key_of(c.ecosystem, c.name, c.version) for c in pkgs if c.ecosystem and c.version}
|
|
87
|
+
lock_scopes = {(d.ecosystem, d.service_dir) for d in lock_deps if d.version and d.lockfile.rsplit("/", 1)[-1] not in ("go.sum",)}
|
|
88
|
+
|
|
89
|
+
missing_from_sbom = []
|
|
90
|
+
for k, d in lock_keys.items():
|
|
91
|
+
# go.sum lists modules that may legitimately be absent from the build list; do not call those missing
|
|
92
|
+
if d.lockfile.endswith("go.sum"):
|
|
93
|
+
continue
|
|
94
|
+
if k[:3] not in sbom_global:
|
|
95
|
+
missing_from_sbom.append({"package": d.name, "version": d.version, "ecosystem": d.ecosystem,
|
|
96
|
+
"lockfile": d.lockfile, "service": d.service_dir})
|
|
97
|
+
lock_key_set_by_scope: dict[tuple, set] = defaultdict(set)
|
|
98
|
+
for k, d in lock_keys.items():
|
|
99
|
+
lock_key_set_by_scope[(d.ecosystem, d.service_dir)].add(k[:3])
|
|
100
|
+
absent_from_lock = []
|
|
101
|
+
for c in pkgs:
|
|
102
|
+
if not (c.ecosystem and c.version):
|
|
103
|
+
continue
|
|
104
|
+
scope = (c.ecosystem, c.service_dir)
|
|
105
|
+
if scope in lock_scopes and key_of(c.ecosystem, c.name, c.version) not in lock_key_set_by_scope[scope]:
|
|
106
|
+
absent_from_lock.append({"package": c.name, "version": c.version, "ecosystem": c.ecosystem,
|
|
107
|
+
"service": c.service_dir, "found_by": c.found_by, "locations": c.locations[:2]})
|
|
108
|
+
uncovered = sorted({c.ecosystem or c.purl_type or "unknown" for c in pkgs
|
|
109
|
+
if (c.ecosystem, c.service_dir) not in lock_scopes and (c.ecosystem or c.purl_type)})
|
|
110
|
+
|
|
111
|
+
# ---- unresolved identities
|
|
112
|
+
unresolved = [c for c in pkgs if not c.purl or not c.ecosystem or not c.version]
|
|
113
|
+
unsupported_eco = Counter(c.purl_type for c in pkgs if c.purl and not c.ecosystem)
|
|
114
|
+
|
|
115
|
+
# ---- status
|
|
116
|
+
if not syft_ok:
|
|
117
|
+
inv = "unavailable"
|
|
118
|
+
limitations.append("No SBOM was generated; inventory relies on lockfile parsing only.")
|
|
119
|
+
elif not pkgs:
|
|
120
|
+
inv = "no_components"
|
|
121
|
+
limitations.append("The SBOM contains no package components.")
|
|
122
|
+
elif missing_from_sbom:
|
|
123
|
+
inv = "incomplete"
|
|
124
|
+
elif absent_from_lock or unresolved or dup_refs:
|
|
125
|
+
inv = "partial"
|
|
126
|
+
else:
|
|
127
|
+
inv = "consistent_with_lockfiles"
|
|
128
|
+
if inv == "consistent_with_lockfiles":
|
|
129
|
+
limitations.append("Consistency with parsed lockfiles does not prove completeness (unparsed ecosystems, "
|
|
130
|
+
"vendored code and runtime-installed packages are not covered).")
|
|
131
|
+
if unsupported_eco:
|
|
132
|
+
limitations.append("Components of ecosystems without vulnerability-database mapping: " + ", ".join(f"{k} ({v})" for k, v in unsupported_eco.items()))
|
|
133
|
+
if unpinned:
|
|
134
|
+
limitations.append(f"{len(unpinned)} declared dependencies have no pinned version and cannot be matched to advisories.")
|
|
135
|
+
if lock_errors:
|
|
136
|
+
limitations.append(f"{len(lock_errors)} manifest/lockfile(s) could not be parsed.")
|
|
137
|
+
limitations.extend(inspection.limitations)
|
|
138
|
+
if rel_status in ("absent", "partial"):
|
|
139
|
+
limitations.append("Dependency relationships are " + rel_status + " in the SBOM; transitive tracing is limited to what the SBOM and lockfiles record.")
|
|
140
|
+
|
|
141
|
+
meta_status = "complete_for_checked_fields" if not any(miss[k] for k in ("version", "purl", "license", "supplier")) else "partial"
|
|
142
|
+
|
|
143
|
+
def _ratio(num: int, den: int, desc: str) -> dict:
|
|
144
|
+
return {"numerator": num, "denominator": den, "ratio": round(num / den, 4) if den > 0 else None, "description": desc}
|
|
145
|
+
|
|
146
|
+
n_pkgs = len(pkgs)
|
|
147
|
+
n_lock = len([k for k, d in lock_keys.items() if not d.lockfile.endswith("go.sum")])
|
|
148
|
+
matched_lock = max(n_lock - len(missing_from_sbom), 0)
|
|
149
|
+
versioned_pkgs = n_pkgs - len(miss["version"])
|
|
150
|
+
rel_pkgs = n_pkgs - len(no_rel)
|
|
151
|
+
integrity_pkgs = sum(1 for c in pkgs if c.hashes or (c.integrity or {}).get("status") == "verified")
|
|
152
|
+
license_pkgs = n_pkgs - len(miss["license"])
|
|
153
|
+
|
|
154
|
+
coverage_metrics = {
|
|
155
|
+
"inventory_coverage": _ratio(matched_lock, n_lock, "Pinned lockfile packages present in SBOM / total pinned lockfile packages"),
|
|
156
|
+
"version_resolution_completeness": _ratio(versioned_pkgs, n_pkgs, "SBOM package components with a resolved version / total package components"),
|
|
157
|
+
"relationship_completeness": _ratio(rel_pkgs, n_pkgs, "Package components connected in dependency graph / total package components"),
|
|
158
|
+
"integrity_metadata_availability": _ratio(integrity_pkgs, n_pkgs, "Package components with cryptographic hashes or verified integrity / total package components"),
|
|
159
|
+
"license_metadata_availability": _ratio(license_pkgs, n_pkgs, "Package components with license metadata / total package components"),
|
|
160
|
+
}
|
|
161
|
+
scanner_provenance = dict(Counter(src for c in pkgs for src in (c.sources or [c.found_by or "unknown"])))
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
"inventory_status": inv,
|
|
165
|
+
"dependency_relationships": rel_status,
|
|
166
|
+
"metadata_status": meta_status,
|
|
167
|
+
"coverage_metrics": coverage_metrics,
|
|
168
|
+
"scanner_provenance": scanner_provenance,
|
|
169
|
+
"unsupported_ecosystems": dict(unsupported_eco),
|
|
170
|
+
"total_components": len(components),
|
|
171
|
+
"package_components": len(pkgs),
|
|
172
|
+
"components_by_ecosystem": dict(Counter(c.ecosystem or c.purl_type or "unknown" for c in pkgs)),
|
|
173
|
+
"lockfile_dependencies": len(lock_keys),
|
|
174
|
+
"unpinned_declared_dependencies": len(unpinned),
|
|
175
|
+
"unresolved_components": len(unresolved),
|
|
176
|
+
"missing_metadata": {k: len(v) for k, v in miss.items()},
|
|
177
|
+
"missing_metadata_examples": {k: v[:EXAMPLE_LIMIT] for k, v in miss.items()},
|
|
178
|
+
"missing_relationships": len(no_rel),
|
|
179
|
+
"relationship_edges": edge_count,
|
|
180
|
+
"lockfile_missing_from_sbom": missing_from_sbom[:200],
|
|
181
|
+
"lockfile_missing_from_sbom_count": len(missing_from_sbom),
|
|
182
|
+
"sbom_absent_from_lockfile": absent_from_lock[:200],
|
|
183
|
+
"sbom_absent_from_lockfile_count": len(absent_from_lock),
|
|
184
|
+
"duplicate_bom_refs": dup_refs[:20],
|
|
185
|
+
"duplicate_component_records": dup_records[:50],
|
|
186
|
+
"multiple_versions_same_service": multiple_versions[:50],
|
|
187
|
+
"ecosystems_without_lockfile_scope": uncovered,
|
|
188
|
+
"unpinned_examples": unpinned[:EXAMPLE_LIMIT],
|
|
189
|
+
"lockfile_parse_errors": lock_errors,
|
|
190
|
+
"limitations": limitations,
|
|
191
|
+
}
|