tzero-mcp 10.7.4 → 11.0.0

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +56 -29
  2. package/CONTRIBUTING.md +71 -71
  3. package/README.md +64 -64
  4. package/bin/tzero-mcp.js +62 -66
  5. package/bin/tzero.js +61 -65
  6. package/index.d.ts +25 -25
  7. package/index.js +15 -15
  8. package/package.json +88 -88
  9. package/src/addmcp.py +14 -11
  10. package/src/app.py +1810 -0
  11. package/src/main.py +1 -1
  12. package/src/pc_fixer_mcp.py +25 -0
  13. package/src/tzero/__init__.py +54 -0
  14. package/src/tzero/__main__.py +6 -0
  15. package/src/tzero/siber_akademi.ico +0 -0
  16. package/src/tzero/tzero_arch_test.py +463 -0
  17. package/src/{tzero_benchmark.py → tzero/tzero_benchmark.py} +475 -475
  18. package/src/tzero/tzero_blackboard.py +257 -0
  19. package/src/{tzero_bridge.py → tzero/tzero_bridge.py} +546 -362
  20. package/src/tzero/tzero_budget.py +195 -0
  21. package/src/{tzero_ci.py → tzero/tzero_ci.py} +153 -153
  22. package/src/{tzero_commit.py → tzero/tzero_commit.py} +192 -192
  23. package/src/tzero/tzero_contracts.py +1093 -0
  24. package/src/{tzero_cost.py → tzero/tzero_cost.py} +166 -163
  25. package/src/{tzero_dashboard.py → tzero/tzero_dashboard.py} +531 -19
  26. package/src/tzero/tzero_debt.py +461 -0
  27. package/src/{tzero_deps.py → tzero/tzero_deps.py} +179 -4
  28. package/src/{tzero_drift.py → tzero/tzero_drift.py} +208 -208
  29. package/src/{tzero_explain.py → tzero/tzero_explain.py} +73 -7
  30. package/src/{tzero_features.py → tzero/tzero_features.py} +19 -17
  31. package/src/tzero/tzero_federation.py +299 -0
  32. package/src/{tzero_fix.py → tzero/tzero_fix.py} +228 -228
  33. package/src/{tzero_fixer → tzero/tzero_fixer}/__init__.py +63 -63
  34. package/src/{tzero_fixer → tzero/tzero_fixer}/ast_syntax_healer.py +464 -464
  35. package/src/{tzero_fixer → tzero/tzero_fixer}/ast_type_modernizer.py +288 -288
  36. package/src/{tzero_fixer → tzero/tzero_fixer}/async_io_modernizer.py +127 -127
  37. package/src/{tzero_fixer → tzero/tzero_fixer}/automated_regression_suite.py +600 -600
  38. package/src/{tzero_fixer → tzero/tzero_fixer}/benchmarks_and_diagnostics.py +174 -174
  39. package/src/{tzero_fixer → tzero/tzero_fixer}/ci_cd_self_healing_gate.py +246 -246
  40. package/src/{tzero_fixer → tzero/tzero_fixer}/code_duplicity_and_refactorer.py +151 -151
  41. package/src/{tzero_fixer → tzero/tzero_fixer}/code_smells_healer.py +260 -260
  42. package/src/{tzero_fixer → tzero/tzero_fixer}/cwe_remediator.py +171 -171
  43. package/src/{tzero_fixer → tzero/tzero_fixer}/dead_code_eliminator.py +150 -150
  44. package/src/{tzero_fixer → tzero/tzero_fixer}/dependency_vulnerability_auditor.py +309 -309
  45. package/src/{tzero_fixer → tzero/tzero_fixer}/git_advanced_surgeon.py +1 -1
  46. package/src/{tzero_fixer → tzero/tzero_fixer}/hardware_and_disk_doctor.py +1 -1
  47. package/src/{tzero_fixer → tzero/tzero_fixer}/import_graph_healer.py +412 -412
  48. package/src/{tzero_fixer → tzero/tzero_fixer}/interactive_tui.py +91 -91
  49. package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base.py +295 -295
  50. package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base_extended.py +940 -940
  51. package/src/{tzero_fixer → tzero/tzero_fixer}/linters_and_static_analyzer.py +307 -307
  52. package/src/{tzero_fixer → tzero/tzero_fixer}/mcp_server.py +49 -7
  53. package/src/{tzero_fixer → tzero/tzero_fixer}/os_doctor.py +502 -502
  54. package/src/{tzero_fixer → tzero/tzero_fixer}/packaging_abi_surgeon.py +1 -1
  55. package/src/{tzero_fixer → tzero/tzero_fixer}/pc_fixer_doctor.py +600 -599
  56. package/src/{tzero_fixer → tzero/tzero_fixer}/performance_and_memory_profiler.py +274 -274
  57. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_ast_parsers.py +313 -313
  58. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_build_healer.py +1 -1
  59. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_config_healer.py +318 -318
  60. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_doctor.py +372 -372
  61. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_linters.py +1 -1
  62. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_schema_validator.py +305 -305
  63. package/src/{tzero_fixer → tzero/tzero_fixer}/security_cwe_database.py +444 -444
  64. package/src/{tzero_fixer → tzero/tzero_fixer}/security_deep_rules.py +114 -114
  65. package/src/{tzero_fixer → tzero/tzero_fixer}/security_rules_catalog.py +110 -110
  66. package/src/{tzero_fixer → tzero/tzero_fixer}/security_zero_leak.py +326 -326
  67. package/src/{tzero_fixer → tzero/tzero_fixer}/smart_patch_recommender.py +223 -223
  68. package/src/{tzero_fixer → tzero/tzero_fixer}/synthetic_workspace_generator.py +220 -220
  69. package/src/{tzero_fixer → tzero/tzero_fixer}/system_diagnostics_extended.py +1 -1
  70. package/src/{tzero_fixer → tzero/tzero_fixer}/system_repair_recipes.py +447 -447
  71. package/src/{tzero_fixer → tzero/tzero_fixer}/venv_doctor.py +309 -309
  72. package/src/tzero/tzero_golden.py +319 -0
  73. package/src/tzero/tzero_graph_hud.html +338 -0
  74. package/src/tzero/tzero_graph_rag.py +263 -0
  75. package/src/{tzero_guard.py → tzero/tzero_guard.py} +243 -243
  76. package/src/tzero/tzero_hooks.py +565 -0
  77. package/src/{tzero_infra.py → tzero/tzero_infra.py} +274 -274
  78. package/src/{tzero_jarvis → tzero/tzero_jarvis}/__init__.py +124 -124
  79. package/src/{tzero_jarvis → tzero/tzero_jarvis}/causal_graph.py +310 -310
  80. package/src/{tzero_jarvis → tzero/tzero_jarvis}/graph_visualizer.py +395 -395
  81. package/src/{tzero_jarvis → tzero/tzero_jarvis}/hybrid_search.py +214 -214
  82. package/src/{tzero_jarvis → tzero/tzero_jarvis}/latent_press.py +137 -137
  83. package/src/{tzero_jarvis → tzero/tzero_jarvis}/memory_consolidation.py +212 -212
  84. package/src/{tzero_jarvis → tzero/tzero_jarvis}/minhash_lsh.py +184 -184
  85. package/src/{tzero_jarvis → tzero/tzero_jarvis}/orchestrator.py +335 -335
  86. package/src/{tzero_jarvis → tzero/tzero_jarvis}/self_healing.py +308 -308
  87. package/src/{tzero_jarvis → tzero/tzero_jarvis}/semantic_compressor.py +887 -887
  88. package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm.py +261 -261
  89. package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm_bft.py +144 -144
  90. package/src/{tzero_jarvis → tzero/tzero_jarvis}/workspace_orchestrator.py +1167 -1167
  91. package/src/{tzero_jarvis → tzero/tzero_jarvis}/zero_key_router.py +173 -173
  92. package/src/tzero/tzero_lsp.py +634 -0
  93. package/src/{tzero_mcp.py → tzero/tzero_mcp.py} +479 -100
  94. package/src/tzero/tzero_mutation.py +358 -0
  95. package/src/tzero/tzero_packer.py +577 -0
  96. package/src/{tzero_patch.py → tzero/tzero_patch.py} +624 -624
  97. package/src/{tzero_pc_fixer.py → tzero/tzero_pc_fixer.py} +12699 -12657
  98. package/src/{tzero_pipe.py → tzero/tzero_pipe.py} +95 -95
  99. package/src/tzero/tzero_polyglot.py +799 -0
  100. package/src/tzero/tzero_proxy.py +127 -0
  101. package/src/{tzero_reachability.py → tzero/tzero_reachability.py} +272 -272
  102. package/src/{tzero_replay.py → tzero/tzero_replay.py} +141 -141
  103. package/src/tzero/tzero_rust_bridge.py +198 -0
  104. package/src/tzero/tzero_scip.py +368 -0
  105. package/src/{tzero_security.py → tzero/tzero_security.py} +5 -2
  106. package/src/tzero/tzero_semantic_merge.py +189 -0
  107. package/src/tzero/tzero_snapshot.py +471 -0
  108. package/src/{tzero_stubs.py → tzero/tzero_stubs.py} +313 -313
  109. package/src/tzero/tzero_subagent_engine.py +459 -0
  110. package/src/{tzero_superdesign.py → tzero/tzero_superdesign.py} +774 -774
  111. package/src/{tzero_sync.py → tzero/tzero_sync.py} +241 -241
  112. package/src/{tzero_task_benchmark.py → tzero/tzero_task_benchmark.py} +458 -363
  113. package/src/{tzero_tui.py → tzero/tzero_tui.py} +91 -22
  114. package/src/tzero/tzero_turbo.py +264 -0
  115. package/src/{tzero_v3.py → tzero/tzero_v3.py} +628 -163
  116. package/src/tzero.py +2 -54
  117. package/test/package.test.js +55 -43
  118. package/src/tzero/jarvis/semantic_compressor.py +0 -373
  119. package/src/tzero_gateway.py +0 -885
  120. package/src/tzero_packer.py +0 -370
  121. package/src/tzero_polyglot.py +0 -422
  122. package/src/tzero_snapshot.py +0 -258
  123. /package/src/{siber_akademi_icon.py → tzero/siber_akademi_icon.py} +0 -0
  124. /package/src/{tzero_fixer → tzero/tzero_fixer}/amalgamation.py +0 -0
  125. /package/src/{tzero_fixer → tzero/tzero_fixer}/models.py +0 -0
  126. /package/src/{tzero_fixer → tzero/tzero_fixer}/orchestrator.py +0 -0
  127. /package/src/{tzero_neural_cortex.py → tzero/tzero_neural_cortex.py} +0 -0
@@ -1,309 +1,309 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- T-Zero Offline Dependency Vulnerability & Advisory Auditor
4
- ==========================================================
5
- Zero-dependency, 100% offline vulnerability auditing engine for software dependencies.
6
- Inspects package manifests (requirements.txt, pyproject.toml, package.json, Cargo.toml)
7
- against an embedded database of known Critical and High severity CVE advisories.
8
-
9
- Provides:
10
- - Python vulnerability scanner (requests, urllib3, jinja2, flask, django, cryptography, etc.)
11
- - Node.js vulnerability scanner (lodash, axios, tar, jsonwebtoken, express, etc.)
12
- - Rust & Cargo advisory scanner
13
- - Minimum safe version upgrade recommendations
14
- - 100% offline, local-only analysis with zero network requests or telemetry
15
-
16
- Author: Siber Akademi T-Zero R&D Team
17
- License: MIT (100% Free, Local Offline, Zero-Leak)
18
- """
19
-
20
- from __future__ import annotations
21
-
22
- import os
23
- import re
24
- from dataclasses import dataclass, field
25
- from pathlib import Path
26
- from typing import Any, Dict, List, Optional, Set, Tuple
27
-
28
- from tzero_fixer.models import (
29
- DiagnosticCategory,
30
- DiagnosticIssue,
31
- HealAction,
32
- SeverityLevel,
33
- )
34
-
35
-
36
- @dataclass
37
- class VulnerabilityAdvisory:
38
- package_name: str
39
- ecosystem: str
40
- cve_id: str
41
- vulnerable_spec: str
42
- safe_version: str
43
- summary: str
44
- severity: str
45
- cvss_score: float = 7.5
46
-
47
-
48
- class DependencyVulnerabilityAuditor:
49
- """
50
- Scans project dependency files offline against known CVE security advisories.
51
- """
52
-
53
- ADVISORIES: List[VulnerabilityAdvisory] = [
54
- # --- Python Ecosystem ---
55
- VulnerabilityAdvisory(
56
- package_name="requests",
57
- ecosystem="pypi",
58
- cve_id="CVE-2023-32681",
59
- vulnerable_spec="<2.31.0",
60
- safe_version="2.31.0",
61
- summary="Requests leaks Proxy-Authorization headers to destination servers on redirects.",
62
- severity="warning",
63
- cvss_score=6.1,
64
- ),
65
- VulnerabilityAdvisory(
66
- package_name="urllib3",
67
- ecosystem="pypi",
68
- cve_id="CVE-2023-45803",
69
- vulnerable_spec="<2.0.7",
70
- safe_version="2.0.7",
71
- summary="urllib3 does not remove HTTP Request body on cross-origin redirects.",
72
- severity="warning",
73
- cvss_score=6.5,
74
- ),
75
- VulnerabilityAdvisory(
76
- package_name="jinja2",
77
- ecosystem="pypi",
78
- cve_id="CVE-2024-22195",
79
- vulnerable_spec="<3.1.3",
80
- safe_version="3.1.3",
81
- summary="Jinja2 xmlattr filter accepts keys containing attribute injection characters.",
82
- severity="warning",
83
- cvss_score=6.5,
84
- ),
85
- VulnerabilityAdvisory(
86
- package_name="flask",
87
- ecosystem="pypi",
88
- cve_id="CVE-2023-30861",
89
- vulnerable_spec="<2.2.5",
90
- safe_version="2.2.5",
91
- summary="Flask session cookies may be cached by shared caching proxies if Vary header missing.",
92
- severity="critical",
93
- cvss_score=7.5,
94
- ),
95
- VulnerabilityAdvisory(
96
- package_name="django",
97
- ecosystem="pypi",
98
- cve_id="CVE-2023-46695",
99
- vulnerable_spec="<4.2.8",
100
- safe_version="4.2.8",
101
- summary="Django UsernameField susceptible to polynomial regex DoS in login views.",
102
- severity="critical",
103
- cvss_score=7.5,
104
- ),
105
- VulnerabilityAdvisory(
106
- package_name="cryptography",
107
- ecosystem="pypi",
108
- cve_id="CVE-2023-49083",
109
- vulnerable_spec="<41.0.6",
110
- safe_version="41.0.6",
111
- summary="NULL pointer dereference when loading PKCS#7 certificates with empty certificates set.",
112
- severity="critical",
113
- cvss_score=7.5,
114
- ),
115
- VulnerabilityAdvisory(
116
- package_name="werkzeug",
117
- ecosystem="pypi",
118
- cve_id="CVE-2023-46136",
119
- vulnerable_spec="<3.0.1",
120
- safe_version="3.0.1",
121
- summary="High resource consumption when parsing excessively large multipart form boundaries.",
122
- severity="critical",
123
- cvss_score=7.5,
124
- ),
125
- VulnerabilityAdvisory(
126
- package_name="pillow",
127
- ecosystem="pypi",
128
- cve_id="CVE-2023-50447",
129
- vulnerable_spec="<10.2.0",
130
- safe_version="10.2.0",
131
- summary="Arbitrary code execution via environment evaluation in ImageMath.eval.",
132
- severity="critical",
133
- cvss_score=8.8,
134
- ),
135
- VulnerabilityAdvisory(
136
- package_name="pydantic",
137
- ecosystem="pypi",
138
- cve_id="CVE-2021-29510",
139
- vulnerable_spec="<1.8.2",
140
- safe_version="1.8.2",
141
- summary="Infinite loop in pydantic date parser when parsing invalid inputs.",
142
- severity="warning",
143
- cvss_score=5.3,
144
- ),
145
- VulnerabilityAdvisory(
146
- package_name="tornado",
147
- ecosystem="pypi",
148
- cve_id="CVE-2023-28370",
149
- vulnerable_spec="<6.3.2",
150
- safe_version="6.3.2",
151
- summary="Open redirect in StaticFileHandler with crafted URI paths.",
152
- severity="warning",
153
- cvss_score=6.1,
154
- ),
155
-
156
- # --- Node.js & npm Ecosystem ---
157
- VulnerabilityAdvisory(
158
- package_name="lodash",
159
- ecosystem="npm",
160
- cve_id="CVE-2021-23337",
161
- vulnerable_spec="<4.17.21",
162
- safe_version="4.17.21",
163
- summary="Prototype pollution in lodash.template via sourceURL parameter.",
164
- severity="critical",
165
- cvss_score=7.2,
166
- ),
167
- VulnerabilityAdvisory(
168
- package_name="axios",
169
- ecosystem="npm",
170
- cve_id="CVE-2023-45857",
171
- vulnerable_spec="<1.6.0",
172
- safe_version="1.6.0",
173
- summary="Axios leaks session cookies to cross-domain destinations on redirects.",
174
- severity="warning",
175
- cvss_score=6.5,
176
- ),
177
- VulnerabilityAdvisory(
178
- package_name="tar",
179
- ecosystem="npm",
180
- cve_id="CVE-2021-37712",
181
- vulnerable_spec="<6.1.9",
182
- safe_version="6.1.9",
183
- summary="Arbitrary file overwrite via directory traversal in tar extraction.",
184
- severity="critical",
185
- cvss_score=8.6,
186
- ),
187
- VulnerabilityAdvisory(
188
- package_name="semver",
189
- ecosystem="npm",
190
- cve_id="CVE-2022-25883",
191
- vulnerable_spec="<7.5.2",
192
- safe_version="7.5.2",
193
- summary="Regular expression denial of service in semver range parsing.",
194
- severity="critical",
195
- cvss_score=7.5,
196
- ),
197
- VulnerabilityAdvisory(
198
- package_name="jsonwebtoken",
199
- ecosystem="npm",
200
- cve_id="CVE-2022-23529",
201
- vulnerable_spec="<9.0.0",
202
- safe_version="9.0.0",
203
- summary="Remote code execution when secretOrPublicKey parameter is a modified object.",
204
- severity="critical",
205
- cvss_score=9.8,
206
- ),
207
- ]
208
-
209
- @classmethod
210
- def _parse_version_tuple(cls, ver_str: str) -> Tuple[int, ...]:
211
- clean = re.sub(r"[^\d.]", "", ver_str)
212
- try:
213
- return tuple(int(x) for x in clean.split(".") if x)
214
- except Exception:
215
- return (0,)
216
-
217
- @classmethod
218
- def scan_requirements_txt(cls, file_path: str, content: str) -> List[DiagnosticIssue]:
219
- issues: List[DiagnosticIssue] = []
220
- lines = content.splitlines()
221
-
222
- for idx, line in enumerate(lines, 1):
223
- stripped = line.strip()
224
- if not stripped or stripped.startswith("#"):
225
- continue
226
-
227
- match = re.match(r"^([A-Za-z0-9_\-\.]+)\s*==\s*([0-9\.]+)", stripped)
228
- if match:
229
- pkg_name = match.group(1).lower()
230
- version = match.group(2)
231
- ver_tuple = cls._parse_version_tuple(version)
232
-
233
- for adv in cls.ADVISORIES:
234
- if adv.ecosystem == "pypi" and adv.package_name.lower() == pkg_name:
235
- safe_tuple = cls._parse_version_tuple(adv.safe_version)
236
- if ver_tuple < safe_tuple:
237
- issues.append(
238
- DiagnosticIssue(
239
- category=DiagnosticCategory.SECURITY.value,
240
- severity=SeverityLevel.CRITICAL.value if adv.severity == "critical" else SeverityLevel.WARNING.value,
241
- file_path=file_path,
242
- line=idx,
243
- error_code="TZ-DEP-VULN",
244
- message=f"Vulnerable dependency '{pkg_name}=={version}' ({adv.cve_id}): {adv.summary}",
245
- suggested_fix=f"Upgrade '{pkg_name}' to minimum safe version '{adv.safe_version}'.",
246
- auto_fixable=True,
247
- metadata={
248
- "action": "upgrade_package_version",
249
- "lineno": idx,
250
- "package": pkg_name,
251
- "old_version": version,
252
- "new_version": adv.safe_version,
253
- "path": file_path,
254
- },
255
- )
256
- )
257
- return issues
258
-
259
- @classmethod
260
- def execute_upgrades(cls, issues: List[DiagnosticIssue], dry_run: bool = False) -> List[HealAction]:
261
- actions: List[HealAction] = []
262
- for issue in issues:
263
- action = issue.metadata.get("action")
264
- file_p = issue.metadata.get("path")
265
- lineno = issue.metadata.get("lineno")
266
- pkg_name = issue.metadata.get("package")
267
- new_v = issue.metadata.get("new_version")
268
-
269
- if action != "upgrade_package_version" or not file_p or not lineno or not pkg_name or not new_v:
270
- continue
271
-
272
- p = Path(file_p)
273
- if not p.is_file():
274
- continue
275
-
276
- try:
277
- with open(p, "r", encoding="utf-8", errors="replace") as f:
278
- lines = f.readlines()
279
-
280
- if 0 < lineno <= len(lines):
281
- orig = lines[lineno - 1]
282
- mod = re.sub(rf"^({re.escape(pkg_name)})\s*==\s*[0-9\.]+", rf"\1=={new_v}", orig, flags=re.IGNORECASE)
283
- if mod != orig:
284
- lines[lineno - 1] = mod
285
- if not dry_run:
286
- with open(p, "w", encoding="utf-8", newline="\n") as f:
287
- f.writelines(lines)
288
- actions.append(
289
- HealAction(
290
- category=DiagnosticCategory.SECURITY.value,
291
- action_type="upgrade_package_version",
292
- file_path=file_p,
293
- description=f"Upgraded vulnerable {pkg_name} to safe version {new_v} in {p.name}",
294
- success=True,
295
- )
296
- )
297
- except Exception as e:
298
- actions.append(
299
- HealAction(
300
- category=DiagnosticCategory.SECURITY.value,
301
- action_type="upgrade_package_version",
302
- file_path=file_p,
303
- description=f"Failed upgrade: {e}",
304
- success=False,
305
- )
306
- )
307
-
308
- return actions
309
-
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ T-Zero Offline Dependency Vulnerability & Advisory Auditor
4
+ ==========================================================
5
+ Zero-dependency, 100% offline vulnerability auditing engine for software dependencies.
6
+ Inspects package manifests (requirements.txt, pyproject.toml, package.json, Cargo.toml)
7
+ against an embedded database of known Critical and High severity CVE advisories.
8
+
9
+ Provides:
10
+ - Python vulnerability scanner (requests, urllib3, jinja2, flask, django, cryptography, etc.)
11
+ - Node.js vulnerability scanner (lodash, axios, tar, jsonwebtoken, express, etc.)
12
+ - Rust & Cargo advisory scanner
13
+ - Minimum safe version upgrade recommendations
14
+ - 100% offline, local-only analysis with zero network requests or telemetry
15
+
16
+ Author: Siber Akademi T-Zero R&D Team
17
+ License: MIT (100% Free, Local Offline, Zero-Leak)
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import os
23
+ import re
24
+ from dataclasses import dataclass, field
25
+ from pathlib import Path
26
+ from typing import Any, Dict, List, Optional, Set, Tuple
27
+
28
+ from tzero.tzero_fixer.models import (
29
+ DiagnosticCategory,
30
+ DiagnosticIssue,
31
+ HealAction,
32
+ SeverityLevel,
33
+ )
34
+
35
+
36
+ @dataclass
37
+ class VulnerabilityAdvisory:
38
+ package_name: str
39
+ ecosystem: str
40
+ cve_id: str
41
+ vulnerable_spec: str
42
+ safe_version: str
43
+ summary: str
44
+ severity: str
45
+ cvss_score: float = 7.5
46
+
47
+
48
+ class DependencyVulnerabilityAuditor:
49
+ """
50
+ Scans project dependency files offline against known CVE security advisories.
51
+ """
52
+
53
+ ADVISORIES: List[VulnerabilityAdvisory] = [
54
+ # --- Python Ecosystem ---
55
+ VulnerabilityAdvisory(
56
+ package_name="requests",
57
+ ecosystem="pypi",
58
+ cve_id="CVE-2023-32681",
59
+ vulnerable_spec="<2.31.0",
60
+ safe_version="2.31.0",
61
+ summary="Requests leaks Proxy-Authorization headers to destination servers on redirects.",
62
+ severity="warning",
63
+ cvss_score=6.1,
64
+ ),
65
+ VulnerabilityAdvisory(
66
+ package_name="urllib3",
67
+ ecosystem="pypi",
68
+ cve_id="CVE-2023-45803",
69
+ vulnerable_spec="<2.0.7",
70
+ safe_version="2.0.7",
71
+ summary="urllib3 does not remove HTTP Request body on cross-origin redirects.",
72
+ severity="warning",
73
+ cvss_score=6.5,
74
+ ),
75
+ VulnerabilityAdvisory(
76
+ package_name="jinja2",
77
+ ecosystem="pypi",
78
+ cve_id="CVE-2024-22195",
79
+ vulnerable_spec="<3.1.3",
80
+ safe_version="3.1.3",
81
+ summary="Jinja2 xmlattr filter accepts keys containing attribute injection characters.",
82
+ severity="warning",
83
+ cvss_score=6.5,
84
+ ),
85
+ VulnerabilityAdvisory(
86
+ package_name="flask",
87
+ ecosystem="pypi",
88
+ cve_id="CVE-2023-30861",
89
+ vulnerable_spec="<2.2.5",
90
+ safe_version="2.2.5",
91
+ summary="Flask session cookies may be cached by shared caching proxies if Vary header missing.",
92
+ severity="critical",
93
+ cvss_score=7.5,
94
+ ),
95
+ VulnerabilityAdvisory(
96
+ package_name="django",
97
+ ecosystem="pypi",
98
+ cve_id="CVE-2023-46695",
99
+ vulnerable_spec="<4.2.8",
100
+ safe_version="4.2.8",
101
+ summary="Django UsernameField susceptible to polynomial regex DoS in login views.",
102
+ severity="critical",
103
+ cvss_score=7.5,
104
+ ),
105
+ VulnerabilityAdvisory(
106
+ package_name="cryptography",
107
+ ecosystem="pypi",
108
+ cve_id="CVE-2023-49083",
109
+ vulnerable_spec="<41.0.6",
110
+ safe_version="41.0.6",
111
+ summary="NULL pointer dereference when loading PKCS#7 certificates with empty certificates set.",
112
+ severity="critical",
113
+ cvss_score=7.5,
114
+ ),
115
+ VulnerabilityAdvisory(
116
+ package_name="werkzeug",
117
+ ecosystem="pypi",
118
+ cve_id="CVE-2023-46136",
119
+ vulnerable_spec="<3.0.1",
120
+ safe_version="3.0.1",
121
+ summary="High resource consumption when parsing excessively large multipart form boundaries.",
122
+ severity="critical",
123
+ cvss_score=7.5,
124
+ ),
125
+ VulnerabilityAdvisory(
126
+ package_name="pillow",
127
+ ecosystem="pypi",
128
+ cve_id="CVE-2023-50447",
129
+ vulnerable_spec="<10.2.0",
130
+ safe_version="10.2.0",
131
+ summary="Arbitrary code execution via environment evaluation in ImageMath.eval.",
132
+ severity="critical",
133
+ cvss_score=8.8,
134
+ ),
135
+ VulnerabilityAdvisory(
136
+ package_name="pydantic",
137
+ ecosystem="pypi",
138
+ cve_id="CVE-2021-29510",
139
+ vulnerable_spec="<1.8.2",
140
+ safe_version="1.8.2",
141
+ summary="Infinite loop in pydantic date parser when parsing invalid inputs.",
142
+ severity="warning",
143
+ cvss_score=5.3,
144
+ ),
145
+ VulnerabilityAdvisory(
146
+ package_name="tornado",
147
+ ecosystem="pypi",
148
+ cve_id="CVE-2023-28370",
149
+ vulnerable_spec="<6.3.2",
150
+ safe_version="6.3.2",
151
+ summary="Open redirect in StaticFileHandler with crafted URI paths.",
152
+ severity="warning",
153
+ cvss_score=6.1,
154
+ ),
155
+
156
+ # --- Node.js & npm Ecosystem ---
157
+ VulnerabilityAdvisory(
158
+ package_name="lodash",
159
+ ecosystem="npm",
160
+ cve_id="CVE-2021-23337",
161
+ vulnerable_spec="<4.17.21",
162
+ safe_version="4.17.21",
163
+ summary="Prototype pollution in lodash.template via sourceURL parameter.",
164
+ severity="critical",
165
+ cvss_score=7.2,
166
+ ),
167
+ VulnerabilityAdvisory(
168
+ package_name="axios",
169
+ ecosystem="npm",
170
+ cve_id="CVE-2023-45857",
171
+ vulnerable_spec="<1.6.0",
172
+ safe_version="1.6.0",
173
+ summary="Axios leaks session cookies to cross-domain destinations on redirects.",
174
+ severity="warning",
175
+ cvss_score=6.5,
176
+ ),
177
+ VulnerabilityAdvisory(
178
+ package_name="tar",
179
+ ecosystem="npm",
180
+ cve_id="CVE-2021-37712",
181
+ vulnerable_spec="<6.1.9",
182
+ safe_version="6.1.9",
183
+ summary="Arbitrary file overwrite via directory traversal in tar extraction.",
184
+ severity="critical",
185
+ cvss_score=8.6,
186
+ ),
187
+ VulnerabilityAdvisory(
188
+ package_name="semver",
189
+ ecosystem="npm",
190
+ cve_id="CVE-2022-25883",
191
+ vulnerable_spec="<7.5.2",
192
+ safe_version="7.5.2",
193
+ summary="Regular expression denial of service in semver range parsing.",
194
+ severity="critical",
195
+ cvss_score=7.5,
196
+ ),
197
+ VulnerabilityAdvisory(
198
+ package_name="jsonwebtoken",
199
+ ecosystem="npm",
200
+ cve_id="CVE-2022-23529",
201
+ vulnerable_spec="<9.0.0",
202
+ safe_version="9.0.0",
203
+ summary="Remote code execution when secretOrPublicKey parameter is a modified object.",
204
+ severity="critical",
205
+ cvss_score=9.8,
206
+ ),
207
+ ]
208
+
209
+ @classmethod
210
+ def _parse_version_tuple(cls, ver_str: str) -> Tuple[int, ...]:
211
+ clean = re.sub(r"[^\d.]", "", ver_str)
212
+ try:
213
+ return tuple(int(x) for x in clean.split(".") if x)
214
+ except Exception:
215
+ return (0,)
216
+
217
+ @classmethod
218
+ def scan_requirements_txt(cls, file_path: str, content: str) -> List[DiagnosticIssue]:
219
+ issues: List[DiagnosticIssue] = []
220
+ lines = content.splitlines()
221
+
222
+ for idx, line in enumerate(lines, 1):
223
+ stripped = line.strip()
224
+ if not stripped or stripped.startswith("#"):
225
+ continue
226
+
227
+ match = re.match(r"^([A-Za-z0-9_\-\.]+)\s*==\s*([0-9\.]+)", stripped)
228
+ if match:
229
+ pkg_name = match.group(1).lower()
230
+ version = match.group(2)
231
+ ver_tuple = cls._parse_version_tuple(version)
232
+
233
+ for adv in cls.ADVISORIES:
234
+ if adv.ecosystem == "pypi" and adv.package_name.lower() == pkg_name:
235
+ safe_tuple = cls._parse_version_tuple(adv.safe_version)
236
+ if ver_tuple < safe_tuple:
237
+ issues.append(
238
+ DiagnosticIssue(
239
+ category=DiagnosticCategory.SECURITY.value,
240
+ severity=SeverityLevel.CRITICAL.value if adv.severity == "critical" else SeverityLevel.WARNING.value,
241
+ file_path=file_path,
242
+ line=idx,
243
+ error_code="TZ-DEP-VULN",
244
+ message=f"Vulnerable dependency '{pkg_name}=={version}' ({adv.cve_id}): {adv.summary}",
245
+ suggested_fix=f"Upgrade '{pkg_name}' to minimum safe version '{adv.safe_version}'.",
246
+ auto_fixable=True,
247
+ metadata={
248
+ "action": "upgrade_package_version",
249
+ "lineno": idx,
250
+ "package": pkg_name,
251
+ "old_version": version,
252
+ "new_version": adv.safe_version,
253
+ "path": file_path,
254
+ },
255
+ )
256
+ )
257
+ return issues
258
+
259
+ @classmethod
260
+ def execute_upgrades(cls, issues: List[DiagnosticIssue], dry_run: bool = False) -> List[HealAction]:
261
+ actions: List[HealAction] = []
262
+ for issue in issues:
263
+ action = issue.metadata.get("action")
264
+ file_p = issue.metadata.get("path")
265
+ lineno = issue.metadata.get("lineno")
266
+ pkg_name = issue.metadata.get("package")
267
+ new_v = issue.metadata.get("new_version")
268
+
269
+ if action != "upgrade_package_version" or not file_p or not lineno or not pkg_name or not new_v:
270
+ continue
271
+
272
+ p = Path(file_p)
273
+ if not p.is_file():
274
+ continue
275
+
276
+ try:
277
+ with open(p, "r", encoding="utf-8", errors="replace") as f:
278
+ lines = f.readlines()
279
+
280
+ if 0 < lineno <= len(lines):
281
+ orig = lines[lineno - 1]
282
+ mod = re.sub(rf"^({re.escape(pkg_name)})\s*==\s*[0-9\.]+", rf"\1=={new_v}", orig, flags=re.IGNORECASE)
283
+ if mod != orig:
284
+ lines[lineno - 1] = mod
285
+ if not dry_run:
286
+ with open(p, "w", encoding="utf-8", newline="\n") as f:
287
+ f.writelines(lines)
288
+ actions.append(
289
+ HealAction(
290
+ category=DiagnosticCategory.SECURITY.value,
291
+ action_type="upgrade_package_version",
292
+ file_path=file_p,
293
+ description=f"Upgraded vulnerable {pkg_name} to safe version {new_v} in {p.name}",
294
+ success=True,
295
+ )
296
+ )
297
+ except Exception as e:
298
+ actions.append(
299
+ HealAction(
300
+ category=DiagnosticCategory.SECURITY.value,
301
+ action_type="upgrade_package_version",
302
+ file_path=file_p,
303
+ description=f"Failed upgrade: {e}",
304
+ success=False,
305
+ )
306
+ )
307
+
308
+ return actions
309
+
@@ -29,7 +29,7 @@ from dataclasses import dataclass, field
29
29
  from pathlib import Path
30
30
  from typing import Any, Dict, List, Optional, Set, Tuple
31
31
 
32
- from tzero_fixer.models import (
32
+ from tzero.tzero_fixer.models import (
33
33
  DiagnosticCategory,
34
34
  DiagnosticIssue,
35
35
  HealAction,
@@ -29,7 +29,7 @@ from dataclasses import dataclass, field
29
29
  from pathlib import Path
30
30
  from typing import Any, Dict, List, Optional, Set, Tuple
31
31
 
32
- from tzero_fixer.models import (
32
+ from tzero.tzero_fixer.models import (
33
33
  DiagnosticCategory,
34
34
  DiagnosticIssue,
35
35
  HealAction,