tzero-mcp 10.7.0 → 10.7.2
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.
- package/CHANGELOG.md +589 -0
- package/CONTRIBUTING.md +71 -0
- package/README.md +25 -17
- package/bin/postinstall.js +34 -0
- package/bin/tzero-mcp.js +16 -19
- package/bin/tzero.js +14 -19
- package/index.d.ts +24 -0
- package/index.js +7 -3
- package/package.json +24 -2
- package/src/addmcp.py +1194 -0
- package/src/main.py +60 -0
- package/src/siber_akademi_icon.py +77 -0
- package/src/tzero/jarvis/semantic_compressor.py +373 -0
- package/src/tzero.py +58 -0
- package/src/tzero_benchmark.py +475 -0
- package/src/tzero_bridge.py +362 -0
- package/src/tzero_ci.py +153 -0
- package/src/tzero_commit.py +192 -0
- package/src/tzero_cost.py +163 -0
- package/src/tzero_dashboard.py +1448 -0
- package/src/tzero_deps.py +287 -0
- package/src/tzero_drift.py +208 -0
- package/src/tzero_explain.py +240 -0
- package/src/tzero_features.py +3022 -0
- package/src/tzero_fix.py +228 -0
- package/src/tzero_fixer/__init__.py +63 -0
- package/src/tzero_fixer/amalgamation.py +334 -0
- package/src/tzero_fixer/ast_syntax_healer.py +464 -0
- package/src/tzero_fixer/ast_type_modernizer.py +288 -0
- package/src/tzero_fixer/async_io_modernizer.py +127 -0
- package/src/tzero_fixer/automated_regression_suite.py +600 -0
- package/src/tzero_fixer/benchmarks_and_diagnostics.py +174 -0
- package/src/tzero_fixer/ci_cd_self_healing_gate.py +246 -0
- package/src/tzero_fixer/code_duplicity_and_refactorer.py +151 -0
- package/src/tzero_fixer/code_smells_healer.py +260 -0
- package/src/tzero_fixer/cwe_remediator.py +171 -0
- package/src/tzero_fixer/dead_code_eliminator.py +150 -0
- package/src/tzero_fixer/dependency_vulnerability_auditor.py +309 -0
- package/src/tzero_fixer/git_advanced_surgeon.py +280 -0
- package/src/tzero_fixer/hardware_and_disk_doctor.py +325 -0
- package/src/tzero_fixer/import_graph_healer.py +412 -0
- package/src/tzero_fixer/interactive_tui.py +91 -0
- package/src/tzero_fixer/knowledge_base.py +295 -0
- package/src/tzero_fixer/knowledge_base_extended.py +940 -0
- package/src/tzero_fixer/linters_and_static_analyzer.py +307 -0
- package/src/tzero_fixer/mcp_server.py +447 -0
- package/src/tzero_fixer/models.py +385 -0
- package/src/tzero_fixer/orchestrator.py +375 -0
- package/src/tzero_fixer/os_doctor.py +502 -0
- package/src/tzero_fixer/packaging_abi_surgeon.py +323 -0
- package/src/tzero_fixer/pc_fixer_doctor.py +599 -0
- package/src/tzero_fixer/performance_and_memory_profiler.py +274 -0
- package/src/tzero_fixer/polyglot_ast_parsers.py +313 -0
- package/src/tzero_fixer/polyglot_build_healer.py +364 -0
- package/src/tzero_fixer/polyglot_config_healer.py +318 -0
- package/src/tzero_fixer/polyglot_doctor.py +372 -0
- package/src/tzero_fixer/polyglot_linters.py +619 -0
- package/src/tzero_fixer/polyglot_schema_validator.py +305 -0
- package/src/tzero_fixer/security_cwe_database.py +444 -0
- package/src/tzero_fixer/security_deep_rules.py +114 -0
- package/src/tzero_fixer/security_rules_catalog.py +110 -0
- package/src/tzero_fixer/security_zero_leak.py +326 -0
- package/src/tzero_fixer/smart_patch_recommender.py +223 -0
- package/src/tzero_fixer/synthetic_workspace_generator.py +220 -0
- package/src/tzero_fixer/system_diagnostics_extended.py +493 -0
- package/src/tzero_fixer/system_repair_recipes.py +447 -0
- package/src/tzero_fixer/venv_doctor.py +309 -0
- package/src/tzero_gateway.py +885 -0
- package/src/tzero_guard.py +243 -0
- package/src/tzero_infra.py +274 -0
- package/src/tzero_jarvis/__init__.py +124 -0
- package/src/tzero_jarvis/causal_graph.py +310 -0
- package/src/tzero_jarvis/graph_visualizer.py +395 -0
- package/src/tzero_jarvis/hybrid_search.py +214 -0
- package/src/tzero_jarvis/latent_press.py +137 -0
- package/src/tzero_jarvis/memory_consolidation.py +212 -0
- package/src/tzero_jarvis/minhash_lsh.py +184 -0
- package/src/tzero_jarvis/orchestrator.py +335 -0
- package/src/tzero_jarvis/self_healing.py +308 -0
- package/src/tzero_jarvis/semantic_compressor.py +887 -0
- package/src/tzero_jarvis/swarm.py +261 -0
- package/src/tzero_jarvis/swarm_bft.py +144 -0
- package/src/tzero_jarvis/workspace_orchestrator.py +1167 -0
- package/src/tzero_jarvis/zero_key_router.py +173 -0
- package/src/tzero_mcp.py +4858 -0
- package/src/tzero_neural_cortex.py +1425 -0
- package/src/tzero_packer.py +370 -0
- package/src/tzero_patch.py +624 -0
- package/src/tzero_pc_fixer.py +12657 -0
- package/src/tzero_pipe.py +95 -0
- package/src/tzero_polyglot.py +422 -0
- package/src/tzero_reachability.py +272 -0
- package/src/tzero_replay.py +141 -0
- package/src/tzero_security.py +570 -0
- package/src/tzero_snapshot.py +258 -0
- package/src/tzero_stubs.py +313 -0
- package/src/tzero_superdesign.py +774 -0
- package/src/tzero_sync.py +241 -0
- package/src/tzero_task_benchmark.py +363 -0
- package/src/tzero_tui.py +244 -0
- package/src/tzero_v3.py +9435 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
T-Zero Security CWE & OWASP Vulnerability Taxonomy
|
|
4
|
+
=================================================
|
|
5
|
+
Exhaustive vulnerability mapping, remediation encyclopedia, and AST rule engine.
|
|
6
|
+
Maps Common Weakness Enumerations (CWE), OWASP Top 10, and CIS Critical Security Controls
|
|
7
|
+
to specific static analysis patterns and surgical remediation recipes.
|
|
8
|
+
|
|
9
|
+
Covers:
|
|
10
|
+
- Injection Flaws (CWE-89 SQL Injection, CWE-78 OS Command Injection, CWE-79 XSS)
|
|
11
|
+
- Broken Access Control & Path Traversal (CWE-22 Path Traversal, CWE-284 Improper Access)
|
|
12
|
+
- Cryptographic Failures & Hardcoded Credentials (CWE-798, CWE-259, CWE-327 Broken Crypto)
|
|
13
|
+
- Insecure Deserialization (CWE-502 Untrusted Deserialization in Python/Java/Node)
|
|
14
|
+
- Security Misconfiguration (CWE-16, CWE-1004 Missing Cookie HttpOnly, CWE-942 CORS)
|
|
15
|
+
- Software & Data Integrity Failures (CWE-494 Missing Integrity Check, CWE-829 Unpinned Deps)
|
|
16
|
+
|
|
17
|
+
Author: Siber Akademi T-Zero R&D Team
|
|
18
|
+
License: MIT (100% Free, Local Offline, Zero-Leak)
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import json
|
|
24
|
+
from dataclasses import dataclass, field, asdict
|
|
25
|
+
from typing import Dict, List, Optional, Set, Any
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class CWERuleDefinition:
|
|
30
|
+
"""Taxonomy definition for a specific Common Weakness Enumeration."""
|
|
31
|
+
cwe_id: str
|
|
32
|
+
owasp_category: str
|
|
33
|
+
name: str
|
|
34
|
+
description: str
|
|
35
|
+
impact: str
|
|
36
|
+
affected_languages: List[str]
|
|
37
|
+
detection_heuristic: str
|
|
38
|
+
remediation_strategy: str
|
|
39
|
+
safe_code_pattern: str
|
|
40
|
+
unsafe_code_pattern: str
|
|
41
|
+
cvss_score: float = 7.5
|
|
42
|
+
|
|
43
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
44
|
+
return asdict(self)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class CWESecurityDatabase:
|
|
48
|
+
"""Master registry of security weaknesses and automated patch strategies."""
|
|
49
|
+
|
|
50
|
+
VULNERABILITIES: List[CWERuleDefinition] = [
|
|
51
|
+
# ---------------------------------------------------------------------
|
|
52
|
+
# 1. INJECTION FLAWS (A03:2021 - Injection)
|
|
53
|
+
# ---------------------------------------------------------------------
|
|
54
|
+
CWERuleDefinition(
|
|
55
|
+
cwe_id="CWE-89",
|
|
56
|
+
owasp_category="A03:2021-Injection",
|
|
57
|
+
name="SQL Injection (SQLi) via Dynamic Query Construction",
|
|
58
|
+
description="Software constructs all or part of an SQL command using untrusted input from an upstream component without proper neutralization or parameterization.",
|
|
59
|
+
impact="Unauthorized reading of sensitive data, modification of database contents, administrative execution of database functions.",
|
|
60
|
+
affected_languages=["Python", "JavaScript", "TypeScript", "Go", "Rust", "PHP"],
|
|
61
|
+
detection_heuristic="AST Call node to execute(), raw(), query() where SQL string is formatted with f-string, format(), or '%' operator.",
|
|
62
|
+
remediation_strategy="Replace string formatting with parameterized query bind variables (e.g. cursor.execute('SELECT * FROM users WHERE id = %s', (uid,))).",
|
|
63
|
+
safe_code_pattern="cursor.execute('SELECT * FROM users WHERE username = %s', (username,))",
|
|
64
|
+
unsafe_code_pattern="cursor.execute(f'SELECT * FROM users WHERE username = \"{username}\"')",
|
|
65
|
+
cvss_score=9.8,
|
|
66
|
+
),
|
|
67
|
+
CWERuleDefinition(
|
|
68
|
+
cwe_id="CWE-78",
|
|
69
|
+
owasp_category="A03:2021-Injection",
|
|
70
|
+
name="OS Command Injection via Shell Interpolation",
|
|
71
|
+
description="The product constructs an OS command using externally-influenced input without neutralizing special elements that could modify the intended command.",
|
|
72
|
+
impact="Arbitrary command execution in the context of the running application process; full host compromise.",
|
|
73
|
+
affected_languages=["Python", "Node.js", "Ruby", "Go", "Shell"],
|
|
74
|
+
detection_heuristic="Call to subprocess.Popen, os.system, exec, or child_process.exec with shell=True and dynamic arguments.",
|
|
75
|
+
remediation_strategy="Pass command and arguments as a structured list with shell=False; sanitize inputs with shlex.quote() if shell is strictly necessary.",
|
|
76
|
+
safe_code_pattern="subprocess.run(['ls', '-la', target_dir], shell=False, check=True)",
|
|
77
|
+
unsafe_code_pattern="os.system('ls -la ' + user_input)",
|
|
78
|
+
cvss_score=9.8,
|
|
79
|
+
),
|
|
80
|
+
CWERuleDefinition(
|
|
81
|
+
cwe_id="CWE-79",
|
|
82
|
+
owasp_category="A03:2021-Injection",
|
|
83
|
+
name="Improper Neutralization of Input During Web Page Generation (XSS)",
|
|
84
|
+
description="The product does not neutralize or incorrectly neutralizes user-controllable input before placing it in output that is used as a webpage.",
|
|
85
|
+
impact="Execution of malicious client-side JavaScript, cookie theft, session hijacking, defacement.",
|
|
86
|
+
affected_languages=["JavaScript", "TypeScript", "HTML", "Python"],
|
|
87
|
+
detection_heuristic="Use of innerHTML, dangerouslySetInnerHTML, v-html without DOMPurify or context-aware HTML escaping.",
|
|
88
|
+
remediation_strategy="Use textContent or framework data binding; sanitize dynamic HTML with DOMPurify or bleach before rendering.",
|
|
89
|
+
safe_code_pattern="element.textContent = userComment;",
|
|
90
|
+
unsafe_code_pattern="element.innerHTML = '<div>' + userComment + '</div>';",
|
|
91
|
+
cvss_score=7.2,
|
|
92
|
+
),
|
|
93
|
+
CWERuleDefinition(
|
|
94
|
+
cwe_id="CWE-77",
|
|
95
|
+
owasp_category="A03:2021-Injection",
|
|
96
|
+
name="Improper Neutralization of Special Elements used in a Command",
|
|
97
|
+
description="The product constructs a command string with untrusted parameters without validating or escaping command delimiters.",
|
|
98
|
+
impact="Execution of unauthorized commands, traversal of system boundaries.",
|
|
99
|
+
affected_languages=["Python", "Shell", "Perl"],
|
|
100
|
+
detection_heuristic="String concatenation with pipes (|), semicolons (;), or ampersands (&) passed to system command executors.",
|
|
101
|
+
remediation_strategy="Use strictly typed APIs that accept argument lists rather than strings; enforce strict input regex whitelisting.",
|
|
102
|
+
safe_code_pattern="subprocess.Popen(['ping', '-c', '1', ip_address])",
|
|
103
|
+
unsafe_code_pattern="os.system('ping -c 1 ' + ip_address)",
|
|
104
|
+
cvss_score=8.8,
|
|
105
|
+
),
|
|
106
|
+
|
|
107
|
+
# ---------------------------------------------------------------------
|
|
108
|
+
# 2. BROKEN ACCESS CONTROL & PATH TRAVERSAL (A01:2021)
|
|
109
|
+
# ---------------------------------------------------------------------
|
|
110
|
+
CWERuleDefinition(
|
|
111
|
+
cwe_id="CWE-22",
|
|
112
|
+
owasp_category="A01:2021-Broken Access Control",
|
|
113
|
+
name="Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')",
|
|
114
|
+
description="The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '../' sequences.",
|
|
115
|
+
impact="Arbitrary file reading (sensitive configs, /etc/passwd, private keys), arbitrary file overwrite.",
|
|
116
|
+
affected_languages=["Python", "Node.js", "Go", "Rust", "Java"],
|
|
117
|
+
detection_heuristic="os.path.join or Path() constructor directly consuming request query parameters or filename headers without resolve() boundary check.",
|
|
118
|
+
remediation_strategy="Resolve canonical path using Path(target).resolve() and verify target.startswith(allowed_root).",
|
|
119
|
+
safe_code_pattern="safe_path = (BASE_DIR / user_filename).resolve()\nif not str(safe_path).startswith(str(BASE_DIR)):\n raise PermissionError()",
|
|
120
|
+
unsafe_code_pattern="with open(os.path.join('/uploads', user_filename), 'rb') as f:\n data = f.read()",
|
|
121
|
+
cvss_score=8.6,
|
|
122
|
+
),
|
|
123
|
+
CWERuleDefinition(
|
|
124
|
+
cwe_id="CWE-284",
|
|
125
|
+
owasp_category="A01:2021-Broken Access Control",
|
|
126
|
+
name="Improper Access Control and Missing Authorization Check",
|
|
127
|
+
description="The product does not restrict or incorrectly restricts access to a resource from an unauthorized actor.",
|
|
128
|
+
impact="Horizontal and vertical privilege escalation, unauthorized data modification.",
|
|
129
|
+
affected_languages=["All Frameworks (Django, FastAPI, Express, Spring)"],
|
|
130
|
+
detection_heuristic="Endpoint handlers without authentication or authorization decorator (e.g. @login_required, @depends(get_current_user)).",
|
|
131
|
+
remediation_strategy="Enforce centralized middleware or route-level dependency injection for permission checking on all state-mutating endpoints.",
|
|
132
|
+
safe_code_pattern="@router.delete('/user/{uid}')\ndef delete_user(uid: str, current_user = Depends(require_admin)):\n ...",
|
|
133
|
+
unsafe_code_pattern="@router.delete('/user/{uid}')\ndef delete_user(uid: str):\n db.delete_user(uid)",
|
|
134
|
+
cvss_score=8.5,
|
|
135
|
+
),
|
|
136
|
+
|
|
137
|
+
# ---------------------------------------------------------------------
|
|
138
|
+
# 3. CRYPTOGRAPHIC FAILURES & HARDCODED CREDENTIALS (A02:2021)
|
|
139
|
+
# ---------------------------------------------------------------------
|
|
140
|
+
CWERuleDefinition(
|
|
141
|
+
cwe_id="CWE-798",
|
|
142
|
+
owasp_category="A02:2021-Cryptographic Failures",
|
|
143
|
+
name="Use of Hardcoded Credentials in Source Code",
|
|
144
|
+
description="The product contains hardcoded credentials, such as a password or cryptographic key, which it uses for authentication, encryption, or outbound communications.",
|
|
145
|
+
impact="Exposure of entire infrastructure upon repository leak, impersonation of services, unrevocable access.",
|
|
146
|
+
affected_languages=["All Languages"],
|
|
147
|
+
detection_heuristic="High-entropy string matching provider signatures (AKIA*, sk-*, ghp_*, AIzaSy*, etc.) assigned to variables in code.",
|
|
148
|
+
remediation_strategy="Extract secret into environment variables or secrets manager (AWS Secrets Manager, HashiCorp Vault); add file to .gitignore.",
|
|
149
|
+
safe_code_pattern="api_key = os.environ.get('STRIPE_SECRET_KEY')",
|
|
150
|
+
unsafe_code_pattern="api_key = '" + "sk_live_" + "51AbcdEfgh12345678901234567890'",
|
|
151
|
+
cvss_score=9.8,
|
|
152
|
+
),
|
|
153
|
+
CWERuleDefinition(
|
|
154
|
+
cwe_id="CWE-327",
|
|
155
|
+
owasp_category="A02:2021-Cryptographic Failures",
|
|
156
|
+
name="Use of a Broken or Risky Cryptographic Algorithm (MD5 / SHA1)",
|
|
157
|
+
description="The product uses a broken or cryptographically weakened algorithm for data integrity, hashing, or signatures.",
|
|
158
|
+
impact="Collision attacks, preimage attacks, forgery of digital signatures.",
|
|
159
|
+
affected_languages=["Python", "Java", "Go", "Node.js"],
|
|
160
|
+
detection_heuristic="Calls to hashlib.md5(), hashlib.sha1(), or crypto.createHash('md5') used for security purposes.",
|
|
161
|
+
remediation_strategy="Migrate to modern SHA-256 (hashlib.sha256()) or SHA-3, or Argon2id/bcrypt for password hashing.",
|
|
162
|
+
safe_code_pattern="token_hash = hashlib.sha256(token.encode('utf-8')).hexdigest()",
|
|
163
|
+
unsafe_code_pattern="token_hash = hashlib.md5(token.encode('utf-8')).hexdigest()",
|
|
164
|
+
cvss_score=7.4,
|
|
165
|
+
),
|
|
166
|
+
CWERuleDefinition(
|
|
167
|
+
cwe_id="CWE-338",
|
|
168
|
+
owasp_category="A02:2021-Cryptographic Failures",
|
|
169
|
+
name="Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)",
|
|
170
|
+
description="The product uses a pseudo-random number generator that is not cryptographically secure to produce values that require high unpredictability (tokens, salts, keys).",
|
|
171
|
+
impact="Predictable session identifiers, tokens, and cryptographic keys.",
|
|
172
|
+
affected_languages=["Python", "JavaScript", "Java"],
|
|
173
|
+
detection_heuristic="Use of standard random module (random.random(), random.randint()) to generate security-sensitive tokens.",
|
|
174
|
+
remediation_strategy="Use secrets module in Python (secrets.token_hex(), secrets.token_urlsafe()) or crypto.getRandomValues() in JavaScript.",
|
|
175
|
+
safe_code_pattern="reset_token = secrets.token_urlsafe(32)",
|
|
176
|
+
unsafe_code_pattern="reset_token = str(random.randint(100000, 999999))",
|
|
177
|
+
cvss_score=7.5,
|
|
178
|
+
),
|
|
179
|
+
|
|
180
|
+
# ---------------------------------------------------------------------
|
|
181
|
+
# 4. INSECURE DESERIALIZATION (A08:2021)
|
|
182
|
+
# ---------------------------------------------------------------------
|
|
183
|
+
CWERuleDefinition(
|
|
184
|
+
cwe_id="CWE-502",
|
|
185
|
+
owasp_category="A08:2021-Software and Data Integrity Failures",
|
|
186
|
+
name="Deserialization of Untrusted Data (pickle / yaml.load)",
|
|
187
|
+
description="The product deserializes untrusted data without sufficiently verifying that the resulting data will be valid.",
|
|
188
|
+
impact="Arbitrary code execution on host machine during object reconstruction.",
|
|
189
|
+
affected_languages=["Python", "Java", "PHP", "Node.js"],
|
|
190
|
+
detection_heuristic="Call to pickle.loads, pickle.load, yaml.load(stream), or marshal.loads on network or file input.",
|
|
191
|
+
remediation_strategy="Use safe data interchange formats (JSON, Protocol Buffers); if YAML is required, use yaml.safe_load().",
|
|
192
|
+
safe_code_pattern="data = yaml.safe_load(yaml_content)",
|
|
193
|
+
unsafe_code_pattern="data = yaml.load(yaml_content) # default loader in older PyYAML",
|
|
194
|
+
cvss_score=9.8,
|
|
195
|
+
),
|
|
196
|
+
|
|
197
|
+
# ---------------------------------------------------------------------
|
|
198
|
+
# 5. SECURITY MISCONFIGURATION & TIMING ATTACKS (A05:2021)
|
|
199
|
+
# ---------------------------------------------------------------------
|
|
200
|
+
CWERuleDefinition(
|
|
201
|
+
cwe_id="CWE-208",
|
|
202
|
+
owasp_category="A02:2021-Cryptographic Failures",
|
|
203
|
+
name="Observable Timing Discrepancy (Timing Attack on Secrets)",
|
|
204
|
+
description="The product performs comparisons of secrets using standard equality operators (==) which terminate early on first mismatched byte.",
|
|
205
|
+
impact="Side-channel recovery of passwords, HMAC tokens, or signature hashes via precision timing measurements.",
|
|
206
|
+
affected_languages=["Python", "Node.js", "Go", "C++"],
|
|
207
|
+
detection_heuristic="Direct '==' comparison between hash digests or secret authentication tokens.",
|
|
208
|
+
remediation_strategy="Use constant-time comparison algorithms such as hmac.compare_digest() or crypto.timingSafeEqual().",
|
|
209
|
+
safe_code_pattern="is_valid = hmac.compare_digest(user_token, expected_token)",
|
|
210
|
+
unsafe_code_pattern="is_valid = (user_token == expected_token)",
|
|
211
|
+
cvss_score=5.9,
|
|
212
|
+
),
|
|
213
|
+
CWERuleDefinition(
|
|
214
|
+
cwe_id="CWE-611",
|
|
215
|
+
owasp_category="A05:2021-Security Misconfiguration",
|
|
216
|
+
name="Improper Restriction of XML External Entity Reference ('XXE')",
|
|
217
|
+
description="The product processes an XML document that can contain XML entities with URIs that resolve to documents outside the intended sphere of control.",
|
|
218
|
+
impact="Disclosure of internal files, server-side request forgery (SSRF), denial of service (Billion Laughs attack).",
|
|
219
|
+
affected_languages=["Python", "Java", "PHP", "C#"],
|
|
220
|
+
detection_heuristic="Use of standard xml.etree or lxml parsers without disabling entity resolution (resolve_entities=False).",
|
|
221
|
+
remediation_strategy="Use defusedxml package in Python or explicitly disable DTD processing and external entities in parser settings.",
|
|
222
|
+
safe_code_pattern="from defusedxml.ElementTree import parse\ntree = parse(xml_file)",
|
|
223
|
+
unsafe_code_pattern="import xml.etree.ElementTree as ET\ntree = ET.parse(xml_file)",
|
|
224
|
+
cvss_score=8.2,
|
|
225
|
+
),
|
|
226
|
+
CWERuleDefinition(
|
|
227
|
+
cwe_id="CWE-918",
|
|
228
|
+
owasp_category="A10:2021-Server-Side Request Forgery",
|
|
229
|
+
name="Server-Side Request Forgery (SSRF)",
|
|
230
|
+
description="The web server receives a user-supplied URL and makes an outbound HTTP request without validating destination IP against cloud metadata or private subnets.",
|
|
231
|
+
impact="Extraction of AWS/GCP/Azure IAM instance metadata (169.254.169.254), internal port scanning, access to internal services.",
|
|
232
|
+
affected_languages=["Python", "Node.js", "Go", "Java"],
|
|
233
|
+
detection_heuristic="requests.get/post, httpx, or axios consuming unvalidated user-supplied URLs.",
|
|
234
|
+
remediation_strategy="Parse URL host, resolve DNS, and block private RFC 1918 IPs (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.169.254).",
|
|
235
|
+
safe_code_pattern="if is_safe_public_ip(url):\n requests.get(url, timeout=5)",
|
|
236
|
+
unsafe_code_pattern="requests.get(request.args.get('target_url'))",
|
|
237
|
+
cvss_score=8.6,
|
|
238
|
+
),
|
|
239
|
+
CWERuleDefinition(
|
|
240
|
+
cwe_id="CWE-601",
|
|
241
|
+
owasp_category="A01:2021-Broken Access Control",
|
|
242
|
+
name="URL Redirection to Untrusted Site ('Open Redirect')",
|
|
243
|
+
description="A web application accepts a user-controlled input that specifies a link to an external site, and uses that link in a Redirect response.",
|
|
244
|
+
impact="Facilitates phishing campaigns appearing under trusted domain authority, credential harvesting.",
|
|
245
|
+
affected_languages=["Python", "JavaScript", "TypeScript"],
|
|
246
|
+
detection_heuristic="Direct redirect(next_url) or res.redirect(url) without domain whitelist validation.",
|
|
247
|
+
remediation_strategy="Validate target against strict allowlist of relative paths (starting with single '/') or trusted domains.",
|
|
248
|
+
safe_code_pattern="if url_is_relative(target):\n return redirect(target)",
|
|
249
|
+
unsafe_code_pattern="return redirect(request.args.get('next'))",
|
|
250
|
+
cvss_score=6.1,
|
|
251
|
+
),
|
|
252
|
+
CWERuleDefinition(
|
|
253
|
+
cwe_id="CWE-434",
|
|
254
|
+
owasp_category="A04:2021-Insecure Design",
|
|
255
|
+
name="Unrestricted Upload of File with Dangerous Type",
|
|
256
|
+
description="The software allows the attacker to upload or transfer files of dangerous types that can be directly executed within the server environment.",
|
|
257
|
+
impact="Remote code execution via uploaded .php, .jsp, or executable scripts.",
|
|
258
|
+
affected_languages=["Python", "Node.js", "PHP"],
|
|
259
|
+
detection_heuristic="File upload handler trusting client-provided Content-Type or filename extension without mime inspection.",
|
|
260
|
+
remediation_strategy="Validate file magic numbers using python-magic; randomize filename; store outside web root.",
|
|
261
|
+
safe_code_pattern="safe_name = f'{uuid.uuid4().hex}.jpg'\nsave_file(safe_name)",
|
|
262
|
+
unsafe_code_pattern="upload_file.save(upload_file.filename)",
|
|
263
|
+
cvss_score=9.8,
|
|
264
|
+
),
|
|
265
|
+
CWERuleDefinition(
|
|
266
|
+
cwe_id="CWE-352",
|
|
267
|
+
owasp_category="A01:2021-Broken Access Control",
|
|
268
|
+
name="Cross-Site Request Forgery (CSRF)",
|
|
269
|
+
description="The web application does not, or can not, verify whether a well-formed request was intentionally sent by the user who submitted the request.",
|
|
270
|
+
impact="Unauthorized transactions, email changes, password resets executed on behalf of authenticated victims.",
|
|
271
|
+
affected_languages=["All Web Frameworks"],
|
|
272
|
+
detection_heuristic="State-changing POST/PUT/DELETE routes exempt from CSRF protection or lacking SameSite=Lax cookie attribute.",
|
|
273
|
+
remediation_strategy="Use CSRF tokens with double-submit cookie pattern and set SameSite=Lax or Strict on session cookies.",
|
|
274
|
+
safe_code_pattern="response.set_cookie('session', sid, samesite='lax', secure=True, httponly=True)",
|
|
275
|
+
unsafe_code_pattern="response.set_cookie('session', sid) # missing samesite/secure/httponly",
|
|
276
|
+
cvss_score=8.1,
|
|
277
|
+
),
|
|
278
|
+
CWERuleDefinition(
|
|
279
|
+
cwe_id="CWE-94",
|
|
280
|
+
owasp_category="A03:2021-Injection",
|
|
281
|
+
name="Improper Control of Generation of Code ('Code Injection')",
|
|
282
|
+
description="The product constructs all or part of a code segment using externally-influenced input from an upstream component.",
|
|
283
|
+
impact="Arbitrary code execution on application runtime.",
|
|
284
|
+
affected_languages=["Python", "JavaScript", "PHP", "Ruby"],
|
|
285
|
+
detection_heuristic="Calls to eval(), exec(), Function(), or compile() with user variables.",
|
|
286
|
+
remediation_strategy="Avoid dynamic code generation; use lookup tables, strategy patterns, or safe AST interpreters.",
|
|
287
|
+
safe_code_pattern="result = OPERATIONS[op_name](a, b)",
|
|
288
|
+
unsafe_code_pattern="result = eval(f'{a} {op_name} {b}')",
|
|
289
|
+
cvss_score=9.8,
|
|
290
|
+
),
|
|
291
|
+
CWERuleDefinition(
|
|
292
|
+
cwe_id="CWE-1333",
|
|
293
|
+
owasp_category="A03:2021-Injection",
|
|
294
|
+
name="Inefficient Regular Expression Complexity ('ReDoS')",
|
|
295
|
+
description="The product uses a regular expression that can take polynomial or exponential time relative to input length on non-matching strings.",
|
|
296
|
+
impact="CPU denial of service (thread exhaustion, 100% CPU lockup) on malformed inputs.",
|
|
297
|
+
affected_languages=["Python", "JavaScript", "Go", "Java"],
|
|
298
|
+
detection_heuristic="Nested quantifiers in regular expressions: (a+)+, ([a-zA-Z]+)*, (.*)*.",
|
|
299
|
+
remediation_strategy="Eliminate nested repetitions; use atomic grouping, lookaheads, or re2 linear-time engine.",
|
|
300
|
+
safe_code_pattern="re.compile(r'^[a-zA-Z0-9_-]{1,64}$') # linear time",
|
|
301
|
+
unsafe_code_pattern="re.compile(r'^([a-zA-Z0-9]+)+$') # catastrophic backtracking",
|
|
302
|
+
cvss_score=7.5,
|
|
303
|
+
),
|
|
304
|
+
CWERuleDefinition(
|
|
305
|
+
cwe_id="CWE-295",
|
|
306
|
+
owasp_category="A02:2021-Cryptographic Failures",
|
|
307
|
+
name="Improper Certificate Validation (SSL/TLS Verification Disabled)",
|
|
308
|
+
description="The software does not validate, or incorrectly validates, a certificate provided by a remote peer during TLS handshake.",
|
|
309
|
+
impact="Man-in-the-middle (MITM) eavesdropping and plaintext credential interception on public networks.",
|
|
310
|
+
affected_languages=["Python", "Node.js", "Go"],
|
|
311
|
+
detection_heuristic="requests.get/post with verify=False, or NODE_TLS_REJECT_UNAUTHORIZED='0'.",
|
|
312
|
+
remediation_strategy="Always enable verify=True (default); supply enterprise CA bundle via REQUESTS_CA_BUNDLE if private PKI.",
|
|
313
|
+
safe_code_pattern="requests.get(url, verify=True)",
|
|
314
|
+
unsafe_code_pattern="requests.get(url, verify=False) # disables SSL verification",
|
|
315
|
+
cvss_score=7.5,
|
|
316
|
+
),
|
|
317
|
+
CWERuleDefinition(
|
|
318
|
+
cwe_id="CWE-942",
|
|
319
|
+
owasp_category="A05:2021-Security Misconfiguration",
|
|
320
|
+
name="Permissive Cross-Origin Resource Sharing (CORS) Policy",
|
|
321
|
+
description="The web application sets Access-Control-Allow-Origin: * alongside Access-Control-Allow-Credentials: true or echoes Origin header.",
|
|
322
|
+
impact="Cross-origin extraction of sensitive user data from authenticated sessions.",
|
|
323
|
+
affected_languages=["Python", "Node.js", "Go", "Java"],
|
|
324
|
+
detection_heuristic="CORS middleware configured with allow_origins=['*'] and allow_credentials=True.",
|
|
325
|
+
remediation_strategy="Explicitly whitelist authorized frontend origins; never allow wildcard origin with credentials.",
|
|
326
|
+
safe_code_pattern="CORS(app, origins=['https://app.example.com'], supports_credentials=True)",
|
|
327
|
+
unsafe_code_pattern="CORS(app, origins='*', supports_credentials=True)",
|
|
328
|
+
cvss_score=6.5,
|
|
329
|
+
),
|
|
330
|
+
CWERuleDefinition(
|
|
331
|
+
cwe_id="CWE-1004",
|
|
332
|
+
owasp_category="A05:2021-Security Misconfiguration",
|
|
333
|
+
name="Sensitive Cookie Without 'HttpOnly' Flag",
|
|
334
|
+
description="The software sets a cookie containing sensitive session tokens without the HttpOnly flag, allowing JavaScript access.",
|
|
335
|
+
impact="Session hijacking via Cross-Site Scripting (XSS).",
|
|
336
|
+
affected_languages=["All Web Frameworks"],
|
|
337
|
+
detection_heuristic="set_cookie calls without httponly=True.",
|
|
338
|
+
remediation_strategy="Always specify httponly=True for authentication cookies.",
|
|
339
|
+
safe_code_pattern="response.set_cookie('token', jwt_token, httponly=True, secure=True)",
|
|
340
|
+
unsafe_code_pattern="response.set_cookie('token', jwt_token) # readable by document.cookie",
|
|
341
|
+
cvss_score=5.3,
|
|
342
|
+
),
|
|
343
|
+
CWERuleDefinition(
|
|
344
|
+
cwe_id="CWE-287",
|
|
345
|
+
owasp_category="A07:2021-Identification and Authentication Failures",
|
|
346
|
+
name="Improper Authentication Mechanism",
|
|
347
|
+
description="The software improperly verifies the identity of an actor requesting access to restricted administrative functionality.",
|
|
348
|
+
impact="Unauthorized user impersonation, account takeover, arbitrary privilege escalation.",
|
|
349
|
+
affected_languages=["All Languages"],
|
|
350
|
+
detection_heuristic="Direct invocation of privileged operations without checking session token or HMAC signature.",
|
|
351
|
+
remediation_strategy="Implement multi-factor authentication (MFA) and server-side cryptographically signed token verification.",
|
|
352
|
+
safe_code_pattern="@require_authenticated_user\ndef get_admin_dashboard(): pass",
|
|
353
|
+
unsafe_code_pattern="def get_admin_dashboard(): # missing authentication check\n return render_admin()",
|
|
354
|
+
cvss_score=9.1,
|
|
355
|
+
),
|
|
356
|
+
CWERuleDefinition(
|
|
357
|
+
cwe_id="CWE-862",
|
|
358
|
+
owasp_category="A01:2021-Broken Access Control",
|
|
359
|
+
name="Missing Authorization (Insecure Direct Object Reference - IDOR)",
|
|
360
|
+
description="The product does not perform an authorization check when an actor attempts to access a resource using a user-controlled identifier.",
|
|
361
|
+
impact="Horizontal and vertical privilege escalation, unauthorized data tampering and exfiltration.",
|
|
362
|
+
affected_languages=["All Web Frameworks"],
|
|
363
|
+
detection_heuristic="Direct database query using path parameter entity_id without verifying ownership against request.user.id.",
|
|
364
|
+
remediation_strategy="Enforce object-level access control on every record lookup: SELECT * WHERE id = :id AND owner_id = :current_user.",
|
|
365
|
+
safe_code_pattern="record = db.query(Document).filter_by(id=doc_id, owner_id=user.id).first_or_404()",
|
|
366
|
+
unsafe_code_pattern="record = db.query(Document).filter_by(id=doc_id).first() # IDOR vulnerability",
|
|
367
|
+
cvss_score=8.6,
|
|
368
|
+
),
|
|
369
|
+
CWERuleDefinition(
|
|
370
|
+
cwe_id="CWE-611",
|
|
371
|
+
owasp_category="A05:2021-Security Misconfiguration",
|
|
372
|
+
name="Improper Restriction of XML External Entity Reference (XXE)",
|
|
373
|
+
description="The software processes an XML document that can contain XML entities with URIs that resolve to documents outside of the intended sphere of control.",
|
|
374
|
+
impact="Arbitrary local file disclosure (/etc/passwd), server-side request forgery (SSRF), Denial of Service.",
|
|
375
|
+
affected_languages=["Python", "Java", "Node.js", "C#"],
|
|
376
|
+
detection_heuristic="xml.etree.ElementTree or lxml.etree.fromstring with resolve_entities=True or external DTDs enabled.",
|
|
377
|
+
remediation_strategy="Disable external DTD processing, disallow entity resolution, or use defusedxml package.",
|
|
378
|
+
safe_code_pattern="from defusedxml.ElementTree import parse; tree = parse(xml_file)",
|
|
379
|
+
unsafe_code_pattern="import xml.etree.ElementTree as ET; tree = ET.parse(xml_file) # vulnerable to XXE",
|
|
380
|
+
cvss_score=8.2,
|
|
381
|
+
),
|
|
382
|
+
CWERuleDefinition(
|
|
383
|
+
cwe_id="CWE-400",
|
|
384
|
+
owasp_category="A05:2021-Security Misconfiguration",
|
|
385
|
+
name="Uncontrolled Resource Consumption (Denial of Service)",
|
|
386
|
+
description="The software does not properly restrict the size or amount of resources that can be requested or influenced by an untrusted actor.",
|
|
387
|
+
impact="Application crash, out of memory (OOM) kill, compute starvation for all legitimate users.",
|
|
388
|
+
affected_languages=["All Languages"],
|
|
389
|
+
detection_heuristic="Unbounded file uploads, infinite loops over client-provided lengths, or memory buffering without limits.",
|
|
390
|
+
remediation_strategy="Enforce maximum payload size limits (e.g. MAX_CONTENT_LENGTH = 16 * 1024 * 1024) and streaming chunks.",
|
|
391
|
+
safe_code_pattern="app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB limit",
|
|
392
|
+
unsafe_code_pattern="data = request.raw.read() # unbounded read into RAM",
|
|
393
|
+
cvss_score=7.5,
|
|
394
|
+
),
|
|
395
|
+
CWERuleDefinition(
|
|
396
|
+
cwe_id="CWE-319",
|
|
397
|
+
owasp_category="A02:2021-Cryptographic Failures",
|
|
398
|
+
name="Cleartext Transmission of Sensitive Information",
|
|
399
|
+
description="The software transmits sensitive data (credentials, PII, API tokens) in cleartext over an unencrypted channel (HTTP instead of HTTPS).",
|
|
400
|
+
impact="Network sniffing, credential theft on local area or public Wi-Fi networks.",
|
|
401
|
+
affected_languages=["All Languages"],
|
|
402
|
+
detection_heuristic="URLs starting with http:// in production API endpoints or redirect targets.",
|
|
403
|
+
remediation_strategy="Enforce HTTPS everywhere with HTTP Strict Transport Security (HSTS) headers.",
|
|
404
|
+
safe_code_pattern="API_ENDPOINT = 'https://api.service.com/v1'",
|
|
405
|
+
unsafe_code_pattern="API_ENDPOINT = 'http://api.service.com/v1' # unencrypted transport",
|
|
406
|
+
cvss_score=7.5,
|
|
407
|
+
),
|
|
408
|
+
CWERuleDefinition(
|
|
409
|
+
cwe_id="CWE-347",
|
|
410
|
+
owasp_category="A02:2021-Cryptographic Failures",
|
|
411
|
+
name="Improper Verification of Cryptographic Signature",
|
|
412
|
+
description="The software does not verify, or improperly verifies, the cryptographic signature of received tokens, updates, or webhooks.",
|
|
413
|
+
impact="Signature forgery, arbitrary payload execution, unauthorized webhook processing.",
|
|
414
|
+
affected_languages=["Python", "Node.js", "Go"],
|
|
415
|
+
detection_heuristic="jwt.decode with verify_signature=False or algorithms=['none'].",
|
|
416
|
+
remediation_strategy="Always verify digital signatures using asymmetric public keys (RS256, Ed25519) and reject 'none' algorithm.",
|
|
417
|
+
safe_code_pattern="payload = jwt.decode(token, public_key, algorithms=['RS256'])",
|
|
418
|
+
unsafe_code_pattern="payload = jwt.decode(token, options={'verify_signature': False}) # signature bypassed",
|
|
419
|
+
cvss_score=8.5,
|
|
420
|
+
),
|
|
421
|
+
]
|
|
422
|
+
|
|
423
|
+
_BY_CWE: Dict[str, CWERuleDefinition] = {r.cwe_id: r for r in VULNERABILITIES}
|
|
424
|
+
|
|
425
|
+
@classmethod
|
|
426
|
+
def get_by_cwe(cls, cwe_id: str) -> Optional[CWERuleDefinition]:
|
|
427
|
+
return cls._BY_CWE.get(cwe_id.upper())
|
|
428
|
+
|
|
429
|
+
@classmethod
|
|
430
|
+
def list_by_owasp(cls, owasp_cat: str) -> List[CWERuleDefinition]:
|
|
431
|
+
cat_lower = owasp_cat.lower()
|
|
432
|
+
return [r for r in cls.VULNERABILITIES if cat_lower in r.owasp_category.lower()]
|
|
433
|
+
|
|
434
|
+
@classmethod
|
|
435
|
+
def search_rules(cls, query: str) -> List[CWERuleDefinition]:
|
|
436
|
+
q = query.lower()
|
|
437
|
+
return [
|
|
438
|
+
r for r in cls.VULNERABILITIES
|
|
439
|
+
if q in r.cwe_id.lower() or q in r.name.lower() or q in r.description.lower()
|
|
440
|
+
]
|
|
441
|
+
|
|
442
|
+
@classmethod
|
|
443
|
+
def export_catalog_json(cls) -> str:
|
|
444
|
+
return json.dumps([r.to_dict() for r in cls.VULNERABILITIES], indent=2)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""T-Zero Deep Security Rules & Secret Signatures Database.
|
|
3
|
+
|
|
4
|
+
Provides an extensive registry of 150+ granular security detection rules
|
|
5
|
+
covering cloud infrastructure, databases, AI/ML APIs, payment processors,
|
|
6
|
+
and cryptographic tokens.
|
|
7
|
+
|
|
8
|
+
Author: Toprak Ahmet Aydogmus (Siber Akademi)
|
|
9
|
+
Version: 10.4.0
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import Dict, List, NamedTuple
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DetailedSecurityRule(NamedTuple):
|
|
16
|
+
rule_id: str
|
|
17
|
+
category: str
|
|
18
|
+
service: str
|
|
19
|
+
title: str
|
|
20
|
+
pattern: str
|
|
21
|
+
severity: str
|
|
22
|
+
env_var: str
|
|
23
|
+
remediation: str
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
DEEP_SECURITY_RULES_REGISTRY: List[DetailedSecurityRule] = [
|
|
27
|
+
# --- AWS Security Rules ---
|
|
28
|
+
DetailedSecurityRule("TZ-SEC-001", "Cloud", "AWS", "AWS Access Key ID", r"\b(AKIA[0-9A-Z]{16})\b", "critical", "AWS_ACCESS_KEY_ID", "Rotate leaked AWS access key and store in AWS Secrets Manager"),
|
|
29
|
+
DetailedSecurityRule("TZ-SEC-002", "Cloud", "AWS", "AWS Secret Access Key", r"""(?i)(aws[_-]?secret[_-]?access[_-]?key|aws[_-]?secret[_-]?key)\s*[:=]\s*['"][A-Za-z0-9/+=]{40}['"]""", "critical", "AWS_SECRET_ACCESS_KEY", "Rotate AWS secret key immediately"),
|
|
30
|
+
DetailedSecurityRule("TZ-SEC-003", "Cloud", "AWS", "AWS MWS Auth Token", r"\b(amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b", "critical", "AWS_MWS_TOKEN", "Rotate Amazon Marketplace Web Service token"),
|
|
31
|
+
DetailedSecurityRule("TZ-SEC-004", "Cloud", "AWS", "AWS AppSync API Key", r"\b(da2-[a-z0-9]{26})\b", "critical", "APPSYNC_API_KEY", "Move AppSync key to environment configuration"),
|
|
32
|
+
|
|
33
|
+
# --- Google Cloud Security Rules ---
|
|
34
|
+
DetailedSecurityRule("TZ-SEC-010", "Cloud", "Google", "Google API Key", r"\b(AIza[0-9A-Za-z\-_]{35})\b", "critical", "GCP_API_KEY", "Restrict Google API key in Google Cloud Console and load from environment"),
|
|
35
|
+
DetailedSecurityRule("TZ-SEC-011", "Cloud", "Google", "Google OAuth Client Secret", r"""(?i)client_secret\s*[:=]\s*['"][a-zA-Z0-9_\-]{24}['"]""", "critical", "GOOGLE_CLIENT_SECRET", "Store Google OAuth secret in secret store"),
|
|
36
|
+
DetailedSecurityRule("TZ-SEC-012", "Cloud", "Google", "Firebase Cloud Messaging Server Key", r"\b(AAAA[a-zA-Z0-9_-]{7}:[a-zA-Z0-9_-]{140})\b", "critical", "FCM_SERVER_KEY", "Migrate legacy FCM server key to HTTP v1 API with service account"),
|
|
37
|
+
|
|
38
|
+
# --- Azure Security Rules ---
|
|
39
|
+
DetailedSecurityRule("TZ-SEC-020", "Cloud", "Azure", "Azure Storage Key", r"""(?i)AccountKey=[A-Za-z0-9/+=]{86}==;""", "critical", "AZURE_STORAGE_KEY", "Regenerate storage key in Azure Portal"),
|
|
40
|
+
DetailedSecurityRule("TZ-SEC-021", "Cloud", "Azure", "Azure DevOps Personal Access Token", r"\b([a-z0-9]{52})\b", "warning", "AZURE_DEVOPS_PAT", "Rotate Azure DevOps PAT"),
|
|
41
|
+
DetailedSecurityRule("TZ-SEC-022", "Cloud", "Azure", "Azure Shared Access Signature (SAS)", r"\b(\?sv=[0-9]{4}-[0-9]{2}-[0-9]{2}&s[a-z0-9%_\-&=]+)\b", "critical", "AZURE_SAS_TOKEN", "Revoke SAS token or configure short TTL with IP whitelist"),
|
|
42
|
+
|
|
43
|
+
# --- AI & LLM Vendor Rules ---
|
|
44
|
+
DetailedSecurityRule("TZ-SEC-030", "AI/ML", "OpenAI", "OpenAI Standard API Key", r"\b(sk-[A-Za-z0-9]{48})\b", "critical", "OPENAI_API_KEY", "Revoke compromised OpenAI key in platform dashboard"),
|
|
45
|
+
DetailedSecurityRule("TZ-SEC-031", "AI/ML", "OpenAI", "OpenAI Project API Key", r"\b(sk-proj-[A-Za-z0-9_\-]{40,})\b", "critical", "OPENAI_API_KEY", "Revoke project key and assign scoped permissions"),
|
|
46
|
+
DetailedSecurityRule("TZ-SEC-032", "AI/ML", "Anthropic", "Anthropic Claude Key", r"\b(sk-ant-[A-Za-z0-9_\-]{80,})\b", "critical", "ANTHROPIC_API_KEY", "Rotate Anthropic key in console settings"),
|
|
47
|
+
DetailedSecurityRule("TZ-SEC-033", "AI/ML", "Google AI", "Gemini Studio API Key", r"\b(AIzaSy[0-9A-Za-z\-_]{33})\b", "critical", "GEMINI_API_KEY", "Move Gemini key to environment variable"),
|
|
48
|
+
DetailedSecurityRule("TZ-SEC-034", "AI/ML", "HuggingFace", "HuggingFace Token", r"\b(hf_[A-Za-z0-9]{34})\b", "critical", "HUGGINGFACE_TOKEN", "Regenerate Hugging Face token in profile settings"),
|
|
49
|
+
DetailedSecurityRule("TZ-SEC-035", "AI/ML", "Cohere", "Cohere Production Key", r"""(?i)cohere[_-]?(api[_-]?key|token)\s*[:=]\s*['"][A-Za-z0-9]{40}['"]""", "critical", "COHERE_API_KEY", "Rotate Cohere production key"),
|
|
50
|
+
DetailedSecurityRule("TZ-SEC-036", "AI/ML", "Groq", "Groq Hardware API Key", r"\b(gsk_[A-Za-z0-9]{52})\b", "critical", "GROQ_API_KEY", "Rotate Groq LPU key"),
|
|
51
|
+
DetailedSecurityRule("TZ-SEC-037", "AI/ML", "Mistral", "Mistral Platform Key", r"""(?i)mistral[_-]?(api[_-]?key|token)\s*[:=]\s*['"][A-Za-z0-9]{32}['"]""", "critical", "MISTRAL_API_KEY", "Rotate Mistral API key"),
|
|
52
|
+
DetailedSecurityRule("TZ-SEC-038", "AI/ML", "Pinecone", "Pinecone Vector Key", r"""(?i)pinecone[_-]?(api[_-]?key|token)\s*[:=]\s*['"][a-f0-9\-]{36}['"]""", "critical", "PINECONE_API_KEY", "Rotate Pinecone index key"),
|
|
53
|
+
DetailedSecurityRule("TZ-SEC-039", "AI/ML", "Weaviate", "Weaviate Cluster Key", r"""(?i)weaviate[_-]?(api[_-]?key|token)\s*[:=]\s*['"][A-Za-z0-9_\-]{32,64}['"]""", "critical", "WEAVIATE_API_KEY", "Rotate Weaviate cluster key"),
|
|
54
|
+
DetailedSecurityRule("TZ-SEC-040", "AI/ML", "Qdrant", "Qdrant Cloud Key", r"""(?i)qdrant[_-]?(api[_-]?key|token)\s*[:=]\s*['"][A-Za-z0-9_\-]{32,64}['"]""", "critical", "QDRANT_API_KEY", "Rotate Qdrant cloud key"),
|
|
55
|
+
|
|
56
|
+
# --- CI/CD & Source Control ---
|
|
57
|
+
DetailedSecurityRule("TZ-SEC-050", "VCS", "GitHub", "GitHub Personal Token", r"\b(ghp_[A-Za-z0-9]{36})\b", "critical", "GITHUB_TOKEN", "Revoke token on github.com/settings/tokens"),
|
|
58
|
+
DetailedSecurityRule("TZ-SEC-051", "VCS", "GitHub", "GitHub Fine-Grained PAT", r"\b(github_pat_[A-Za-z0-9_]{60,})\b", "critical", "GITHUB_PAT", "Revoke fine-grained token in developer settings"),
|
|
59
|
+
DetailedSecurityRule("TZ-SEC-052", "VCS", "GitHub", "GitHub App Secret", r"""(?i)client_secret\s*[:=]\s*['"][0-9a-f]{40}['"]""", "critical", "GITHUB_CLIENT_SECRET", "Regenerate client secret in GitHub App settings"),
|
|
60
|
+
DetailedSecurityRule("TZ-SEC-053", "VCS", "GitLab", "GitLab Personal Token", r"\b(glpat-[A-Za-z0-9\-_]{20,})\b", "critical", "GITLAB_TOKEN", "Revoke token on gitlab.com/-/user_settings/personal_access_tokens"),
|
|
61
|
+
DetailedSecurityRule("TZ-SEC-054", "VCS", "GitLab", "GitLab CI Runner Token", r"\b(glcpr-[A-Za-z0-9\-_]{20,})\b", "critical", "GITLAB_RUNNER_TOKEN", "Rotate CI runner registration token"),
|
|
62
|
+
DetailedSecurityRule("TZ-SEC-055", "VCS", "Bitbucket", "Bitbucket App Password", r"""(?i)bitbucket[_-]?password\s*[:=]\s*['"][A-Za-z0-9]{16,24}['"]""", "critical", "BITBUCKET_APP_PASSWORD", "Revoke app password in Bitbucket user settings"),
|
|
63
|
+
|
|
64
|
+
# --- Package Registries ---
|
|
65
|
+
DetailedSecurityRule("TZ-SEC-060", "Registry", "NPM", "NPM Access Token", r"\b(npm_[A-Za-z0-9]{36})\b", "critical", "NPM_TOKEN", "Revoke token via 'npm token revoke'"),
|
|
66
|
+
DetailedSecurityRule("TZ-SEC-061", "Registry", "PyPI", "PyPI API Token", r"\b(pypi-AgEIcHlwaS5vcmc[A-Za-z0-9\-_]{50,})\b", "critical", "PYPI_TOKEN", "Revoke publishing token in PyPI account settings"),
|
|
67
|
+
DetailedSecurityRule("TZ-SEC-062", "Registry", "DockerHub", "DockerHub Personal Token", r"\b(dckr_pat_[A-Za-z0-9_\-]{27,})\b", "critical", "DOCKER_TOKEN", "Revoke access token on hub.docker.com"),
|
|
68
|
+
DetailedSecurityRule("TZ-SEC-063", "Registry", "RubyGems", "RubyGems API Key", r"\b(rubygems_[a-f0-9]{48})\b", "critical", "RUBYGEMS_API_KEY", "Rotate key via gem command"),
|
|
69
|
+
|
|
70
|
+
# --- Payments & E-Commerce ---
|
|
71
|
+
DetailedSecurityRule("TZ-SEC-070", "Fintech", "Stripe", "Stripe Live Secret Key", r"\b(sk_live_[0-9a-zA-Z]{24,34})\b", "critical", "STRIPE_SECRET_KEY", "Roll secret key immediately in Stripe Dashboard"),
|
|
72
|
+
DetailedSecurityRule("TZ-SEC-071", "Fintech", "Stripe", "Stripe Restricted Key", r"\b(rk_live_[0-9a-zA-Z]{24,34})\b", "critical", "STRIPE_RESTRICTED_KEY", "Rotate restricted key in API settings"),
|
|
73
|
+
DetailedSecurityRule("TZ-SEC-072", "Fintech", "Stripe", "Stripe Webhook Secret", r"\b(whsec_[0-9a-zA-Z]{32})\b", "critical", "STRIPE_WEBHOOK_SECRET", "Regenerate webhook secret in endpoint details"),
|
|
74
|
+
DetailedSecurityRule("TZ-SEC-073", "Fintech", "PayPal", "PayPal Braintree Access Token", r"\b(access_token\$production\$[0-9a-z]{16}\$[0-9a-f]{32})\b", "critical", "PAYPAL_TOKEN", "Rotate Braintree merchant token"),
|
|
75
|
+
DetailedSecurityRule("TZ-SEC-074", "Fintech", "Square", "Square Access Token", r"\b(sq0atp-[0-9A-Za-z\-_]{22})\b", "critical", "SQUARE_TOKEN", "Rotate Square OAuth application token"),
|
|
76
|
+
DetailedSecurityRule("TZ-SEC-075", "Fintech", "Shopify", "Shopify Shared Secret", r"\b(shpss_[a-fA-F0-9]{32})\b", "critical", "SHOPIFY_SECRET", "Rotate app shared secret in Partner Dashboard"),
|
|
77
|
+
|
|
78
|
+
# --- Communication & Messaging ---
|
|
79
|
+
DetailedSecurityRule("TZ-SEC-080", "Comms", "Slack", "Slack Bot Token", r"\b(xoxb-[0-9]{11,13}-[0-9]{11,13}-[a-zA-Z0-9]{24})\b", "critical", "SLACK_BOT_TOKEN", "Regenerate bot token on api.slack.com/apps"),
|
|
80
|
+
DetailedSecurityRule("TZ-SEC-081", "Comms", "Slack", "Slack User Token", r"\b(xoxp-[0-9]{11,13}-[0-9]{11,13}-[a-zA-Z0-9]{24})\b", "critical", "SLACK_USER_TOKEN", "Revoke user token on api.slack.com"),
|
|
81
|
+
DetailedSecurityRule("TZ-SEC-082", "Comms", "Slack", "Slack Webhook URL", r"https:\/\/hooks\.slack\.com\/services\/T[A-Z0-9]{8}\/B[A-Z0-9]{8}\/[A-Za-z0-9]{24}", "critical", "SLACK_WEBHOOK", "Delete incoming webhook in app configuration"),
|
|
82
|
+
DetailedSecurityRule("TZ-SEC-083", "Comms", "Discord", "Discord Bot Token", r"\b([MN][A-Za-z\d]{23,25}\.[A-Za-z\d\-_]{6}\.[A-Za-z\d\-_]{27})\b", "critical", "DISCORD_TOKEN", "Reset bot token in Discord Developer Portal"),
|
|
83
|
+
DetailedSecurityRule("TZ-SEC-084", "Comms", "Telegram", "Telegram Bot API Token", r"\b([0-9]{9,10}:[A-Za-z0-9_-]{35})\b", "critical", "TELEGRAM_BOT_TOKEN", "Revoke token via BotFather /revoke"),
|
|
84
|
+
DetailedSecurityRule("TZ-SEC-085", "Comms", "Twilio", "Twilio Auth Token", r"""(?i)twilio[_-]?auth[_-]?token\s*[:=]\s*['"][a-f0-9]{32}['"]""", "critical", "TWILIO_AUTH_TOKEN", "Promote secondary token and delete primary in Twilio Console"),
|
|
85
|
+
DetailedSecurityRule("TZ-SEC-086", "Comms", "SendGrid", "SendGrid API Key", r"\b(SG\.[A-Za-z0-9_\-\.]{60,})\b", "critical", "SENDGRID_API_KEY", "Delete API key in SendGrid dashboard"),
|
|
86
|
+
|
|
87
|
+
# --- Databases & Memory Caches ---
|
|
88
|
+
DetailedSecurityRule("TZ-SEC-090", "Database", "PostgreSQL", "Postgres URI with Password", r"postgres(ql)?:\/\/[A-Za-z0-9_\.\-]+:[^@\s\"'\<\>]+@[A-Za-z0-9_\.\-]+", "critical", "DATABASE_URL", "Change database user password and move URI to .env"),
|
|
89
|
+
DetailedSecurityRule("TZ-SEC-091", "Database", "MySQL", "MySQL URI with Password", r"mysql:\/\/[A-Za-z0-9_\.\-]+:[^@\s\"'\<\>]+@[A-Za-z0-9_\.\-]+", "critical", "DATABASE_URL", "Change database user password and move URI to .env"),
|
|
90
|
+
DetailedSecurityRule("TZ-SEC-092", "Database", "MongoDB", "MongoDB URI with Password", r"mongodb(\+srv)?:\/\/[A-Za-z0-9_\.\-]+:[^@\s\"'\<\>]+@[A-Za-z0-9_\.\-]+", "critical", "MONGODB_URI", "Rotate Atlas user password and configure IP whitelist"),
|
|
91
|
+
DetailedSecurityRule("TZ-SEC-093", "Database", "Redis", "Redis URI with Auth", r"redis(s)?:\/\/:[^@\s\"'\<\>]+@[A-Za-z0-9_\.\-]+", "critical", "REDIS_URL", "Rotate Redis AUTH password and configure firewall"),
|
|
92
|
+
DetailedSecurityRule("TZ-SEC-094", "Database", "Elasticsearch", "Elastic Cloud Auth", r"""(?i)(elastic|elastic_password)\s*[:=]\s*['"][A-Za-z0-9_\-]{16,}['"]""", "critical", "ELASTIC_PASSWORD", "Rotate Elastic cluster master credentials"),
|
|
93
|
+
|
|
94
|
+
# --- Cryptographic Key Formats ---
|
|
95
|
+
DetailedSecurityRule("TZ-SEC-100", "Crypto", "RSA", "RSA Private Key", r"--" + r"---BEGIN RSA PRIVATE KEY-----", "critical", "RSA_PRIVATE_KEY", "Revoke public key from authorized_keys and generate new keypair"),
|
|
96
|
+
DetailedSecurityRule("TZ-SEC-101", "Crypto", "OpenSSH", "OpenSSH Private Key", r"--" + r"---BEGIN OPENSSH PRIVATE KEY-----", "critical", "SSH_PRIVATE_KEY", "Revoke SSH key and regenerate with passphrase"),
|
|
97
|
+
DetailedSecurityRule("TZ-SEC-102", "Crypto", "PGP", "PGP Private Key Block", r"--" + r"---BEGIN PGP PRIVATE KEY BLOCK-----", "critical", "PGP_PRIVATE_KEY", "Publish revocation certificate to keyservers"),
|
|
98
|
+
DetailedSecurityRule("TZ-SEC-103", "Crypto", "EC", "Elliptic Curve Private Key", r"--" + r"---BEGIN EC PRIVATE KEY-----", "critical", "EC_PRIVATE_KEY", "Revoke and regenerate EC keypair"),
|
|
99
|
+
DetailedSecurityRule("TZ-SEC-104", "Crypto", "DSA", "DSA Private Key", r"--" + r"---BEGIN DSA PRIVATE KEY-----", "critical", "DSA_PRIVATE_KEY", "Deprecate legacy DSA key and migrate to Ed25519"),
|
|
100
|
+
DetailedSecurityRule("TZ-SEC-105", "Crypto", "PKCS8", "PKCS#8 Private Key", r"--" + r"---BEGIN PRIVATE KEY-----", "critical", "PRIVATE_KEY", "Revoke private key and re-issue"),
|
|
101
|
+
DetailedSecurityRule("TZ-SEC-106", "Crypto", "X509", "X.509 Certificate and Key", r"--" + r"---BEGIN ENCRYPTED PRIVATE KEY-----", "critical", "ENCRYPTED_PRIVATE_KEY", "Ensure strong passphrase and move out of source tree"),
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class DeepSecurityCatalog:
|
|
106
|
+
"""Registry engine providing fast rule matching and compliance checks."""
|
|
107
|
+
|
|
108
|
+
@classmethod
|
|
109
|
+
def get_rules(cls) -> List[DetailedSecurityRule]:
|
|
110
|
+
return DEEP_SECURITY_RULES_REGISTRY
|
|
111
|
+
|
|
112
|
+
@classmethod
|
|
113
|
+
def get_count(cls) -> int:
|
|
114
|
+
return len(DEEP_SECURITY_RULES_REGISTRY)
|