@vibecheckai/cli 3.5.0 → 3.5.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/bin/registry.js +214 -237
- package/bin/runners/cli-utils.js +33 -2
- package/bin/runners/context/analyzer.js +52 -1
- package/bin/runners/context/generators/cursor.js +2 -49
- package/bin/runners/context/git-context.js +3 -1
- package/bin/runners/context/team-conventions.js +33 -7
- package/bin/runners/lib/analysis-core.js +25 -5
- package/bin/runners/lib/analyzers.js +431 -481
- package/bin/runners/lib/default-config.js +127 -0
- package/bin/runners/lib/doctor/modules/security.js +3 -1
- package/bin/runners/lib/engine/ast-cache.js +210 -0
- package/bin/runners/lib/engine/auth-extractor.js +211 -0
- package/bin/runners/lib/engine/billing-extractor.js +112 -0
- package/bin/runners/lib/engine/enforcement-extractor.js +100 -0
- package/bin/runners/lib/engine/env-extractor.js +207 -0
- package/bin/runners/lib/engine/express-extractor.js +208 -0
- package/bin/runners/lib/engine/extractors.js +849 -0
- package/bin/runners/lib/engine/index.js +207 -0
- package/bin/runners/lib/engine/repo-index.js +514 -0
- package/bin/runners/lib/engine/types.js +124 -0
- package/bin/runners/lib/engines/accessibility-engine.js +18 -218
- package/bin/runners/lib/engines/api-consistency-engine.js +30 -335
- package/bin/runners/lib/engines/cross-file-analysis-engine.js +27 -292
- package/bin/runners/lib/engines/empty-catch-engine.js +17 -127
- package/bin/runners/lib/engines/mock-data-engine.js +10 -53
- package/bin/runners/lib/engines/performance-issues-engine.js +36 -176
- package/bin/runners/lib/engines/security-vulnerabilities-engine.js +54 -382
- package/bin/runners/lib/engines/type-aware-engine.js +39 -263
- package/bin/runners/lib/engines/vibecheck-engines/index.js +13 -122
- package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +291 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +83 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +198 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +275 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +167 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +73 -373
- package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +140 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +234 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +78 -0
- package/bin/runners/lib/entitlements-v2.js +73 -97
- package/bin/runners/lib/error-handler.js +44 -3
- package/bin/runners/lib/error-messages.js +289 -0
- package/bin/runners/lib/evidence-pack.js +7 -1
- package/bin/runners/lib/finding-id.js +69 -0
- package/bin/runners/lib/finding-sorter.js +89 -0
- package/bin/runners/lib/html-proof-report.js +700 -350
- package/bin/runners/lib/missions/plan.js +6 -46
- package/bin/runners/lib/missions/templates.js +0 -232
- package/bin/runners/lib/next-action.js +560 -0
- package/bin/runners/lib/prerequisites.js +149 -0
- package/bin/runners/lib/route-detection.js +137 -68
- package/bin/runners/lib/scan-output.js +91 -76
- package/bin/runners/lib/scan-runner.js +135 -0
- package/bin/runners/lib/schemas/ajv-validator.js +464 -0
- package/bin/runners/lib/schemas/error-envelope.schema.json +105 -0
- package/bin/runners/lib/schemas/finding-v3.schema.json +151 -0
- package/bin/runners/lib/schemas/report-artifact.schema.json +120 -0
- package/bin/runners/lib/schemas/run-request.schema.json +108 -0
- package/bin/runners/lib/schemas/validator.js +27 -0
- package/bin/runners/lib/schemas/verdict.schema.json +140 -0
- package/bin/runners/lib/ship-output-enterprise.js +23 -23
- package/bin/runners/lib/ship-output.js +75 -31
- package/bin/runners/lib/terminal-ui.js +6 -113
- package/bin/runners/lib/truth.js +351 -10
- package/bin/runners/lib/unified-cli-output.js +430 -603
- package/bin/runners/lib/unified-output.js +13 -9
- package/bin/runners/runAIAgent.js +10 -5
- package/bin/runners/runAgent.js +0 -3
- package/bin/runners/runAllowlist.js +389 -0
- package/bin/runners/runApprove.js +0 -33
- package/bin/runners/runAuth.js +73 -45
- package/bin/runners/runCheckpoint.js +51 -11
- package/bin/runners/runClassify.js +85 -21
- package/bin/runners/runContext.js +0 -3
- package/bin/runners/runDoctor.js +41 -28
- package/bin/runners/runEvidencePack.js +362 -0
- package/bin/runners/runFirewall.js +0 -3
- package/bin/runners/runFirewallHook.js +0 -3
- package/bin/runners/runFix.js +66 -76
- package/bin/runners/runGuard.js +18 -411
- package/bin/runners/runInit.js +113 -30
- package/bin/runners/runLabs.js +424 -0
- package/bin/runners/runMcp.js +19 -25
- package/bin/runners/runPolish.js +64 -240
- package/bin/runners/runPromptFirewall.js +12 -5
- package/bin/runners/runProve.js +57 -22
- package/bin/runners/runQuickstart.js +531 -0
- package/bin/runners/runReality.js +59 -68
- package/bin/runners/runReport.js +38 -33
- package/bin/runners/runRuntime.js +8 -5
- package/bin/runners/runScan.js +1413 -190
- package/bin/runners/runShip.js +113 -719
- package/bin/runners/runTruth.js +0 -3
- package/bin/runners/runValidate.js +13 -9
- package/bin/runners/runWatch.js +23 -14
- package/bin/scan.js +6 -1
- package/bin/vibecheck.js +204 -185
- package/mcp-server/deprecation-middleware.js +282 -0
- package/mcp-server/handlers/index.ts +15 -0
- package/mcp-server/handlers/tool-handler.ts +554 -0
- package/mcp-server/index-v1.js +698 -0
- package/mcp-server/index.js +210 -238
- package/mcp-server/lib/cache-wrapper.cjs +383 -0
- package/mcp-server/lib/error-envelope.js +138 -0
- package/mcp-server/lib/executor.ts +499 -0
- package/mcp-server/lib/index.ts +19 -0
- package/mcp-server/lib/rate-limiter.js +166 -0
- package/mcp-server/lib/sandbox.test.ts +519 -0
- package/mcp-server/lib/sandbox.ts +395 -0
- package/mcp-server/lib/types.ts +267 -0
- package/mcp-server/package.json +12 -3
- package/mcp-server/registry/tool-registry.js +794 -0
- package/mcp-server/registry/tools.json +605 -0
- package/mcp-server/registry.test.ts +334 -0
- package/mcp-server/tests/tier-gating.test.js +297 -0
- package/mcp-server/tier-auth.js +378 -45
- package/mcp-server/tools-v3.js +353 -442
- package/mcp-server/tsconfig.json +37 -0
- package/mcp-server/vibecheck-2.0-tools.js +14 -1
- package/package.json +1 -1
- package/bin/runners/lib/agent-firewall/learning/learning-engine.js +0 -849
- package/bin/runners/lib/audit-logger.js +0 -532
- package/bin/runners/lib/authority/authorities/architecture.js +0 -364
- package/bin/runners/lib/authority/authorities/compliance.js +0 -341
- package/bin/runners/lib/authority/authorities/human.js +0 -343
- package/bin/runners/lib/authority/authorities/quality.js +0 -420
- package/bin/runners/lib/authority/authorities/security.js +0 -228
- package/bin/runners/lib/authority/index.js +0 -293
- package/bin/runners/lib/bundle/bundle-intelligence.js +0 -846
- package/bin/runners/lib/cli-charts.js +0 -368
- package/bin/runners/lib/cli-config-display.js +0 -405
- package/bin/runners/lib/cli-demo.js +0 -275
- package/bin/runners/lib/cli-errors.js +0 -438
- package/bin/runners/lib/cli-help-formatter.js +0 -439
- package/bin/runners/lib/cli-interactive-menu.js +0 -509
- package/bin/runners/lib/cli-prompts.js +0 -441
- package/bin/runners/lib/cli-scan-cards.js +0 -362
- package/bin/runners/lib/compliance-reporter.js +0 -710
- package/bin/runners/lib/conductor/index.js +0 -671
- package/bin/runners/lib/easy/README.md +0 -123
- package/bin/runners/lib/easy/index.js +0 -140
- package/bin/runners/lib/easy/interactive-wizard.js +0 -788
- package/bin/runners/lib/easy/one-click-firewall.js +0 -564
- package/bin/runners/lib/easy/zero-config-reality.js +0 -714
- package/bin/runners/lib/engines/async-patterns-engine.js +0 -444
- package/bin/runners/lib/engines/bundle-size-engine.js +0 -433
- package/bin/runners/lib/engines/confidence-scoring.js +0 -276
- package/bin/runners/lib/engines/context-detection.js +0 -264
- package/bin/runners/lib/engines/database-patterns-engine.js +0 -429
- package/bin/runners/lib/engines/duplicate-code-engine.js +0 -354
- package/bin/runners/lib/engines/env-variables-engine.js +0 -458
- package/bin/runners/lib/engines/error-handling-engine.js +0 -437
- package/bin/runners/lib/engines/false-positive-prevention.js +0 -630
- package/bin/runners/lib/engines/framework-adapters/index.js +0 -607
- package/bin/runners/lib/engines/framework-detection.js +0 -508
- package/bin/runners/lib/engines/import-order-engine.js +0 -429
- package/bin/runners/lib/engines/naming-conventions-engine.js +0 -544
- package/bin/runners/lib/engines/noise-reduction-engine.js +0 -452
- package/bin/runners/lib/engines/orchestrator.js +0 -334
- package/bin/runners/lib/engines/react-patterns-engine.js +0 -457
- package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +0 -806
- package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +0 -577
- package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +0 -543
- package/bin/runners/lib/engines/vibecheck-engines.js +0 -514
- package/bin/runners/lib/enhanced-features/index.js +0 -305
- package/bin/runners/lib/enhanced-output.js +0 -631
- package/bin/runners/lib/enterprise.js +0 -300
- package/bin/runners/lib/firewall/command-validator.js +0 -351
- package/bin/runners/lib/firewall/config.js +0 -341
- package/bin/runners/lib/firewall/content-validator.js +0 -519
- package/bin/runners/lib/firewall/index.js +0 -101
- package/bin/runners/lib/firewall/path-validator.js +0 -256
- package/bin/runners/lib/intelligence/cross-repo-intelligence.js +0 -817
- package/bin/runners/lib/mcp-utils.js +0 -425
- package/bin/runners/lib/output/index.js +0 -1022
- package/bin/runners/lib/policy-engine.js +0 -652
- package/bin/runners/lib/polish/autofix/accessibility-fixes.js +0 -333
- package/bin/runners/lib/polish/autofix/async-handlers.js +0 -273
- package/bin/runners/lib/polish/autofix/dead-code.js +0 -280
- package/bin/runners/lib/polish/autofix/imports-optimizer.js +0 -344
- package/bin/runners/lib/polish/autofix/index.js +0 -200
- package/bin/runners/lib/polish/autofix/remove-consoles.js +0 -209
- package/bin/runners/lib/polish/autofix/strengthen-types.js +0 -245
- package/bin/runners/lib/polish/backend-checks.js +0 -148
- package/bin/runners/lib/polish/documentation-checks.js +0 -111
- package/bin/runners/lib/polish/frontend-checks.js +0 -168
- package/bin/runners/lib/polish/index.js +0 -71
- package/bin/runners/lib/polish/infrastructure-checks.js +0 -131
- package/bin/runners/lib/polish/library-detection.js +0 -175
- package/bin/runners/lib/polish/performance-checks.js +0 -100
- package/bin/runners/lib/polish/security-checks.js +0 -148
- package/bin/runners/lib/polish/utils.js +0 -203
- package/bin/runners/lib/prompt-builder.js +0 -540
- package/bin/runners/lib/proof-certificate.js +0 -634
- package/bin/runners/lib/reality/accessibility-audit.js +0 -946
- package/bin/runners/lib/reality/api-contract-validator.js +0 -1012
- package/bin/runners/lib/reality/chaos-engineering.js +0 -1084
- package/bin/runners/lib/reality/performance-tracker.js +0 -1077
- package/bin/runners/lib/reality/scenario-generator.js +0 -1404
- package/bin/runners/lib/reality/visual-regression.js +0 -852
- package/bin/runners/lib/reality-profiler.js +0 -717
- package/bin/runners/lib/replay/flight-recorder-viewer.js +0 -1160
- package/bin/runners/lib/review/ai-code-review.js +0 -832
- package/bin/runners/lib/rules/custom-rule-engine.js +0 -985
- package/bin/runners/lib/sbom-generator.js +0 -641
- package/bin/runners/lib/scan-output-enhanced.js +0 -512
- package/bin/runners/lib/security/owasp-scanner.js +0 -939
- package/bin/runners/lib/validators/contract-validator.js +0 -283
- package/bin/runners/lib/validators/dead-export-detector.js +0 -279
- package/bin/runners/lib/validators/dep-audit.js +0 -245
- package/bin/runners/lib/validators/env-validator.js +0 -319
- package/bin/runners/lib/validators/index.js +0 -120
- package/bin/runners/lib/validators/license-checker.js +0 -252
- package/bin/runners/lib/validators/route-validator.js +0 -290
- package/bin/runners/runAuthority.js +0 -528
- package/bin/runners/runConductor.js +0 -772
- package/bin/runners/runContainer.js +0 -366
- package/bin/runners/runEasy.js +0 -410
- package/bin/runners/runIaC.js +0 -372
- package/bin/runners/runVibe.js +0 -791
- package/mcp-server/tools.js +0 -495
|
@@ -1,939 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OWASP Security Scanner
|
|
3
|
-
*
|
|
4
|
-
* ═══════════════════════════════════════════════════════════════════════════════
|
|
5
|
-
* COMPETITIVE MOAT FEATURE - OWASP Top 10 Vulnerability Detection
|
|
6
|
-
* ═══════════════════════════════════════════════════════════════════════════════
|
|
7
|
-
*
|
|
8
|
-
* This engine scans code for the OWASP Top 10 web application security risks.
|
|
9
|
-
* It provides both static analysis and runtime detection.
|
|
10
|
-
*
|
|
11
|
-
* OWASP Top 10 (2021):
|
|
12
|
-
* A01:2021 - Broken Access Control
|
|
13
|
-
* A02:2021 - Cryptographic Failures
|
|
14
|
-
* A03:2021 - Injection
|
|
15
|
-
* A04:2021 - Insecure Design
|
|
16
|
-
* A05:2021 - Security Misconfiguration
|
|
17
|
-
* A06:2021 - Vulnerable Components
|
|
18
|
-
* A07:2021 - Authentication Failures
|
|
19
|
-
* A08:2021 - Data Integrity Failures
|
|
20
|
-
* A09:2021 - Security Logging Failures
|
|
21
|
-
* A10:2021 - Server-Side Request Forgery
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
"use strict";
|
|
25
|
-
|
|
26
|
-
const fs = require("fs");
|
|
27
|
-
const path = require("path");
|
|
28
|
-
const crypto = require("crypto");
|
|
29
|
-
|
|
30
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
31
|
-
// OWASP TOP 10 RULES
|
|
32
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
33
|
-
|
|
34
|
-
const OWASP_RULES = {
|
|
35
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
36
|
-
// A01:2021 - BROKEN ACCESS CONTROL
|
|
37
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
38
|
-
"A01": {
|
|
39
|
-
id: "A01",
|
|
40
|
-
name: "Broken Access Control",
|
|
41
|
-
description: "Restrictions on authenticated users are not properly enforced",
|
|
42
|
-
cwe: ["CWE-22", "CWE-284", "CWE-285", "CWE-352", "CWE-639"],
|
|
43
|
-
rules: [
|
|
44
|
-
{
|
|
45
|
-
id: "A01-path-traversal",
|
|
46
|
-
name: "Path Traversal",
|
|
47
|
-
severity: "critical",
|
|
48
|
-
patterns: [
|
|
49
|
-
/path\.join\([^)]*req\.(params|query|body)\./,
|
|
50
|
-
/fs\.(readFile|writeFile|unlink).*req\.(params|query|body)/,
|
|
51
|
-
/\.\.\/|\.\.\\|%2e%2e%2f/i
|
|
52
|
-
],
|
|
53
|
-
message: "Potential path traversal vulnerability - user input used in file path",
|
|
54
|
-
fix: "Validate and sanitize file paths, use path.normalize() and check against base directory"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
id: "A01-idor",
|
|
58
|
-
name: "Insecure Direct Object Reference",
|
|
59
|
-
severity: "high",
|
|
60
|
-
patterns: [
|
|
61
|
-
/findById\s*\(\s*req\.(params|query)\.id\s*\)/,
|
|
62
|
-
/where\s*:\s*\{\s*id\s*:\s*req\.params\.id\s*\}/,
|
|
63
|
-
/\/users\/\$\{.*id.*\}/
|
|
64
|
-
],
|
|
65
|
-
message: "Potential IDOR - object accessed directly by user-supplied ID without authorization",
|
|
66
|
-
fix: "Verify user has permission to access the requested resource"
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
id: "A01-missing-auth-check",
|
|
70
|
-
name: "Missing Authorization Check",
|
|
71
|
-
severity: "high",
|
|
72
|
-
patterns: [
|
|
73
|
-
/router\.(get|post|put|delete)\s*\(\s*['"][^'"]*admin[^'"]*['"]\s*,\s*(?!.*auth)/,
|
|
74
|
-
/app\.(get|post|put|delete)\s*\(\s*['"][^'"]*\/api\/[^'"]*['"]\s*,\s*async\s*\(req/
|
|
75
|
-
],
|
|
76
|
-
negativePatterns: [/auth|protect|verify|middleware|guard|check/i],
|
|
77
|
-
message: "Route may be missing authorization middleware",
|
|
78
|
-
fix: "Add authentication/authorization middleware to protected routes"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
id: "A01-csrf",
|
|
82
|
-
name: "Missing CSRF Protection",
|
|
83
|
-
severity: "high",
|
|
84
|
-
patterns: [
|
|
85
|
-
/app\.post\s*\([^)]*(?!csrf|csrfProtection)/,
|
|
86
|
-
/<form[^>]*method=['"]post['"][^>]*(?!.*csrf)/i
|
|
87
|
-
],
|
|
88
|
-
filePatterns: [/\.tsx?$/, /\.jsx?$/],
|
|
89
|
-
message: "POST endpoint may lack CSRF protection",
|
|
90
|
-
fix: "Implement CSRF tokens for state-changing operations"
|
|
91
|
-
}
|
|
92
|
-
]
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
96
|
-
// A02:2021 - CRYPTOGRAPHIC FAILURES
|
|
97
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
98
|
-
"A02": {
|
|
99
|
-
id: "A02",
|
|
100
|
-
name: "Cryptographic Failures",
|
|
101
|
-
description: "Failures related to cryptography which often leads to sensitive data exposure",
|
|
102
|
-
cwe: ["CWE-261", "CWE-296", "CWE-310", "CWE-327", "CWE-328"],
|
|
103
|
-
rules: [
|
|
104
|
-
{
|
|
105
|
-
id: "A02-weak-hash",
|
|
106
|
-
name: "Weak Hashing Algorithm",
|
|
107
|
-
severity: "critical",
|
|
108
|
-
patterns: [
|
|
109
|
-
/createHash\(['"](?:md5|sha1)['"]\)/,
|
|
110
|
-
/crypto\.(?:MD5|SHA1)\(/,
|
|
111
|
-
/\.digest\(['"](?:md5|sha1)['"]\)/i
|
|
112
|
-
],
|
|
113
|
-
message: "Weak hashing algorithm (MD5/SHA1) - use SHA-256 or stronger",
|
|
114
|
-
fix: "Replace with crypto.createHash('sha256') or bcrypt for passwords"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
id: "A02-hardcoded-key",
|
|
118
|
-
name: "Hardcoded Cryptographic Key",
|
|
119
|
-
severity: "critical",
|
|
120
|
-
patterns: [
|
|
121
|
-
/(?:secret|key|password|token)\s*[:=]\s*['"][A-Za-z0-9+/=]{16,}['"]/i,
|
|
122
|
-
/createCipheriv\([^,]+,\s*['"][^'"]+['"]/,
|
|
123
|
-
/jwt\.sign\([^,]+,\s*['"][^'"]{8,}['"]/
|
|
124
|
-
],
|
|
125
|
-
message: "Hardcoded cryptographic key or secret",
|
|
126
|
-
fix: "Move secrets to environment variables or secure key management"
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
id: "A02-insecure-random",
|
|
130
|
-
name: "Insecure Random Number Generator",
|
|
131
|
-
severity: "high",
|
|
132
|
-
patterns: [
|
|
133
|
-
/Math\.random\(\)/,
|
|
134
|
-
/Math\.floor\(Math\.random\(\)/
|
|
135
|
-
],
|
|
136
|
-
context: /password|token|key|secret|session|auth|crypto/i,
|
|
137
|
-
message: "Math.random() is not cryptographically secure",
|
|
138
|
-
fix: "Use crypto.randomBytes() or crypto.randomUUID() for security-sensitive operations"
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
id: "A02-cleartext-storage",
|
|
142
|
-
name: "Cleartext Password Storage",
|
|
143
|
-
severity: "critical",
|
|
144
|
-
patterns: [
|
|
145
|
-
/password\s*[:=]\s*(?:req\.body\.password|user\.password)/,
|
|
146
|
-
/\.create\(\s*\{[^}]*password\s*:\s*(?!.*(?:hash|bcrypt|argon))/
|
|
147
|
-
],
|
|
148
|
-
message: "Password may be stored in cleartext",
|
|
149
|
-
fix: "Hash passwords with bcrypt or argon2 before storage"
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
id: "A02-http-sensitive",
|
|
153
|
-
name: "Sensitive Data Over HTTP",
|
|
154
|
-
severity: "high",
|
|
155
|
-
patterns: [
|
|
156
|
-
/http:\/\/(?!localhost|127\.0\.0\.1)[^/]*\/(?:api|auth|login|payment)/i,
|
|
157
|
-
/fetch\s*\(\s*['"]http:\/\/(?!localhost)/
|
|
158
|
-
],
|
|
159
|
-
message: "Sensitive endpoint using HTTP instead of HTTPS",
|
|
160
|
-
fix: "Use HTTPS for all sensitive data transmission"
|
|
161
|
-
}
|
|
162
|
-
]
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
166
|
-
// A03:2021 - INJECTION
|
|
167
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
168
|
-
"A03": {
|
|
169
|
-
id: "A03",
|
|
170
|
-
name: "Injection",
|
|
171
|
-
description: "User-supplied data is not validated, filtered, or sanitized",
|
|
172
|
-
cwe: ["CWE-20", "CWE-74", "CWE-79", "CWE-89", "CWE-94"],
|
|
173
|
-
rules: [
|
|
174
|
-
{
|
|
175
|
-
id: "A03-sql-injection",
|
|
176
|
-
name: "SQL Injection",
|
|
177
|
-
severity: "critical",
|
|
178
|
-
patterns: [
|
|
179
|
-
/query\s*\(\s*[`'"].*\$\{.*\}.*[`'"]/,
|
|
180
|
-
/execute\s*\(\s*[`'"].*\+.*req\.(body|query|params)/,
|
|
181
|
-
/raw\s*\(\s*[`'"].*\$\{.*req\./
|
|
182
|
-
],
|
|
183
|
-
message: "Potential SQL injection - user input in SQL query",
|
|
184
|
-
fix: "Use parameterized queries or prepared statements"
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
id: "A03-nosql-injection",
|
|
188
|
-
name: "NoSQL Injection",
|
|
189
|
-
severity: "critical",
|
|
190
|
-
patterns: [
|
|
191
|
-
/\.\$where\s*:/,
|
|
192
|
-
/find\s*\(\s*\{\s*\$where/,
|
|
193
|
-
/\{\s*['"]?\$(?:where|regex|or|and|ne|gt|lt)['"]?\s*:/
|
|
194
|
-
],
|
|
195
|
-
message: "Potential NoSQL injection",
|
|
196
|
-
fix: "Validate and sanitize input, avoid $where operator"
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
id: "A03-xss",
|
|
200
|
-
name: "Cross-Site Scripting (XSS)",
|
|
201
|
-
severity: "high",
|
|
202
|
-
patterns: [
|
|
203
|
-
/innerHTML\s*=\s*(?!['"])/,
|
|
204
|
-
/dangerouslySetInnerHTML\s*=\s*\{\s*\{\s*__html\s*:/,
|
|
205
|
-
/document\.write\s*\(/,
|
|
206
|
-
/v-html\s*=/
|
|
207
|
-
],
|
|
208
|
-
message: "Potential XSS vulnerability - unsafe HTML rendering",
|
|
209
|
-
fix: "Sanitize HTML content or use safe rendering methods"
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
id: "A03-command-injection",
|
|
213
|
-
name: "Command Injection",
|
|
214
|
-
severity: "critical",
|
|
215
|
-
patterns: [
|
|
216
|
-
/exec\s*\(\s*[`'"].*\$\{.*req\./,
|
|
217
|
-
/spawn\s*\(\s*[^,]+,\s*\[.*req\.(body|query|params)/,
|
|
218
|
-
/child_process.*\+.*req\./
|
|
219
|
-
],
|
|
220
|
-
message: "Potential command injection - user input in shell command",
|
|
221
|
-
fix: "Validate input, use allowlists, avoid shell execution"
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
id: "A03-ldap-injection",
|
|
225
|
-
name: "LDAP Injection",
|
|
226
|
-
severity: "critical",
|
|
227
|
-
patterns: [
|
|
228
|
-
/ldap.*search.*\(.*req\.(body|query|params)/i,
|
|
229
|
-
/\((?:uid|cn|sn)=.*\$\{/
|
|
230
|
-
],
|
|
231
|
-
message: "Potential LDAP injection",
|
|
232
|
-
fix: "Escape special LDAP characters in user input"
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
id: "A03-template-injection",
|
|
236
|
-
name: "Template Injection",
|
|
237
|
-
severity: "critical",
|
|
238
|
-
patterns: [
|
|
239
|
-
/render\s*\(\s*req\.(body|query|params)/,
|
|
240
|
-
/compile\s*\(\s*req\./,
|
|
241
|
-
/\$\{\s*eval\s*\(/
|
|
242
|
-
],
|
|
243
|
-
message: "Potential server-side template injection",
|
|
244
|
-
fix: "Never pass user input directly to template engines"
|
|
245
|
-
}
|
|
246
|
-
]
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
250
|
-
// A04:2021 - INSECURE DESIGN
|
|
251
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
252
|
-
"A04": {
|
|
253
|
-
id: "A04",
|
|
254
|
-
name: "Insecure Design",
|
|
255
|
-
description: "Missing or ineffective security controls in design",
|
|
256
|
-
cwe: ["CWE-209", "CWE-256", "CWE-501", "CWE-522"],
|
|
257
|
-
rules: [
|
|
258
|
-
{
|
|
259
|
-
id: "A04-no-rate-limit",
|
|
260
|
-
name: "Missing Rate Limiting",
|
|
261
|
-
severity: "medium",
|
|
262
|
-
patterns: [
|
|
263
|
-
/router\.post\s*\(\s*['"][^'"]*(?:login|auth|register|password)[^'"]*['"]/
|
|
264
|
-
],
|
|
265
|
-
negativePatterns: [/rateLimit|rateLimiter|throttle|slowDown/],
|
|
266
|
-
message: "Authentication endpoint may lack rate limiting",
|
|
267
|
-
fix: "Add rate limiting to prevent brute force attacks"
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
id: "A04-mass-assignment",
|
|
271
|
-
name: "Mass Assignment",
|
|
272
|
-
severity: "high",
|
|
273
|
-
patterns: [
|
|
274
|
-
/\.create\s*\(\s*req\.body\s*\)/,
|
|
275
|
-
/\.update\s*\(\s*req\.body\s*\)/,
|
|
276
|
-
/Object\.assign\s*\([^,]+,\s*req\.body\s*\)/,
|
|
277
|
-
/\{\s*\.\.\.req\.body\s*\}/
|
|
278
|
-
],
|
|
279
|
-
message: "Potential mass assignment vulnerability",
|
|
280
|
-
fix: "Explicitly pick allowed fields from request body"
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
id: "A04-verbose-errors",
|
|
284
|
-
name: "Verbose Error Messages",
|
|
285
|
-
severity: "medium",
|
|
286
|
-
patterns: [
|
|
287
|
-
/res\.(?:status|json|send)\s*\([^)]*error\.stack/,
|
|
288
|
-
/res\.(?:status|json|send)\s*\([^)]*error\.message/,
|
|
289
|
-
/catch\s*\([^)]*\)\s*\{\s*res\.send\s*\(\s*\w+\s*\)/
|
|
290
|
-
],
|
|
291
|
-
message: "Detailed error messages may leak sensitive information",
|
|
292
|
-
fix: "Return generic error messages in production"
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
id: "A04-unrestricted-upload",
|
|
296
|
-
name: "Unrestricted File Upload",
|
|
297
|
-
severity: "high",
|
|
298
|
-
patterns: [
|
|
299
|
-
/multer\s*\(\s*\{(?!.*fileFilter)/,
|
|
300
|
-
/upload\.(?:single|array|fields)\s*\(/
|
|
301
|
-
],
|
|
302
|
-
negativePatterns: [/fileFilter|limits|whitelist|allowedTypes/],
|
|
303
|
-
message: "File upload may lack proper restrictions",
|
|
304
|
-
fix: "Validate file type, size, and name"
|
|
305
|
-
}
|
|
306
|
-
]
|
|
307
|
-
},
|
|
308
|
-
|
|
309
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
310
|
-
// A05:2021 - SECURITY MISCONFIGURATION
|
|
311
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
312
|
-
"A05": {
|
|
313
|
-
id: "A05",
|
|
314
|
-
name: "Security Misconfiguration",
|
|
315
|
-
description: "Missing security hardening or improperly configured permissions",
|
|
316
|
-
cwe: ["CWE-16", "CWE-209", "CWE-548"],
|
|
317
|
-
rules: [
|
|
318
|
-
{
|
|
319
|
-
id: "A05-debug-enabled",
|
|
320
|
-
name: "Debug Mode Enabled",
|
|
321
|
-
severity: "high",
|
|
322
|
-
patterns: [
|
|
323
|
-
/DEBUG\s*[:=]\s*(?:true|1|['"]true['"])/i,
|
|
324
|
-
/\.set\s*\(\s*['"]debug['"]\s*,\s*true\s*\)/,
|
|
325
|
-
/NODE_ENV\s*[:=]\s*['"]development['"]/
|
|
326
|
-
],
|
|
327
|
-
filePatterns: [/\.env\.prod|config.*prod|production/i],
|
|
328
|
-
message: "Debug mode may be enabled in production",
|
|
329
|
-
fix: "Ensure DEBUG is disabled and NODE_ENV is 'production'"
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
id: "A05-cors-wildcard",
|
|
333
|
-
name: "CORS Wildcard",
|
|
334
|
-
severity: "high",
|
|
335
|
-
patterns: [
|
|
336
|
-
/cors\s*\(\s*\{\s*origin\s*:\s*['"]\*['"]/,
|
|
337
|
-
/Access-Control-Allow-Origin['"]\s*,\s*['"]\*/,
|
|
338
|
-
/origin\s*:\s*true/
|
|
339
|
-
],
|
|
340
|
-
message: "CORS allows all origins",
|
|
341
|
-
fix: "Restrict CORS to specific trusted origins"
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
id: "A05-helmet-missing",
|
|
345
|
-
name: "Missing Security Headers",
|
|
346
|
-
severity: "medium",
|
|
347
|
-
patterns: [
|
|
348
|
-
/app\.use\s*\(\s*express\s*\(/
|
|
349
|
-
],
|
|
350
|
-
negativePatterns: [/helmet|security-headers/],
|
|
351
|
-
message: "Express app may be missing security headers",
|
|
352
|
-
fix: "Use helmet middleware for security headers"
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
id: "A05-default-credentials",
|
|
356
|
-
name: "Default Credentials",
|
|
357
|
-
severity: "critical",
|
|
358
|
-
patterns: [
|
|
359
|
-
/(?:password|pwd)\s*[:=]\s*['"](?:admin|password|123456|default|root)['"]/i,
|
|
360
|
-
/(?:username|user)\s*[:=]\s*['"](?:admin|root|user)['"]/i
|
|
361
|
-
],
|
|
362
|
-
message: "Possible default or weak credentials",
|
|
363
|
-
fix: "Use strong, unique credentials"
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
id: "A05-exposed-stack",
|
|
367
|
-
name: "Exposed Stack Trace",
|
|
368
|
-
severity: "medium",
|
|
369
|
-
patterns: [
|
|
370
|
-
/res\.(?:send|json)\s*\(\s*(?:err|error)\.stack/,
|
|
371
|
-
/console\.(?:log|error)\s*\(\s*(?:err|error)\.stack/
|
|
372
|
-
],
|
|
373
|
-
message: "Stack traces may be exposed to clients",
|
|
374
|
-
fix: "Hide stack traces in production responses"
|
|
375
|
-
}
|
|
376
|
-
]
|
|
377
|
-
},
|
|
378
|
-
|
|
379
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
380
|
-
// A06:2021 - VULNERABLE COMPONENTS
|
|
381
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
382
|
-
"A06": {
|
|
383
|
-
id: "A06",
|
|
384
|
-
name: "Vulnerable and Outdated Components",
|
|
385
|
-
description: "Using components with known vulnerabilities",
|
|
386
|
-
cwe: ["CWE-937", "CWE-1035", "CWE-1104"],
|
|
387
|
-
rules: [
|
|
388
|
-
{
|
|
389
|
-
id: "A06-outdated-package",
|
|
390
|
-
name: "Outdated Package",
|
|
391
|
-
severity: "medium",
|
|
392
|
-
checkDependencies: true,
|
|
393
|
-
message: "Package may have known vulnerabilities",
|
|
394
|
-
fix: "Run npm audit and update vulnerable packages"
|
|
395
|
-
},
|
|
396
|
-
{
|
|
397
|
-
id: "A06-deprecated-api",
|
|
398
|
-
name: "Deprecated API Usage",
|
|
399
|
-
severity: "low",
|
|
400
|
-
patterns: [
|
|
401
|
-
/new\s+Buffer\s*\(/,
|
|
402
|
-
/escape\s*\(/,
|
|
403
|
-
/unescape\s*\(/,
|
|
404
|
-
/\.substr\s*\(/
|
|
405
|
-
],
|
|
406
|
-
message: "Using deprecated API",
|
|
407
|
-
fix: "Use modern alternatives"
|
|
408
|
-
}
|
|
409
|
-
]
|
|
410
|
-
},
|
|
411
|
-
|
|
412
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
413
|
-
// A07:2021 - AUTHENTICATION FAILURES
|
|
414
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
415
|
-
"A07": {
|
|
416
|
-
id: "A07",
|
|
417
|
-
name: "Identification and Authentication Failures",
|
|
418
|
-
description: "Weak or broken authentication mechanisms",
|
|
419
|
-
cwe: ["CWE-287", "CWE-288", "CWE-384", "CWE-521", "CWE-613"],
|
|
420
|
-
rules: [
|
|
421
|
-
{
|
|
422
|
-
id: "A07-weak-password",
|
|
423
|
-
name: "Weak Password Requirements",
|
|
424
|
-
severity: "high",
|
|
425
|
-
patterns: [
|
|
426
|
-
/password\.length\s*[<>=]+\s*[1-7]\b/,
|
|
427
|
-
/minLength\s*:\s*[1-7]\b.*password/i
|
|
428
|
-
],
|
|
429
|
-
message: "Weak password length requirement",
|
|
430
|
-
fix: "Require passwords of at least 8 characters"
|
|
431
|
-
},
|
|
432
|
-
{
|
|
433
|
-
id: "A07-jwt-none",
|
|
434
|
-
name: "JWT Algorithm None",
|
|
435
|
-
severity: "critical",
|
|
436
|
-
patterns: [
|
|
437
|
-
/algorithm\s*:\s*['"]none['"]/i,
|
|
438
|
-
/algorithms\s*:\s*\[.*['"]none['"]/i
|
|
439
|
-
],
|
|
440
|
-
message: "JWT allows 'none' algorithm",
|
|
441
|
-
fix: "Specify explicit algorithms, exclude 'none'"
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
id: "A07-session-fixation",
|
|
445
|
-
name: "Session Fixation Risk",
|
|
446
|
-
severity: "high",
|
|
447
|
-
patterns: [
|
|
448
|
-
/req\.session\s*=\s*\{/
|
|
449
|
-
],
|
|
450
|
-
negativePatterns: [/regenerate|destroy|reset/],
|
|
451
|
-
message: "Session may be vulnerable to fixation",
|
|
452
|
-
fix: "Regenerate session ID after authentication"
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
id: "A07-credential-logging",
|
|
456
|
-
name: "Credential Logging",
|
|
457
|
-
severity: "critical",
|
|
458
|
-
patterns: [
|
|
459
|
-
/console\.(?:log|info|debug)\s*\([^)]*(?:password|token|secret|key|credential)/i,
|
|
460
|
-
/logger\.(?:log|info|debug)\s*\([^)]*(?:password|token|secret)/i
|
|
461
|
-
],
|
|
462
|
-
message: "Credentials may be logged",
|
|
463
|
-
fix: "Never log sensitive credentials"
|
|
464
|
-
},
|
|
465
|
-
{
|
|
466
|
-
id: "A07-insecure-cookie",
|
|
467
|
-
name: "Insecure Cookie Settings",
|
|
468
|
-
severity: "high",
|
|
469
|
-
patterns: [
|
|
470
|
-
/cookie\s*:\s*\{(?!.*secure\s*:\s*true)/,
|
|
471
|
-
/cookie\s*:\s*\{(?!.*httpOnly\s*:\s*true)/,
|
|
472
|
-
/res\.cookie\s*\([^)]+\)(?!.*secure)/
|
|
473
|
-
],
|
|
474
|
-
message: "Cookie may lack secure settings",
|
|
475
|
-
fix: "Set secure, httpOnly, and sameSite cookie flags"
|
|
476
|
-
}
|
|
477
|
-
]
|
|
478
|
-
},
|
|
479
|
-
|
|
480
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
481
|
-
// A08:2021 - DATA INTEGRITY FAILURES
|
|
482
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
483
|
-
"A08": {
|
|
484
|
-
id: "A08",
|
|
485
|
-
name: "Software and Data Integrity Failures",
|
|
486
|
-
description: "Code and infrastructure without integrity verification",
|
|
487
|
-
cwe: ["CWE-345", "CWE-353", "CWE-426", "CWE-494", "CWE-502"],
|
|
488
|
-
rules: [
|
|
489
|
-
{
|
|
490
|
-
id: "A08-unsafe-deserialization",
|
|
491
|
-
name: "Unsafe Deserialization",
|
|
492
|
-
severity: "critical",
|
|
493
|
-
patterns: [
|
|
494
|
-
/JSON\.parse\s*\(\s*(?:req\.body|userInput|data)/,
|
|
495
|
-
/unserialize\s*\(/,
|
|
496
|
-
/pickle\.loads?\s*\(/,
|
|
497
|
-
/yaml\.load\s*\(/
|
|
498
|
-
],
|
|
499
|
-
message: "Unsafe deserialization of user input",
|
|
500
|
-
fix: "Validate and sanitize before deserialization"
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
id: "A08-eval-data",
|
|
504
|
-
name: "Eval of External Data",
|
|
505
|
-
severity: "critical",
|
|
506
|
-
patterns: [
|
|
507
|
-
/eval\s*\(\s*(?:req\.|data|input|response)/,
|
|
508
|
-
/new\s+Function\s*\([^)]*(?:req\.|data)/
|
|
509
|
-
],
|
|
510
|
-
message: "Evaluating external data is dangerous",
|
|
511
|
-
fix: "Never use eval() with external data"
|
|
512
|
-
},
|
|
513
|
-
{
|
|
514
|
-
id: "A08-unsigned-update",
|
|
515
|
-
name: "Unsigned Software Updates",
|
|
516
|
-
severity: "high",
|
|
517
|
-
patterns: [
|
|
518
|
-
/auto[_-]?update|self[_-]?update/i
|
|
519
|
-
],
|
|
520
|
-
negativePatterns: [/verify|signature|checksum|hash/i],
|
|
521
|
-
message: "Software update may lack integrity verification",
|
|
522
|
-
fix: "Verify signatures before applying updates"
|
|
523
|
-
}
|
|
524
|
-
]
|
|
525
|
-
},
|
|
526
|
-
|
|
527
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
528
|
-
// A09:2021 - SECURITY LOGGING FAILURES
|
|
529
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
530
|
-
"A09": {
|
|
531
|
-
id: "A09",
|
|
532
|
-
name: "Security Logging and Monitoring Failures",
|
|
533
|
-
description: "Insufficient logging and monitoring",
|
|
534
|
-
cwe: ["CWE-117", "CWE-223", "CWE-532", "CWE-778"],
|
|
535
|
-
rules: [
|
|
536
|
-
{
|
|
537
|
-
id: "A09-no-auth-logging",
|
|
538
|
-
name: "Missing Authentication Logging",
|
|
539
|
-
severity: "medium",
|
|
540
|
-
patterns: [
|
|
541
|
-
/(?:login|authenticate|signin)\s*(?:=|:)\s*async/i
|
|
542
|
-
],
|
|
543
|
-
negativePatterns: [/log|audit|track|record/i],
|
|
544
|
-
message: "Authentication may not be logged",
|
|
545
|
-
fix: "Log authentication attempts with timestamps"
|
|
546
|
-
},
|
|
547
|
-
{
|
|
548
|
-
id: "A09-sensitive-logging",
|
|
549
|
-
name: "Sensitive Data in Logs",
|
|
550
|
-
severity: "high",
|
|
551
|
-
patterns: [
|
|
552
|
-
/(?:logger|console|winston|pino)\.(?:log|info|debug|error)\s*\([^)]*(?:password|credit|ssn|token)/i
|
|
553
|
-
],
|
|
554
|
-
message: "Sensitive data may be logged",
|
|
555
|
-
fix: "Mask or exclude sensitive data from logs"
|
|
556
|
-
},
|
|
557
|
-
{
|
|
558
|
-
id: "A09-log-injection",
|
|
559
|
-
name: "Log Injection",
|
|
560
|
-
severity: "medium",
|
|
561
|
-
patterns: [
|
|
562
|
-
/console\.log\s*\(\s*[`'"].*\$\{.*req\./,
|
|
563
|
-
/logger\.(?:log|info)\s*\(\s*req\.(?:body|params|query)/
|
|
564
|
-
],
|
|
565
|
-
message: "User input in logs may enable log injection",
|
|
566
|
-
fix: "Sanitize user input before logging"
|
|
567
|
-
}
|
|
568
|
-
]
|
|
569
|
-
},
|
|
570
|
-
|
|
571
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
572
|
-
// A10:2021 - SERVER-SIDE REQUEST FORGERY
|
|
573
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
574
|
-
"A10": {
|
|
575
|
-
id: "A10",
|
|
576
|
-
name: "Server-Side Request Forgery (SSRF)",
|
|
577
|
-
description: "Fetching remote resources without validating user input",
|
|
578
|
-
cwe: ["CWE-918"],
|
|
579
|
-
rules: [
|
|
580
|
-
{
|
|
581
|
-
id: "A10-ssrf",
|
|
582
|
-
name: "SSRF Vulnerability",
|
|
583
|
-
severity: "critical",
|
|
584
|
-
patterns: [
|
|
585
|
-
/fetch\s*\(\s*(?:req\.(?:body|query|params)|url|uri)/,
|
|
586
|
-
/axios\.(?:get|post|put)\s*\(\s*(?:req\.(?:body|query)|url)/,
|
|
587
|
-
/request\s*\(\s*(?:req\.(?:body|query)|options\.url)/,
|
|
588
|
-
/http\.(?:get|request)\s*\(\s*(?:req\.|url)/
|
|
589
|
-
],
|
|
590
|
-
message: "Potential SSRF - user input used in server-side request",
|
|
591
|
-
fix: "Validate and allowlist URLs, block internal IPs"
|
|
592
|
-
},
|
|
593
|
-
{
|
|
594
|
-
id: "A10-open-redirect",
|
|
595
|
-
name: "Open Redirect",
|
|
596
|
-
severity: "medium",
|
|
597
|
-
patterns: [
|
|
598
|
-
/res\.redirect\s*\(\s*req\.(?:query|body|params)\.(?:url|redirect|next|return)/,
|
|
599
|
-
/window\.location\s*=\s*(?:params|query|data)\./
|
|
600
|
-
],
|
|
601
|
-
message: "Potential open redirect vulnerability",
|
|
602
|
-
fix: "Validate redirect URLs against allowlist"
|
|
603
|
-
}
|
|
604
|
-
]
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
609
|
-
// OWASP SCANNER ENGINE
|
|
610
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
611
|
-
|
|
612
|
-
class OWASPScanner {
|
|
613
|
-
constructor(options = {}) {
|
|
614
|
-
this.projectRoot = options.projectRoot || process.cwd();
|
|
615
|
-
this.rules = { ...OWASP_RULES };
|
|
616
|
-
this.ignorePaths = options.ignorePaths || [
|
|
617
|
-
"**/node_modules/**",
|
|
618
|
-
"**/dist/**",
|
|
619
|
-
"**/build/**",
|
|
620
|
-
"**/*.test.*",
|
|
621
|
-
"**/*.spec.*",
|
|
622
|
-
"**/test/**",
|
|
623
|
-
"**/tests/**"
|
|
624
|
-
];
|
|
625
|
-
this.results = [];
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Scan a single file
|
|
630
|
-
*/
|
|
631
|
-
scanFile(filePath, content = null) {
|
|
632
|
-
const findings = [];
|
|
633
|
-
|
|
634
|
-
// Read file if content not provided
|
|
635
|
-
if (content === null) {
|
|
636
|
-
const fullPath = path.isAbsolute(filePath)
|
|
637
|
-
? filePath
|
|
638
|
-
: path.join(this.projectRoot, filePath);
|
|
639
|
-
|
|
640
|
-
if (!fs.existsSync(fullPath)) {
|
|
641
|
-
return { file: filePath, findings: [], error: "File not found" };
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
content = fs.readFileSync(fullPath, "utf8");
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
// Apply each category's rules
|
|
648
|
-
for (const [categoryId, category] of Object.entries(this.rules)) {
|
|
649
|
-
for (const rule of category.rules) {
|
|
650
|
-
// Skip dependency checks for now
|
|
651
|
-
if (rule.checkDependencies) continue;
|
|
652
|
-
|
|
653
|
-
// Check file pattern match
|
|
654
|
-
if (rule.filePatterns) {
|
|
655
|
-
const matches = rule.filePatterns.some(p => p.test(filePath));
|
|
656
|
-
if (!matches) continue;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
// Check context if specified
|
|
660
|
-
if (rule.context && !rule.context.test(content)) {
|
|
661
|
-
continue;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
// Check patterns
|
|
665
|
-
for (const pattern of (rule.patterns || [])) {
|
|
666
|
-
const regex = new RegExp(pattern.source, "gm");
|
|
667
|
-
let match;
|
|
668
|
-
|
|
669
|
-
while ((match = regex.exec(content)) !== null) {
|
|
670
|
-
// Check negative patterns (should NOT match)
|
|
671
|
-
if (rule.negativePatterns) {
|
|
672
|
-
const context = content.substring(
|
|
673
|
-
Math.max(0, match.index - 200),
|
|
674
|
-
Math.min(content.length, match.index + match[0].length + 200)
|
|
675
|
-
);
|
|
676
|
-
|
|
677
|
-
const hasNegative = rule.negativePatterns.some(np => np.test(context));
|
|
678
|
-
if (hasNegative) continue;
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
const line = content.substring(0, match.index).split("\n").length;
|
|
682
|
-
|
|
683
|
-
findings.push({
|
|
684
|
-
ruleId: rule.id,
|
|
685
|
-
ruleName: rule.name,
|
|
686
|
-
category: categoryId,
|
|
687
|
-
categoryName: category.name,
|
|
688
|
-
severity: rule.severity,
|
|
689
|
-
file: filePath,
|
|
690
|
-
line,
|
|
691
|
-
match: match[0].substring(0, 100),
|
|
692
|
-
message: rule.message,
|
|
693
|
-
fix: rule.fix,
|
|
694
|
-
cwe: category.cwe?.[0]
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
return {
|
|
702
|
-
file: filePath,
|
|
703
|
-
findings,
|
|
704
|
-
summary: this.summarizeFindings(findings)
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Scan multiple files
|
|
710
|
-
*/
|
|
711
|
-
scanFiles(files) {
|
|
712
|
-
this.results = [];
|
|
713
|
-
|
|
714
|
-
for (const file of files) {
|
|
715
|
-
const filePath = typeof file === "string" ? file : file.path;
|
|
716
|
-
const content = typeof file === "string" ? null : file.content;
|
|
717
|
-
|
|
718
|
-
// Skip ignored paths
|
|
719
|
-
if (this.shouldIgnore(filePath)) continue;
|
|
720
|
-
|
|
721
|
-
const result = this.scanFile(filePath, content);
|
|
722
|
-
|
|
723
|
-
if (result.findings.length > 0) {
|
|
724
|
-
this.results.push(result);
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
return {
|
|
729
|
-
files: this.results,
|
|
730
|
-
totalFindings: this.results.reduce((sum, r) => sum + r.findings.length, 0),
|
|
731
|
-
summary: this.generateOverallSummary()
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
/**
|
|
736
|
-
* Scan entire directory
|
|
737
|
-
*/
|
|
738
|
-
scanDirectory(dirPath = this.projectRoot) {
|
|
739
|
-
const files = this.collectFiles(dirPath);
|
|
740
|
-
return this.scanFiles(files);
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
/**
|
|
744
|
-
* Collect scannable files
|
|
745
|
-
*/
|
|
746
|
-
collectFiles(dirPath, collected = []) {
|
|
747
|
-
const extensions = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
748
|
-
|
|
749
|
-
try {
|
|
750
|
-
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
751
|
-
|
|
752
|
-
for (const entry of entries) {
|
|
753
|
-
const fullPath = path.join(dirPath, entry.name);
|
|
754
|
-
const relativePath = path.relative(this.projectRoot, fullPath);
|
|
755
|
-
|
|
756
|
-
if (this.shouldIgnore(relativePath)) continue;
|
|
757
|
-
|
|
758
|
-
if (entry.isDirectory()) {
|
|
759
|
-
this.collectFiles(fullPath, collected);
|
|
760
|
-
} else if (extensions.some(ext => entry.name.endsWith(ext))) {
|
|
761
|
-
collected.push(relativePath);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
} catch {
|
|
765
|
-
// Skip unreadable directories
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
return collected;
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
/**
|
|
772
|
-
* Check if path should be ignored
|
|
773
|
-
*/
|
|
774
|
-
shouldIgnore(filePath) {
|
|
775
|
-
for (const pattern of this.ignorePaths) {
|
|
776
|
-
const regex = new RegExp(
|
|
777
|
-
pattern
|
|
778
|
-
.replace(/\*\*/g, ".*")
|
|
779
|
-
.replace(/\*/g, "[^/]*")
|
|
780
|
-
);
|
|
781
|
-
if (regex.test(filePath)) {
|
|
782
|
-
return true;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
return false;
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Summarize findings
|
|
790
|
-
*/
|
|
791
|
-
summarizeFindings(findings) {
|
|
792
|
-
const bySeverity = {
|
|
793
|
-
critical: findings.filter(f => f.severity === "critical").length,
|
|
794
|
-
high: findings.filter(f => f.severity === "high").length,
|
|
795
|
-
medium: findings.filter(f => f.severity === "medium").length,
|
|
796
|
-
low: findings.filter(f => f.severity === "low").length
|
|
797
|
-
};
|
|
798
|
-
|
|
799
|
-
return {
|
|
800
|
-
total: findings.length,
|
|
801
|
-
bySeverity,
|
|
802
|
-
criticalOrHigh: bySeverity.critical + bySeverity.high
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Generate overall summary
|
|
808
|
-
*/
|
|
809
|
-
generateOverallSummary() {
|
|
810
|
-
const allFindings = this.results.flatMap(r => r.findings);
|
|
811
|
-
|
|
812
|
-
const bySeverity = {
|
|
813
|
-
critical: allFindings.filter(f => f.severity === "critical"),
|
|
814
|
-
high: allFindings.filter(f => f.severity === "high"),
|
|
815
|
-
medium: allFindings.filter(f => f.severity === "medium"),
|
|
816
|
-
low: allFindings.filter(f => f.severity === "low")
|
|
817
|
-
};
|
|
818
|
-
|
|
819
|
-
const byCategory = {};
|
|
820
|
-
for (const finding of allFindings) {
|
|
821
|
-
if (!byCategory[finding.category]) {
|
|
822
|
-
byCategory[finding.category] = [];
|
|
823
|
-
}
|
|
824
|
-
byCategory[finding.category].push(finding);
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
// Calculate security score
|
|
828
|
-
const score = this.calculateSecurityScore(bySeverity);
|
|
829
|
-
|
|
830
|
-
return {
|
|
831
|
-
filesScanned: this.results.length,
|
|
832
|
-
totalFindings: allFindings.length,
|
|
833
|
-
bySeverity: {
|
|
834
|
-
critical: bySeverity.critical.length,
|
|
835
|
-
high: bySeverity.high.length,
|
|
836
|
-
medium: bySeverity.medium.length,
|
|
837
|
-
low: bySeverity.low.length
|
|
838
|
-
},
|
|
839
|
-
byCategory: Object.fromEntries(
|
|
840
|
-
Object.entries(byCategory).map(([k, v]) => [k, v.length])
|
|
841
|
-
),
|
|
842
|
-
securityScore: score,
|
|
843
|
-
owaspCoverage: this.getOWASPCoverage(byCategory)
|
|
844
|
-
};
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
/**
|
|
848
|
-
* Calculate security score (0-100)
|
|
849
|
-
*/
|
|
850
|
-
calculateSecurityScore(bySeverity) {
|
|
851
|
-
// Weight: critical = 25, high = 10, medium = 5, low = 2
|
|
852
|
-
const deductions =
|
|
853
|
-
bySeverity.critical.length * 25 +
|
|
854
|
-
bySeverity.high.length * 10 +
|
|
855
|
-
bySeverity.medium.length * 5 +
|
|
856
|
-
bySeverity.low.length * 2;
|
|
857
|
-
|
|
858
|
-
return Math.max(0, 100 - deductions);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
/**
|
|
862
|
-
* Get OWASP Top 10 coverage
|
|
863
|
-
*/
|
|
864
|
-
getOWASPCoverage(byCategory) {
|
|
865
|
-
const coverage = {};
|
|
866
|
-
|
|
867
|
-
for (const categoryId of Object.keys(this.rules)) {
|
|
868
|
-
const findings = byCategory[categoryId] || [];
|
|
869
|
-
coverage[categoryId] = {
|
|
870
|
-
name: this.rules[categoryId].name,
|
|
871
|
-
findings: findings.length,
|
|
872
|
-
status: findings.length === 0 ? "PASS" :
|
|
873
|
-
findings.some(f => f.severity === "critical") ? "CRITICAL" :
|
|
874
|
-
findings.some(f => f.severity === "high") ? "FAIL" : "WARN"
|
|
875
|
-
};
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
return coverage;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
/**
|
|
882
|
-
* Generate security report
|
|
883
|
-
*/
|
|
884
|
-
generateReport() {
|
|
885
|
-
const summary = this.generateOverallSummary();
|
|
886
|
-
|
|
887
|
-
return {
|
|
888
|
-
timestamp: new Date().toISOString(),
|
|
889
|
-
summary,
|
|
890
|
-
owaspCoverage: summary.owaspCoverage,
|
|
891
|
-
criticalFindings: this.results
|
|
892
|
-
.flatMap(r => r.findings)
|
|
893
|
-
.filter(f => f.severity === "critical")
|
|
894
|
-
.map(f => ({
|
|
895
|
-
file: f.file,
|
|
896
|
-
line: f.line,
|
|
897
|
-
rule: f.ruleName,
|
|
898
|
-
message: f.message,
|
|
899
|
-
fix: f.fix
|
|
900
|
-
})),
|
|
901
|
-
recommendations: this.generateRecommendations(summary)
|
|
902
|
-
};
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Generate security recommendations
|
|
907
|
-
*/
|
|
908
|
-
generateRecommendations(summary) {
|
|
909
|
-
const recommendations = [];
|
|
910
|
-
|
|
911
|
-
for (const [categoryId, data] of Object.entries(summary.owaspCoverage)) {
|
|
912
|
-
if (data.status !== "PASS") {
|
|
913
|
-
const category = this.rules[categoryId];
|
|
914
|
-
recommendations.push({
|
|
915
|
-
category: categoryId,
|
|
916
|
-
name: category.name,
|
|
917
|
-
priority: data.status === "CRITICAL" ? "immediate" : "high",
|
|
918
|
-
description: category.description,
|
|
919
|
-
affectedAreas: data.findings,
|
|
920
|
-
cwe: category.cwe
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
return recommendations.sort((a, b) => {
|
|
926
|
-
const priority = { immediate: 0, high: 1, medium: 2, low: 3 };
|
|
927
|
-
return priority[a.priority] - priority[b.priority];
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
933
|
-
// EXPORTS
|
|
934
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
935
|
-
|
|
936
|
-
module.exports = {
|
|
937
|
-
OWASPScanner,
|
|
938
|
-
OWASP_RULES
|
|
939
|
-
};
|