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,861 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Evidence Correlation Engine (Person 2 - Phase 2)
|
|
3
|
+
Deterministic cross-signal correlation across repository commits, dependencies,
|
|
4
|
+
lifecycle scripts, registry configurations, CI/CD pipelines, and container build files.
|
|
5
|
+
|
|
6
|
+
Correlates individual signals into defensible multi-vector supply-chain attack scenarios:
|
|
7
|
+
1. Malicious Dependency Injection with Install-Time Hook (Ohm et al., 2020)
|
|
8
|
+
2. CI/CD Pipeline Hijacking & Supply Chain Pivot (Wang et al., 2026)
|
|
9
|
+
3. Dependency Confusion & Registry Source Tampering (Ladisa et al., 2023; Birsan, 2021)
|
|
10
|
+
4. Typosquatting / Package Masquerading with Shadow Execution (Ohm et al., 2020)
|
|
11
|
+
5. Container Build Poisoning via Mutable Base Images & Build-Time Downloads (Docker CIS)
|
|
12
|
+
6. Lockfile-Manifest Desynchronization / Covert Dependency Tampering (Ladisa et al., 2023)
|
|
13
|
+
|
|
14
|
+
Strict Invariants:
|
|
15
|
+
- Preserves all original finding IDs and source references.
|
|
16
|
+
- Records both supporting and contradicting evidence for every scenario.
|
|
17
|
+
- Strictly distinguishes observed facts from suspected attack scenarios.
|
|
18
|
+
- Assigns severity and confidence deterministically based on evidence composition.
|
|
19
|
+
- Generates composite findings with traceable graph relationships.
|
|
20
|
+
- Does not invoke LLMs or non-deterministic heuristics.
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import re
|
|
25
|
+
from typing import Any, Dict, List, Optional, Set, Tuple
|
|
26
|
+
from pydantic import BaseModel, Field
|
|
27
|
+
|
|
28
|
+
# Research Citations
|
|
29
|
+
CITATIONS = {
|
|
30
|
+
"ohm_2020": "Ohm et al. (2020), Backstabber's Knife Collection: A Review of Open Source Software Supply Chain Attacks",
|
|
31
|
+
"ladisa_2023": "Ladisa et al. (2023), SoK: Taxonomy of Attacks on Open-Source Software Supply Chains",
|
|
32
|
+
"wang_2026": "Wang et al. (2026), Demystifying and Detecting Agentic Workflow Injection Vulnerabilities in GitHub Actions",
|
|
33
|
+
"lin_2024": "Lin et al. (2024), UntrustIDE: Exploiting Weaknesses in VS Code Extensions",
|
|
34
|
+
"birsan_2021": "Birsan (2021), Dependency Confusion: How I Hacked Into Apple, Microsoft and Dozens of Other Companies",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
SEVERITY_LEVELS = ["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"]
|
|
38
|
+
CONFIDENCE_LEVELS = ["HIGH", "MEDIUM", "LOW"]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class TraceableRelationship(BaseModel):
|
|
42
|
+
source_id: str
|
|
43
|
+
target_id: str
|
|
44
|
+
relationship: str
|
|
45
|
+
rationale: str
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class CompositeFinding(BaseModel):
|
|
49
|
+
composite_id: str
|
|
50
|
+
scenario_name: str
|
|
51
|
+
scenario_type: str
|
|
52
|
+
attack_technique: str
|
|
53
|
+
primary_finding_ids: List[str]
|
|
54
|
+
related_files: List[str]
|
|
55
|
+
correlation_confidence: str # HIGH, MEDIUM, LOW
|
|
56
|
+
severity: str # CRITICAL, HIGH, MEDIUM, LOW
|
|
57
|
+
status: str # CONFIRMED_MULTI_VECTOR, SUSPECTED_SCENARIO
|
|
58
|
+
observed_facts: List[str]
|
|
59
|
+
suspected_scenario: str
|
|
60
|
+
supporting_evidence: List[Dict[str, Any]]
|
|
61
|
+
contradicting_evidence: List[Dict[str, Any]]
|
|
62
|
+
traceable_relationships: List[TraceableRelationship]
|
|
63
|
+
reasoning_chain: List[str]
|
|
64
|
+
recommended_investigation_steps: List[str]
|
|
65
|
+
citations: List[str]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class ChangeCorrelator:
|
|
69
|
+
"""
|
|
70
|
+
Deterministic correlation engine that synthesizes individual findings
|
|
71
|
+
into evidence-backed attack scenarios.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
def __init__(self, findings: List[Dict[str, Any]]):
|
|
75
|
+
self.raw_findings = findings
|
|
76
|
+
# Index findings by ID, category, file, and package name
|
|
77
|
+
self.by_id: Dict[str, Dict[str, Any]] = {f.get("id", ""): f for f in findings if f.get("id")}
|
|
78
|
+
self.by_category: Dict[str, List[Dict[str, Any]]] = {}
|
|
79
|
+
self.by_file: Dict[str, List[Dict[str, Any]]] = {}
|
|
80
|
+
self.by_package: Dict[str, List[Dict[str, Any]]] = {}
|
|
81
|
+
|
|
82
|
+
for f in findings:
|
|
83
|
+
cat = f.get("category", "General")
|
|
84
|
+
self.by_category.setdefault(cat, []).append(f)
|
|
85
|
+
|
|
86
|
+
file_path = f.get("affected_file", "")
|
|
87
|
+
if file_path:
|
|
88
|
+
self.by_file.setdefault(file_path, []).append(f)
|
|
89
|
+
|
|
90
|
+
pkg = self._extract_package_name(f)
|
|
91
|
+
if pkg:
|
|
92
|
+
self.by_package.setdefault(pkg.lower(), []).append(f)
|
|
93
|
+
|
|
94
|
+
def _extract_package_name(self, finding: Dict[str, Any]) -> Optional[str]:
|
|
95
|
+
"""Extract associated package name from ID, title, or evidence."""
|
|
96
|
+
fid = finding.get("id", "")
|
|
97
|
+
evidence = finding.get("evidence", "")
|
|
98
|
+
title = finding.get("title", "")
|
|
99
|
+
|
|
100
|
+
# Lock install script: LOCK-INSTALL-SCRIPT-<PKG>
|
|
101
|
+
m = re.match(r"^LOCK-INSTALL-SCRIPT-([A-Z0-9_\-]+)", fid)
|
|
102
|
+
if m:
|
|
103
|
+
return m.group(1).lower().replace("_", "-")
|
|
104
|
+
|
|
105
|
+
# Dependency change: SUSP-DEP-FLOATING-<PKG> or DIFF-DEP-ADDED-<PKG>
|
|
106
|
+
m = re.match(r"^(?:SUSP-DEP-FLOATING|DIFF-DEP-ADDED|DIFF-DEP-MODIFIED|DIFF-DEP-REMOVED)-([A-Z0-9_\-]+)", fid)
|
|
107
|
+
if m:
|
|
108
|
+
return m.group(1).lower().replace("_", "-")
|
|
109
|
+
|
|
110
|
+
# Typosquatting: SUSP-TYPO-<PKG> or SUSP-TYPO-LOCK-<PKG>
|
|
111
|
+
m = re.match(r"^SUSP-TYPO-(?:LOCK-)?([A-Z0-9_\-]+)", fid)
|
|
112
|
+
if m:
|
|
113
|
+
return m.group(1).lower().replace("_", "-")
|
|
114
|
+
|
|
115
|
+
# Source dependency: SRC-GIT-DEP-<PKG> or SRC-TARBALL-DEP-<PKG>
|
|
116
|
+
m = re.match(r"^SRC-(?:GIT|TARBALL)-DEP-([A-Z0-9_\-]+)", fid)
|
|
117
|
+
if m:
|
|
118
|
+
return m.group(1).lower().replace("_", "-")
|
|
119
|
+
|
|
120
|
+
# Look in title: Dependency 'pkg' or Package 'pkg'
|
|
121
|
+
m = re.search(r"(?:Dependency|Package)\s+'([^']+)'", title)
|
|
122
|
+
if m:
|
|
123
|
+
return m.group(1).lower()
|
|
124
|
+
|
|
125
|
+
# Look in evidence: "pkg": ...
|
|
126
|
+
m = re.search(r'"([a-zA-Z0-9_\-/@]+)":\s*(?:\{|")', evidence)
|
|
127
|
+
if m and not m.group(1).startswith("node_modules/"):
|
|
128
|
+
return m.group(1).lower()
|
|
129
|
+
|
|
130
|
+
return None
|
|
131
|
+
|
|
132
|
+
def correlate(self) -> List[CompositeFinding]:
|
|
133
|
+
"""Execute all deterministic correlation rules."""
|
|
134
|
+
composites: List[CompositeFinding] = []
|
|
135
|
+
|
|
136
|
+
# Rule 1: Dependency Injection + Install-Time Execution Hook
|
|
137
|
+
composites.extend(self._correlate_dep_and_install_execution())
|
|
138
|
+
|
|
139
|
+
# Rule 2: CI/CD Pipeline Hijacking (Unpinned Action + Elevated Token / Script Injection)
|
|
140
|
+
composites.extend(self._correlate_ci_pipeline_tampering())
|
|
141
|
+
|
|
142
|
+
# Rule 3: Dependency Confusion & Registry Source Tampering
|
|
143
|
+
composites.extend(self._correlate_registry_and_sources())
|
|
144
|
+
|
|
145
|
+
# Rule 4: Typosquatting Masquerading with Execution Vector
|
|
146
|
+
composites.extend(self._correlate_typosquat_execution())
|
|
147
|
+
|
|
148
|
+
# Rule 5: Container Build Poisoning (Unpinned Base Image + Build-Time Fetch / Root)
|
|
149
|
+
composites.extend(self._correlate_container_poisoning())
|
|
150
|
+
|
|
151
|
+
# Rule 6: Lockfile-Manifest Desynchronization
|
|
152
|
+
composites.extend(self._correlate_lockfile_desync())
|
|
153
|
+
|
|
154
|
+
# Deterministic sorting: severity rank, then confidence, then composite_id
|
|
155
|
+
sev_order = {s: i for i, s in enumerate(SEVERITY_LEVELS)}
|
|
156
|
+
conf_order = {c: i for i, c in enumerate(CONFIDENCE_LEVELS)}
|
|
157
|
+
composites.sort(key=lambda x: (sev_order.get(x.severity, 99), conf_order.get(x.correlation_confidence, 99), x.composite_id))
|
|
158
|
+
|
|
159
|
+
return composites
|
|
160
|
+
|
|
161
|
+
# --------------------------------------------------------------------------
|
|
162
|
+
# Scenario 1: Dependency Injection + Install-Time Hook
|
|
163
|
+
# --------------------------------------------------------------------------
|
|
164
|
+
def _correlate_dep_and_install_execution(self) -> List[CompositeFinding]:
|
|
165
|
+
results: List[CompositeFinding] = []
|
|
166
|
+
dep_findings = self.by_category.get("Dependency Change", []) + self.by_category.get("Dependency Source", [])
|
|
167
|
+
script_findings = self.by_category.get("Lifecycle Script", [])
|
|
168
|
+
|
|
169
|
+
if not dep_findings or not script_findings:
|
|
170
|
+
return results
|
|
171
|
+
|
|
172
|
+
# 1A. Package-level correlation (same package has both dependency anomaly and install hook)
|
|
173
|
+
matched_packages = set()
|
|
174
|
+
for pkg, p_findings in self.by_package.items():
|
|
175
|
+
deps = [f for f in p_findings if f.get("category") in ("Dependency Change", "Dependency Source")]
|
|
176
|
+
scripts = [f for f in p_findings if f.get("category") == "Lifecycle Script"]
|
|
177
|
+
|
|
178
|
+
if deps and scripts:
|
|
179
|
+
matched_packages.add(pkg)
|
|
180
|
+
results.append(self._build_dep_install_composite(pkg, deps, scripts))
|
|
181
|
+
|
|
182
|
+
# 1B. Manifest-level correlation: Unpinned/floating dependency added in manifest AND manifest has dangerous install script
|
|
183
|
+
manifest_files = {f.get("affected_file") for f in dep_findings if f.get("affected_file", "").endswith("package.json")}
|
|
184
|
+
for m_file in manifest_files:
|
|
185
|
+
file_deps = [f for f in self.by_file.get(m_file, []) if f.get("category") in ("Dependency Change", "Dependency Source")]
|
|
186
|
+
file_scripts = [f for f in self.by_file.get(m_file, []) if f.get("category") == "Lifecycle Script" and f.get("severity") in ("CRITICAL", "HIGH")]
|
|
187
|
+
|
|
188
|
+
if file_deps and file_scripts:
|
|
189
|
+
comp_id = f"CORR-MANIFEST-INSTALL-CHAIN-{len(results)+1:03d}"
|
|
190
|
+
results.append(self._build_manifest_chain_composite(comp_id, m_file, file_deps, file_scripts))
|
|
191
|
+
|
|
192
|
+
return results
|
|
193
|
+
|
|
194
|
+
def _build_dep_install_composite(self, pkg: str, deps: List[Dict[str, Any]], scripts: List[Dict[str, Any]]) -> CompositeFinding:
|
|
195
|
+
primary_ids = [f["id"] for f in deps + scripts]
|
|
196
|
+
files = sorted(list({f.get("affected_file", "") for f in deps + scripts if f.get("affected_file")}))
|
|
197
|
+
|
|
198
|
+
# Collect supporting evidence
|
|
199
|
+
supporting = []
|
|
200
|
+
for d in deps:
|
|
201
|
+
supporting.append({
|
|
202
|
+
"finding_id": d["id"],
|
|
203
|
+
"role": "Dependency Specification",
|
|
204
|
+
"detail": d.get("explanation", ""),
|
|
205
|
+
"evidence": d.get("evidence", "")
|
|
206
|
+
})
|
|
207
|
+
for s in scripts:
|
|
208
|
+
supporting.append({
|
|
209
|
+
"finding_id": s["id"],
|
|
210
|
+
"role": "Install Execution Hook",
|
|
211
|
+
"detail": s.get("explanation", ""),
|
|
212
|
+
"evidence": s.get("evidence", "")
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
# Evaluate contradicting evidence
|
|
216
|
+
contradicting = []
|
|
217
|
+
is_pinned = any(
|
|
218
|
+
"SHA" in d.get("explanation", "")
|
|
219
|
+
or "SHA" in d.get("title", "")
|
|
220
|
+
or "@sha" in d.get("evidence", "").lower()
|
|
221
|
+
or bool(re.search(r"#[0-9a-fA-F]{40}", d.get("evidence", "")))
|
|
222
|
+
for d in deps
|
|
223
|
+
)
|
|
224
|
+
if is_pinned:
|
|
225
|
+
contradicting.append({
|
|
226
|
+
"factor": "Exact Cryptographic Pinning",
|
|
227
|
+
"detail": "Dependency is pinned to an immutable commit SHA or hash rather than a floating tag.",
|
|
228
|
+
"mitigation_strength": "HIGH"
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
is_benign_build = any("node-gyp" in s.get("evidence", "").lower() or "tsc" in s.get("evidence", "").lower() for s in scripts)
|
|
232
|
+
if is_benign_build:
|
|
233
|
+
contradicting.append({
|
|
234
|
+
"factor": "Standard Native Compilation",
|
|
235
|
+
"detail": "Install script command matches standard native build tools (node-gyp/tsc).",
|
|
236
|
+
"mitigation_strength": "MEDIUM"
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
# Deterministic severity and confidence calculation
|
|
240
|
+
has_critical_script = any(s.get("severity") == "CRITICAL" for s in scripts)
|
|
241
|
+
has_floating_dep = any("floating" in d.get("title", "").lower() or "latest" in d.get("evidence", "").lower() for d in deps)
|
|
242
|
+
all_introduced_in_range = all(f.get("change_origin") == "INTRODUCED_IN_RANGE" for f in deps + scripts)
|
|
243
|
+
|
|
244
|
+
if has_critical_script:
|
|
245
|
+
sev = "CRITICAL"
|
|
246
|
+
elif has_floating_dep and any(s.get("severity") in ("HIGH", "MEDIUM") for s in scripts):
|
|
247
|
+
sev = "HIGH"
|
|
248
|
+
else:
|
|
249
|
+
sev = "MEDIUM"
|
|
250
|
+
|
|
251
|
+
if contradicting and any(c["mitigation_strength"] == "HIGH" for c in contradicting):
|
|
252
|
+
# Downgrade severity by 1 level due to strong contradiction
|
|
253
|
+
idx = SEVERITY_LEVELS.index(sev)
|
|
254
|
+
sev = SEVERITY_LEVELS[min(idx + 1, len(SEVERITY_LEVELS) - 1)]
|
|
255
|
+
|
|
256
|
+
# Confidence
|
|
257
|
+
if all_introduced_in_range and not contradicting:
|
|
258
|
+
conf = "HIGH"
|
|
259
|
+
status = "CONFIRMED_MULTI_VECTOR"
|
|
260
|
+
elif any(f.get("evidence_type") == "OBSERVED_CHANGE" for f in deps + scripts):
|
|
261
|
+
conf = "MEDIUM"
|
|
262
|
+
status = "SUSPECTED_SCENARIO"
|
|
263
|
+
else:
|
|
264
|
+
conf = "LOW" if contradicting else "MEDIUM"
|
|
265
|
+
status = "SUSPECTED_SCENARIO"
|
|
266
|
+
|
|
267
|
+
# Build traceable relationships
|
|
268
|
+
relationships = []
|
|
269
|
+
for d in deps:
|
|
270
|
+
for s in scripts:
|
|
271
|
+
relationships.append(TraceableRelationship(
|
|
272
|
+
source_id=d["id"],
|
|
273
|
+
target_id=s["id"],
|
|
274
|
+
relationship="triggers_execution_of",
|
|
275
|
+
rationale=f"Dependency '{pkg}' declared in manifest triggers install hook declared in lockfile/manifest upon 'npm install'."
|
|
276
|
+
))
|
|
277
|
+
|
|
278
|
+
observed_facts = [
|
|
279
|
+
f"Package '{pkg}' is referenced across multiple configuration layers: {', '.join(files)}.",
|
|
280
|
+
f"Dependency configuration defines: {[d.get('evidence', '') for d in deps]}.",
|
|
281
|
+
f"Package registers automated install hook: {[s.get('evidence', '') for s in scripts]}."
|
|
282
|
+
]
|
|
283
|
+
|
|
284
|
+
reasoning = [
|
|
285
|
+
f"Step 1: Analyzed package '{pkg}' across dependency manifest and lockfile declarations.",
|
|
286
|
+
f"Step 2: Identified dependency anomaly ({', '.join(d['id'] for d in deps)}) indicating unpinned or direct sourcing.",
|
|
287
|
+
f"Step 3: Correlated corresponding lifecycle hook ({', '.join(s['id'] for s in scripts)}) executing on host during installation.",
|
|
288
|
+
f"Step 4: Evaluated mitigations (identified {len(contradicting)} contradicting factor(s)).",
|
|
289
|
+
f"Step 5: Concluded {'CONFIRMED' if status == 'CONFIRMED_MULTI_VECTOR' else 'SUSPECTED'} install-time execution risk."
|
|
290
|
+
]
|
|
291
|
+
|
|
292
|
+
return CompositeFinding(
|
|
293
|
+
composite_id=f"CORR-DEP-INSTALL-{pkg.upper().replace('@', '').replace('/', '_')}",
|
|
294
|
+
scenario_name=f"Install-Time Code Execution via Dependency '{pkg}'",
|
|
295
|
+
scenario_type="dependency_install_execution",
|
|
296
|
+
attack_technique="MITRE ATT&CK T1195.001 (Compromise Software Dependencies)",
|
|
297
|
+
primary_finding_ids=primary_ids,
|
|
298
|
+
related_files=files,
|
|
299
|
+
correlation_confidence=conf,
|
|
300
|
+
severity=sev,
|
|
301
|
+
status=status,
|
|
302
|
+
observed_facts=observed_facts,
|
|
303
|
+
suspected_scenario=(
|
|
304
|
+
f"An attacker leverages unpinned or direct dependency '{pkg}' to automatically trigger arbitrary "
|
|
305
|
+
"code execution on developer workstations and CI/CD build environments at install time."
|
|
306
|
+
),
|
|
307
|
+
supporting_evidence=supporting,
|
|
308
|
+
contradicting_evidence=contradicting,
|
|
309
|
+
traceable_relationships=relationships,
|
|
310
|
+
reasoning_chain=reasoning,
|
|
311
|
+
recommended_investigation_steps=[
|
|
312
|
+
f"Inspect the complete tarball and source code repository of '{pkg}'.",
|
|
313
|
+
"Execute build using 'npm install --ignore-scripts' in an isolated container to block lifecycle hooks.",
|
|
314
|
+
"Replace floating or direct URL constraints with pinned semantic versions verified against official registries."
|
|
315
|
+
],
|
|
316
|
+
citations=[CITATIONS["ohm_2020"], CITATIONS["ladisa_2023"]]
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
def _build_manifest_chain_composite(
|
|
320
|
+
self, comp_id: str, m_file: str, deps: List[Dict[str, Any]], scripts: List[Dict[str, Any]]
|
|
321
|
+
) -> CompositeFinding:
|
|
322
|
+
primary_ids = [f["id"] for f in deps + scripts]
|
|
323
|
+
has_critical = any(s.get("severity") == "CRITICAL" for s in scripts)
|
|
324
|
+
has_observed = any(f.get("evidence_type") == "OBSERVED_CHANGE" for f in deps + scripts)
|
|
325
|
+
all_introduced = all(f.get("change_origin") == "INTRODUCED_IN_RANGE" for f in deps + scripts)
|
|
326
|
+
|
|
327
|
+
sev = "CRITICAL" if has_critical else "HIGH"
|
|
328
|
+
conf = "HIGH" if (has_observed and all_introduced) else "MEDIUM"
|
|
329
|
+
status = "CONFIRMED_MULTI_VECTOR" if (has_observed and all_introduced) else "SUSPECTED_SCENARIO"
|
|
330
|
+
|
|
331
|
+
return CompositeFinding(
|
|
332
|
+
composite_id=comp_id,
|
|
333
|
+
scenario_name=f"Co-Located Dependency Anomaly and Dangerous Lifecycle Hook in '{m_file}'",
|
|
334
|
+
scenario_type="manifest_lifecycle_chain",
|
|
335
|
+
attack_technique="MITRE ATT&CK T1195.001 (Compromise Software Dependencies)",
|
|
336
|
+
primary_finding_ids=primary_ids,
|
|
337
|
+
related_files=[m_file],
|
|
338
|
+
correlation_confidence=conf,
|
|
339
|
+
severity=sev,
|
|
340
|
+
status=status,
|
|
341
|
+
observed_facts=[
|
|
342
|
+
f"Manifest '{m_file}' defines unpinned dependencies: {[d.get('evidence') for d in deps]}.",
|
|
343
|
+
f"Manifest '{m_file}' defines high-severity install script commands: {[s.get('evidence') for s in scripts]}."
|
|
344
|
+
],
|
|
345
|
+
suspected_scenario="Coordinated modification introducing both external dependencies and shell execution in the same project manifest.",
|
|
346
|
+
supporting_evidence=[{"finding_id": f["id"], "evidence": f.get("evidence", "")} for f in deps + scripts],
|
|
347
|
+
contradicting_evidence=[],
|
|
348
|
+
traceable_relationships=[
|
|
349
|
+
TraceableRelationship(
|
|
350
|
+
source_id=deps[0]["id"],
|
|
351
|
+
target_id=scripts[0]["id"],
|
|
352
|
+
relationship="co_located_in_manifest",
|
|
353
|
+
rationale=f"Both dependency specification and execution hook reside within '{m_file}'."
|
|
354
|
+
)
|
|
355
|
+
],
|
|
356
|
+
reasoning_chain=[
|
|
357
|
+
f"Step 1: Detected dependency constraint anomalies in '{m_file}'.",
|
|
358
|
+
f"Step 2: Detected dangerous script commands in the same manifest.",
|
|
359
|
+
"Step 3: Correlated as a single co-located project configuration risk."
|
|
360
|
+
],
|
|
361
|
+
recommended_investigation_steps=[
|
|
362
|
+
"Review Git commit history for who introduced the script commands and unpinned dependencies.",
|
|
363
|
+
"Audit build scripts for exfiltration or secondary payload downloads."
|
|
364
|
+
],
|
|
365
|
+
citations=[CITATIONS["ohm_2020"]]
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
# --------------------------------------------------------------------------
|
|
369
|
+
# Scenario 2: CI/CD Pipeline Hijacking & Supply Chain Pivot
|
|
370
|
+
# --------------------------------------------------------------------------
|
|
371
|
+
def _correlate_ci_pipeline_tampering(self) -> List[CompositeFinding]:
|
|
372
|
+
results: List[CompositeFinding] = []
|
|
373
|
+
ci_findings = self.by_category.get("Docker & CI/CD", [])
|
|
374
|
+
if not ci_findings:
|
|
375
|
+
return results
|
|
376
|
+
|
|
377
|
+
# Group by workflow file
|
|
378
|
+
workflows = {f.get("affected_file", "") for f in ci_findings if ".github/workflows" in f.get("affected_file", "")}
|
|
379
|
+
|
|
380
|
+
for wf in workflows:
|
|
381
|
+
wf_findings = [f for f in ci_findings if f.get("affected_file") == wf]
|
|
382
|
+
unpinned_actions = [f for f in wf_findings if "UNPINNED" in f.get("id", "") or "GHA001" in f.get("id", "") or "DF001" in f.get("id", "")]
|
|
383
|
+
priv_or_perm = [f for f in wf_findings if "PERM" in f.get("id", "") or "GHA004" in f.get("id", "") or "GHA002" in f.get("id", "")]
|
|
384
|
+
injection = [f for f in wf_findings if "GHA003" in f.get("id", "") or "injection" in f.get("title", "").lower()]
|
|
385
|
+
remote_shell = [f for f in wf_findings if "GHA007" in f.get("id", "") or "curl|sh" in f.get("evidence", "").lower()]
|
|
386
|
+
|
|
387
|
+
# Distinguish first-party (actions/*, github/*) from third-party actions
|
|
388
|
+
first_party_actions = [
|
|
389
|
+
f for f in unpinned_actions
|
|
390
|
+
if any(fp in f.get("evidence", "").lower() for fp in ("actions/", "github/"))
|
|
391
|
+
]
|
|
392
|
+
third_party_actions = [
|
|
393
|
+
f for f in unpinned_actions
|
|
394
|
+
if not any(fp in f.get("evidence", "").lower() for fp in ("actions/", "github/"))
|
|
395
|
+
]
|
|
396
|
+
has_third_party = len(third_party_actions) > 0
|
|
397
|
+
all_first_party = len(unpinned_actions) > 0 and not has_third_party
|
|
398
|
+
|
|
399
|
+
# Pipeline attack scenario correlation requires an actual untrusted external attack vector:
|
|
400
|
+
# either an unpinned third-party action, an expression injection, or a remote shell execution.
|
|
401
|
+
# Official first-party actions without injection or remote download represent maintenance risks,
|
|
402
|
+
# not exploitable multi-vector supply-chain attacks.
|
|
403
|
+
has_attack_vector = has_third_party or len(injection) > 0 or len(remote_shell) > 0
|
|
404
|
+
|
|
405
|
+
if has_attack_vector and (priv_or_perm or injection):
|
|
406
|
+
primary_ids = [f["id"] for f in unpinned_actions + priv_or_perm + injection + remote_shell]
|
|
407
|
+
wf_name = wf.rsplit("/", 1)[-1]
|
|
408
|
+
comp_id = f"CORR-PIPELINE-{wf_name.upper().replace('.', '_').replace('-', '_')}"
|
|
409
|
+
|
|
410
|
+
action_scope_label = (
|
|
411
|
+
"Third-Party GitHub Action" if has_third_party else "First-Party GitHub-Maintained Action"
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
supporting = [{"finding_id": f["id"], "title": f["title"], "evidence": f.get("evidence", "")} for f in unpinned_actions + priv_or_perm + injection + remote_shell]
|
|
415
|
+
|
|
416
|
+
contradicting = []
|
|
417
|
+
if all_first_party:
|
|
418
|
+
contradicting.append({
|
|
419
|
+
"factor": "First-Party Action Maintained by GitHub",
|
|
420
|
+
"detail": (
|
|
421
|
+
"All unpinned actions in this workflow originate from official GitHub-maintained "
|
|
422
|
+
"repositories (actions/*, github/*). While tag mutation is theoretically possible, "
|
|
423
|
+
"it does not present third-party maintainer account takeover risk."
|
|
424
|
+
),
|
|
425
|
+
"mitigation_strength": "HIGH"
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
# Evaluate permissions accurately: do not assume missing permissions = write access
|
|
429
|
+
has_explicit_write = any("write-all" in f.get("evidence", "").lower() or "write scopes" in f.get("evidence", "").lower() for f in priv_or_perm)
|
|
430
|
+
missing_explicit_perm = any("no `permissions:`" in f.get("evidence", "").lower() or "lacks 'permissions:'" in f.get("evidence", "").lower() for f in priv_or_perm)
|
|
431
|
+
|
|
432
|
+
if missing_explicit_perm and not has_explicit_write:
|
|
433
|
+
perm_fact = (
|
|
434
|
+
f"Workflow '{wf}' does not specify an explicit 'permissions:' block; effective token privileges "
|
|
435
|
+
"depend on repository/organization default settings (which default to read-only in modern GitHub "
|
|
436
|
+
"organizations, but may grant write access in legacy or self-hosted settings)."
|
|
437
|
+
)
|
|
438
|
+
else:
|
|
439
|
+
perm_fact = f"Workflow '{wf}' explicitly configures elevated or unconstrained token permissions."
|
|
440
|
+
|
|
441
|
+
# Calibrated severity and confidence:
|
|
442
|
+
# - Script injection or explicit write permissions + third-party action: HIGH
|
|
443
|
+
# - Third-party unpinned action without explicit write: MEDIUM
|
|
444
|
+
# - Only first-party actions unpinned and no injection: LOW (due to HIGH mitigation)
|
|
445
|
+
if injection or (has_third_party and has_explicit_write):
|
|
446
|
+
sev = "HIGH"
|
|
447
|
+
conf = "HIGH" if any(f.get("change_origin") == "INTRODUCED_IN_RANGE" for f in wf_findings) else "MEDIUM"
|
|
448
|
+
elif has_third_party:
|
|
449
|
+
sev = "MEDIUM"
|
|
450
|
+
conf = "MEDIUM"
|
|
451
|
+
else:
|
|
452
|
+
# All first party, no injection
|
|
453
|
+
sev = "LOW"
|
|
454
|
+
conf = "LOW"
|
|
455
|
+
|
|
456
|
+
relationships = []
|
|
457
|
+
if unpinned_actions and priv_or_perm:
|
|
458
|
+
relationships.append(TraceableRelationship(
|
|
459
|
+
source_id=unpinned_actions[0]["id"],
|
|
460
|
+
target_id=priv_or_perm[0]["id"],
|
|
461
|
+
relationship="inherits_permissions_of",
|
|
462
|
+
rationale=(
|
|
463
|
+
f"{action_scope_label} executes inside a runner whose effective token authorization "
|
|
464
|
+
f"is governed by {priv_or_perm[0]['id']}."
|
|
465
|
+
)
|
|
466
|
+
))
|
|
467
|
+
if injection and priv_or_perm:
|
|
468
|
+
relationships.append(TraceableRelationship(
|
|
469
|
+
source_id=injection[0]["id"],
|
|
470
|
+
target_id=priv_or_perm[0]["id"],
|
|
471
|
+
relationship="executes_with_privilege",
|
|
472
|
+
rationale="Injected script commands expand in runner context and inherit effective GITHUB_TOKEN permissions."
|
|
473
|
+
))
|
|
474
|
+
|
|
475
|
+
scenario_title = (
|
|
476
|
+
f"Third-Party CI/CD Pipeline Attack Vector in '{wf_name}'"
|
|
477
|
+
if has_third_party
|
|
478
|
+
else f"Unpinned First-Party Action Maintenance Risk in '{wf_name}'"
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
suspected_narrative = (
|
|
482
|
+
f"An attacker compromises upstream third-party action repository tags in '{wf_name}' "
|
|
483
|
+
"or leverages script injection to execute commands with runner privileges."
|
|
484
|
+
if has_third_party or injection
|
|
485
|
+
else f"Workflow '{wf_name}' references mutable first-party action tags (@v1, @v2) without SHA pinning. "
|
|
486
|
+
"While published by GitHub, moving tags can introduce unexpected breaking changes or runtime updates."
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
results.append(CompositeFinding(
|
|
490
|
+
composite_id=comp_id,
|
|
491
|
+
scenario_name=scenario_title,
|
|
492
|
+
scenario_type="pipeline_hijack",
|
|
493
|
+
attack_technique="MITRE ATT&CK T1195.002 (Compromise CI/CD Toolchain) / T1059 (Command and Scripting Interpreter)",
|
|
494
|
+
primary_finding_ids=primary_ids,
|
|
495
|
+
related_files=[wf],
|
|
496
|
+
correlation_confidence=conf,
|
|
497
|
+
severity=sev,
|
|
498
|
+
status="SUSPECTED_SCENARIO",
|
|
499
|
+
observed_facts=[
|
|
500
|
+
perm_fact,
|
|
501
|
+
f"Workflow incorporates unpinned references or command expansions: {[f.get('evidence', '') for f in unpinned_actions + injection]}."
|
|
502
|
+
],
|
|
503
|
+
suspected_scenario=suspected_narrative,
|
|
504
|
+
supporting_evidence=supporting,
|
|
505
|
+
contradicting_evidence=contradicting,
|
|
506
|
+
traceable_relationships=relationships,
|
|
507
|
+
reasoning_chain=[
|
|
508
|
+
f"Step 1: Evaluated CI/CD workflow security controls in '{wf}'.",
|
|
509
|
+
f"Step 2: Analyzed action provenance ({len(third_party_actions)} third-party, {len(first_party_actions)} first-party).",
|
|
510
|
+
f"Step 3: Assessed token permissions (explicit write: {has_explicit_write}, missing block: {missing_explicit_perm}).",
|
|
511
|
+
f"Step 4: Applied mitigating factors (first-party actions: {all_first_party}).",
|
|
512
|
+
f"Step 5: Synthesized calibrated {sev} severity pipeline scenario with {conf} confidence."
|
|
513
|
+
],
|
|
514
|
+
recommended_investigation_steps=[
|
|
515
|
+
"Pin actions to full 40-character commit SHAs (e.g. actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11).",
|
|
516
|
+
"Add a top-level 'permissions: contents: read' block to declare explicit least privilege.",
|
|
517
|
+
"Pass untrusted input through environment variables rather than direct inline expansion."
|
|
518
|
+
],
|
|
519
|
+
citations=[CITATIONS["wang_2026"], CITATIONS["ladisa_2023"]]
|
|
520
|
+
))
|
|
521
|
+
|
|
522
|
+
return results
|
|
523
|
+
|
|
524
|
+
# --------------------------------------------------------------------------
|
|
525
|
+
# Scenario 3: Dependency Confusion & Registry Source Tampering
|
|
526
|
+
# --------------------------------------------------------------------------
|
|
527
|
+
def _correlate_registry_and_sources(self) -> List[CompositeFinding]:
|
|
528
|
+
results: List[CompositeFinding] = []
|
|
529
|
+
reg_findings = self.by_category.get("Registry & Source", [])
|
|
530
|
+
src_findings = self.by_category.get("Dependency Source", [])
|
|
531
|
+
|
|
532
|
+
if not reg_findings and not src_findings:
|
|
533
|
+
return results
|
|
534
|
+
|
|
535
|
+
# Insecure HTTP registry or disabled TLS + direct raw tarball / Git URLs
|
|
536
|
+
insecure_transports = [f for f in reg_findings if "INSECURE" in f["id"] or "STRICT-SSL" in f["id"]]
|
|
537
|
+
raw_sources = [f for f in src_findings if "TARBALL" in f["id"] or "GIT" in f["id"] or "HTTP" in f["id"]]
|
|
538
|
+
|
|
539
|
+
# Isolate unpinned or cleartext sources that represent actual tampering exposure
|
|
540
|
+
suspicious_sources = [
|
|
541
|
+
f for f in raw_sources
|
|
542
|
+
if "HTTP" in f.get("id", "")
|
|
543
|
+
or ("TARBALL" in f.get("id", "") and "https://" not in f.get("evidence", ""))
|
|
544
|
+
or ("GIT" in f.get("id", "") and not re.search(r"#[0-9a-fA-F]{40}", f.get("evidence", "")))
|
|
545
|
+
]
|
|
546
|
+
|
|
547
|
+
if insecure_transports or (len(suspicious_sources) >= 1 and reg_findings):
|
|
548
|
+
primary_ids = [f["id"] for f in insecure_transports + raw_sources]
|
|
549
|
+
files = sorted(list({f.get("affected_file", "") for f in insecure_transports + raw_sources if f.get("affected_file")}))
|
|
550
|
+
|
|
551
|
+
supporting = [{"finding_id": f["id"], "evidence": f.get("evidence", ""), "detail": f.get("explanation", "")} for f in insecure_transports + raw_sources]
|
|
552
|
+
contradicting = []
|
|
553
|
+
|
|
554
|
+
# Check if source is official GitHub HTTPS URL or commit-pinned
|
|
555
|
+
for rs in raw_sources:
|
|
556
|
+
ev = rs.get("evidence", "")
|
|
557
|
+
if re.search(r"#[0-9a-fA-F]{40}", ev):
|
|
558
|
+
contradicting.append({
|
|
559
|
+
"factor": "Exact Cryptographic Commit Pinning",
|
|
560
|
+
"detail": f"Git dependency in '{rs.get('affected_file')}' is pinned to an immutable 40-character commit SHA.",
|
|
561
|
+
"mitigation_strength": "HIGH"
|
|
562
|
+
})
|
|
563
|
+
elif "https://github.com" in ev:
|
|
564
|
+
contradicting.append({
|
|
565
|
+
"factor": "Encrypted Upstream Host",
|
|
566
|
+
"detail": f"Tarball/Git dependency in '{rs.get('affected_file')}' is fetched over HTTPS from GitHub infrastructure.",
|
|
567
|
+
"mitigation_strength": "LOW"
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
has_cleartext = any("HTTP" in f.get("id", "") for f in insecure_transports + raw_sources)
|
|
571
|
+
sev = "HIGH" if has_cleartext else "MEDIUM"
|
|
572
|
+
conf = "HIGH" if any(f.get("change_origin") == "INTRODUCED_IN_RANGE" for f in insecure_transports + raw_sources) else "MEDIUM"
|
|
573
|
+
|
|
574
|
+
if contradicting and any(c["mitigation_strength"] == "HIGH" for c in contradicting) and not has_cleartext:
|
|
575
|
+
idx = SEVERITY_LEVELS.index(sev)
|
|
576
|
+
sev = SEVERITY_LEVELS[min(idx + 1, len(SEVERITY_LEVELS) - 1)]
|
|
577
|
+
conf = "LOW"
|
|
578
|
+
|
|
579
|
+
relationships = []
|
|
580
|
+
if insecure_transports and raw_sources:
|
|
581
|
+
relationships.append(TraceableRelationship(
|
|
582
|
+
source_id=insecure_transports[0]["id"],
|
|
583
|
+
target_id=raw_sources[0]["id"],
|
|
584
|
+
relationship="downgrades_security_of",
|
|
585
|
+
rationale="Insecure registry transport configurations permit interception of package fetches."
|
|
586
|
+
))
|
|
587
|
+
|
|
588
|
+
results.append(CompositeFinding(
|
|
589
|
+
composite_id=f"CORR-REGISTRY-SOURCE-CHAIN-{len(results)+1:03d}",
|
|
590
|
+
scenario_name="Unencrypted Transport / Non-Standard Dependency Source Vector",
|
|
591
|
+
scenario_type="registry_source_confusion",
|
|
592
|
+
attack_technique="MITRE ATT&CK T1195.001 (Compromise Software Dependencies)",
|
|
593
|
+
primary_finding_ids=primary_ids,
|
|
594
|
+
related_files=files,
|
|
595
|
+
correlation_confidence=conf,
|
|
596
|
+
severity=sev,
|
|
597
|
+
status="SUSPECTED_SCENARIO",
|
|
598
|
+
observed_facts=[
|
|
599
|
+
f"Configuration files specify insecure or external sources: {[f.get('evidence', '') for f in insecure_transports + raw_sources]}."
|
|
600
|
+
],
|
|
601
|
+
suspected_scenario=(
|
|
602
|
+
"An adversary positioned on the network (MITM) or leveraging public package namespace confusion "
|
|
603
|
+
"intercepts or replaces dependencies downloaded outside standard authenticated registries."
|
|
604
|
+
),
|
|
605
|
+
supporting_evidence=supporting,
|
|
606
|
+
contradicting_evidence=contradicting,
|
|
607
|
+
traceable_relationships=relationships,
|
|
608
|
+
reasoning_chain=[
|
|
609
|
+
"Step 1: Evaluated registry transport protocols and external package sources.",
|
|
610
|
+
"Step 2: Identified unencrypted HTTP transport or direct tarball references bypassing central validation.",
|
|
611
|
+
"Step 3: Correlated transport exposure with dependency resolution risks.",
|
|
612
|
+
"Step 4: Evaluated mitigations (TLS presence, trusted hostnames).",
|
|
613
|
+
"Step 5: Generated composite registry and source correlation."
|
|
614
|
+
],
|
|
615
|
+
recommended_investigation_steps=[
|
|
616
|
+
"Ensure all registry endpoints in .npmrc and .yarnrc enforce 'https://'.",
|
|
617
|
+
"Remove 'strict-ssl=false' and configure valid CA trust stores.",
|
|
618
|
+
"Pin tarball dependencies with SHA-512 cryptographic subresource integrity hashes."
|
|
619
|
+
],
|
|
620
|
+
citations=[CITATIONS["birsan_2021"], CITATIONS["ladisa_2023"]]
|
|
621
|
+
))
|
|
622
|
+
|
|
623
|
+
return results
|
|
624
|
+
|
|
625
|
+
# --------------------------------------------------------------------------
|
|
626
|
+
# Scenario 4: Typosquatting Masquerading + Shadow Execution Vector
|
|
627
|
+
# --------------------------------------------------------------------------
|
|
628
|
+
def _correlate_typosquat_execution(self) -> List[CompositeFinding]:
|
|
629
|
+
results: List[CompositeFinding] = []
|
|
630
|
+
typo_findings = self.by_category.get("Typosquatting", [])
|
|
631
|
+
if not typo_findings:
|
|
632
|
+
return results
|
|
633
|
+
|
|
634
|
+
for tf in typo_findings:
|
|
635
|
+
pkg = self._extract_package_name(tf)
|
|
636
|
+
if not pkg:
|
|
637
|
+
continue
|
|
638
|
+
|
|
639
|
+
# Look for related lifecycle scripts or floating versions for this typosquat package
|
|
640
|
+
related_scripts = [f for f in self.by_package.get(pkg, []) if f.get("category") == "Lifecycle Script"]
|
|
641
|
+
related_deps = [f for f in self.by_package.get(pkg, []) if f.get("category") == "Dependency Change"]
|
|
642
|
+
|
|
643
|
+
if related_scripts or related_deps:
|
|
644
|
+
primary_ids = [tf["id"]] + [f["id"] for f in related_scripts + related_deps]
|
|
645
|
+
files = sorted(list({f.get("affected_file", "") for f in [tf] + related_scripts + related_deps if f.get("affected_file")}))
|
|
646
|
+
|
|
647
|
+
supporting = [
|
|
648
|
+
{"finding_id": tf["id"], "evidence": tf.get("evidence", ""), "detail": tf.get("explanation", "")}
|
|
649
|
+
]
|
|
650
|
+
for rs in related_scripts:
|
|
651
|
+
supporting.append({"finding_id": rs["id"], "evidence": rs.get("evidence", ""), "detail": "Automated install script execution"})
|
|
652
|
+
for rd in related_deps:
|
|
653
|
+
supporting.append({"finding_id": rd["id"], "evidence": rd.get("evidence", ""), "detail": "Dependency specification anomaly"})
|
|
654
|
+
|
|
655
|
+
# Contradicting evidence: Is this a well-known legacy package?
|
|
656
|
+
contradicting = []
|
|
657
|
+
if "bcrypt-nodejs" in pkg:
|
|
658
|
+
contradicting.append({
|
|
659
|
+
"factor": "Established Legacy Implementation",
|
|
660
|
+
"detail": "'bcrypt-nodejs' is a historically recognized pure-JavaScript implementation of bcrypt created to avoid native build dependencies, not a malicious typosquat.",
|
|
661
|
+
"mitigation_strength": "HIGH"
|
|
662
|
+
})
|
|
663
|
+
elif "object-assign" in pkg:
|
|
664
|
+
contradicting.append({
|
|
665
|
+
"factor": "Standard Polyfill/Ponyfill",
|
|
666
|
+
"detail": "'object-assign' is a widely utilized ECMAScript 6 polyfill maintained by standard community members with millions of weekly downloads.",
|
|
667
|
+
"mitigation_strength": "HIGH"
|
|
668
|
+
})
|
|
669
|
+
|
|
670
|
+
# Severity: never CRITICAL for typosquatting heuristics
|
|
671
|
+
sev = "LOW" if contradicting else "MEDIUM"
|
|
672
|
+
conf = "LOW" if contradicting else "MEDIUM"
|
|
673
|
+
|
|
674
|
+
relationships = []
|
|
675
|
+
for rs in related_scripts:
|
|
676
|
+
relationships.append(TraceableRelationship(
|
|
677
|
+
source_id=tf["id"],
|
|
678
|
+
target_id=rs["id"],
|
|
679
|
+
relationship="executes_code_via",
|
|
680
|
+
rationale=f"Similar-named package '{pkg}' registers an active install hook."
|
|
681
|
+
))
|
|
682
|
+
|
|
683
|
+
results.append(CompositeFinding(
|
|
684
|
+
composite_id=f"CORR-TYPOSQUAT-EXEC-{pkg.upper().replace('@', '').replace('/', '_')}",
|
|
685
|
+
scenario_name=f"Typosquatting Masquerading Risk for '{pkg}'",
|
|
686
|
+
scenario_type="typosquat_masquerading",
|
|
687
|
+
attack_technique="MITRE ATT&CK T1036.005 (Masquerading: Match Legitimate Name)",
|
|
688
|
+
primary_finding_ids=primary_ids,
|
|
689
|
+
related_files=files,
|
|
690
|
+
correlation_confidence=conf,
|
|
691
|
+
severity=sev,
|
|
692
|
+
status="SUSPECTED_SCENARIO",
|
|
693
|
+
observed_facts=[
|
|
694
|
+
f"Package '{pkg}' shares string similarity with popular canonical package: {tf.get('evidence', '')}.",
|
|
695
|
+
f"Package declarations in repository: {[f.get('evidence', '') for f in related_scripts + related_deps]}."
|
|
696
|
+
],
|
|
697
|
+
suspected_scenario=(
|
|
698
|
+
f"A developer intended to install a popular library but mistakenly specified '{pkg}', "
|
|
699
|
+
"which registers automated install lifecycle behavior."
|
|
700
|
+
),
|
|
701
|
+
supporting_evidence=supporting,
|
|
702
|
+
contradicting_evidence=contradicting,
|
|
703
|
+
traceable_relationships=relationships,
|
|
704
|
+
reasoning_chain=[
|
|
705
|
+
f"Step 1: Computed string distance and affix variations for '{pkg}'.",
|
|
706
|
+
f"Step 2: Identified related execution hooks or version anomalies.",
|
|
707
|
+
f"Step 3: Evaluated package legitimacy and history ({len(contradicting)} mitigating factor(s)).",
|
|
708
|
+
"Step 4: Formulated balanced typosquatting assessment without arbitrary elevation."
|
|
709
|
+
],
|
|
710
|
+
recommended_investigation_steps=[
|
|
711
|
+
f"Verify if the project explicitly requires '{pkg}' or intended the canonical package.",
|
|
712
|
+
"Check the publisher reputation and download statistics on npmjs.com.",
|
|
713
|
+
"Audit the package contents before executing install scripts."
|
|
714
|
+
],
|
|
715
|
+
citations=[CITATIONS["ohm_2020"]]
|
|
716
|
+
))
|
|
717
|
+
|
|
718
|
+
return results
|
|
719
|
+
|
|
720
|
+
# --------------------------------------------------------------------------
|
|
721
|
+
# Scenario 5: Container Build Poisoning (Mutable Base Image + Remote Download)
|
|
722
|
+
# --------------------------------------------------------------------------
|
|
723
|
+
def _correlate_container_poisoning(self) -> List[CompositeFinding]:
|
|
724
|
+
results: List[CompositeFinding] = []
|
|
725
|
+
docker_findings = [f for f in self.by_category.get("Docker & CI/CD", []) if "Dockerfile" in f.get("affected_file", "") or "compose" in f.get("affected_file", "")]
|
|
726
|
+
if not docker_findings:
|
|
727
|
+
return results
|
|
728
|
+
|
|
729
|
+
unpinned_bases = [f for f in docker_findings if "DF001" in f.get("id", "") or "DF002" in f.get("id", "") or "DF012" in f.get("id", "")]
|
|
730
|
+
build_downloads = [f for f in docker_findings if "DF004" in f.get("id", "") or "DF005" in f.get("id", "")]
|
|
731
|
+
|
|
732
|
+
if unpinned_bases and len(unpinned_bases) >= 1:
|
|
733
|
+
primary_ids = [f["id"] for f in unpinned_bases + build_downloads]
|
|
734
|
+
files = sorted(list({f.get("affected_file", "") for f in unpinned_bases + build_downloads if f.get("affected_file")}))
|
|
735
|
+
|
|
736
|
+
supporting = [{"finding_id": f["id"], "evidence": f.get("evidence", ""), "detail": f.get("explanation", "")} for f in unpinned_bases + build_downloads]
|
|
737
|
+
contradicting = []
|
|
738
|
+
|
|
739
|
+
# Check if base image is official (node, alpine, mongo)
|
|
740
|
+
for ub in unpinned_bases:
|
|
741
|
+
ev = ub.get("evidence", "").lower()
|
|
742
|
+
if any(official in ev for official in ("from node:", "from alpine:", "image: mongo:")):
|
|
743
|
+
contradicting.append({
|
|
744
|
+
"factor": "Official Base Image Publisher",
|
|
745
|
+
"detail": f"Base image in '{ub.get('affected_file')}' originates from an official Docker Hub verified repository.",
|
|
746
|
+
"mitigation_strength": "LOW"
|
|
747
|
+
})
|
|
748
|
+
|
|
749
|
+
sev = "HIGH" if build_downloads else "MEDIUM"
|
|
750
|
+
conf = "HIGH" if any(f.get("change_origin") == "INTRODUCED_IN_RANGE" for f in unpinned_bases + build_downloads) else "MEDIUM"
|
|
751
|
+
|
|
752
|
+
results.append(CompositeFinding(
|
|
753
|
+
composite_id=f"CORR-CONTAINER-POISONING-{len(results)+1:03d}",
|
|
754
|
+
scenario_name="Container Image Supply Chain Vulnerability",
|
|
755
|
+
scenario_type="container_poisoning",
|
|
756
|
+
attack_technique="MITRE ATT&CK T1525 (Implant Internal Image)",
|
|
757
|
+
primary_finding_ids=primary_ids,
|
|
758
|
+
related_files=files,
|
|
759
|
+
correlation_confidence=conf,
|
|
760
|
+
severity=sev,
|
|
761
|
+
status="SUSPECTED_SCENARIO",
|
|
762
|
+
observed_facts=[
|
|
763
|
+
f"Container build specifications reference mutable base image tags: {[f.get('evidence', '') for f in unpinned_bases]}."
|
|
764
|
+
],
|
|
765
|
+
suspected_scenario=(
|
|
766
|
+
"Container build specifications do not pin base images by cryptographic sha256 digest. "
|
|
767
|
+
"Upstream tag mutations or compromised registry layers could silently alter build output."
|
|
768
|
+
),
|
|
769
|
+
supporting_evidence=supporting,
|
|
770
|
+
contradicting_evidence=contradicting,
|
|
771
|
+
traceable_relationships=[],
|
|
772
|
+
reasoning_chain=[
|
|
773
|
+
"Step 1: Inspected Dockerfiles and Docker Compose build files.",
|
|
774
|
+
f"Step 2: Identified {len(unpinned_bases)} unpinned or end-of-life base image declaration(s).",
|
|
775
|
+
"Step 3: Assessed reproducibility and immutable layer integrity.",
|
|
776
|
+
"Step 4: Evaluated mitigations (official Docker Hub publishers).",
|
|
777
|
+
"Step 5: Formulated container supply chain correlation."
|
|
778
|
+
],
|
|
779
|
+
recommended_investigation_steps=[
|
|
780
|
+
"Pin container base images using immutable SHA-256 digests (e.g. FROM node:12-alpine@sha256:...).",
|
|
781
|
+
"Migrate end-of-life runtimes (e.g. Node 12, Mongo 4.4) to actively supported LTS releases.",
|
|
782
|
+
"Avoid build-time remote downloads without cryptographic verification."
|
|
783
|
+
],
|
|
784
|
+
citations=[CITATIONS["ladisa_2023"]]
|
|
785
|
+
))
|
|
786
|
+
|
|
787
|
+
return results
|
|
788
|
+
|
|
789
|
+
# --------------------------------------------------------------------------
|
|
790
|
+
# Scenario 6: Lockfile-Manifest Desynchronization
|
|
791
|
+
# --------------------------------------------------------------------------
|
|
792
|
+
def _correlate_lockfile_desync(self) -> List[CompositeFinding]:
|
|
793
|
+
results: List[CompositeFinding] = []
|
|
794
|
+
lock_findings = [f for f in self.raw_findings if "DIFF-LOCK-MANIFEST-MISMATCH" in f.get("id", "") or "LOCK-UNEXPLAINED" in f.get("id", "")]
|
|
795
|
+
|
|
796
|
+
for lf in lock_findings:
|
|
797
|
+
results.append(CompositeFinding(
|
|
798
|
+
composite_id=f"CORR-LOCKFILE-DESYNC-{len(results)+1:03d}",
|
|
799
|
+
scenario_name="Lockfile Manipulation without Manifest Modification",
|
|
800
|
+
scenario_type="lockfile_tampering",
|
|
801
|
+
attack_technique="MITRE ATT&CK T1195.001 (Compromise Software Dependencies)",
|
|
802
|
+
primary_finding_ids=[lf["id"]],
|
|
803
|
+
related_files=[lf.get("affected_file", "")],
|
|
804
|
+
correlation_confidence="HIGH" if lf.get("evidence_type") == "OBSERVED_CHANGE" else "MEDIUM",
|
|
805
|
+
severity="HIGH",
|
|
806
|
+
status="CONFIRMED_MULTI_VECTOR" if lf.get("evidence_type") == "OBSERVED_CHANGE" else "SUSPECTED_SCENARIO",
|
|
807
|
+
observed_facts=[f"Lockfile was modified in commit history without corresponding manifest changes: {lf.get('evidence', '')}."],
|
|
808
|
+
suspected_scenario="Covert dependency substitution or tampering executed directly against the lockfile to bypass manifest reviews.",
|
|
809
|
+
supporting_evidence=[{"finding_id": lf["id"], "evidence": lf.get("evidence", ""), "detail": lf.get("explanation", "")}],
|
|
810
|
+
contradicting_evidence=[],
|
|
811
|
+
traceable_relationships=[],
|
|
812
|
+
reasoning_chain=[
|
|
813
|
+
"Step 1: Compared Git diff between package.json and package-lock.json.",
|
|
814
|
+
"Step 2: Detected lockfile changes uncorroborated by manifest intent.",
|
|
815
|
+
"Step 3: Flagged as potential covert dependency modification."
|
|
816
|
+
],
|
|
817
|
+
recommended_investigation_steps=[
|
|
818
|
+
"Regenerate package-lock.json cleanly from package.json using 'npm install --package-lock-only'.",
|
|
819
|
+
"Diff the generated lockfile against version control to isolate unexplained records."
|
|
820
|
+
],
|
|
821
|
+
citations=[CITATIONS["ladisa_2023"]]
|
|
822
|
+
))
|
|
823
|
+
|
|
824
|
+
return results
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
def correlate_suspicious_changes(findings: List[Dict[str, Any]]) -> Dict[str, Any]:
|
|
828
|
+
"""
|
|
829
|
+
Public entry point: Correlates raw findings and generates structured composite findings.
|
|
830
|
+
Returns:
|
|
831
|
+
{
|
|
832
|
+
"total_composites": int,
|
|
833
|
+
"scenarios": [CompositeFinding.model_dump(), ...],
|
|
834
|
+
"metrics": {
|
|
835
|
+
"by_severity": {...},
|
|
836
|
+
"by_scenario_type": {...},
|
|
837
|
+
"by_confidence": {...}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
"""
|
|
841
|
+
correlator = ChangeCorrelator(findings)
|
|
842
|
+
composites = correlator.correlate()
|
|
843
|
+
|
|
844
|
+
sev_counts: Dict[str, int] = {}
|
|
845
|
+
type_counts: Dict[str, int] = {}
|
|
846
|
+
conf_counts: Dict[str, int] = {}
|
|
847
|
+
|
|
848
|
+
for c in composites:
|
|
849
|
+
sev_counts[c.severity] = sev_counts.get(c.severity, 0) + 1
|
|
850
|
+
type_counts[c.scenario_type] = type_counts.get(c.scenario_type, 0) + 1
|
|
851
|
+
conf_counts[c.correlation_confidence] = conf_counts.get(c.correlation_confidence, 0) + 1
|
|
852
|
+
|
|
853
|
+
return {
|
|
854
|
+
"total_composites": len(composites),
|
|
855
|
+
"scenarios": [c.model_dump() for c in composites],
|
|
856
|
+
"metrics": {
|
|
857
|
+
"by_severity": sev_counts,
|
|
858
|
+
"by_scenario_type": type_counts,
|
|
859
|
+
"by_confidence": conf_counts,
|
|
860
|
+
}
|
|
861
|
+
}
|