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,252 @@
|
|
|
1
|
+
"""Production Context Analysis for Contextual Risk Scoring v2.0.
|
|
2
|
+
|
|
3
|
+
Evaluates Dimension P (Production Code Reachability):
|
|
4
|
+
Confirmed production execution path: 100
|
|
5
|
+
Strong production indicators: 70
|
|
6
|
+
Production inclusion without verified execution: 40
|
|
7
|
+
Dev/Test-only: 0
|
|
8
|
+
Unknown: None (preserved for missing-evidence policy)
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any, Optional
|
|
15
|
+
|
|
16
|
+
from reachability.scanners import SourceIndex, Usage, _matches
|
|
17
|
+
from risk_analysis.contextual_scorer import DimensionScore
|
|
18
|
+
|
|
19
|
+
# Patterns identifying core production service entry points
|
|
20
|
+
PROD_ENTRY_PATTERNS = (
|
|
21
|
+
"main.py", "app.py", "server.py", "wsgi.py", "asgi.py", "manage.py",
|
|
22
|
+
"index.js", "server.js", "app.js", "main.ts", "server.ts", "index.ts",
|
|
23
|
+
"main.go", "server.go", "Application.java", "App.java"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# Route and handler definition keywords
|
|
27
|
+
SERVER_ROUTE_PATTERNS = (
|
|
28
|
+
"@app.get", "@app.post", "@app.put", "@app.delete", "@app.route",
|
|
29
|
+
"@router.get", "@router.post", "Blueprint(", "Flask(", "FastAPI(",
|
|
30
|
+
"app.get(", "app.post(", "app.use(", "router.get(", "router.post(",
|
|
31
|
+
"http.HandleFunc", "r.GET(", "r.POST(", "gin.Default()",
|
|
32
|
+
"@RestController", "@GetMapping", "@PostMapping", "@RequestMapping"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# Worker and background daemon keywords
|
|
36
|
+
WORKER_PATTERNS = (
|
|
37
|
+
"@app.task", "@shared_task", "celery", "kafka", "rabbitmq", "consumer",
|
|
38
|
+
"background_tasks", "threading.Thread", "multiprocessing.Process"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ProductionContextAnalyzer:
|
|
43
|
+
"""Analyzes whether a package participates in production execution paths."""
|
|
44
|
+
|
|
45
|
+
def __init__(self, repo_dir: Optional[Path] = None):
|
|
46
|
+
self.repo_dir = Path(repo_dir) if repo_dir else None
|
|
47
|
+
self._cached_entry_points: Optional[list[str]] = None
|
|
48
|
+
self._cached_has_dockerfile: Optional[bool] = None
|
|
49
|
+
self._cached_ci_deploy_signals: Optional[list[str]] = None
|
|
50
|
+
|
|
51
|
+
def _discover_entry_points(self) -> list[str]:
|
|
52
|
+
if self._cached_entry_points is not None:
|
|
53
|
+
return self._cached_entry_points
|
|
54
|
+
if not self.repo_dir or not self.repo_dir.exists():
|
|
55
|
+
self._cached_entry_points = []
|
|
56
|
+
return []
|
|
57
|
+
|
|
58
|
+
entries = []
|
|
59
|
+
for root, _, files in os.walk(self.repo_dir):
|
|
60
|
+
rel_dir = os.path.relpath(root, self.repo_dir).replace("\\", "/")
|
|
61
|
+
if any(p in rel_dir.lower() for p in ("test", "spec", ".git", "node_modules", "vendor", "dist", "build")):
|
|
62
|
+
continue
|
|
63
|
+
for f in files:
|
|
64
|
+
if f in PROD_ENTRY_PATTERNS or f.endswith(("Handler.java", "Controller.java", "routes.py", "api.py")):
|
|
65
|
+
entries.append(os.path.join(rel_dir, f).replace("\\", "/").lstrip("./"))
|
|
66
|
+
self._cached_entry_points = entries
|
|
67
|
+
return entries
|
|
68
|
+
|
|
69
|
+
def _check_dockerfile(self) -> bool:
|
|
70
|
+
if self._cached_has_dockerfile is not None:
|
|
71
|
+
return self._cached_has_dockerfile
|
|
72
|
+
if not self.repo_dir or not self.repo_dir.exists():
|
|
73
|
+
self._cached_has_dockerfile = False
|
|
74
|
+
return False
|
|
75
|
+
|
|
76
|
+
has_df = any((self.repo_dir / f).exists() for f in ("Dockerfile", "docker-compose.yml", "Containerfile"))
|
|
77
|
+
self._cached_has_dockerfile = has_df
|
|
78
|
+
return has_df
|
|
79
|
+
|
|
80
|
+
def evaluate_production_reachability(
|
|
81
|
+
self,
|
|
82
|
+
package_name: str,
|
|
83
|
+
ecosystem: str,
|
|
84
|
+
source_index: Optional[SourceIndex],
|
|
85
|
+
is_dev: bool = False,
|
|
86
|
+
asset_type: str = "source_dependency",
|
|
87
|
+
dependency_type: str = "direct",
|
|
88
|
+
pipeline_findings: Optional[list[dict]] = None,
|
|
89
|
+
container_details: Optional[dict[str, Any]] = None,
|
|
90
|
+
) -> DimensionScore:
|
|
91
|
+
"""Evaluate Dimension P (Production Code Reachability) on a 0-100 scale."""
|
|
92
|
+
dim_name = "Production Code Reachability"
|
|
93
|
+
weight = 0.35
|
|
94
|
+
|
|
95
|
+
# 1. Dev / Test-only exclusion
|
|
96
|
+
if is_dev:
|
|
97
|
+
return DimensionScore(
|
|
98
|
+
dimension="P",
|
|
99
|
+
name=dim_name,
|
|
100
|
+
weight=weight,
|
|
101
|
+
raw_value="dev_dependency",
|
|
102
|
+
normalized_score=0.0,
|
|
103
|
+
status="dev_only",
|
|
104
|
+
weighted_contribution=0.0,
|
|
105
|
+
evidence=["Explicitly marked as development-only dependency in manifest/lockfile"],
|
|
106
|
+
confidence="high",
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
# 2. Container image asset type
|
|
110
|
+
if asset_type == "container_image":
|
|
111
|
+
image_name = (container_details or {}).get("image_name", "container image")
|
|
112
|
+
return DimensionScore(
|
|
113
|
+
dimension="P",
|
|
114
|
+
name=dim_name,
|
|
115
|
+
weight=weight,
|
|
116
|
+
raw_value="container_image_asset",
|
|
117
|
+
normalized_score=100.0,
|
|
118
|
+
status="confirmed_production_container",
|
|
119
|
+
weighted_contribution=round(weight * 100.0, 2),
|
|
120
|
+
evidence=[
|
|
121
|
+
f"Confirmed production asset: package is bundled in container image '{image_name}'",
|
|
122
|
+
"OS/runtime packages inside deployed images directly expose container execution surface",
|
|
123
|
+
],
|
|
124
|
+
confidence="high",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
if not source_index or not self.repo_dir:
|
|
128
|
+
return DimensionScore(
|
|
129
|
+
dimension="P",
|
|
130
|
+
name=dim_name,
|
|
131
|
+
weight=weight,
|
|
132
|
+
raw_value="unindexed_repository",
|
|
133
|
+
normalized_score=None,
|
|
134
|
+
status="unknown",
|
|
135
|
+
weighted_contribution=0.0,
|
|
136
|
+
evidence=["Repository source or production manifests were not accessible for production verification"],
|
|
137
|
+
confidence="none",
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
entry_files = set(self._discover_entry_points())
|
|
141
|
+
has_docker = self._check_dockerfile()
|
|
142
|
+
|
|
143
|
+
# Find matching usages
|
|
144
|
+
lang = next((l for l, e in {"py": "PyPI", "js": "npm", "java": "Maven", "go": "Go"}.items() if e == ecosystem), None)
|
|
145
|
+
app_usages: list[Usage] = []
|
|
146
|
+
test_usages: list[Usage] = []
|
|
147
|
+
if lang and source_index.by_lang.get(lang):
|
|
148
|
+
usages = [u for u in source_index.by_lang.get(lang, []) if _matches(ecosystem, package_name, u.module)]
|
|
149
|
+
app_usages = [u for u in usages if not u.test]
|
|
150
|
+
test_usages = [u for u in usages if u.test]
|
|
151
|
+
|
|
152
|
+
# If exclusively used in test code
|
|
153
|
+
if not app_usages and test_usages:
|
|
154
|
+
return DimensionScore(
|
|
155
|
+
dimension="P",
|
|
156
|
+
name=dim_name,
|
|
157
|
+
weight=weight,
|
|
158
|
+
raw_value="test_files_only",
|
|
159
|
+
normalized_score=0.0,
|
|
160
|
+
status="test_only",
|
|
161
|
+
weighted_contribution=0.0,
|
|
162
|
+
evidence=[
|
|
163
|
+
f"Excluded from production: imported only in {len(test_usages)} test file(s)",
|
|
164
|
+
"Never executed during standard application runtime",
|
|
165
|
+
],
|
|
166
|
+
confidence="high",
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
# Check if imported in a verified production entry point or route
|
|
170
|
+
entry_imports = [u for u in app_usages if u.path in entry_files or any(u.path.endswith(ep) for ep in PROD_ENTRY_PATTERNS)]
|
|
171
|
+
if entry_imports:
|
|
172
|
+
entry_paths = sorted({u.path for u in entry_imports})
|
|
173
|
+
return DimensionScore(
|
|
174
|
+
dimension="P",
|
|
175
|
+
name=dim_name,
|
|
176
|
+
weight=weight,
|
|
177
|
+
raw_value={"entry_imports": entry_paths},
|
|
178
|
+
normalized_score=100.0,
|
|
179
|
+
status="confirmed_production_execution",
|
|
180
|
+
weighted_contribution=round(weight * 100.0, 2),
|
|
181
|
+
evidence=[
|
|
182
|
+
f"Confirmed production path: imported directly in application entry point(s): {', '.join(entry_paths[:3])}",
|
|
183
|
+
"Executes in the core application runtime lifecycle",
|
|
184
|
+
],
|
|
185
|
+
confidence="high",
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
# Strong production indicators: application code usage + container/service inclusion
|
|
189
|
+
if app_usages:
|
|
190
|
+
app_paths = sorted({u.path for u in app_usages})
|
|
191
|
+
if has_docker:
|
|
192
|
+
return DimensionScore(
|
|
193
|
+
dimension="P",
|
|
194
|
+
name=dim_name,
|
|
195
|
+
weight=weight,
|
|
196
|
+
raw_value={"app_files": len(app_paths), "docker": True},
|
|
197
|
+
normalized_score=70.0,
|
|
198
|
+
status="strong_production_indicators",
|
|
199
|
+
weighted_contribution=round(weight * 70.0, 2),
|
|
200
|
+
evidence=[
|
|
201
|
+
f"Strong production indicators: imported in {len(app_paths)} app files and containerized via Dockerfile",
|
|
202
|
+
f"Files: {', '.join(app_paths[:3])}",
|
|
203
|
+
],
|
|
204
|
+
confidence="high",
|
|
205
|
+
)
|
|
206
|
+
return DimensionScore(
|
|
207
|
+
dimension="P",
|
|
208
|
+
name=dim_name,
|
|
209
|
+
weight=weight,
|
|
210
|
+
raw_value={"app_files": len(app_paths)},
|
|
211
|
+
normalized_score=70.0,
|
|
212
|
+
status="strong_production_indicators",
|
|
213
|
+
weighted_contribution=round(weight * 70.0, 2),
|
|
214
|
+
evidence=[
|
|
215
|
+
f"Strong production indicators: active in {len(app_paths)} application non-test source files",
|
|
216
|
+
f"Files: {', '.join(app_paths[:3])}",
|
|
217
|
+
],
|
|
218
|
+
confidence="medium",
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
# Not directly imported, but a non-dev dependency
|
|
222
|
+
if dependency_type == "direct":
|
|
223
|
+
return DimensionScore(
|
|
224
|
+
dimension="P",
|
|
225
|
+
name=dim_name,
|
|
226
|
+
weight=weight,
|
|
227
|
+
raw_value="production_manifest_inclusion",
|
|
228
|
+
normalized_score=40.0,
|
|
229
|
+
status="production_inclusion_unverified_execution",
|
|
230
|
+
weighted_contribution=round(weight * 40.0, 2),
|
|
231
|
+
evidence=[
|
|
232
|
+
"Included as direct non-dev dependency in production manifest",
|
|
233
|
+
"Static import in primary entrypoints was not identified, but package is shipped with application",
|
|
234
|
+
],
|
|
235
|
+
confidence="medium",
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
# Transitive or unimported
|
|
239
|
+
return DimensionScore(
|
|
240
|
+
dimension="P",
|
|
241
|
+
name=dim_name,
|
|
242
|
+
weight=weight,
|
|
243
|
+
raw_value="unimported_or_transitive",
|
|
244
|
+
normalized_score=20.0 if dependency_type == "transitive" else 0.0,
|
|
245
|
+
status="minimal_production_evidence",
|
|
246
|
+
weighted_contribution=round(weight * (20.0 if dependency_type == "transitive" else 0.0), 2),
|
|
247
|
+
evidence=[
|
|
248
|
+
"No direct production entry point imports detected",
|
|
249
|
+
"Transitive dependency shipped in lockfile" if dependency_type == "transitive" else "No production runtime evidence",
|
|
250
|
+
],
|
|
251
|
+
confidence="medium",
|
|
252
|
+
)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Configurable, documented risk rules (rule set version is recorded on every assessment).
|
|
2
|
+
|
|
3
|
+
Contextual Vulnerability Risk Scoring v2.0 linear model:
|
|
4
|
+
R = 0.15*C + 0.20*A + 0.35*P + 0.30*I
|
|
5
|
+
Points are normalized 0-100; threat intelligence (CISA KEV, EPSS) is decoupled as an independent priority escalation layer.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import copy
|
|
10
|
+
import json
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
RULES_VERSION = "2.2-contextual"
|
|
14
|
+
|
|
15
|
+
DEFAULT_RULES: dict = {
|
|
16
|
+
"thresholds": {"CRITICAL": 70, "HIGH": 45, "MEDIUM": 25, "LOW": 10}, # score >= threshold -> label
|
|
17
|
+
"contextual_v2": {
|
|
18
|
+
"weights": {"C": 0.15, "A": 0.20, "P": 0.35, "I": 0.30},
|
|
19
|
+
"thresholds": {"CRITICAL": 70, "HIGH": 45, "MEDIUM": 25, "LOW": 10},
|
|
20
|
+
"impact_subfactor_weights": {"F": 0.25, "S": 0.25, "B": 0.20, "D": 0.20, "X": 0.10},
|
|
21
|
+
},
|
|
22
|
+
"vulnerability": {
|
|
23
|
+
"severity_points": {"CRITICAL": 55, "HIGH": 40, "MEDIUM": 22, "LOW": 8, "UNAVAILABLE": 12},
|
|
24
|
+
"kev": 30,
|
|
25
|
+
"kev_ransomware": 5,
|
|
26
|
+
"exposure": {"direct": 8, "direct_inferred": 6, "transitive": 0, "unknown": 0},
|
|
27
|
+
"multiple_roots": 5,
|
|
28
|
+
"no_fix_recorded": 5,
|
|
29
|
+
"dev_dependency": -10,
|
|
30
|
+
"unconfirmed_applicability_cap": "MEDIUM",
|
|
31
|
+
"unreachable_cap": "MEDIUM",
|
|
32
|
+
"test_only_cap": "MEDIUM",
|
|
33
|
+
"correlated_lockfile_change": 5,
|
|
34
|
+
"epss": [[0.5, 20], [0.1, 10], [0.01, 3]],
|
|
35
|
+
"reachability": {
|
|
36
|
+
"used_by_app_heavy": 35,
|
|
37
|
+
"used_by_app_moderate": 20,
|
|
38
|
+
"used_by_app_single": 12,
|
|
39
|
+
"used_by_app": 20,
|
|
40
|
+
"reachable_via_dependency_heavy": 18,
|
|
41
|
+
"reachable_via_dependency": 8,
|
|
42
|
+
"used_in_tests_only": -10,
|
|
43
|
+
"not_imported": -25,
|
|
44
|
+
"unknown": 0,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
"pipeline": {
|
|
48
|
+
"severity_points": {"CRITICAL": 75, "HIGH": 50, "MEDIUM": 28, "LOW": 12, "INFO": 4},
|
|
49
|
+
"heuristic_penalty": -8,
|
|
50
|
+
"third_party_unpinned_action": 5,
|
|
51
|
+
},
|
|
52
|
+
"typosquatting": {
|
|
53
|
+
"strength_points": {"high": 45, "medium": 30, "low": 15},
|
|
54
|
+
"exposure": {"direct": 5, "direct_inferred": 4, "transitive": 0, "unknown": 0},
|
|
55
|
+
"correlated_lockfile_addition": 10,
|
|
56
|
+
"correlated_vulnerability": 5,
|
|
57
|
+
"cap": "HIGH",
|
|
58
|
+
},
|
|
59
|
+
"lockfile_change": {
|
|
60
|
+
"classification_points": {"potentially_suspicious": 30, "unexplained_change": 12, "normal_update": 0, "insufficient_baseline": 0},
|
|
61
|
+
"strength_bonus": {"high": 20, "medium": 8, "low": 0},
|
|
62
|
+
"correlated_vulnerability": 10,
|
|
63
|
+
"correlated_typosquat": 10,
|
|
64
|
+
"cap": "HIGH",
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def load_rules(path: str | Path | None = None) -> dict:
|
|
70
|
+
rules = copy.deepcopy(DEFAULT_RULES)
|
|
71
|
+
if path and Path(path).exists():
|
|
72
|
+
override = json.loads(Path(path).read_text(encoding="utf-8"))
|
|
73
|
+
|
|
74
|
+
def merge(a, b):
|
|
75
|
+
for k, v in b.items():
|
|
76
|
+
if isinstance(v, dict) and isinstance(a.get(k), dict):
|
|
77
|
+
merge(a[k], v)
|
|
78
|
+
else:
|
|
79
|
+
a[k] = v
|
|
80
|
+
merge(rules, override)
|
|
81
|
+
return rules
|