@h1dr0n/skill-pool 0.1.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.
- package/LICENSE +21 -0
- package/README.md +296 -0
- package/bin/cli.js +157 -0
- package/package.json +41 -0
- package/skills/api/agents/backend-specialist.md +69 -0
- package/skills/api/agents/database-optimizer.md +176 -0
- package/skills/api/manifest.yaml +20 -0
- package/skills/api/rules/auth-security.md +45 -0
- package/skills/api/skills/api-patterns/SKILL.md +81 -0
- package/skills/api/skills/api-patterns/api-style.md +42 -0
- package/skills/api/skills/api-patterns/auth.md +24 -0
- package/skills/api/skills/api-patterns/documentation.md +26 -0
- package/skills/api/skills/api-patterns/graphql.md +41 -0
- package/skills/api/skills/api-patterns/rate-limiting.md +31 -0
- package/skills/api/skills/api-patterns/response.md +37 -0
- package/skills/api/skills/api-patterns/rest.md +40 -0
- package/skills/api/skills/api-patterns/scripts/api_validator.py +211 -0
- package/skills/api/skills/api-patterns/security-testing.md +122 -0
- package/skills/api/skills/api-patterns/trpc.md +41 -0
- package/skills/api/skills/api-patterns/versioning.md +22 -0
- package/skills/api/skills/database-patterns.md +126 -0
- package/skills/api/skills/deployment-patterns.md +105 -0
- package/skills/api/skills/docker-patterns.md +135 -0
- package/skills/common/agents/code-reviewer.md +78 -0
- package/skills/common/agents/planner.md +80 -0
- package/skills/common/agents/security-reviewer.md +82 -0
- package/skills/common/agents/software-architect.md +81 -0
- package/skills/common/manifest.yaml +25 -0
- package/skills/common/rules/coding-style.md +39 -0
- package/skills/common/rules/git-workflow.md +33 -0
- package/skills/common/rules/security.md +25 -0
- package/skills/common/skills/architecture/SKILL.md +55 -0
- package/skills/common/skills/architecture/context-discovery.md +43 -0
- package/skills/common/skills/architecture/examples.md +94 -0
- package/skills/common/skills/architecture/pattern-selection.md +68 -0
- package/skills/common/skills/architecture/patterns-reference.md +50 -0
- package/skills/common/skills/architecture/trade-off-analysis.md +77 -0
- package/skills/common/skills/brainstorming/SKILL.md +163 -0
- package/skills/common/skills/brainstorming/dynamic-questioning.md +350 -0
- package/skills/common/skills/clean-code.md +99 -0
- package/skills/common/skills/code-review-checklist.md +86 -0
- package/skills/common/skills/plan-writing/SKILL.md +152 -0
- package/skills/common/skills/skill-feedback.md +94 -0
- package/skills/common/skills/tdd-workflow.md +130 -0
- package/skills/common/skills/verification-loop.md +112 -0
- package/skills/cpp/agents/cpp-build-resolver.md +90 -0
- package/skills/cpp/agents/cpp-reviewer.md +72 -0
- package/skills/cpp/manifest.yaml +15 -0
- package/skills/cpp/skills/cpp-coding-standards.md +722 -0
- package/skills/cpp/skills/cpp-testing.md +323 -0
- package/skills/devops/agents/devops-automator.md +376 -0
- package/skills/devops/agents/sre.md +90 -0
- package/skills/devops/manifest.yaml +20 -0
- package/skills/devops/skills/deployment-patterns.md +427 -0
- package/skills/devops/skills/deployment-procedures/SKILL.md +241 -0
- package/skills/devops/skills/docker-patterns.md +364 -0
- package/skills/devops/skills/e2e-testing.md +326 -0
- package/skills/devops/skills/github-ops.md +144 -0
- package/skills/django/manifest.yaml +16 -0
- package/skills/django/skills/django-patterns.md +734 -0
- package/skills/django/skills/django-security.md +593 -0
- package/skills/django/skills/django-tdd.md +729 -0
- package/skills/django/skills/django-verification.md +469 -0
- package/skills/dotnet/agents/csharp-reviewer.md +101 -0
- package/skills/dotnet/manifest.yaml +14 -0
- package/skills/dotnet/skills/csharp-testing.md +321 -0
- package/skills/dotnet/skills/dotnet-patterns.md +321 -0
- package/skills/go/agents/code-reviewer.md +76 -0
- package/skills/go/agents/go-build-resolver.md +94 -0
- package/skills/go/agents/go-reviewer.md +76 -0
- package/skills/go/manifest.yaml +17 -0
- package/skills/go/rules/go-style.md +55 -0
- package/skills/go/skills/golang-patterns.md +674 -0
- package/skills/go/skills/golang-testing.md +720 -0
- package/skills/java/agents/java-build-resolver.md +153 -0
- package/skills/java/agents/java-reviewer.md +92 -0
- package/skills/java/manifest.yaml +18 -0
- package/skills/java/skills/java-coding-standards.md +147 -0
- package/skills/java/skills/jpa-patterns.md +151 -0
- package/skills/java/skills/springboot-patterns.md +314 -0
- package/skills/java/skills/springboot-security.md +272 -0
- package/skills/kotlin/agents/kotlin-build-resolver.md +118 -0
- package/skills/kotlin/agents/kotlin-reviewer.md +159 -0
- package/skills/kotlin/manifest.yaml +17 -0
- package/skills/kotlin/skills/kotlin-coroutines-flows.md +284 -0
- package/skills/kotlin/skills/kotlin-patterns.md +711 -0
- package/skills/kotlin/skills/kotlin-testing.md +824 -0
- package/skills/laravel/manifest.yaml +15 -0
- package/skills/laravel/skills/laravel-patterns.md +409 -0
- package/skills/laravel/skills/laravel-security.md +279 -0
- package/skills/laravel/skills/laravel-tdd.md +277 -0
- package/skills/laravel/skills/laravel-verification.md +173 -0
- package/skills/mobile/agents/dart-build-resolver.md +201 -0
- package/skills/mobile/agents/flutter-reviewer.md +243 -0
- package/skills/mobile/manifest.yaml +19 -0
- package/skills/mobile/skills/android-clean-architecture.md +339 -0
- package/skills/mobile/skills/dart-flutter-patterns.md +563 -0
- package/skills/mobile/skills/swiftui-patterns.md +259 -0
- package/skills/nestjs/manifest.yaml +13 -0
- package/skills/nestjs/skills/nestjs-patterns.md +230 -0
- package/skills/perl/manifest.yaml +13 -0
- package/skills/perl/skills/perl-patterns.md +504 -0
- package/skills/perl/skills/perl-security.md +503 -0
- package/skills/perl/skills/perl-testing.md +475 -0
- package/skills/python/agents/python-reviewer.md +98 -0
- package/skills/python/manifest.yaml +18 -0
- package/skills/python/rules/python-style.md +69 -0
- package/skills/python/skills/python-patterns/SKILL.md +441 -0
- package/skills/python/skills/python-patterns.md +90 -0
- package/skills/python/skills/python-testing.md +81 -0
- package/skills/rust/agents/rust-build-resolver.md +148 -0
- package/skills/rust/agents/rust-reviewer.md +94 -0
- package/skills/rust/manifest.yaml +16 -0
- package/skills/rust/rules/rust-style.md +107 -0
- package/skills/rust/skills/rust-patterns.md +499 -0
- package/skills/rust/skills/rust-testing.md +500 -0
- package/skills/security/agents/accessibility-auditor.md +316 -0
- package/skills/security/agents/security-reviewer.md +108 -0
- package/skills/security/manifest.yaml +19 -0
- package/skills/security/skills/red-team-tactics/SKILL.md +199 -0
- package/skills/security/skills/security-bounty-hunter.md +99 -0
- package/skills/security/skills/security-review.md +495 -0
- package/skills/security/skills/security-scan.md +165 -0
- package/skills/security/skills/vulnerability-scanner/SKILL.md +276 -0
- package/skills/security/skills/vulnerability-scanner/checklists.md +121 -0
- package/skills/security/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
- package/skills/swift/manifest.yaml +16 -0
- package/skills/swift/skills/swift-actor-persistence.md +142 -0
- package/skills/swift/skills/swift-concurrency.md +216 -0
- package/skills/swift/skills/swift-protocol-di-testing.md +190 -0
- package/skills/swift/skills/swiftui-patterns.md +259 -0
- package/skills/unity/agents/game-designer.md +167 -0
- package/skills/unity/agents/unity-architect.md +52 -0
- package/skills/unity/agents/unity-editor-tool-developer.md +310 -0
- package/skills/unity/agents/unity-multiplayer-engineer.md +321 -0
- package/skills/unity/agents/unity-shader-graph-artist.md +269 -0
- package/skills/unity/manifest.yaml +21 -0
- package/skills/unity/rules/csharp-patterns.md +48 -0
- package/skills/unity/rules/unity-specific.md +53 -0
- package/skills/unity/skills/systematic-debugging.md +92 -0
- package/skills/unity/skills/unity-architecture.md +173 -0
- package/skills/unreal/agents/level-designer.md +208 -0
- package/skills/unreal/agents/technical-artist.md +229 -0
- package/skills/unreal/agents/unreal-multiplayer-architect.md +313 -0
- package/skills/unreal/agents/unreal-systems-engineer.md +310 -0
- package/skills/unreal/agents/unreal-technical-artist.md +256 -0
- package/skills/unreal/agents/unreal-world-builder.md +273 -0
- package/skills/unreal/manifest.yaml +21 -0
- package/skills/unreal/skills/unreal-patterns.md +183 -0
- package/skills/web/agents/frontend-specialist.md +71 -0
- package/skills/web/agents/ui-designer.md +383 -0
- package/skills/web/agents/ux-architect.md +469 -0
- package/skills/web/manifest.yaml +22 -0
- package/skills/web/rules/accessibility.md +54 -0
- package/skills/web/rules/css-performance.md +52 -0
- package/skills/web/skills/e2e-testing.md +132 -0
- package/skills/web/skills/frontend-design/SKILL.md +452 -0
- package/skills/web/skills/frontend-design/animation-guide.md +331 -0
- package/skills/web/skills/frontend-design/color-system.md +311 -0
- package/skills/web/skills/frontend-design/decision-trees.md +418 -0
- package/skills/web/skills/frontend-design/motion-graphics.md +306 -0
- package/skills/web/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/skills/web/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/skills/web/skills/frontend-design/typography-system.md +345 -0
- package/skills/web/skills/frontend-design/ux-psychology.md +1116 -0
- package/skills/web/skills/frontend-design/visual-effects.md +383 -0
- package/skills/web/skills/react-nextjs.md +135 -0
- package/skills/web/skills/tailwind-patterns/SKILL.md +269 -0
- package/src/adapters/antigravity.js +164 -0
- package/src/adapters/claude.js +188 -0
- package/src/adapters/cursor.js +161 -0
- package/src/adapters/index.js +67 -0
- package/src/adapters/windsurf.js +158 -0
- package/src/commands/add.js +266 -0
- package/src/commands/create.js +127 -0
- package/src/commands/diff.js +78 -0
- package/src/commands/info.js +88 -0
- package/src/commands/init.js +224 -0
- package/src/commands/install.js +90 -0
- package/src/commands/list.js +54 -0
- package/src/commands/remove.js +101 -0
- package/src/commands/targets.js +32 -0
- package/src/commands/update.js +57 -0
- package/src/core/manifest.js +57 -0
- package/src/core/plugins.js +86 -0
- package/src/core/resolver.js +84 -0
- package/src/core/tracker.js +49 -0
- package/src/utils/fs.js +80 -0
- package/src/utils/git.js +52 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Skill: vulnerability-scanner
|
|
4
|
+
Script: security_scan.py
|
|
5
|
+
Purpose: Validate that security principles from SKILL.md are applied correctly
|
|
6
|
+
Usage: python security_scan.py <project_path> [--scan-type all|deps|secrets|patterns|config]
|
|
7
|
+
Output: JSON with validation findings
|
|
8
|
+
|
|
9
|
+
This script verifies:
|
|
10
|
+
1. Dependencies - Supply chain security (OWASP A03)
|
|
11
|
+
2. Secrets - No hardcoded credentials (OWASP A04)
|
|
12
|
+
3. Code Patterns - Dangerous patterns identified (OWASP A05)
|
|
13
|
+
4. Configuration - Security settings validated (OWASP A02)
|
|
14
|
+
"""
|
|
15
|
+
import subprocess
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
import sys
|
|
19
|
+
import re
|
|
20
|
+
import argparse
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Dict, List, Any
|
|
23
|
+
from datetime import datetime
|
|
24
|
+
|
|
25
|
+
# Fix Windows console encoding for Unicode output
|
|
26
|
+
try:
|
|
27
|
+
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
28
|
+
sys.stderr.reconfigure(encoding='utf-8', errors='replace')
|
|
29
|
+
except AttributeError:
|
|
30
|
+
pass # Python < 3.7
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# ============================================================================
|
|
34
|
+
# CONFIGURATION
|
|
35
|
+
# ============================================================================
|
|
36
|
+
|
|
37
|
+
SECRET_PATTERNS = [
|
|
38
|
+
# API Keys & Tokens
|
|
39
|
+
(r'api[_-]?key\s*[=:]\s*["\'][^"\']{10,}["\']', "API Key", "high"),
|
|
40
|
+
(r'token\s*[=:]\s*["\'][^"\']{10,}["\']', "Token", "high"),
|
|
41
|
+
(r'bearer\s+[a-zA-Z0-9\-_.]+', "Bearer Token", "critical"),
|
|
42
|
+
|
|
43
|
+
# Cloud Credentials
|
|
44
|
+
(r'AKIA[0-9A-Z]{16}', "AWS Access Key", "critical"),
|
|
45
|
+
(r'aws[_-]?secret[_-]?access[_-]?key\s*[=:]\s*["\'][^"\']+["\']', "AWS Secret", "critical"),
|
|
46
|
+
(r'AZURE[_-]?[A-Z_]+\s*[=:]\s*["\'][^"\']+["\']', "Azure Credential", "critical"),
|
|
47
|
+
(r'GOOGLE[_-]?[A-Z_]+\s*[=:]\s*["\'][^"\']+["\']', "GCP Credential", "critical"),
|
|
48
|
+
|
|
49
|
+
# Database & Connections
|
|
50
|
+
(r'password\s*[=:]\s*["\'][^"\']{4,}["\']', "Password", "high"),
|
|
51
|
+
(r'(mongodb|postgres|mysql|redis):\/\/[^\s"\']+', "Database Connection String", "critical"),
|
|
52
|
+
|
|
53
|
+
# Private Keys
|
|
54
|
+
(r'-----BEGIN\s+(RSA|PRIVATE|EC)\s+KEY-----', "Private Key", "critical"),
|
|
55
|
+
(r'ssh-rsa\s+[A-Za-z0-9+/]+', "SSH Key", "critical"),
|
|
56
|
+
|
|
57
|
+
# JWT
|
|
58
|
+
(r'eyJ[A-Za-z0-9-_]+\.eyJ[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+', "JWT Token", "high"),
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
DANGEROUS_PATTERNS = [
|
|
62
|
+
# Injection risks
|
|
63
|
+
(r'eval\s*\(', "eval() usage", "critical", "Code Injection risk"),
|
|
64
|
+
(r'exec\s*\(', "exec() usage", "critical", "Code Injection risk"),
|
|
65
|
+
(r'new\s+Function\s*\(', "Function constructor", "high", "Code Injection risk"),
|
|
66
|
+
(r'child_process\.exec\s*\(', "child_process.exec", "high", "Command Injection risk"),
|
|
67
|
+
(r'subprocess\.call\s*\([^)]*shell\s*=\s*True', "subprocess with shell=True", "high", "Command Injection risk"),
|
|
68
|
+
|
|
69
|
+
# XSS risks
|
|
70
|
+
(r'dangerouslySetInnerHTML', "dangerouslySetInnerHTML", "high", "XSS risk"),
|
|
71
|
+
(r'\.innerHTML\s*=', "innerHTML assignment", "medium", "XSS risk"),
|
|
72
|
+
(r'document\.write\s*\(', "document.write", "medium", "XSS risk"),
|
|
73
|
+
|
|
74
|
+
# SQL Injection indicators
|
|
75
|
+
(r'["\'][^"\']*\+\s*[a-zA-Z_]+\s*\+\s*["\'].*(?:SELECT|INSERT|UPDATE|DELETE)', "SQL String Concat", "critical", "SQL Injection risk"),
|
|
76
|
+
(r'f"[^"]*(?:SELECT|INSERT|UPDATE|DELETE)[^"]*\{', "SQL f-string", "critical", "SQL Injection risk"),
|
|
77
|
+
|
|
78
|
+
# Insecure configurations
|
|
79
|
+
(r'verify\s*=\s*False', "SSL Verify Disabled", "high", "MITM risk"),
|
|
80
|
+
(r'--insecure', "Insecure flag", "medium", "Security disabled"),
|
|
81
|
+
(r'disable[_-]?ssl', "SSL Disabled", "high", "MITM risk"),
|
|
82
|
+
|
|
83
|
+
# Unsafe deserialization
|
|
84
|
+
(r'pickle\.loads?\s*\(', "pickle usage", "high", "Deserialization risk"),
|
|
85
|
+
(r'yaml\.load\s*\([^)]*\)(?!\s*,\s*Loader)', "Unsafe YAML load", "high", "Deserialization risk"),
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
SKIP_DIRS = {'node_modules', '.git', 'dist', 'build', '__pycache__', '.venv', 'venv', '.next'}
|
|
89
|
+
CODE_EXTENSIONS = {'.js', '.ts', '.jsx', '.tsx', '.py', '.go', '.java', '.rb', '.php'}
|
|
90
|
+
CONFIG_EXTENSIONS = {'.json', '.yaml', '.yml', '.toml', '.env', '.env.local', '.env.development'}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# ============================================================================
|
|
94
|
+
# SCANNING FUNCTIONS
|
|
95
|
+
# ============================================================================
|
|
96
|
+
|
|
97
|
+
def scan_dependencies(project_path: str) -> Dict[str, Any]:
|
|
98
|
+
"""
|
|
99
|
+
Validate supply chain security (OWASP A03).
|
|
100
|
+
Checks: npm audit, lock file presence, dependency age.
|
|
101
|
+
"""
|
|
102
|
+
results = {"tool": "dependency_scanner", "findings": [], "status": "[OK] Secure"}
|
|
103
|
+
|
|
104
|
+
# Check for lock files
|
|
105
|
+
lock_files = {
|
|
106
|
+
"npm": ["package-lock.json", "npm-shrinkwrap.json"],
|
|
107
|
+
"yarn": ["yarn.lock"],
|
|
108
|
+
"pnpm": ["pnpm-lock.yaml"],
|
|
109
|
+
"pip": ["requirements.txt", "Pipfile.lock", "poetry.lock"],
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
found_locks = []
|
|
113
|
+
missing_locks = []
|
|
114
|
+
|
|
115
|
+
for manager, files in lock_files.items():
|
|
116
|
+
pkg_file = "package.json" if manager in ["npm", "yarn", "pnpm"] else "setup.py"
|
|
117
|
+
pkg_path = Path(project_path) / pkg_file
|
|
118
|
+
|
|
119
|
+
if pkg_path.exists() or (manager == "pip" and (Path(project_path) / "requirements.txt").exists()):
|
|
120
|
+
has_lock = any((Path(project_path) / f).exists() for f in files)
|
|
121
|
+
if has_lock:
|
|
122
|
+
found_locks.append(manager)
|
|
123
|
+
else:
|
|
124
|
+
missing_locks.append(manager)
|
|
125
|
+
results["findings"].append({
|
|
126
|
+
"type": "Missing Lock File",
|
|
127
|
+
"severity": "high",
|
|
128
|
+
"message": f"{manager}: No lock file found. Supply chain integrity at risk."
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
# Run npm audit if applicable
|
|
132
|
+
if (Path(project_path) / "package.json").exists():
|
|
133
|
+
try:
|
|
134
|
+
result = subprocess.run(
|
|
135
|
+
["npm", "audit", "--json"],
|
|
136
|
+
cwd=project_path,
|
|
137
|
+
capture_output=True,
|
|
138
|
+
text=True,
|
|
139
|
+
timeout=60
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
audit_data = json.loads(result.stdout)
|
|
144
|
+
vulnerabilities = audit_data.get("vulnerabilities", {})
|
|
145
|
+
|
|
146
|
+
severity_count = {"critical": 0, "high": 0, "moderate": 0, "low": 0}
|
|
147
|
+
for vuln in vulnerabilities.values():
|
|
148
|
+
sev = vuln.get("severity", "low").lower()
|
|
149
|
+
if sev in severity_count:
|
|
150
|
+
severity_count[sev] += 1
|
|
151
|
+
|
|
152
|
+
if severity_count["critical"] > 0:
|
|
153
|
+
results["status"] = "[!!] Critical vulnerabilities"
|
|
154
|
+
results["findings"].append({
|
|
155
|
+
"type": "npm audit",
|
|
156
|
+
"severity": "critical",
|
|
157
|
+
"message": f"{severity_count['critical']} critical vulnerabilities in dependencies"
|
|
158
|
+
})
|
|
159
|
+
elif severity_count["high"] > 0:
|
|
160
|
+
results["status"] = "[!] High vulnerabilities"
|
|
161
|
+
results["findings"].append({
|
|
162
|
+
"type": "npm audit",
|
|
163
|
+
"severity": "high",
|
|
164
|
+
"message": f"{severity_count['high']} high severity vulnerabilities"
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
results["npm_audit"] = severity_count
|
|
168
|
+
|
|
169
|
+
except json.JSONDecodeError:
|
|
170
|
+
pass
|
|
171
|
+
|
|
172
|
+
except (FileNotFoundError, subprocess.TimeoutExpired):
|
|
173
|
+
pass
|
|
174
|
+
|
|
175
|
+
if not results["findings"]:
|
|
176
|
+
results["status"] = "[OK] Supply chain checks passed"
|
|
177
|
+
|
|
178
|
+
return results
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def scan_secrets(project_path: str) -> Dict[str, Any]:
|
|
182
|
+
"""
|
|
183
|
+
Validate no hardcoded secrets (OWASP A04).
|
|
184
|
+
Checks: API keys, tokens, passwords, cloud credentials.
|
|
185
|
+
"""
|
|
186
|
+
results = {
|
|
187
|
+
"tool": "secret_scanner",
|
|
188
|
+
"findings": [],
|
|
189
|
+
"status": "[OK] No secrets detected",
|
|
190
|
+
"scanned_files": 0,
|
|
191
|
+
"by_severity": {"critical": 0, "high": 0, "medium": 0}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
for root, dirs, files in os.walk(project_path):
|
|
195
|
+
dirs[:] = [d for d in dirs if d not in SKIP_DIRS]
|
|
196
|
+
|
|
197
|
+
for file in files:
|
|
198
|
+
ext = Path(file).suffix.lower()
|
|
199
|
+
if ext not in CODE_EXTENSIONS and ext not in CONFIG_EXTENSIONS:
|
|
200
|
+
continue
|
|
201
|
+
|
|
202
|
+
filepath = Path(root) / file
|
|
203
|
+
results["scanned_files"] += 1
|
|
204
|
+
|
|
205
|
+
try:
|
|
206
|
+
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
|
|
207
|
+
content = f.read()
|
|
208
|
+
|
|
209
|
+
for pattern, secret_type, severity in SECRET_PATTERNS:
|
|
210
|
+
matches = re.findall(pattern, content, re.IGNORECASE)
|
|
211
|
+
if matches:
|
|
212
|
+
results["findings"].append({
|
|
213
|
+
"file": str(filepath.relative_to(project_path)),
|
|
214
|
+
"type": secret_type,
|
|
215
|
+
"severity": severity,
|
|
216
|
+
"count": len(matches)
|
|
217
|
+
})
|
|
218
|
+
results["by_severity"][severity] += len(matches)
|
|
219
|
+
|
|
220
|
+
except Exception:
|
|
221
|
+
pass
|
|
222
|
+
|
|
223
|
+
if results["by_severity"]["critical"] > 0:
|
|
224
|
+
results["status"] = "[!!] CRITICAL: Secrets exposed!"
|
|
225
|
+
elif results["by_severity"]["high"] > 0:
|
|
226
|
+
results["status"] = "[!] HIGH: Secrets found"
|
|
227
|
+
elif sum(results["by_severity"].values()) > 0:
|
|
228
|
+
results["status"] = "[?] Potential secrets detected"
|
|
229
|
+
|
|
230
|
+
# Limit findings for output
|
|
231
|
+
results["findings"] = results["findings"][:15]
|
|
232
|
+
|
|
233
|
+
return results
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def scan_code_patterns(project_path: str) -> Dict[str, Any]:
|
|
237
|
+
"""
|
|
238
|
+
Validate dangerous code patterns (OWASP A05).
|
|
239
|
+
Checks: Injection risks, XSS, unsafe deserialization.
|
|
240
|
+
"""
|
|
241
|
+
results = {
|
|
242
|
+
"tool": "pattern_scanner",
|
|
243
|
+
"findings": [],
|
|
244
|
+
"status": "[OK] No dangerous patterns",
|
|
245
|
+
"scanned_files": 0,
|
|
246
|
+
"by_category": {}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
for root, dirs, files in os.walk(project_path):
|
|
250
|
+
dirs[:] = [d for d in dirs if d not in SKIP_DIRS]
|
|
251
|
+
|
|
252
|
+
for file in files:
|
|
253
|
+
ext = Path(file).suffix.lower()
|
|
254
|
+
if ext not in CODE_EXTENSIONS:
|
|
255
|
+
continue
|
|
256
|
+
|
|
257
|
+
filepath = Path(root) / file
|
|
258
|
+
results["scanned_files"] += 1
|
|
259
|
+
|
|
260
|
+
try:
|
|
261
|
+
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
|
|
262
|
+
lines = f.readlines()
|
|
263
|
+
|
|
264
|
+
for line_num, line in enumerate(lines, 1):
|
|
265
|
+
for pattern, name, severity, category in DANGEROUS_PATTERNS:
|
|
266
|
+
if re.search(pattern, line, re.IGNORECASE):
|
|
267
|
+
results["findings"].append({
|
|
268
|
+
"file": str(filepath.relative_to(project_path)),
|
|
269
|
+
"line": line_num,
|
|
270
|
+
"pattern": name,
|
|
271
|
+
"severity": severity,
|
|
272
|
+
"category": category,
|
|
273
|
+
"snippet": line.strip()[:80]
|
|
274
|
+
})
|
|
275
|
+
results["by_category"][category] = results["by_category"].get(category, 0) + 1
|
|
276
|
+
|
|
277
|
+
except Exception:
|
|
278
|
+
pass
|
|
279
|
+
|
|
280
|
+
critical_count = sum(1 for f in results["findings"] if f["severity"] == "critical")
|
|
281
|
+
high_count = sum(1 for f in results["findings"] if f["severity"] == "high")
|
|
282
|
+
|
|
283
|
+
if critical_count > 0:
|
|
284
|
+
results["status"] = f"[!!] CRITICAL: {critical_count} dangerous patterns"
|
|
285
|
+
elif high_count > 0:
|
|
286
|
+
results["status"] = f"[!] HIGH: {high_count} risky patterns"
|
|
287
|
+
elif results["findings"]:
|
|
288
|
+
results["status"] = "[?] Some patterns need review"
|
|
289
|
+
|
|
290
|
+
# Limit findings
|
|
291
|
+
results["findings"] = results["findings"][:20]
|
|
292
|
+
|
|
293
|
+
return results
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def scan_configuration(project_path: str) -> Dict[str, Any]:
|
|
297
|
+
"""
|
|
298
|
+
Validate security configuration (OWASP A02).
|
|
299
|
+
Checks: Security headers, CORS, debug modes.
|
|
300
|
+
"""
|
|
301
|
+
results = {
|
|
302
|
+
"tool": "config_scanner",
|
|
303
|
+
"findings": [],
|
|
304
|
+
"status": "[OK] Configuration secure",
|
|
305
|
+
"checks": {}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
# Check common config files for issues
|
|
309
|
+
config_issues = [
|
|
310
|
+
(r'"DEBUG"\s*:\s*true', "Debug mode enabled", "high"),
|
|
311
|
+
(r'debug\s*=\s*True', "Debug mode enabled", "high"),
|
|
312
|
+
(r'NODE_ENV.*development', "Development mode in config", "medium"),
|
|
313
|
+
(r'"CORS_ALLOW_ALL".*true', "CORS allow all origins", "high"),
|
|
314
|
+
(r'"Access-Control-Allow-Origin".*\*', "CORS wildcard", "high"),
|
|
315
|
+
(r'allowCredentials.*true.*origin.*\*', "Dangerous CORS combo", "critical"),
|
|
316
|
+
]
|
|
317
|
+
|
|
318
|
+
for root, dirs, files in os.walk(project_path):
|
|
319
|
+
dirs[:] = [d for d in dirs if d not in SKIP_DIRS]
|
|
320
|
+
|
|
321
|
+
for file in files:
|
|
322
|
+
ext = Path(file).suffix.lower()
|
|
323
|
+
if ext not in CONFIG_EXTENSIONS and file not in ['next.config.js', 'webpack.config.js', '.eslintrc.js']:
|
|
324
|
+
continue
|
|
325
|
+
|
|
326
|
+
filepath = Path(root) / file
|
|
327
|
+
|
|
328
|
+
try:
|
|
329
|
+
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
|
|
330
|
+
content = f.read()
|
|
331
|
+
|
|
332
|
+
for pattern, issue, severity in config_issues:
|
|
333
|
+
if re.search(pattern, content, re.IGNORECASE):
|
|
334
|
+
results["findings"].append({
|
|
335
|
+
"file": str(filepath.relative_to(project_path)),
|
|
336
|
+
"issue": issue,
|
|
337
|
+
"severity": severity
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
except Exception:
|
|
341
|
+
pass
|
|
342
|
+
|
|
343
|
+
# Check for security header configurations
|
|
344
|
+
header_files = ["next.config.js", "next.config.mjs", "middleware.ts", "nginx.conf"]
|
|
345
|
+
for hf in header_files:
|
|
346
|
+
hf_path = Path(project_path) / hf
|
|
347
|
+
if hf_path.exists():
|
|
348
|
+
results["checks"]["security_headers_config"] = True
|
|
349
|
+
break
|
|
350
|
+
else:
|
|
351
|
+
results["checks"]["security_headers_config"] = False
|
|
352
|
+
results["findings"].append({
|
|
353
|
+
"issue": "No security headers configuration found",
|
|
354
|
+
"severity": "medium",
|
|
355
|
+
"recommendation": "Configure CSP, HSTS, X-Frame-Options headers"
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
if any(f["severity"] == "critical" for f in results["findings"]):
|
|
359
|
+
results["status"] = "[!!] CRITICAL: Configuration issues"
|
|
360
|
+
elif any(f["severity"] == "high" for f in results["findings"]):
|
|
361
|
+
results["status"] = "[!] HIGH: Configuration review needed"
|
|
362
|
+
elif results["findings"]:
|
|
363
|
+
results["status"] = "[?] Minor configuration issues"
|
|
364
|
+
|
|
365
|
+
return results
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
# ============================================================================
|
|
369
|
+
# MAIN
|
|
370
|
+
# ============================================================================
|
|
371
|
+
|
|
372
|
+
def run_full_scan(project_path: str, scan_type: str = "all") -> Dict[str, Any]:
|
|
373
|
+
"""Execute security validation scans."""
|
|
374
|
+
|
|
375
|
+
report = {
|
|
376
|
+
"project": project_path,
|
|
377
|
+
"timestamp": datetime.now().isoformat(),
|
|
378
|
+
"scan_type": scan_type,
|
|
379
|
+
"scans": {},
|
|
380
|
+
"summary": {
|
|
381
|
+
"total_findings": 0,
|
|
382
|
+
"critical": 0,
|
|
383
|
+
"high": 0,
|
|
384
|
+
"overall_status": "[OK] SECURE"
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
scanners = {
|
|
389
|
+
"deps": ("dependencies", scan_dependencies),
|
|
390
|
+
"secrets": ("secrets", scan_secrets),
|
|
391
|
+
"patterns": ("code_patterns", scan_code_patterns),
|
|
392
|
+
"config": ("configuration", scan_configuration),
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
for key, (name, scanner) in scanners.items():
|
|
396
|
+
if scan_type == "all" or scan_type == key:
|
|
397
|
+
result = scanner(project_path)
|
|
398
|
+
report["scans"][name] = result
|
|
399
|
+
|
|
400
|
+
findings_count = len(result.get("findings", []))
|
|
401
|
+
report["summary"]["total_findings"] += findings_count
|
|
402
|
+
|
|
403
|
+
for finding in result.get("findings", []):
|
|
404
|
+
sev = finding.get("severity", "low")
|
|
405
|
+
if sev == "critical":
|
|
406
|
+
report["summary"]["critical"] += 1
|
|
407
|
+
elif sev == "high":
|
|
408
|
+
report["summary"]["high"] += 1
|
|
409
|
+
|
|
410
|
+
# Determine overall status
|
|
411
|
+
if report["summary"]["critical"] > 0:
|
|
412
|
+
report["summary"]["overall_status"] = "[!!] CRITICAL ISSUES FOUND"
|
|
413
|
+
elif report["summary"]["high"] > 0:
|
|
414
|
+
report["summary"]["overall_status"] = "[!] HIGH RISK ISSUES"
|
|
415
|
+
elif report["summary"]["total_findings"] > 0:
|
|
416
|
+
report["summary"]["overall_status"] = "[?] REVIEW RECOMMENDED"
|
|
417
|
+
|
|
418
|
+
return report
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def main():
|
|
422
|
+
parser = argparse.ArgumentParser(
|
|
423
|
+
description="Validate security principles from vulnerability-scanner skill"
|
|
424
|
+
)
|
|
425
|
+
parser.add_argument("project_path", nargs="?", default=".", help="Project directory to scan")
|
|
426
|
+
parser.add_argument("--scan-type", choices=["all", "deps", "secrets", "patterns", "config"],
|
|
427
|
+
default="all", help="Type of scan to run")
|
|
428
|
+
parser.add_argument("--output", choices=["json", "summary"], default="json",
|
|
429
|
+
help="Output format")
|
|
430
|
+
|
|
431
|
+
args = parser.parse_args()
|
|
432
|
+
|
|
433
|
+
if not os.path.isdir(args.project_path):
|
|
434
|
+
print(json.dumps({"error": f"Directory not found: {args.project_path}"}))
|
|
435
|
+
sys.exit(1)
|
|
436
|
+
|
|
437
|
+
result = run_full_scan(args.project_path, args.scan_type)
|
|
438
|
+
|
|
439
|
+
if args.output == "summary":
|
|
440
|
+
print(f"\n{'='*60}")
|
|
441
|
+
print(f"Security Scan: {result['project']}")
|
|
442
|
+
print(f"{'='*60}")
|
|
443
|
+
print(f"Status: {result['summary']['overall_status']}")
|
|
444
|
+
print(f"Total Findings: {result['summary']['total_findings']}")
|
|
445
|
+
print(f" Critical: {result['summary']['critical']}")
|
|
446
|
+
print(f" High: {result['summary']['high']}")
|
|
447
|
+
print(f"{'='*60}\n")
|
|
448
|
+
|
|
449
|
+
for scan_name, scan_result in result['scans'].items():
|
|
450
|
+
print(f"\n{scan_name.upper()}: {scan_result['status']}")
|
|
451
|
+
for finding in scan_result.get('findings', [])[:5]:
|
|
452
|
+
print(f" - {finding}")
|
|
453
|
+
else:
|
|
454
|
+
print(json.dumps(result, indent=2))
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
if __name__ == "__main__":
|
|
458
|
+
main()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: swift
|
|
2
|
+
version: 0.1.0
|
|
3
|
+
description: Swift and SwiftUI development - patterns, concurrency, actors, dependency injection, testing
|
|
4
|
+
depends:
|
|
5
|
+
- common
|
|
6
|
+
tags:
|
|
7
|
+
- swift
|
|
8
|
+
- swiftui
|
|
9
|
+
- ios
|
|
10
|
+
- macos
|
|
11
|
+
rules: []
|
|
12
|
+
skills:
|
|
13
|
+
- skills/swiftui-patterns.md
|
|
14
|
+
- skills/swift-concurrency.md
|
|
15
|
+
- skills/swift-actor-persistence.md
|
|
16
|
+
- skills/swift-protocol-di-testing.md
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: swift-actor-persistence
|
|
3
|
+
description: Thread-safe data persistence in Swift using actors — in-memory cache with file-backed storage, eliminating data races by design.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Swift Actors for Thread-Safe Persistence
|
|
7
|
+
|
|
8
|
+
Patterns for building thread-safe data persistence layers using Swift actors. Combines in-memory caching with file-backed storage, leveraging the actor model to eliminate data races at compile time.
|
|
9
|
+
|
|
10
|
+
## When to Activate
|
|
11
|
+
|
|
12
|
+
- Building a data persistence layer in Swift 5.5+
|
|
13
|
+
- Need thread-safe access to shared mutable state
|
|
14
|
+
- Want to eliminate manual synchronization (locks, DispatchQueues)
|
|
15
|
+
- Building offline-first apps with local storage
|
|
16
|
+
|
|
17
|
+
## Core Pattern
|
|
18
|
+
|
|
19
|
+
### Actor-Based Repository
|
|
20
|
+
|
|
21
|
+
The actor model guarantees serialized access — no data races, enforced by the compiler.
|
|
22
|
+
|
|
23
|
+
```swift
|
|
24
|
+
public actor LocalRepository<T: Codable & Identifiable> where T.ID == String {
|
|
25
|
+
private var cache: [String: T] = [:]
|
|
26
|
+
private let fileURL: URL
|
|
27
|
+
|
|
28
|
+
public init(directory: URL = .documentsDirectory, filename: String = "data.json") {
|
|
29
|
+
self.fileURL = directory.appendingPathComponent(filename)
|
|
30
|
+
// Synchronous load during init (actor isolation not yet active)
|
|
31
|
+
self.cache = Self.loadSynchronously(from: fileURL)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// MARK: - Public API
|
|
35
|
+
|
|
36
|
+
public func save(_ item: T) throws {
|
|
37
|
+
cache[item.id] = item
|
|
38
|
+
try persistToFile()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public func delete(_ id: String) throws {
|
|
42
|
+
cache[id] = nil
|
|
43
|
+
try persistToFile()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public func find(by id: String) -> T? {
|
|
47
|
+
cache[id]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public func loadAll() -> [T] {
|
|
51
|
+
Array(cache.values)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// MARK: - Private
|
|
55
|
+
|
|
56
|
+
private func persistToFile() throws {
|
|
57
|
+
let data = try JSONEncoder().encode(Array(cache.values))
|
|
58
|
+
try data.write(to: fileURL, options: .atomic)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private static func loadSynchronously(from url: URL) -> [String: T] {
|
|
62
|
+
guard let data = try? Data(contentsOf: url),
|
|
63
|
+
let items = try? JSONDecoder().decode([T].self, from: data) else {
|
|
64
|
+
return [:]
|
|
65
|
+
}
|
|
66
|
+
return Dictionary(uniqueKeysWithValues: items.map { ($0.id, $0) })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Usage
|
|
72
|
+
|
|
73
|
+
All calls are automatically async due to actor isolation:
|
|
74
|
+
|
|
75
|
+
```swift
|
|
76
|
+
let repository = LocalRepository<Question>()
|
|
77
|
+
|
|
78
|
+
// Read — fast O(1) lookup from in-memory cache
|
|
79
|
+
let question = await repository.find(by: "q-001")
|
|
80
|
+
let allQuestions = await repository.loadAll()
|
|
81
|
+
|
|
82
|
+
// Write — updates cache and persists to file atomically
|
|
83
|
+
try await repository.save(newQuestion)
|
|
84
|
+
try await repository.delete("q-001")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Combining with @Observable ViewModel
|
|
88
|
+
|
|
89
|
+
```swift
|
|
90
|
+
@Observable
|
|
91
|
+
final class QuestionListViewModel {
|
|
92
|
+
private(set) var questions: [Question] = []
|
|
93
|
+
private let repository: LocalRepository<Question>
|
|
94
|
+
|
|
95
|
+
init(repository: LocalRepository<Question> = LocalRepository()) {
|
|
96
|
+
self.repository = repository
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
func load() async {
|
|
100
|
+
questions = await repository.loadAll()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func add(_ question: Question) async throws {
|
|
104
|
+
try await repository.save(question)
|
|
105
|
+
questions = await repository.loadAll()
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Key Design Decisions
|
|
111
|
+
|
|
112
|
+
| Decision | Rationale |
|
|
113
|
+
|----------|-----------|
|
|
114
|
+
| Actor (not class + lock) | Compiler-enforced thread safety, no manual synchronization |
|
|
115
|
+
| In-memory cache + file persistence | Fast reads from cache, durable writes to disk |
|
|
116
|
+
| Synchronous init loading | Avoids async initialization complexity |
|
|
117
|
+
| Dictionary keyed by ID | O(1) lookups by identifier |
|
|
118
|
+
| Generic over `Codable & Identifiable` | Reusable across any model type |
|
|
119
|
+
| Atomic file writes (`.atomic`) | Prevents partial writes on crash |
|
|
120
|
+
|
|
121
|
+
## Best Practices
|
|
122
|
+
|
|
123
|
+
- **Use `Sendable` types** for all data crossing actor boundaries
|
|
124
|
+
- **Keep the actor's public API minimal** — only expose domain operations, not persistence details
|
|
125
|
+
- **Use `.atomic` writes** to prevent data corruption if the app crashes mid-write
|
|
126
|
+
- **Load synchronously in `init`** — async initializers add complexity with minimal benefit for local files
|
|
127
|
+
- **Combine with `@Observable`** ViewModels for reactive UI updates
|
|
128
|
+
|
|
129
|
+
## Anti-Patterns to Avoid
|
|
130
|
+
|
|
131
|
+
- Using `DispatchQueue` or `NSLock` instead of actors for new Swift concurrency code
|
|
132
|
+
- Exposing the internal cache dictionary to external callers
|
|
133
|
+
- Making the file URL configurable without validation
|
|
134
|
+
- Forgetting that all actor method calls are `await` — callers must handle async context
|
|
135
|
+
- Using `nonisolated` to bypass actor isolation (defeats the purpose)
|
|
136
|
+
|
|
137
|
+
## When to Use
|
|
138
|
+
|
|
139
|
+
- Local data storage in iOS/macOS apps (user data, settings, cached content)
|
|
140
|
+
- Offline-first architectures that sync to a server later
|
|
141
|
+
- Any shared mutable state that multiple parts of the app access concurrently
|
|
142
|
+
- Replacing legacy `DispatchQueue`-based thread safety with modern Swift concurrency
|