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,201 @@
|
|
|
1
|
+
"""Page 4: vulnerability findings."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import streamlit as st
|
|
5
|
+
|
|
6
|
+
from ui.components.common import badge, df, kv_table, page_header, require_result, risk_by_id
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _ground_truth(r: dict) -> None:
|
|
10
|
+
ver = r.get("verification")
|
|
11
|
+
with st.expander("Ground-Truth Verification & Golden Set", expanded=False):
|
|
12
|
+
if ver:
|
|
13
|
+
c = st.columns(4)
|
|
14
|
+
c[0].metric("Cross-Checked", ver["components_checked"])
|
|
15
|
+
c[1].metric("Routes Agree", ver["routes_agree"])
|
|
16
|
+
c[2].metric("Reproduced", f"{ver['findings_cross_verified']}/{ver['findings_checked']}")
|
|
17
|
+
c[3].metric("Disagreements", ver["disagreement_count"])
|
|
18
|
+
if ver["disagreements"]:
|
|
19
|
+
df(ver["disagreements"], height=160)
|
|
20
|
+
|
|
21
|
+
if st.button("Run OSV Golden-Set Known-Answer Test", key="run_gt"):
|
|
22
|
+
from config.settings import get_settings
|
|
23
|
+
from core.http import HttpClient
|
|
24
|
+
from storage.cache import Cache
|
|
25
|
+
from storage.database import Database
|
|
26
|
+
from vulnerability.osv_client import OsvClient
|
|
27
|
+
from vulnerability.verification import run_ground_truth
|
|
28
|
+
with st.spinner("Querying OSV golden set..."):
|
|
29
|
+
st.session_state["gt"] = run_ground_truth(OsvClient(HttpClient(), Cache(Database(get_settings().db_path))))
|
|
30
|
+
|
|
31
|
+
gt = st.session_state.get("gt")
|
|
32
|
+
if gt:
|
|
33
|
+
c = st.columns(4)
|
|
34
|
+
c[0].metric("Cases Passed", f"{gt['passed']}/{gt['evaluated']}")
|
|
35
|
+
c[1].metric("Precision", gt["precision"])
|
|
36
|
+
c[2].metric("Recall", gt["recall"])
|
|
37
|
+
c[3].metric("FP / FN", f"{gt['fp']} / {gt['fn']}")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def render() -> None:
|
|
41
|
+
page_header("Vulnerability Findings", "Correlated OSV, NVD (CVSS) and CISA KEV findings with local range validation.")
|
|
42
|
+
r = require_result()
|
|
43
|
+
if not r:
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
vulns = r.get("vulnerabilities", [])
|
|
47
|
+
risks = risk_by_id(r)
|
|
48
|
+
sm = r["summary"]
|
|
49
|
+
sev = sm.get("by_cvss_severity", {})
|
|
50
|
+
|
|
51
|
+
# Consolidated 5 primary security metrics
|
|
52
|
+
c = st.columns(5)
|
|
53
|
+
unconf = sm.get("vulnerabilities_unknown", 0)
|
|
54
|
+
c[0].metric("Total Findings", len(vulns), help=f"{sm.get('vulnerabilities_confirmed', 0)} confirmed, {unconf} unconfirmed" if unconf else "All findings are confirmed affected")
|
|
55
|
+
c[1].metric("Critical · High (CVSS)", f"{sev.get('CRITICAL', 0)} C · {sev.get('HIGH', 0)} H", help="By the advisory's CVSS severity. The contextual risk below also weighs reachability and production impact.")
|
|
56
|
+
c[2].metric("Findings: Direct / Transitive", f"{sm.get('vuln_direct', 0)} / {sm.get('vuln_transitive', 0)}", help="Counts findings, not packages. The Dependency Graph page counts vulnerable packages.")
|
|
57
|
+
c[3].metric("Fix Available", sm.get("with_fix", 0))
|
|
58
|
+
c[4].metric("Known Exploited (KEV)", sm.get("kev", 0))
|
|
59
|
+
|
|
60
|
+
br = sm.get("by_risk") or {}
|
|
61
|
+
if br:
|
|
62
|
+
st.caption("Contextual risk: " + " · ".join(f"{br[k]} {k.lower()}" for k in ("CRITICAL", "HIGH", "MEDIUM", "LOW", "INFORMATIONAL") if br.get(k))
|
|
63
|
+
+ (" · priority " + ", ".join(f"{k} {n}" for k, n in sorted((sm.get("by_priority") or {}).items())) if sm.get("by_priority") else ""))
|
|
64
|
+
|
|
65
|
+
_ground_truth(r)
|
|
66
|
+
|
|
67
|
+
if not vulns:
|
|
68
|
+
st.success("No vulnerability findings were produced for the queried packages.")
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
with st.expander("Filter Findings", expanded=False):
|
|
72
|
+
top_c1, top_c2 = st.columns(2)
|
|
73
|
+
f_asset = top_c1.selectbox("Asset Source", ["All Assets", "Source Dependencies (OSV)", "Container Images (Trivy)"])
|
|
74
|
+
f_pkg_class = top_c2.selectbox("Container Package Class", ["All", "OS Packages (Debian/Alpine/RPM)", "Application Libraries"]) if f_asset != "Source Dependencies (OSV)" else "All"
|
|
75
|
+
|
|
76
|
+
a, b, d, e = st.columns(4)
|
|
77
|
+
f_sev = a.multiselect("CVSS Severity", ["CRITICAL", "HIGH", "MEDIUM", "LOW", "UNKNOWN"])
|
|
78
|
+
f_eco = b.multiselect("Ecosystem", sorted({v["ecosystem"] for v in vulns}))
|
|
79
|
+
f_dep = d.multiselect("Dependency Type", ["direct", "direct_inferred", "transitive", "container_package"])
|
|
80
|
+
f_stat = e.multiselect("Status", ["confirmed_affected", "unknown"])
|
|
81
|
+
c1, c2, c3 = st.columns([1, 1, 1])
|
|
82
|
+
f_pkg = c1.text_input("Package contains", placeholder="e.g. lodash")
|
|
83
|
+
f_id = c2.text_input("Vulnerability ID", placeholder="e.g. CVE-2021-...")
|
|
84
|
+
f_fix = c3.checkbox("Fix available only")
|
|
85
|
+
|
|
86
|
+
rows = [
|
|
87
|
+
v for v in vulns
|
|
88
|
+
if (f_asset == "All Assets" or (f_asset.startswith("Source") and v.get("asset_type", "source_dependency") == "source_dependency") or (f_asset.startswith("Container") and v.get("asset_type") == "container_image"))
|
|
89
|
+
and (f_pkg_class == "All" or (f_pkg_class.startswith("OS") and (v.get("container_details") or {}).get("package_type") == "os_pkg") or (f_pkg_class.startswith("App") and (v.get("container_details") or {}).get("package_type") == "lang_pkg"))
|
|
90
|
+
and (not f_sev or (v["severity"] or "UNKNOWN") in f_sev)
|
|
91
|
+
and (not f_eco or v["ecosystem"] in f_eco)
|
|
92
|
+
and (not f_dep or v["dependency_type"] in f_dep)
|
|
93
|
+
and (not f_stat or v["affected_status"] in f_stat)
|
|
94
|
+
and (not f_pkg or f_pkg.lower() in v["package_name"].lower())
|
|
95
|
+
and (not f_id or any(f_id.lower() in i.lower() for i in v["vulnerability_ids"]))
|
|
96
|
+
and (not f_fix or v["fixed_versions"])
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
st.caption(f"Showing {len(rows)} of {len(vulns)} findings")
|
|
100
|
+
df([{"ID": v["primary_id"], "Package": v["package_name"], "Installed": v["installed_version"],
|
|
101
|
+
"Ecosystem": v["ecosystem"], "Severity": v["severity"] or "n/a",
|
|
102
|
+
"CVSS": v["cvss_score"] if v["cvss_score"] is not None else "n/a",
|
|
103
|
+
"Score": f"{risks[v['finding_id']]['score']}/100" if v["finding_id"] in risks and risks[v["finding_id"]].get("score") is not None else "n/a",
|
|
104
|
+
"Priority": risks.get(v["finding_id"], {}).get("priority", "P3"),
|
|
105
|
+
"Risk": risks.get(v["finding_id"], {}).get("label", "n/a"),
|
|
106
|
+
"Fixed in": ", ".join(v["fixed_versions"][:2]) or "none",
|
|
107
|
+
"Type": v["dependency_type"], "Source Pkg": ", ".join(v["source_packages"][:2]) or "self",
|
|
108
|
+
"Verdict": (v.get("verdict") or "").replace("_", " "), "EPSS": f"{v['epss']:.1%}" if v.get("epss") is not None else "n/a"} for v in rows], height=380)
|
|
109
|
+
|
|
110
|
+
if rows:
|
|
111
|
+
st.markdown("#### Finding Detail")
|
|
112
|
+
pick = st.selectbox(
|
|
113
|
+
"Select finding to inspect",
|
|
114
|
+
[v["finding_id"] for v in rows],
|
|
115
|
+
format_func=lambda i: next(f"{v['primary_id']} · {v['package_name']}@{v['installed_version']} ({v['severity'] or 'n/a'})" for v in rows if v["finding_id"] == i),
|
|
116
|
+
label_visibility="collapsed",
|
|
117
|
+
)
|
|
118
|
+
v = next(x for x in rows if x["finding_id"] == pick)
|
|
119
|
+
a = risks.get(v["finding_id"], {})
|
|
120
|
+
score_val = a.get("score")
|
|
121
|
+
score_str = f"{score_val}/100" if score_val is not None else "n/a"
|
|
122
|
+
|
|
123
|
+
st.markdown(f"**{v['primary_id']}** · `{v['package_name']}@{v['installed_version']}` · {v['ecosystem']}")
|
|
124
|
+
if v.get("summary"):
|
|
125
|
+
st.caption(v["summary"])
|
|
126
|
+
|
|
127
|
+
m = st.columns(4)
|
|
128
|
+
m[0].metric("Severity", v["severity"] or "n/a", help=f"CVSS {v['cvss_score'] if v['cvss_score'] is not None else 'n/a'} · source: {v.get('severity_source') or 'n/a'}")
|
|
129
|
+
m[1].metric("Risk", a.get("label") or "n/a", help="Contextual risk: advisory severity combined with reachability and production impact")
|
|
130
|
+
m[2].metric("Score", score_str)
|
|
131
|
+
m[3].metric("Priority", a.get("priority", "P3"))
|
|
132
|
+
|
|
133
|
+
t_over, t_risk, t_inv, t_ref = st.tabs(["Overview", "Risk breakdown", "Investigation", "References"])
|
|
134
|
+
|
|
135
|
+
with t_over:
|
|
136
|
+
o1, o2 = st.columns(2)
|
|
137
|
+
o1.markdown(f"**CVSS** `{v['cvss_score'] if v['cvss_score'] is not None else 'n/a'}` \n**Status** `{v['affected_status']}` \n**Dependency type** `{v['dependency_type']}`")
|
|
138
|
+
o2.markdown(f"**Fixed in** `{', '.join(v['fixed_versions']) or 'none'}` \n**Introduced by** `{', '.join(v['source_packages'][:3]) or 'this package'}`")
|
|
139
|
+
path0 = next((p for e_ in v.get("exposures", []) for p in e_.get("paths", [])), [])
|
|
140
|
+
if path0:
|
|
141
|
+
st.markdown("**Dependency path**")
|
|
142
|
+
st.code(" → ".join(path0), language="text")
|
|
143
|
+
if v.get("asset_type") == "container_image":
|
|
144
|
+
cd = v.get("container_details") or {}
|
|
145
|
+
st.markdown("**Container asset**")
|
|
146
|
+
df([{"Image": cd.get("image_name", "n/a"), "Layer": cd.get("target", "n/a"),
|
|
147
|
+
"Package type": "Operating system package" if cd.get("package_type") == "os_pkg" else "Application library",
|
|
148
|
+
"Dockerfile": cd.get("source_file", "n/a")}], height="content")
|
|
149
|
+
if v.get("remediation"):
|
|
150
|
+
st.markdown("**Recommended fix**")
|
|
151
|
+
st.markdown(v["remediation"])
|
|
152
|
+
|
|
153
|
+
with t_risk:
|
|
154
|
+
dims = a.get("dimensions") or {}
|
|
155
|
+
if not dims:
|
|
156
|
+
st.caption("No risk breakdown is available for this finding.")
|
|
157
|
+
else:
|
|
158
|
+
def _fmt(d: dict) -> str:
|
|
159
|
+
n = d.get("normalized_score")
|
|
160
|
+
return f"{n:.0f}/100" if isinstance(n, (int, float)) else "unknown"
|
|
161
|
+
labels = [("C", "Advisory severity", "15%", "CVSS severity of the advisory, normalised to 0-100"),
|
|
162
|
+
("A", "Application reachability", "20%", "Whether application code imports or calls the vulnerable package"),
|
|
163
|
+
("P", "Production reachability", "35%", "Whether it ships in a production entry point, container or deployment"),
|
|
164
|
+
("I", "Function impact", "30%", "Responsibility, data sensitivity, trust boundary and exposure of the code that uses it")]
|
|
165
|
+
df([{"Factor": name, "Weight": w, "Score": _fmt(dims.get(k, {})), "Measures": desc} for k, name, w, desc in labels], height="content")
|
|
166
|
+
st.caption(f"Result: **{a.get('label', 'UNKNOWN')}** · {score_str} · priority {a.get('priority', 'P3')}"
|
|
167
|
+
+ (" · provisional, some evidence is missing" if a.get("provisional") or a.get("is_provisional") else ""))
|
|
168
|
+
if a.get("confidence"):
|
|
169
|
+
st.caption("Confidence basis: " + "; ".join(a["confidence"].get("basis", [])))
|
|
170
|
+
|
|
171
|
+
with t_inv:
|
|
172
|
+
inv = (r.get("investigations") or {}).get(v["finding_id"])
|
|
173
|
+
if not inv:
|
|
174
|
+
st.caption("This finding was not investigated (investigation disabled or not required).")
|
|
175
|
+
else:
|
|
176
|
+
ic = st.columns(3)
|
|
177
|
+
ic[0].metric("Verdict", inv["verdict"].replace("_", " "))
|
|
178
|
+
ic[1].metric("Confidence", f"{inv['confidence']['label']} ({inv['confidence']['score']})")
|
|
179
|
+
ic[2].metric("Reasoned by", "AI (grounded)" if inv.get("ai_assisted") else "Rules")
|
|
180
|
+
st.markdown(inv["rationale"])
|
|
181
|
+
llm = inv.get("llm")
|
|
182
|
+
if llm and llm.get("status") == "rejected":
|
|
183
|
+
st.warning("An AI proposal for this finding was rejected by the grounding gate: " + "; ".join(llm.get("problems", [])))
|
|
184
|
+
elif llm and llm.get("status") == "error":
|
|
185
|
+
st.caption(f"AI reasoning unavailable for this finding ({llm.get('error')}); deterministic result shown.")
|
|
186
|
+
with st.expander("Tool trace and evidence"):
|
|
187
|
+
df([{"Step": n + 1, "Tool": s["tool"], "By": s.get("by", "planner"), "Arguments": ", ".join(f"{k}={val}" for k, val in s["args"].items()), "Evidence": s.get("evidence_id") or (s.get("error") or "")}
|
|
188
|
+
for n, s in enumerate(inv["steps"])], height="content")
|
|
189
|
+
store = {e["id"]: e for e in r.get("evidence_store", [])}
|
|
190
|
+
for eid in inv["evidence_ids"]:
|
|
191
|
+
e = store.get(eid)
|
|
192
|
+
if e:
|
|
193
|
+
st.markdown(f"- `{eid}` · {e['summary']}" + (f" ({e['source']})" if e.get("source") else "") + ("" if e.get("verified", True) else " *(inferred)*"))
|
|
194
|
+
|
|
195
|
+
with t_ref:
|
|
196
|
+
urls = (v.get("advisory_urls", []) + [x["url"] for x in v.get("references", [])])[:8]
|
|
197
|
+
if urls:
|
|
198
|
+
for u in urls:
|
|
199
|
+
st.markdown(f"- {u}")
|
|
200
|
+
else:
|
|
201
|
+
st.caption("No advisory links recorded.")
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""State management access layer for SC Guardian.
|
|
2
|
+
|
|
3
|
+
Encapsulates interactions with st.session_state and provides type-safe,
|
|
4
|
+
graceful fallbacks while leaving backend SQLite storage untouched.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Any, Optional
|
|
9
|
+
|
|
10
|
+
import streamlit as st
|
|
11
|
+
|
|
12
|
+
from config.settings import get_settings
|
|
13
|
+
from storage.database import Database
|
|
14
|
+
|
|
15
|
+
KEY_RESULT = "result"
|
|
16
|
+
KEY_LAST_URL = "last_url"
|
|
17
|
+
KEY_GROUND_TRUTH = "gt"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_active_scan() -> Optional[dict[str, Any]]:
|
|
21
|
+
"""Retrieve the active scan dictionary from session state, if present and non-failed."""
|
|
22
|
+
r = st.session_state.get(KEY_RESULT)
|
|
23
|
+
if not r or not isinstance(r, dict) or r.get("status") == "failed":
|
|
24
|
+
return None
|
|
25
|
+
return r
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_raw_result() -> Optional[dict[str, Any]]:
|
|
29
|
+
"""Retrieve raw result regardless of status (e.g. to inspect failed scan errors)."""
|
|
30
|
+
return st.session_state.get(KEY_RESULT)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def set_active_scan(result: dict[str, Any]) -> None:
|
|
34
|
+
"""Store the scan result into session state."""
|
|
35
|
+
st.session_state[KEY_RESULT] = result
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def clear_active_scan() -> None:
|
|
39
|
+
"""Clear active scan from session state."""
|
|
40
|
+
st.session_state.pop(KEY_RESULT, None)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def has_active_scan() -> bool:
|
|
44
|
+
"""Return True if a valid scan is loaded in session state."""
|
|
45
|
+
return get_active_scan() is not None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def get_last_url() -> str:
|
|
49
|
+
"""Retrieve the last entered repository URL."""
|
|
50
|
+
return str(st.session_state.get(KEY_LAST_URL, ""))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def set_last_url(url: str) -> None:
|
|
54
|
+
"""Store the last entered repository URL."""
|
|
55
|
+
st.session_state[KEY_LAST_URL] = url.strip()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_ground_truth() -> Optional[dict[str, Any]]:
|
|
59
|
+
"""Retrieve OSV golden-set verification results, if computed."""
|
|
60
|
+
return st.session_state.get(KEY_GROUND_TRUTH)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def set_ground_truth(gt_result: dict[str, Any]) -> None:
|
|
64
|
+
"""Store OSV golden-set verification results."""
|
|
65
|
+
st.session_state[KEY_GROUND_TRUTH] = gt_result
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def load_scan_from_db(scan_id: str) -> Optional[dict[str, Any]]:
|
|
69
|
+
"""Load a scan by scan_id from SQLite into session state.
|
|
70
|
+
|
|
71
|
+
Returns the loaded scan dictionary or None if loading fails.
|
|
72
|
+
"""
|
|
73
|
+
if not scan_id:
|
|
74
|
+
return None
|
|
75
|
+
try:
|
|
76
|
+
db = Database(get_settings().db_path)
|
|
77
|
+
data = db.load_scan(scan_id)
|
|
78
|
+
if data:
|
|
79
|
+
set_active_scan(data)
|
|
80
|
+
return data
|
|
81
|
+
except Exception:
|
|
82
|
+
pass
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def list_recent_scans(limit: int = 15) -> list[dict[str, Any]]:
|
|
87
|
+
"""Retrieve recent scans from the SQLite database."""
|
|
88
|
+
try:
|
|
89
|
+
db = Database(get_settings().db_path)
|
|
90
|
+
return db.list_scans(limit)
|
|
91
|
+
except Exception:
|
|
92
|
+
return []
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def get_active_repo_summary() -> Optional[dict[str, Any]]:
|
|
96
|
+
"""Extract a lightweight metadata summary of the currently active scan."""
|
|
97
|
+
r = get_active_scan()
|
|
98
|
+
if not r:
|
|
99
|
+
return None
|
|
100
|
+
repo = r.get("repo", {})
|
|
101
|
+
summary = r.get("summary", {})
|
|
102
|
+
return {
|
|
103
|
+
"name": repo.get("name", "Unknown Repository"),
|
|
104
|
+
"url": repo.get("url", ""),
|
|
105
|
+
"commit_sha": repo.get("commit_sha", ""),
|
|
106
|
+
"commit_short": repo.get("commit_sha", "")[:10] if repo.get("commit_sha") else "n/a",
|
|
107
|
+
"branch": repo.get("branch") or repo.get("ref") or "default",
|
|
108
|
+
"timestamp": repo.get("scan_timestamp", ""),
|
|
109
|
+
"status": r.get("status", "unknown"),
|
|
110
|
+
"from_cache": bool(r.get("from_cache")),
|
|
111
|
+
"components_count": summary.get("components", len(r.get("components", []))),
|
|
112
|
+
"confirmed_vulns": summary.get("vulnerabilities_confirmed", 0),
|
|
113
|
+
"critical_vulns": summary.get("by_cvss_severity", {}).get("CRITICAL", 0),
|
|
114
|
+
"high_vulns": summary.get("by_cvss_severity", {}).get("HIGH", 0),
|
|
115
|
+
"services_count": summary.get("services", len(r.get("inspection", {}).get("services", []))),
|
|
116
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""Design tokens, typography, and semantic theme helpers for StackParity.
|
|
2
|
+
|
|
3
|
+
Provides consistent severity styling, status indicators, SVG icons, and global CSS
|
|
4
|
+
aligned with the Slate/Obsidian palette in .streamlit/config.toml.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
import streamlit as st
|
|
11
|
+
|
|
12
|
+
# Semantic Severity Palette (WCAG 2.1 AA contrast on #0B0F17 / #111827)
|
|
13
|
+
SEV_COLORS: dict[Optional[str], str] = {
|
|
14
|
+
"CRITICAL": "#EF4444",
|
|
15
|
+
"HIGH": "#F97316",
|
|
16
|
+
"MEDIUM": "#EAB308",
|
|
17
|
+
"LOW": "#38BDF8",
|
|
18
|
+
"INFORMATIONAL": "#94A3B8",
|
|
19
|
+
"UNKNOWN": "#64748B",
|
|
20
|
+
None: "#64748B",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
SEV_BG_COLORS: dict[Optional[str], str] = {
|
|
24
|
+
"CRITICAL": "rgba(239, 68, 68, 0.14)",
|
|
25
|
+
"HIGH": "rgba(249, 115, 22, 0.14)",
|
|
26
|
+
"MEDIUM": "rgba(234, 179, 8, 0.14)",
|
|
27
|
+
"LOW": "rgba(56, 189, 248, 0.14)",
|
|
28
|
+
"INFORMATIONAL": "rgba(148, 163, 184, 0.14)",
|
|
29
|
+
"UNKNOWN": "rgba(100, 116, 139, 0.14)",
|
|
30
|
+
None: "rgba(100, 116, 139, 0.14)",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
SEV_BORDER_COLORS: dict[Optional[str], str] = {
|
|
34
|
+
"CRITICAL": "rgba(239, 68, 68, 0.35)",
|
|
35
|
+
"HIGH": "rgba(249, 115, 22, 0.35)",
|
|
36
|
+
"MEDIUM": "rgba(234, 179, 8, 0.35)",
|
|
37
|
+
"LOW": "rgba(56, 189, 248, 0.35)",
|
|
38
|
+
"INFORMATIONAL": "rgba(148, 163, 184, 0.30)",
|
|
39
|
+
"UNKNOWN": "rgba(100, 116, 139, 0.30)",
|
|
40
|
+
None: "rgba(100, 116, 139, 0.30)",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
SEV_RANK: dict[str, int] = {
|
|
44
|
+
"CRITICAL": 4,
|
|
45
|
+
"HIGH": 3,
|
|
46
|
+
"MEDIUM": 2,
|
|
47
|
+
"LOW": 1,
|
|
48
|
+
"INFORMATIONAL": 0,
|
|
49
|
+
"UNKNOWN": 0,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Plain-text severity indicators (emoji-free, safe for widgets/dataframes)
|
|
53
|
+
RISK_ICON: dict[Optional[str], str] = {
|
|
54
|
+
"CRITICAL": "[CRIT]",
|
|
55
|
+
"HIGH": "[HIGH]",
|
|
56
|
+
"MEDIUM": "[MED]",
|
|
57
|
+
"LOW": "[LOW]",
|
|
58
|
+
"INFORMATIONAL": "[INFO]",
|
|
59
|
+
"UNKNOWN": "[UNK]",
|
|
60
|
+
None: "[UNK]",
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
STATUS_COLORS: dict[str, tuple[str, str, str]] = {
|
|
64
|
+
# status -> (text_color, bg_color, border_color)
|
|
65
|
+
"completed": ("#10B981", "rgba(16, 185, 129, 0.14)", "rgba(16, 185, 129, 0.35)"),
|
|
66
|
+
"completed_with_errors": ("#EAB308", "rgba(234, 179, 8, 0.14)", "rgba(234, 179, 8, 0.35)"),
|
|
67
|
+
"failed": ("#EF4444", "rgba(239, 68, 68, 0.14)", "rgba(239, 68, 68, 0.35)"),
|
|
68
|
+
"running": ("#38BDF8", "rgba(56, 189, 248, 0.14)", "rgba(56, 189, 248, 0.35)"),
|
|
69
|
+
"cache": ("#A78BFA", "rgba(167, 139, 250, 0.14)", "rgba(167, 139, 250, 0.35)"),
|
|
70
|
+
"default": ("#94A3B8", "rgba(148, 163, 184, 0.14)", "rgba(148, 163, 184, 0.30)"),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
SHIELD_SVG = (
|
|
74
|
+
'<svg width="18" height="18" viewBox="0 0 24 24" fill="none" '
|
|
75
|
+
'stroke="#3B82F6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" '
|
|
76
|
+
'style="flex-shrink:0;">'
|
|
77
|
+
'<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>'
|
|
78
|
+
'<path d="m9 12 2 2 4-4"/>'
|
|
79
|
+
"</svg>"
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def inject_theme_css() -> None:
|
|
84
|
+
"""Inject global typography, card surfaces, and spacing overrides."""
|
|
85
|
+
st.markdown(
|
|
86
|
+
"""
|
|
87
|
+
<style>
|
|
88
|
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');
|
|
89
|
+
|
|
90
|
+
html, body, [class*="css"] {
|
|
91
|
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
92
|
+
}
|
|
93
|
+
code, pre, .stCode, [data-testid="stCode"] {
|
|
94
|
+
font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* Compact main container spacing */
|
|
98
|
+
.block-container {
|
|
99
|
+
padding-top: 1.5rem !important;
|
|
100
|
+
padding-bottom: 2rem !important;
|
|
101
|
+
max-width: 1360px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Headings */
|
|
105
|
+
h1, h2, h3, h4 {
|
|
106
|
+
font-weight: 600 !important;
|
|
107
|
+
letter-spacing: -0.02em !important;
|
|
108
|
+
color: #F1F5F9 !important;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* Metric cards */
|
|
112
|
+
[data-testid="stMetric"] {
|
|
113
|
+
background-color: #111827;
|
|
114
|
+
border: 1px solid #1E293B;
|
|
115
|
+
border-radius: 8px;
|
|
116
|
+
padding: 12px 14px;
|
|
117
|
+
font-variant-numeric: tabular-nums;
|
|
118
|
+
}
|
|
119
|
+
[data-testid="stMetricLabel"] {
|
|
120
|
+
font-size: 12px !important;
|
|
121
|
+
font-weight: 500 !important;
|
|
122
|
+
color: #94A3B8 !important;
|
|
123
|
+
}
|
|
124
|
+
[data-testid="stMetricValue"] {
|
|
125
|
+
font-size: 22px !important;
|
|
126
|
+
font-weight: 600 !important;
|
|
127
|
+
color: #F1F5F9 !important;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* Sidebar refinement */
|
|
131
|
+
[data-testid="stSidebar"] {
|
|
132
|
+
background-color: #0F1522 !important;
|
|
133
|
+
border-right: 1px solid #1E293B !important;
|
|
134
|
+
}
|
|
135
|
+
[data-testid="stSidebarNav"] a {
|
|
136
|
+
border-radius: 6px;
|
|
137
|
+
font-size: 13.5px;
|
|
138
|
+
font-weight: 500;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* Expanders and containers */
|
|
142
|
+
[data-testid="stExpander"] {
|
|
143
|
+
background-color: #111827;
|
|
144
|
+
border: 1px solid #1E293B !important;
|
|
145
|
+
border-radius: 8px !important;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* Tables */
|
|
149
|
+
[data-testid="stDataFrame"] {
|
|
150
|
+
border: 1px solid #1E293B;
|
|
151
|
+
border-radius: 8px;
|
|
152
|
+
overflow: hidden;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* Tabs */
|
|
156
|
+
.stTabs [data-baseweb="tab-list"] {
|
|
157
|
+
gap: 6px;
|
|
158
|
+
border-bottom: 1px solid #1E293B;
|
|
159
|
+
}
|
|
160
|
+
.stTabs [data-baseweb="tab"] {
|
|
161
|
+
font-size: 13px;
|
|
162
|
+
font-weight: 500;
|
|
163
|
+
padding: 8px 14px;
|
|
164
|
+
}
|
|
165
|
+
</style>
|
|
166
|
+
""",
|
|
167
|
+
unsafe_allow_html=True,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def text_badge(label: Optional[str]) -> str:
|
|
172
|
+
"""Plain-text severity badge safe for widgets that do not render raw HTML."""
|
|
173
|
+
key = (label or "UNKNOWN").upper()
|
|
174
|
+
return key if key != "UNKNOWN" else "n/a"
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def severity_pill_html(label: Optional[str]) -> str:
|
|
178
|
+
"""HTML pill badge for rendering inside markdown or HTML contexts."""
|
|
179
|
+
key = (label or "UNKNOWN").upper()
|
|
180
|
+
color = SEV_COLORS.get(key, "#94A3B8")
|
|
181
|
+
bg = SEV_BG_COLORS.get(key, "rgba(148, 163, 184, 0.14)")
|
|
182
|
+
border = SEV_BORDER_COLORS.get(key, "rgba(148, 163, 184, 0.30)")
|
|
183
|
+
return (
|
|
184
|
+
f'<span style="display:inline-block; font-size:11px; font-weight:600; line-height:1; '
|
|
185
|
+
f'padding:3px 8px; border-radius:9999px; color:{color}; background-color:{bg}; '
|
|
186
|
+
f'border:1px solid {border}; vertical-align:middle; letter-spacing:0.4px;">'
|
|
187
|
+
f'{key}</span>'
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def status_pill_html(status: str, display_name: Optional[str] = None) -> str:
|
|
192
|
+
"""HTML status pill badge (e.g. completed, with errors, from cache)."""
|
|
193
|
+
clean_key = status.lower().replace(" ", "_")
|
|
194
|
+
color, bg, border = STATUS_COLORS.get(clean_key, STATUS_COLORS["default"])
|
|
195
|
+
text = display_name or status.replace("_", " ").title()
|
|
196
|
+
return (
|
|
197
|
+
f'<span style="display:inline-block; font-size:11px; font-weight:600; line-height:1; '
|
|
198
|
+
f'padding:3px 8px; border-radius:9999px; color:{color}; background-color:{bg}; '
|
|
199
|
+
f'border:1px solid {border}; vertical-align:middle;">'
|
|
200
|
+
f'{text}</span>'
|
|
201
|
+
)
|
|
File without changes
|