@yagyeshvyas/vibeguard 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/README.md +600 -0
- package/bin/cli.js +1640 -0
- package/ci/vibeguard.yml +41 -0
- package/ci-templates/Jenkinsfile +26 -0
- package/ci-templates/azure-pipelines.yml +29 -0
- package/ci-templates/circleci.yml +24 -0
- package/ci-templates/gitlab.yml +19 -0
- package/hooks/pre-commit +31 -0
- package/package.json +94 -0
- package/src/ai-guard.js +205 -0
- package/src/ast.js +319 -0
- package/src/audit-trail.js +154 -0
- package/src/autofix.js +524 -0
- package/src/badge.js +42 -0
- package/src/behavior.js +205 -0
- package/src/compliance.js +151 -0
- package/src/crosstaint.js +324 -0
- package/src/cve-intel.js +136 -0
- package/src/dashboard.js +279 -0
- package/src/deps.js +159 -0
- package/src/doctor.js +111 -0
- package/src/engine.js +234 -0
- package/src/external.js +160 -0
- package/src/firewall.js +517 -0
- package/src/history.js +87 -0
- package/src/hook.js +151 -0
- package/src/install.js +248 -0
- package/src/interceptor.js +476 -0
- package/src/mcp-server.js +1804 -0
- package/src/net-audit.js +208 -0
- package/src/pii.js +212 -0
- package/src/plugin.js +80 -0
- package/src/policy-gen.js +288 -0
- package/src/pre-deploy.js +282 -0
- package/src/presets.js +113 -0
- package/src/privacy-audit.js +273 -0
- package/src/repl.js +150 -0
- package/src/report.js +312 -0
- package/src/rules-pack.js +2753 -0
- package/src/rules.js +1446 -0
- package/src/sandbox.js +139 -0
- package/src/scanner.js +651 -0
- package/src/secure-prompt.js +140 -0
- package/src/slopsquat.js +144 -0
- package/src/supply-firewall.js +243 -0
- package/src/suppress.js +89 -0
- package/src/taint.js +168 -0
- package/src/trace.js +220 -0
- package/src/urlscan.js +142 -0
- package/src/vault.js +145 -0
- package/src/verify.js +98 -0
- package/src/verifykeys.js +87 -0
|
@@ -0,0 +1,2753 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Extended rule packs for VibeGuard.
|
|
5
|
+
*
|
|
6
|
+
* Organized by category, each rule follows the same shape as rules.js:
|
|
7
|
+
* { id, severity, confidence, title, re, skipComments, message, fix, owasp, cwe }
|
|
8
|
+
*
|
|
9
|
+
* Design: low false positives, narrow patterns, clear fixes.
|
|
10
|
+
* Every rule is deliberately conservative — noise is what makes people uninstall.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// AUTH: Clerk / Auth.js / NextAuth / Supabase Auth / OAuth
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
const clerkRules = [
|
|
18
|
+
{
|
|
19
|
+
id: 'clerk.middleware-bypass',
|
|
20
|
+
severity: 'high',
|
|
21
|
+
confidence: 'medium',
|
|
22
|
+
title: 'Clerk middleware may not protect all routes',
|
|
23
|
+
re: /clerkMiddleware\s*\(\s*\)/,
|
|
24
|
+
skipComments: true,
|
|
25
|
+
message: 'clerkMiddleware() with no config — routes not in the public list are protected, but verify middleware matcher covers all routes.',
|
|
26
|
+
fix: 'Ensure the middleware matcher in middleware.ts covers all routes, and explicitly list public routes.',
|
|
27
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
28
|
+
cwe: 'CWE-862',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'clerk.secret-key-exposed',
|
|
32
|
+
severity: 'critical',
|
|
33
|
+
confidence: 'high',
|
|
34
|
+
title: 'Clerk secret key exposed to client',
|
|
35
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_|REACT_APP_).*?(?:CLERK_SECRET_KEY|CLERK_SECRET)/i,
|
|
36
|
+
skipComments: true,
|
|
37
|
+
message: 'Clerk secret key is exposed via a public env var prefix — anyone can impersonate your Clerk backend.',
|
|
38
|
+
fix: 'Use CLERK_SECRET_KEY (server-only) — never with NEXT_PUBLIC_ / VITE_ / EXPO_PUBLIC_ prefixes.',
|
|
39
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
40
|
+
cwe: 'CWE-200',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 'clerk.session-localStorage',
|
|
44
|
+
severity: 'medium',
|
|
45
|
+
confidence: 'medium',
|
|
46
|
+
title: 'Clerk session stored in localStorage',
|
|
47
|
+
re: /clerk.*?localStorage|localStorage.*?clerk|sessionStorage.*?clerk/i,
|
|
48
|
+
skipComments: true,
|
|
49
|
+
message: 'Clerk session data in localStorage is accessible to any JS on the page (XSS = session theft).',
|
|
50
|
+
fix: 'Use Clerk\'s built-in cookie-based session management; avoid storing session tokens in localStorage.',
|
|
51
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
52
|
+
cwe: 'CWE-922',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'clerk.frontend-api-proxy-ssrf',
|
|
56
|
+
severity: 'high',
|
|
57
|
+
confidence: 'medium',
|
|
58
|
+
title: 'Clerk frontendApiProxy may allow SSRF',
|
|
59
|
+
re: /clerkFrontendApiProxy\s*:/i,
|
|
60
|
+
skipComments: true,
|
|
61
|
+
message: 'clerkFrontendApiProxy can proxy arbitrary requests — verify it only proxies to Clerk\'s API, not user-controlled URLs.',
|
|
62
|
+
fix: 'Restrict clerkFrontendApiProxy to known Clerk domains; do not proxy user-controlled paths.',
|
|
63
|
+
owasp: 'A10:2025 Server-Side Request Forgery',
|
|
64
|
+
cwe: 'CWE-918',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'clerk.admin-claim-check',
|
|
68
|
+
severity: 'medium',
|
|
69
|
+
confidence: 'low',
|
|
70
|
+
title: 'Admin check uses only Clerk metadata, not server verification',
|
|
71
|
+
re: /has\s*\(\s*\{.*?role.*?:.*?['"]admin['"]/s,
|
|
72
|
+
skipComments: true,
|
|
73
|
+
message: 'Role check uses client-side Clerk metadata only — a modified token or client bypass skips it.',
|
|
74
|
+
fix: 'Verify admin role server-side in the API route or Server Action, not just in the Clerk has() check.',
|
|
75
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
76
|
+
cwe: 'CWE-863',
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const authJsRules = [
|
|
81
|
+
{
|
|
82
|
+
id: 'authjs.state-missing',
|
|
83
|
+
severity: 'high',
|
|
84
|
+
confidence: 'medium',
|
|
85
|
+
title: 'OAuth flow without state parameter',
|
|
86
|
+
re: /signIn\s*\(\s*['"]oauth['"]|signIn\s*\(\s*['"]google['"]|signIn\s*\(\s*['"]github['"]|provider.*?oauth/i,
|
|
87
|
+
skipComments: true,
|
|
88
|
+
message: 'OAuth/OIDC sign-in detected — ensure state parameter and PKCE are enabled (Auth.js handles this by default, but custom providers may not).',
|
|
89
|
+
fix: 'Ensure the provider config includes state: true and uses PKCE (authorization code flow with code_challenge).',
|
|
90
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
91
|
+
cwe: 'CWE-352',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: 'authjs.secret-exposed',
|
|
95
|
+
severity: 'critical',
|
|
96
|
+
confidence: 'high',
|
|
97
|
+
title: 'NextAuth secret exposed to client',
|
|
98
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_|REACT_APP_).*?AUTH_SECRET|NEXTAUTH_SECRET/i,
|
|
99
|
+
skipComments: true,
|
|
100
|
+
message: 'NextAuth/Auth.js secret is exposed via a public env var prefix — session tokens can be forged.',
|
|
101
|
+
fix: 'Use AUTH_SECRET or NEXTAUTH_SECRET without any public prefix — server-only.',
|
|
102
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
103
|
+
cwe: 'CWE-200',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 'authjs.jwt-without-secret',
|
|
107
|
+
severity: 'high',
|
|
108
|
+
confidence: 'medium',
|
|
109
|
+
title: 'Auth.js JWT strategy without a secret',
|
|
110
|
+
re: /strategy\s*:\s*['"]jwt['"].*?(?!secret)/s,
|
|
111
|
+
skipComments: true,
|
|
112
|
+
message: 'JWT strategy without a verified secret — tokens may be unsigned or signed with a default.',
|
|
113
|
+
fix: 'Set AUTH_SECRET / NEXTAUTH_SECRET to a strong random value in your server environment.',
|
|
114
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
115
|
+
cwe: 'CWE-321',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: 'authjs.callback-url-unchecked',
|
|
119
|
+
severity: 'medium',
|
|
120
|
+
confidence: 'low',
|
|
121
|
+
title: 'Auth.js callbackUrl may not be validated',
|
|
122
|
+
re: /callbackUrl\s*:\s*req\.(?:query|body|url)\./i,
|
|
123
|
+
skipComments: true,
|
|
124
|
+
message: 'callbackUrl comes from user input — open redirect after login if not validated.',
|
|
125
|
+
fix: 'Validate callbackUrl against an allowlist of internal paths; never accept absolute URLs from input.',
|
|
126
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
127
|
+
cwe: 'CWE-601',
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
const oauthRules = [
|
|
132
|
+
{
|
|
133
|
+
id: 'oauth.pkce-missing',
|
|
134
|
+
severity: 'medium',
|
|
135
|
+
confidence: 'low',
|
|
136
|
+
title: 'OAuth code flow without PKCE',
|
|
137
|
+
re: /response_type\s*:\s*['"]code['"].*?(?!code_challenge|pkce)/s,
|
|
138
|
+
skipComments: true,
|
|
139
|
+
message: 'OAuth authorization code flow without PKCE — intercepted codes can be exchanged by an attacker.',
|
|
140
|
+
fix: 'Add PKCE: generate a code_verifier, send code_challenge in the auth request, and verify on token exchange.',
|
|
141
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
142
|
+
cwe: 'CWE-384',
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
id: 'oauth.implicit-flow',
|
|
146
|
+
severity: 'medium',
|
|
147
|
+
confidence: 'medium',
|
|
148
|
+
title: 'OAuth implicit flow (tokens in URL fragment)',
|
|
149
|
+
re: /response_type\s*:\s*['"]token['"]/i,
|
|
150
|
+
skipComments: true,
|
|
151
|
+
message: 'Implicit flow returns access tokens in the URL fragment — exposed via browser history and referrer headers.',
|
|
152
|
+
fix: 'Use the authorization code flow with PKCE instead of the implicit flow.',
|
|
153
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
154
|
+
cwe: 'CWE-200',
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
const supabaseAuthRules = [
|
|
159
|
+
{
|
|
160
|
+
id: 'supabase.admin-client-browser',
|
|
161
|
+
severity: 'critical',
|
|
162
|
+
confidence: 'high',
|
|
163
|
+
title: 'Supabase admin client used in browser code',
|
|
164
|
+
re: /createClient\s*\([^)]*service_role/i,
|
|
165
|
+
skipComments: true,
|
|
166
|
+
message: 'Supabase service_role client used in code that may run in the browser — the service role key bypasses RLS.',
|
|
167
|
+
fix: 'Only use the service_role client in server-side code (API routes, server actions, edge functions).',
|
|
168
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
169
|
+
cwe: 'CWE-862',
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
id: 'supabase.auth-admin-browser',
|
|
173
|
+
severity: 'critical',
|
|
174
|
+
confidence: 'high',
|
|
175
|
+
title: 'Supabase auth admin functions in browser code',
|
|
176
|
+
re: /supabase\.auth\.admin\./i,
|
|
177
|
+
skipComments: true,
|
|
178
|
+
message: 'Supabase auth.admin functions (createUser, deleteUser, listUsers) are called in browser-accessible code.',
|
|
179
|
+
fix: 'Move auth.admin calls to server-side code; the browser client should never have admin auth access.',
|
|
180
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
181
|
+
cwe: 'CWE-862',
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
// DATABASE / ORM: Drizzle / Hono / tRPC / Convex / Turso / Kysely / MikroORM
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
const drizzleRules = [
|
|
190
|
+
{
|
|
191
|
+
id: 'drizzle.sql-raw-interpolation',
|
|
192
|
+
severity: 'high',
|
|
193
|
+
confidence: 'high',
|
|
194
|
+
title: 'Drizzle sql.raw() with interpolated value',
|
|
195
|
+
re: /sql\.raw\s*\(\s*[^)]*\$\{|sql\.raw\s*\(\s*`[^`]*\$\{/i,
|
|
196
|
+
skipComments: true,
|
|
197
|
+
message: 'sql.raw() with template interpolation — SQL injection. sql.raw does not parameterize.',
|
|
198
|
+
fix: 'Use sql`` tagged template with ${value} for parameterized values, not sql.raw().',
|
|
199
|
+
owasp: 'A03:2025 Injection',
|
|
200
|
+
cwe: 'CWE-89',
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: 'drizzle.identifier-injection',
|
|
204
|
+
severity: 'high',
|
|
205
|
+
confidence: 'medium',
|
|
206
|
+
title: 'Drizzle identifier from user input',
|
|
207
|
+
re: /sql\.identifier\s*\(\s*[^)]*req\.(?:body|query|params)/i,
|
|
208
|
+
skipComments: true,
|
|
209
|
+
message: 'SQL identifier (table/column name) from user input — identifier injection.',
|
|
210
|
+
fix: 'Allowlist table/column names; never pass user input as an SQL identifier.',
|
|
211
|
+
owasp: 'A03:2025 Injection',
|
|
212
|
+
cwe: 'CWE-89',
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
id: 'drizzle.raw-query-user-input',
|
|
216
|
+
severity: 'high',
|
|
217
|
+
confidence: 'high',
|
|
218
|
+
title: 'Drizzle raw query with user input',
|
|
219
|
+
re: /db\.execute\s*\(\s*sql`[^`]*\$\{[^}]*req\./i,
|
|
220
|
+
skipComments: true,
|
|
221
|
+
message: 'Raw SQL query with request data — SQL injection if not parameterized.',
|
|
222
|
+
fix: 'Use Drizzle\'s query builder or sql tagged template with ${param} for safe parameterization.',
|
|
223
|
+
owasp: 'A03:2025 Injection',
|
|
224
|
+
cwe: 'CWE-89',
|
|
225
|
+
},
|
|
226
|
+
];
|
|
227
|
+
|
|
228
|
+
const honoRules = [
|
|
229
|
+
{
|
|
230
|
+
id: 'hono.setcookie-injection',
|
|
231
|
+
severity: 'medium',
|
|
232
|
+
confidence: 'medium',
|
|
233
|
+
title: 'Hono setCookie with user-controlled value',
|
|
234
|
+
re: /setCookie\s*\(\s*[^,]+,\s*[^,]*req\.(?:body|query|params|header)/i,
|
|
235
|
+
skipComments: true,
|
|
236
|
+
message: 'Cookie value from user input — CRLF injection can set arbitrary cookie attributes.',
|
|
237
|
+
fix: 'Validate/sanitize cookie values; strip \\r and \\n before setting.',
|
|
238
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
239
|
+
cwe: 'CWE-93',
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
id: 'hono.cors-wildcard',
|
|
243
|
+
severity: 'medium',
|
|
244
|
+
confidence: 'high',
|
|
245
|
+
title: 'Hono CORS with wildcard origin',
|
|
246
|
+
re: /cors\s*\(\s*\{[^}]*origin\s*:\s*['"]\*['"]/i,
|
|
247
|
+
skipComments: true,
|
|
248
|
+
message: 'Hono CORS middleware allows all origins — any site can make authenticated requests.',
|
|
249
|
+
fix: 'Set origin to an allowlist of your domains; use a function for dynamic validation.',
|
|
250
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
251
|
+
cwe: 'CWE-942',
|
|
252
|
+
},
|
|
253
|
+
];
|
|
254
|
+
|
|
255
|
+
const trpcRules = [
|
|
256
|
+
{
|
|
257
|
+
id: 'trpc.untyped-input',
|
|
258
|
+
severity: 'medium',
|
|
259
|
+
confidence: 'medium',
|
|
260
|
+
title: 'tRPC procedure without input validation',
|
|
261
|
+
re: /\.procedure\s*\(\s*\{[^}]*\bresolve\b[^}]*\}(?!\.input)/s,
|
|
262
|
+
skipComments: true,
|
|
263
|
+
message: 'tRPC procedure has a resolver but no .input() schema — unvalidated client data reaches the handler.',
|
|
264
|
+
fix: 'Add .input(z.object({...})) before .mutation/.query to validate input.',
|
|
265
|
+
owasp: 'A03:2025 Injection',
|
|
266
|
+
cwe: 'CWE-20',
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
id: 'trpc.public-mutation',
|
|
270
|
+
severity: 'medium',
|
|
271
|
+
confidence: 'low',
|
|
272
|
+
title: 'tRPC mutation without auth middleware',
|
|
273
|
+
re: /\.mutation\s*\(\s*\{[^}]*\bresolve\b/s,
|
|
274
|
+
skipComments: true,
|
|
275
|
+
message: 'tRPC mutation has no visible auth/procedure protection — any caller can invoke it.',
|
|
276
|
+
fix: 'Use protectedProcedure or a middleware that verifies authentication before mutations.',
|
|
277
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
278
|
+
cwe: 'CWE-862',
|
|
279
|
+
},
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
const convexRules = [
|
|
283
|
+
{
|
|
284
|
+
id: 'convex.internal-function-exposed',
|
|
285
|
+
severity: 'high',
|
|
286
|
+
confidence: 'medium',
|
|
287
|
+
title: 'Convex internal function exposed as public',
|
|
288
|
+
re: /export\s+const\s+\w+\s*=\s*(?:query|mutation)\s*\(/i,
|
|
289
|
+
skipComments: true,
|
|
290
|
+
message: 'Convex function is exported as a public query/mutation — no auth check visible.',
|
|
291
|
+
fix: 'Use queryWithAuth / mutationWithAuth, or add an auth check inside the handler.',
|
|
292
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
293
|
+
cwe: 'CWE-862',
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
id: 'convex.client-url-exposed',
|
|
297
|
+
severity: 'medium',
|
|
298
|
+
confidence: 'medium',
|
|
299
|
+
title: 'Convex deployment URL with credentials in client',
|
|
300
|
+
re: /ConvexClient\s*\(\s*['"]https?:\/\/[^'"]*@/i,
|
|
301
|
+
skipComments: true,
|
|
302
|
+
message: 'Convex client URL contains credentials — exposed in client-side code.',
|
|
303
|
+
fix: 'Use environment variables for the Convex URL; do not embed credentials in the client.',
|
|
304
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
305
|
+
cwe: 'CWE-200',
|
|
306
|
+
},
|
|
307
|
+
];
|
|
308
|
+
|
|
309
|
+
const tursoRules = [
|
|
310
|
+
{
|
|
311
|
+
id: 'turso.client-in-browser',
|
|
312
|
+
severity: 'high',
|
|
313
|
+
confidence: 'high',
|
|
314
|
+
title: 'Turso/LibSQL client created in browser code',
|
|
315
|
+
re: /createClient\s*\(\s*['"](?:libsql|turso):/i,
|
|
316
|
+
skipComments: true,
|
|
317
|
+
message: 'Turso/LibSQL client with a direct URL and auth token in browser code — credentials exposed.',
|
|
318
|
+
fix: 'Access Turso through a server-side API route; never expose the database URL and token to the client.',
|
|
319
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
320
|
+
cwe: 'CWE-200',
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
id: 'turso.raw-execute-user-input',
|
|
324
|
+
severity: 'high',
|
|
325
|
+
confidence: 'high',
|
|
326
|
+
title: 'Turso/LibSQL execute with raw user input',
|
|
327
|
+
re: /\.execute\s*\(\s*[^)]*req\.(?:body|query|params)/i,
|
|
328
|
+
skipComments: true,
|
|
329
|
+
message: 'Raw SQL execute with user input — SQL injection.',
|
|
330
|
+
fix: 'Use parameterized queries: execute(sql, { args: [param1, param2] }).',
|
|
331
|
+
owasp: 'A03:2025 Injection',
|
|
332
|
+
cwe: 'CWE-89',
|
|
333
|
+
},
|
|
334
|
+
];
|
|
335
|
+
|
|
336
|
+
const kyselyRules = [
|
|
337
|
+
{
|
|
338
|
+
id: 'kysely.json-path-traversal',
|
|
339
|
+
severity: 'high',
|
|
340
|
+
confidence: 'medium',
|
|
341
|
+
title: 'Kysely JSON path with user input',
|
|
342
|
+
re: /\.jsonPath\s*\(\s*[^)]*req\.(?:body|query|params)/i,
|
|
343
|
+
skipComments: true,
|
|
344
|
+
message: 'Kysely jsonPath with user input — path traversal in JSON columns.',
|
|
345
|
+
fix: 'Validate and sanitize JSON paths; do not pass raw user input to jsonPath().',
|
|
346
|
+
owasp: 'A03:2025 Injection',
|
|
347
|
+
cwe: 'CWE-89',
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
id: 'kysely.raw-sql-interpolation',
|
|
351
|
+
severity: 'high',
|
|
352
|
+
confidence: 'high',
|
|
353
|
+
title: 'Kysely raw SQL with interpolation',
|
|
354
|
+
re: /sql`[^`]*\$\{[^}]*req\.(?:body|query|params)/i,
|
|
355
|
+
skipComments: true,
|
|
356
|
+
message: 'Kysely sql tagged template with request data — verify it uses sql.join/sql.val for parameterization.',
|
|
357
|
+
fix: 'Use sql.val(value) for parameterized values inside sql`` templates.',
|
|
358
|
+
owasp: 'A03:2025 Injection',
|
|
359
|
+
cwe: 'CWE-89',
|
|
360
|
+
},
|
|
361
|
+
];
|
|
362
|
+
|
|
363
|
+
const mikroOrmRules = [
|
|
364
|
+
{
|
|
365
|
+
id: 'mikroorm.raw-query-user-input',
|
|
366
|
+
severity: 'high',
|
|
367
|
+
confidence: 'high',
|
|
368
|
+
title: 'MikroORM raw query with user input',
|
|
369
|
+
re: /em\.execute\s*\(\s*[^)]*req\.(?:body|query|params)/i,
|
|
370
|
+
skipComments: true,
|
|
371
|
+
message: 'MikroORM em.execute with user input — SQL injection if not parameterized.',
|
|
372
|
+
fix: 'Use parameterized queries or the MikroORM query builder.',
|
|
373
|
+
owasp: 'A03:2025 Injection',
|
|
374
|
+
cwe: 'CWE-89',
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
id: 'mikroorm.identifier-from-request',
|
|
378
|
+
severity: 'high',
|
|
379
|
+
confidence: 'medium',
|
|
380
|
+
title: 'MikroORM query with raw identifier from request',
|
|
381
|
+
re: /knex\.raw\s*\(\s*[^)]*req\.(?:body|query|params)/i,
|
|
382
|
+
skipComments: true,
|
|
383
|
+
message: 'MikroORM/Knex raw query with request data — identifier injection.',
|
|
384
|
+
fix: 'Use parameterized queries; never pass request data as a raw SQL identifier.',
|
|
385
|
+
owasp: 'A03:2025 Injection',
|
|
386
|
+
cwe: 'CWE-89',
|
|
387
|
+
},
|
|
388
|
+
];
|
|
389
|
+
|
|
390
|
+
// ---------------------------------------------------------------------------
|
|
391
|
+
// PAYMENTS: Stripe / Polar / LemonSqueezy
|
|
392
|
+
// ---------------------------------------------------------------------------
|
|
393
|
+
|
|
394
|
+
const stripeRules = [
|
|
395
|
+
{
|
|
396
|
+
id: 'stripe.webhook-no-signature',
|
|
397
|
+
severity: 'critical',
|
|
398
|
+
confidence: 'high',
|
|
399
|
+
title: 'Stripe webhook without signature verification',
|
|
400
|
+
re: /stripe\.webhooks\.constructEvent\s*\(/,
|
|
401
|
+
skipComments: true,
|
|
402
|
+
message: 'Stripe webhook endpoint detected — verify constructEvent is called with the signature header and webhook secret.',
|
|
403
|
+
fix: 'Always verify: stripe.webhooks.constructEvent(rawBody, sig, endpointSecret). Never process unverified webhooks.',
|
|
404
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
405
|
+
cwe: 'CWE-345',
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
id: 'stripe.webhook-no-timestamp',
|
|
409
|
+
severity: 'medium',
|
|
410
|
+
confidence: 'medium',
|
|
411
|
+
title: 'Stripe webhook without replay protection',
|
|
412
|
+
re: /stripe\.webhooks\.constructEvent\s*\([^)]*\)/,
|
|
413
|
+
skipComments: true,
|
|
414
|
+
message: 'Stripe webhook verified but no timestamp tolerance check — replay attacks possible with old events.',
|
|
415
|
+
fix: 'Set a tolerance: constructEvent(body, sig, secret, 300) to reject events older than 5 minutes.',
|
|
416
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
417
|
+
cwe: 'CWE-294',
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
id: 'stripe.client-amount',
|
|
421
|
+
severity: 'high',
|
|
422
|
+
confidence: 'high',
|
|
423
|
+
title: 'Stripe payment amount from client request',
|
|
424
|
+
re: /stripe\.(?:paymentIntents|charges|checkout\.sessions)\.create\s*\([^)]*amount\s*:\s*req\./i,
|
|
425
|
+
skipComments: true,
|
|
426
|
+
message: 'Payment amount comes from the client request — price manipulation. The client can set any amount.',
|
|
427
|
+
fix: 'Look up the price server-side from the product/price ID; never accept the amount from the client.',
|
|
428
|
+
owasp: 'A04:2025 Insecure Design',
|
|
429
|
+
cwe: 'CWE-473',
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
id: 'stripe.key-in-client',
|
|
433
|
+
severity: 'critical',
|
|
434
|
+
confidence: 'high',
|
|
435
|
+
title: 'Stripe secret key in client-side code',
|
|
436
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_|REACT_APP_).*?STRIPE_SECRET|sk_live_[A-Za-z0-9]{16,}/i,
|
|
437
|
+
skipComments: true,
|
|
438
|
+
message: 'Stripe secret key is in client-accessible code — anyone can make charges and refunds.',
|
|
439
|
+
fix: 'Use Stripe.js with the publishable key (pk_) on the client; keep sk_live_ on the server only.',
|
|
440
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
441
|
+
cwe: 'CWE-200',
|
|
442
|
+
},
|
|
443
|
+
];
|
|
444
|
+
|
|
445
|
+
const polarRules = [
|
|
446
|
+
{
|
|
447
|
+
id: 'polar.webhook-no-signature',
|
|
448
|
+
severity: 'critical',
|
|
449
|
+
confidence: 'high',
|
|
450
|
+
title: 'Polar.sh webhook without signature verification',
|
|
451
|
+
re: /polar.*?webhook/i,
|
|
452
|
+
skipComments: true,
|
|
453
|
+
message: 'Polar webhook detected — verify the signature header is checked before processing.',
|
|
454
|
+
fix: 'Verify the X-Polar-Signature header using your webhook secret before processing the event.',
|
|
455
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
456
|
+
cwe: 'CWE-345',
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
id: 'polar.secret-in-client',
|
|
460
|
+
severity: 'critical',
|
|
461
|
+
confidence: 'high',
|
|
462
|
+
title: 'Polar.sh access token in client code',
|
|
463
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_).*?POLAR_(?:ACCESS_TOKEN|API_TOKEN|SECRET)/i,
|
|
464
|
+
skipComments: true,
|
|
465
|
+
message: 'Polar access token is exposed via a public env var prefix.',
|
|
466
|
+
fix: 'Use POLAR_ACCESS_TOKEN without any public prefix — server-only.',
|
|
467
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
468
|
+
cwe: 'CWE-200',
|
|
469
|
+
},
|
|
470
|
+
];
|
|
471
|
+
|
|
472
|
+
const lemonRules = [
|
|
473
|
+
{
|
|
474
|
+
id: 'lemon.webhook-no-signature',
|
|
475
|
+
severity: 'critical',
|
|
476
|
+
confidence: 'high',
|
|
477
|
+
title: 'LemonSqueezy webhook without signature verification',
|
|
478
|
+
re: /lemonsqueezy.*?webhook/i,
|
|
479
|
+
skipComments: true,
|
|
480
|
+
message: 'LemonSqueezy webhook detected — verify the X-Signature header is checked.',
|
|
481
|
+
fix: 'Verify the X-Signature header using HMAC-SHA256 with your webhook secret.',
|
|
482
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
483
|
+
cwe: 'CWE-345',
|
|
484
|
+
},
|
|
485
|
+
{
|
|
486
|
+
id: 'lemon.secret-in-client',
|
|
487
|
+
severity: 'critical',
|
|
488
|
+
confidence: 'high',
|
|
489
|
+
title: 'LemonSqueezy API key in client code',
|
|
490
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_).*?LEMON_SQUEEZY_(?:API_KEY|SECRET)/i,
|
|
491
|
+
skipComments: true,
|
|
492
|
+
message: 'LemonSqueezy API key is exposed via a public env var prefix.',
|
|
493
|
+
fix: 'Use LEMON_SQUEEZY_API_KEY without any public prefix — server-only.',
|
|
494
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
495
|
+
cwe: 'CWE-200',
|
|
496
|
+
},
|
|
497
|
+
];
|
|
498
|
+
|
|
499
|
+
// ---------------------------------------------------------------------------
|
|
500
|
+
// SERVICES: Resend / Upstash / Pinecone / PostHog / Uploadthing / Firebase
|
|
501
|
+
// ---------------------------------------------------------------------------
|
|
502
|
+
|
|
503
|
+
const serviceRules = [
|
|
504
|
+
{
|
|
505
|
+
id: 'resend.key-in-client',
|
|
506
|
+
severity: 'critical',
|
|
507
|
+
confidence: 'high',
|
|
508
|
+
title: 'Resend API key in client code',
|
|
509
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_|REACT_APP_).*?RESEND_API_KEY/i,
|
|
510
|
+
skipComments: true,
|
|
511
|
+
message: 'Resend API key is exposed via a public env var prefix — anyone can send emails as you.',
|
|
512
|
+
fix: 'Use RESEND_API_KEY without any public prefix — server-only.',
|
|
513
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
514
|
+
cwe: 'CWE-200',
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
id: 'resend.email-injection',
|
|
518
|
+
severity: 'high',
|
|
519
|
+
confidence: 'medium',
|
|
520
|
+
title: 'Resend email with user-controlled HTML',
|
|
521
|
+
re: /resend.*?send\s*\(\s*\{[^}]*html\s*:\s*[^}]*(?:req\.|user|input)/i,
|
|
522
|
+
skipComments: true,
|
|
523
|
+
message: 'Email HTML body from user input — email HTML injection (phishing, content spoofing).',
|
|
524
|
+
fix: 'Do not pass user input as HTML email content. Use plain text or sanitize/template the HTML.',
|
|
525
|
+
owasp: 'A03:2025 Injection',
|
|
526
|
+
cwe: 'CWE-74',
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
id: 'upstash.token-in-client',
|
|
530
|
+
severity: 'critical',
|
|
531
|
+
confidence: 'high',
|
|
532
|
+
title: 'Upstash Redis token in client code',
|
|
533
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_).*?UPSTASH_REDIS_(?:TOKEN|REST_TOKEN)/i,
|
|
534
|
+
skipComments: true,
|
|
535
|
+
message: 'Upstash Redis token is exposed via a public env var prefix — anyone can read/write your Redis.',
|
|
536
|
+
fix: 'Use UPSTASH_REDIS_TOKEN without any public prefix — server-only.',
|
|
537
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
538
|
+
cwe: 'CWE-200',
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
id: 'pinecone.key-in-client',
|
|
542
|
+
severity: 'critical',
|
|
543
|
+
confidence: 'high',
|
|
544
|
+
title: 'Pinecone API key in client code',
|
|
545
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_).*?PINECONE_API_KEY/i,
|
|
546
|
+
skipComments: true,
|
|
547
|
+
message: 'Pinecone API key is exposed via a public env var prefix — anyone can query/modify your vector DB.',
|
|
548
|
+
fix: 'Use PINECONE_API_KEY without any public prefix — server-only.',
|
|
549
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
550
|
+
cwe: 'CWE-200',
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
id: 'posthog.pii-tracking',
|
|
554
|
+
severity: 'medium',
|
|
555
|
+
confidence: 'low',
|
|
556
|
+
title: 'PostHog capturing PII',
|
|
557
|
+
re: /posthog\.(?:capture|identify)\s*\([^)]*(?:email|password|ssn|credit|phone|address)/i,
|
|
558
|
+
skipComments: true,
|
|
559
|
+
message: 'PostHog is capturing personally identifiable information (email, password, etc.) — GDPR/privacy risk.',
|
|
560
|
+
fix: 'Do not send PII to PostHog; hash or pseudonymize identifiers before capture.',
|
|
561
|
+
owasp: 'A04:2025 Insecure Design',
|
|
562
|
+
cwe: 'CWE-359',
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
id: 'uploadthing.no-auth',
|
|
566
|
+
severity: 'high',
|
|
567
|
+
confidence: 'medium',
|
|
568
|
+
title: 'Uploadthing file upload without auth',
|
|
569
|
+
re: /uploadthing\s*\(\s*\{[^}]*(?: onRequestUploadProtected| onRequestUpload)/i,
|
|
570
|
+
skipComments: true,
|
|
571
|
+
message: 'Uploadthing route may not require authentication — verify all upload routes are protected.',
|
|
572
|
+
fix: 'Use onRequestUploadProtected with an auth check; do not expose uploads as public.',
|
|
573
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
574
|
+
cwe: 'CWE-862',
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
id: 'uploadthing.no-type-check',
|
|
578
|
+
severity: 'medium',
|
|
579
|
+
confidence: 'medium',
|
|
580
|
+
title: 'Uploadthing without file type restrictions',
|
|
581
|
+
re: /createUploadthing\s*\(\s*\)/i,
|
|
582
|
+
skipComments: true,
|
|
583
|
+
message: 'Uploadthing created without Acl or file type checks — any file type can be uploaded.',
|
|
584
|
+
fix: 'Add .fileFingerprinting() and restrict allowed MIME types in the route definition.',
|
|
585
|
+
owasp: 'A04:2025 Insecure Design',
|
|
586
|
+
cwe: 'CWE-434',
|
|
587
|
+
},
|
|
588
|
+
];
|
|
589
|
+
|
|
590
|
+
const firebaseRules = [
|
|
591
|
+
{
|
|
592
|
+
id: 'firebase.admin-sdk-browser',
|
|
593
|
+
severity: 'critical',
|
|
594
|
+
confidence: 'high',
|
|
595
|
+
title: 'Firebase Admin SDK in browser code',
|
|
596
|
+
re: /\badmin\.(?:initializeApp|firestore|auth|database|storage)\b/i,
|
|
597
|
+
skipComments: true,
|
|
598
|
+
message: 'Firebase Admin SDK is used in code that may run in the browser — admin credentials bypass all security rules.',
|
|
599
|
+
fix: 'Only use firebase-admin in server-side code; use the client SDK in the browser.',
|
|
600
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
601
|
+
cwe: 'CWE-862',
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
id: 'firebase.firestore-rules-missing',
|
|
605
|
+
severity: 'high',
|
|
606
|
+
confidence: 'medium',
|
|
607
|
+
title: 'Firebase Firestore without security rules',
|
|
608
|
+
re: /firestore\(\)\s*\./i,
|
|
609
|
+
skipComments: true,
|
|
610
|
+
message: 'Firestore accessed without visible security rules — default rules deny all, but test mode allows all for 30 days.',
|
|
611
|
+
fix: 'Deploy firestore.rules that enforce auth.uid() checks and field-level access control.',
|
|
612
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
613
|
+
cwe: 'CWE-862',
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
id: 'firebase.storage-rules-missing',
|
|
617
|
+
severity: 'medium',
|
|
618
|
+
confidence: 'low',
|
|
619
|
+
title: 'Firebase Storage without security rules',
|
|
620
|
+
re: /storage\(\)\s*(?:ref|child)\s*\(/i,
|
|
621
|
+
skipComments: true,
|
|
622
|
+
message: 'Firebase Storage accessed — verify storage.rules are deployed and restrict access.',
|
|
623
|
+
fix: 'Deploy storage.rules that require auth and validate file size/type.',
|
|
624
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
625
|
+
cwe: 'CWE-862',
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
id: 'firebase.custom-token-client',
|
|
629
|
+
severity: 'high',
|
|
630
|
+
confidence: 'high',
|
|
631
|
+
title: 'Firebase custom token minted in client code',
|
|
632
|
+
re: /admin\.auth\(\)\.createCustomToken\s*\(/i,
|
|
633
|
+
skipComments: true,
|
|
634
|
+
message: 'Firebase custom token creation in browser code — admin SDK exposed, anyone can mint auth tokens.',
|
|
635
|
+
fix: 'Move createCustomToken to server-side code only.',
|
|
636
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
637
|
+
cwe: 'CWE-862',
|
|
638
|
+
},
|
|
639
|
+
];
|
|
640
|
+
|
|
641
|
+
// ---------------------------------------------------------------------------
|
|
642
|
+
// MODERN STACK: Zod / React Server Actions / server-only / webhook / cron / CSP
|
|
643
|
+
// ---------------------------------------------------------------------------
|
|
644
|
+
|
|
645
|
+
const modernStackRules = [
|
|
646
|
+
{
|
|
647
|
+
id: 'zod.passthrough-mass-assignment',
|
|
648
|
+
severity: 'medium',
|
|
649
|
+
confidence: 'medium',
|
|
650
|
+
title: 'Zod schema with .passthrough() allows mass assignment',
|
|
651
|
+
re: /\.passthrough\s*\(\s*\)/,
|
|
652
|
+
skipComments: true,
|
|
653
|
+
message: 'Zod .passthrough() allows unknown keys through — mass assignment if spread into a DB record.',
|
|
654
|
+
fix: 'Use .strict() or .strip() (default) to drop unknown keys; explicitly allowlist each field.',
|
|
655
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
656
|
+
cwe: 'CWE-915',
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
id: 'zod.any-bypass',
|
|
660
|
+
severity: 'medium',
|
|
661
|
+
confidence: 'medium',
|
|
662
|
+
title: 'Zod z.any() bypasses validation',
|
|
663
|
+
re: /z\.any\s*\(\s*\)/,
|
|
664
|
+
skipComments: true,
|
|
665
|
+
message: 'z.any() accepts anything — no validation. If this shapes input to a DB or API, it is an injection vector.',
|
|
666
|
+
fix: 'Replace z.any() with a specific schema (z.object({...}), z.string(), z.number(), etc.).',
|
|
667
|
+
owasp: 'A03:2025 Injection',
|
|
668
|
+
cwe: 'CWE-20',
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
id: 'zod.unknown-bypass',
|
|
672
|
+
severity: 'low',
|
|
673
|
+
confidence: 'low',
|
|
674
|
+
title: 'Zod z.unknown() allows arbitrary keys',
|
|
675
|
+
re: /z\.unknown\s*\(\s*\)/,
|
|
676
|
+
skipComments: true,
|
|
677
|
+
message: 'z.unknown() is slightly safer than z.any() but still accepts arbitrary data.',
|
|
678
|
+
fix: 'Define a specific schema for the expected shape.',
|
|
679
|
+
owasp: 'A03:2025 Injection',
|
|
680
|
+
cwe: 'CWE-20',
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
id: 'react.server-action-no-validation',
|
|
684
|
+
severity: 'medium',
|
|
685
|
+
confidence: 'low',
|
|
686
|
+
title: 'React Server Action without input validation',
|
|
687
|
+
re: /['"]use server['"]\s*[\s\S]*?function\s+\w+\s*\(\s*(?:formData|input|data)\s*\)/i,
|
|
688
|
+
skipComments: true,
|
|
689
|
+
message: 'Server Action accepts input without visible validation — client can send any shape.',
|
|
690
|
+
fix: 'Validate input with Zod or a schema validator at the top of the Server Action.',
|
|
691
|
+
owasp: 'A03:2025 Injection',
|
|
692
|
+
cwe: 'CWE-20',
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
id: 'react.server-action-no-auth',
|
|
696
|
+
severity: 'medium',
|
|
697
|
+
confidence: 'low',
|
|
698
|
+
title: 'React Server Action without auth check',
|
|
699
|
+
re: /['"]use server['"]\s*[\s\S]*?function\s+\w+\s*\(/i,
|
|
700
|
+
skipComments: true,
|
|
701
|
+
message: 'Server Action has no visible auth check — anyone who can reach it can call it.',
|
|
702
|
+
fix: 'Add auth verification (getServerSession, auth(), clerk()) at the top of every Server Action.',
|
|
703
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
704
|
+
cwe: 'CWE-862',
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
id: 'webhook.no-signature-generic',
|
|
708
|
+
severity: 'high',
|
|
709
|
+
confidence: 'medium',
|
|
710
|
+
title: 'Webhook endpoint without signature verification',
|
|
711
|
+
re: /app\.(?:post|all)\s*\(\s*['"]\/?(?:api\/)?webhook/i,
|
|
712
|
+
skipComments: true,
|
|
713
|
+
message: 'Webhook endpoint detected — verify the request signature is checked before processing.',
|
|
714
|
+
fix: 'Verify the webhook signature (HMAC, Stripe-Signature, X-Signature, etc.) before processing the payload.',
|
|
715
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
716
|
+
cwe: 'CWE-345',
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
id: 'cron.no-auth',
|
|
720
|
+
severity: 'medium',
|
|
721
|
+
confidence: 'low',
|
|
722
|
+
title: 'Cron endpoint without authentication',
|
|
723
|
+
re: /app\.(?:get|post)\s*\(\s*['"]\/?(?:api\/)?cron/i,
|
|
724
|
+
skipComments: true,
|
|
725
|
+
message: 'Cron endpoint has no visible auth — anyone who knows the URL can trigger it.',
|
|
726
|
+
fix: 'Require a CRON_SECRET header or Vercel Cron authorization check.',
|
|
727
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
728
|
+
cwe: 'CWE-862',
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
id: 'csp.unsafe-inline',
|
|
732
|
+
severity: 'medium',
|
|
733
|
+
confidence: 'high',
|
|
734
|
+
title: 'CSP with unsafe-inline',
|
|
735
|
+
re: /Content-Security-Policy[^]*unsafe-inline/i,
|
|
736
|
+
skipComments: true,
|
|
737
|
+
message: 'Content-Security-Policy allows unsafe-inline — XSS can inject arbitrary scripts.',
|
|
738
|
+
fix: 'Remove unsafe-inline; use nonces or hashes for inline scripts.',
|
|
739
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
740
|
+
cwe: 'CWE-79',
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
id: 'csp.unsafe-eval',
|
|
744
|
+
severity: 'medium',
|
|
745
|
+
confidence: 'high',
|
|
746
|
+
title: 'CSP with unsafe-eval',
|
|
747
|
+
re: /Content-Security-Policy[^]*unsafe-eval/i,
|
|
748
|
+
skipComments: true,
|
|
749
|
+
message: 'Content-Security-Policy allows unsafe-eval — eval() and new Function() can be used for XSS.',
|
|
750
|
+
fix: 'Remove unsafe-eval; refactor any code that depends on eval/Function.',
|
|
751
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
752
|
+
cwe: 'CWE-79',
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
id: 'server-only-missing',
|
|
756
|
+
severity: 'low',
|
|
757
|
+
confidence: 'low',
|
|
758
|
+
title: 'Server-only module without import guard',
|
|
759
|
+
re: /import\s+\{[^}]*\}\s+from\s+['"]server-only['"]/i,
|
|
760
|
+
skipComments: true,
|
|
761
|
+
message: 'Server-only import detected — good practice. Verify all server-side modules use this guard.',
|
|
762
|
+
fix: 'Add "import \'server-only\'" to every server-side module that should never be bundled for the client.',
|
|
763
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
764
|
+
cwe: 'CWE-200',
|
|
765
|
+
},
|
|
766
|
+
];
|
|
767
|
+
|
|
768
|
+
// ---------------------------------------------------------------------------
|
|
769
|
+
// AI / LLM SECURITY (expanded — 30+ more rules)
|
|
770
|
+
// ---------------------------------------------------------------------------
|
|
771
|
+
|
|
772
|
+
const aiSecurityRules = [
|
|
773
|
+
{
|
|
774
|
+
id: 'ai.mcp-ssrf',
|
|
775
|
+
severity: 'high',
|
|
776
|
+
confidence: 'medium',
|
|
777
|
+
title: 'MCP server fetches a URL from tool input',
|
|
778
|
+
re: /(?:server|tool).*?fetch\s*\(\s*(?:args|input|params|request)\./i,
|
|
779
|
+
skipComments: true,
|
|
780
|
+
message: 'MCP tool fetches a URL from its input — SSRF if the tool is exposed to untrusted callers.',
|
|
781
|
+
fix: 'Allowlist URLs; block internal/metadata addresses (169.254.169.254, localhost, 10.x, 192.168.x).',
|
|
782
|
+
owasp: 'A10:2025 Server-Side Request Forgery',
|
|
783
|
+
cwe: 'CWE-918',
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
id: 'ai.mcp-path-traversal',
|
|
787
|
+
severity: 'high',
|
|
788
|
+
confidence: 'medium',
|
|
789
|
+
title: 'MCP server reads files from tool input',
|
|
790
|
+
re: /(?:readFile|readFileSync|writeFile|readdir)\s*\(\s*(?:args|input|params|request)\./i,
|
|
791
|
+
skipComments: true,
|
|
792
|
+
message: 'MCP tool accesses filesystem paths from its input — path traversal.',
|
|
793
|
+
fix: 'Restrict file access to a sandboxed directory; resolve and validate paths against a base.',
|
|
794
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
795
|
+
cwe: 'CWE-22',
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
id: 'ai.mcp-command-injection',
|
|
799
|
+
severity: 'critical',
|
|
800
|
+
confidence: 'medium',
|
|
801
|
+
title: 'MCP server executes commands from tool input',
|
|
802
|
+
re: /(?:exec|execSync|spawn|execFile)\s*\(\s*(?:args|input|params|request)\./i,
|
|
803
|
+
skipComments: true,
|
|
804
|
+
message: 'MCP tool executes shell commands from its input — command injection.',
|
|
805
|
+
fix: 'Never execute commands from tool input; use a fixed allowlist of commands with validated arguments.',
|
|
806
|
+
owasp: 'A03:2025 Injection',
|
|
807
|
+
cwe: 'CWE-77',
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
id: 'ai.mcp-description-injection-deep',
|
|
811
|
+
severity: 'medium',
|
|
812
|
+
confidence: 'medium',
|
|
813
|
+
title: 'MCP tool description with injection markers',
|
|
814
|
+
re: /description\s*:\s*['"`][^'"`]*(?:ignore\s+(?:all\s+)?(?:previous|prior|above)\s+instructions|you\s+are\s+now|system\s+prompt\s*:|override\s+safety|act\s+as\s+(?:a\s+)?(?:different|new)|forget\s+(?:all\s+)?(?:previous|prior)|disregard\s+(?:the\s+)?(?:above|previous)|jailbreak|DAN\s+mode|developer\s+mode|unrestricted\s+mode)/i,
|
|
815
|
+
skipComments: true,
|
|
816
|
+
message: 'MCP tool description contains prompt-injection markers — if fed to an LLM, it can hijack the model.',
|
|
817
|
+
fix: 'Remove all instruction-like text from tool descriptions; descriptions should be factual, not directive.',
|
|
818
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
819
|
+
cwe: 'CWE-1039',
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
id: 'ai.obfuscated-description',
|
|
823
|
+
severity: 'medium',
|
|
824
|
+
confidence: 'medium',
|
|
825
|
+
title: 'MCP tool description with obfuscated content',
|
|
826
|
+
re: /description\s*:\s*['"`](?:atob|Buffer\.from|fromCharCode|\\x[0-9a-f]{2})/i,
|
|
827
|
+
skipComments: true,
|
|
828
|
+
message: 'MCP tool description contains encoded/obfuscated content — a common prompt-injection evasion technique.',
|
|
829
|
+
fix: 'Use plain-text descriptions; remove any encoded or obfuscated content from tool metadata.',
|
|
830
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
831
|
+
cwe: 'CWE-1039',
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
id: 'ai.unrestricted-shell',
|
|
835
|
+
severity: 'critical',
|
|
836
|
+
confidence: 'high',
|
|
837
|
+
title: 'AI agent with unrestricted shell access',
|
|
838
|
+
re: /(?:agent|tool|function)\s*[:=]\s*[^}]*exec(?:Sync|File)?\s*\(/i,
|
|
839
|
+
skipComments: true,
|
|
840
|
+
message: 'AI agent/tool can execute shell commands — prompt injection becomes remote code execution.',
|
|
841
|
+
fix: 'Restrict to a fixed allowlist of commands; run in a sandbox; never pass user input to exec.',
|
|
842
|
+
owasp: 'A03:2025 Injection',
|
|
843
|
+
cwe: 'CWE-77',
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
id: 'ai.unrestricted-database',
|
|
847
|
+
severity: 'high',
|
|
848
|
+
confidence: 'medium',
|
|
849
|
+
title: 'AI agent with unrestricted database access',
|
|
850
|
+
re: /(?:agent|tool|function)\s*[:=]\s*[^}]*(?:query|execute|raw)\s*\(/i,
|
|
851
|
+
skipComments: true,
|
|
852
|
+
message: 'AI agent/tool can run database queries — prompt injection can exfiltrate or modify data.',
|
|
853
|
+
fix: 'Use parameterized, read-only queries with an allowlist; never let the agent build raw SQL.',
|
|
854
|
+
owasp: 'A03:2025 Injection',
|
|
855
|
+
cwe: 'CWE-89',
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
id: 'ai.missing-max-tokens',
|
|
859
|
+
severity: 'low',
|
|
860
|
+
confidence: 'low',
|
|
861
|
+
title: 'LLM call without maxTokens limit',
|
|
862
|
+
re: /(?:openai|anthropic|ai)\.(?:chat|completions|messages)\.create\s*\(\s*\{(?!.*?maxTokens)/s,
|
|
863
|
+
skipComments: true,
|
|
864
|
+
message: 'LLM API call without maxTokens — unbounded response length (cost and DoS risk).',
|
|
865
|
+
fix: 'Set maxTokens to a reasonable limit for your use case.',
|
|
866
|
+
owasp: 'A04:2025 Insecure Design',
|
|
867
|
+
cwe: 'CWE-770',
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
id: 'ai.agent-no-max-steps',
|
|
871
|
+
severity: 'medium',
|
|
872
|
+
confidence: 'medium',
|
|
873
|
+
title: 'AI agent loop without maxSteps',
|
|
874
|
+
re: /(?:while|for)\s*\([^)]*(?:agent|loop|step|iter)/i,
|
|
875
|
+
skipComments: true,
|
|
876
|
+
message: 'Agent loop without a step limit — infinite loop (cost, resource exhaustion).',
|
|
877
|
+
fix: 'Add a maxSteps/maxIterations counter; break the loop after a reasonable limit.',
|
|
878
|
+
owasp: 'A04:2025 Insecure Design',
|
|
879
|
+
cwe: 'CWE-835',
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
id: 'ai.key-in-url',
|
|
883
|
+
severity: 'high',
|
|
884
|
+
confidence: 'high',
|
|
885
|
+
title: 'AI API key passed in URL parameters',
|
|
886
|
+
re: /(?:api_key|apikey|key)\s*=\s*(?:sk-|sk-ant-)/i,
|
|
887
|
+
skipComments: true,
|
|
888
|
+
message: 'AI API key in a URL — exposed in browser history, server logs, and referrer headers.',
|
|
889
|
+
fix: 'Pass API keys in the Authorization header, never in URL parameters.',
|
|
890
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
891
|
+
cwe: 'CWE-200',
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
id: 'ai.llm-output-sql',
|
|
895
|
+
severity: 'high',
|
|
896
|
+
confidence: 'medium',
|
|
897
|
+
title: 'LLM output used in SQL query',
|
|
898
|
+
re: /(?:query|execute|raw)\s*\(\s*[^)]*(?:completion|response|content|text|output|generated)/i,
|
|
899
|
+
skipComments: true,
|
|
900
|
+
message: 'LLM output is passed to a SQL query — prompt injection becomes SQL injection.',
|
|
901
|
+
fix: 'Never use LLM output in queries. Parse structured data and parameterize.',
|
|
902
|
+
owasp: 'A03:2025 Injection',
|
|
903
|
+
cwe: 'CWE-89',
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
id: 'ai.llm-output-shell',
|
|
907
|
+
severity: 'critical',
|
|
908
|
+
confidence: 'medium',
|
|
909
|
+
title: 'LLM output used in shell command',
|
|
910
|
+
re: /(?:exec|spawn|execFile)\s*\(\s*[^)]*(?:completion|response|content|text|output|generated)/i,
|
|
911
|
+
skipComments: true,
|
|
912
|
+
message: 'LLM output is passed to a shell command — prompt injection becomes RCE.',
|
|
913
|
+
fix: 'Never use LLM output in shell commands. Use a fixed command with validated arguments.',
|
|
914
|
+
owasp: 'A03:2025 Injection',
|
|
915
|
+
cwe: 'CWE-77',
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
id: 'ai.llm-output-dom',
|
|
919
|
+
severity: 'high',
|
|
920
|
+
confidence: 'medium',
|
|
921
|
+
title: 'LLM output rendered in DOM',
|
|
922
|
+
re: /innerHTML\s*=\s*[^;]*(?:completion|response|content|text|output|message|generated)/i,
|
|
923
|
+
skipComments: true,
|
|
924
|
+
message: 'LLM output is set as innerHTML — prompt injection becomes XSS.',
|
|
925
|
+
fix: 'Render LLM output as text, not HTML. Use textContent or sanitize with DOMPurify.',
|
|
926
|
+
owasp: 'A03:2025 Injection',
|
|
927
|
+
cwe: 'CWE-79',
|
|
928
|
+
},
|
|
929
|
+
{
|
|
930
|
+
id: 'ai.llm-output-file',
|
|
931
|
+
severity: 'high',
|
|
932
|
+
confidence: 'medium',
|
|
933
|
+
title: 'LLM output used in file path',
|
|
934
|
+
re: /(?:readFile|writeFile|open|createReadStream)\s*\(\s*[^)]*(?:completion|response|content|text|output|generated)/i,
|
|
935
|
+
skipComments: true,
|
|
936
|
+
message: 'LLM output is used as a file path — path traversal via prompt injection.',
|
|
937
|
+
fix: 'Never use LLM output as a file path; validate and sanitize against a fixed base.',
|
|
938
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
939
|
+
cwe: 'CWE-22',
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
id: 'ai.system-prompt-leak',
|
|
943
|
+
severity: 'medium',
|
|
944
|
+
confidence: 'medium',
|
|
945
|
+
title: 'System prompt logged or returned to client',
|
|
946
|
+
re: /console\.(?:log|error|warn)\s*\([^)]*(?:systemPrompt|system_prompt|SYSTEM_PROMPT)/i,
|
|
947
|
+
skipComments: true,
|
|
948
|
+
message: 'System prompt is logged — visible in server logs, can leak sensitive instructions.',
|
|
949
|
+
fix: 'Never log the system prompt; treat it as a secret.',
|
|
950
|
+
owasp: 'A09:2025 Security Logging and Monitoring Failures',
|
|
951
|
+
cwe: 'CWE-532',
|
|
952
|
+
},
|
|
953
|
+
{
|
|
954
|
+
id: 'ai.prompt-template-injection',
|
|
955
|
+
severity: 'high',
|
|
956
|
+
confidence: 'medium',
|
|
957
|
+
title: 'User input embedded in system prompt',
|
|
958
|
+
re: /system\s*:\s*[^,}]*(?:req\.|user|input|query|params)/i,
|
|
959
|
+
skipComments: true,
|
|
960
|
+
message: 'User input is embedded in the system prompt — direct prompt injection.',
|
|
961
|
+
fix: 'Never put user input in the system prompt. Use the user message role for user content.',
|
|
962
|
+
owasp: 'A03:2025 Injection',
|
|
963
|
+
cwe: 'CWE-1039',
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
id: 'ai.rag-untrusted-data',
|
|
967
|
+
severity: 'medium',
|
|
968
|
+
confidence: 'low',
|
|
969
|
+
title: 'Untrusted data added to RAG vector store',
|
|
970
|
+
re: /(?:add|insert|upsert)\s*\([^)]*(?:req\.|user|input|submission)/i,
|
|
971
|
+
skipComments: true,
|
|
972
|
+
message: 'User-submitted data is added to a RAG/vector store without verification — poisoning.',
|
|
973
|
+
fix: 'Verify/moderate user-submitted content before adding to the vector store; separate trusted vs untrusted sources.',
|
|
974
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
975
|
+
cwe: 'CWE-20',
|
|
976
|
+
},
|
|
977
|
+
{
|
|
978
|
+
id: 'ai.tool-broad-file-access',
|
|
979
|
+
severity: 'medium',
|
|
980
|
+
confidence: 'medium',
|
|
981
|
+
title: 'AI tool with broad filesystem access',
|
|
982
|
+
re: /(?:readFile|readDir|glob|readdirSync)\s*\(\s*['"`](?:\/|\.\.\/|\*|~)/i,
|
|
983
|
+
skipComments: true,
|
|
984
|
+
message: 'AI tool reads from a broad path (root, parent, or wildcard) — excessive file access.',
|
|
985
|
+
fix: 'Restrict file access to a specific sandboxed directory; avoid wildcards and parent paths.',
|
|
986
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
987
|
+
cwe: 'CWE-22',
|
|
988
|
+
},
|
|
989
|
+
{
|
|
990
|
+
id: 'ai.tool-broad-network',
|
|
991
|
+
severity: 'medium',
|
|
992
|
+
confidence: 'medium',
|
|
993
|
+
title: 'AI tool with unrestricted network access',
|
|
994
|
+
re: /fetch\s*\(\s*(?:args|input|params|request)\.(?:url|host|endpoint|target)/i,
|
|
995
|
+
skipComments: true,
|
|
996
|
+
message: 'AI tool can fetch any URL from its input — SSRF and data exfiltration.',
|
|
997
|
+
fix: 'Allowlist URLs; block internal/metadata addresses; validate the scheme and host.',
|
|
998
|
+
owasp: 'A10:2025 Server-Side Request Forgery',
|
|
999
|
+
cwe: 'CWE-918',
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
id: 'ai.model-id-injection',
|
|
1003
|
+
severity: 'medium',
|
|
1004
|
+
confidence: 'low',
|
|
1005
|
+
title: 'AI model ID from user input',
|
|
1006
|
+
re: /model\s*:\s*req\.(?:body|query|params)\./i,
|
|
1007
|
+
skipComments: true,
|
|
1008
|
+
message: 'Model ID from user input — can access restricted models or cause unexpected behavior.',
|
|
1009
|
+
fix: 'Use a fixed model ID or validate against an allowlist of approved models.',
|
|
1010
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1011
|
+
cwe: 'CWE-20',
|
|
1012
|
+
},
|
|
1013
|
+
{
|
|
1014
|
+
id: 'ai.temperature-max',
|
|
1015
|
+
severity: 'low',
|
|
1016
|
+
confidence: 'low',
|
|
1017
|
+
title: 'LLM temperature set to maximum',
|
|
1018
|
+
re: /temperature\s*:\s*(?:2(?:\.0)?|1\.[89]|2\.0)\b/,
|
|
1019
|
+
skipComments: true,
|
|
1020
|
+
message: 'Temperature at maximum — outputs are unpredictable and may ignore safety constraints.',
|
|
1021
|
+
fix: 'Use a lower temperature (0.0–0.7) for most use cases; higher values increase hallucination risk.',
|
|
1022
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1023
|
+
cwe: 'CWE-1188',
|
|
1024
|
+
},
|
|
1025
|
+
{
|
|
1026
|
+
id: 'ai.openai-key-public',
|
|
1027
|
+
severity: 'critical',
|
|
1028
|
+
confidence: 'high',
|
|
1029
|
+
title: 'OpenAI API key exposed via public env prefix',
|
|
1030
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_|REACT_APP_).*?OPENAI_API_KEY/i,
|
|
1031
|
+
skipComments: true,
|
|
1032
|
+
message: 'OpenAI API key is exposed via a public env var prefix — anyone can use your OpenAI account.',
|
|
1033
|
+
fix: 'Use OPENAI_API_KEY without any public prefix — server-only.',
|
|
1034
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1035
|
+
cwe: 'CWE-200',
|
|
1036
|
+
},
|
|
1037
|
+
{
|
|
1038
|
+
id: 'ai.anthropic-key-public',
|
|
1039
|
+
severity: 'critical',
|
|
1040
|
+
confidence: 'high',
|
|
1041
|
+
title: 'Anthropic API key exposed via public env prefix',
|
|
1042
|
+
re: /(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_|REACT_APP_).*?ANTHROPIC_API_KEY/i,
|
|
1043
|
+
skipComments: true,
|
|
1044
|
+
message: 'Anthropic API key is exposed via a public env var prefix.',
|
|
1045
|
+
fix: 'Use ANTHROPIC_API_KEY without any public prefix — server-only.',
|
|
1046
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1047
|
+
cwe: 'CWE-200',
|
|
1048
|
+
},
|
|
1049
|
+
{
|
|
1050
|
+
id: 'ai.agent-can-modify-auth',
|
|
1051
|
+
severity: 'high',
|
|
1052
|
+
confidence: 'medium',
|
|
1053
|
+
title: 'AI agent can modify authentication config',
|
|
1054
|
+
re: /(?:agent|tool|function)\s*[:=]\s*[^}]*(?:auth|password|session|token|user|role)\s*(?:update|create|delete|modify|set|reset)/i,
|
|
1055
|
+
skipComments: true,
|
|
1056
|
+
message: 'AI agent/tool can modify auth-related data — prompt injection can create admin accounts or reset passwords.',
|
|
1057
|
+
fix: 'Never let an AI agent modify auth data; require a human-in-the-loop for auth changes.',
|
|
1058
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
1059
|
+
cwe: 'CWE-862',
|
|
1060
|
+
},
|
|
1061
|
+
{
|
|
1062
|
+
id: 'ai.agent-can-deploy',
|
|
1063
|
+
severity: 'high',
|
|
1064
|
+
confidence: 'medium',
|
|
1065
|
+
title: 'AI agent can trigger deployment',
|
|
1066
|
+
re: /(?:agent|tool|function)\s*[:=]\s*[^}]*(?:deploy|publish|release|ship)/i,
|
|
1067
|
+
skipComments: true,
|
|
1068
|
+
message: 'AI agent can trigger a deployment — prompt injection can ship malicious code.',
|
|
1069
|
+
fix: 'Never let an AI agent deploy; require a human review step before any deployment.',
|
|
1070
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1071
|
+
cwe: 'CWE-862',
|
|
1072
|
+
},
|
|
1073
|
+
{
|
|
1074
|
+
id: 'ai.agent-can-install-packages',
|
|
1075
|
+
severity: 'high',
|
|
1076
|
+
confidence: 'medium',
|
|
1077
|
+
title: 'AI agent can install packages',
|
|
1078
|
+
re: /(?:agent|tool|function)\s*[:=]\s*[^}]*(?:npm\s+install|pip\s+install|yarn\s+add|pnpm\s+add)/i,
|
|
1079
|
+
skipComments: true,
|
|
1080
|
+
message: 'AI agent can install packages — prompt injection can introduce supply-chain attacks.',
|
|
1081
|
+
fix: 'Never let an AI agent install packages; require a human review for dependency changes.',
|
|
1082
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
1083
|
+
cwe: 'CWE-494',
|
|
1084
|
+
},
|
|
1085
|
+
{
|
|
1086
|
+
id: 'ai.agent-can-access-secrets',
|
|
1087
|
+
severity: 'high',
|
|
1088
|
+
confidence: 'medium',
|
|
1089
|
+
title: 'AI agent can access environment secrets',
|
|
1090
|
+
re: /(?:agent|tool|function)\s*[:=]\s*[^}]*(?:process\.env|environment|secrets|\.env)/i,
|
|
1091
|
+
skipComments: true,
|
|
1092
|
+
message: 'AI agent can read environment variables — prompt injection can exfiltrate API keys and secrets.',
|
|
1093
|
+
fix: 'Never expose process.env to an AI agent; pass only the specific values it needs.',
|
|
1094
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1095
|
+
cwe: 'CWE-200',
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
id: 'ai.no-content-filter',
|
|
1099
|
+
severity: 'low',
|
|
1100
|
+
confidence: 'low',
|
|
1101
|
+
title: 'LLM call without content filtering / safety settings',
|
|
1102
|
+
re: /(?:openai|anthropic|google|ai)\.(?:chat|completions|messages|generateContent)\.create\s*\(\s*\{(?!.*?(?:safetySettings|content_filter|moderation|harm_categories))/s,
|
|
1103
|
+
skipComments: true,
|
|
1104
|
+
message: 'LLM API call without content filtering — harmful content may be generated or passed through.',
|
|
1105
|
+
fix: 'Enable moderation/safety settings for user-facing AI applications.',
|
|
1106
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1107
|
+
cwe: 'CWE-20',
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
id: 'ai.streaming-no-content-type',
|
|
1111
|
+
severity: 'low',
|
|
1112
|
+
confidence: 'low',
|
|
1113
|
+
title: 'AI streaming response without content-type check',
|
|
1114
|
+
re: /stream\s*:\s*true.*?(?!content-type)/i,
|
|
1115
|
+
skipComments: true,
|
|
1116
|
+
message: 'AI streaming response without content-type validation — a malicious stream can inject content.',
|
|
1117
|
+
fix: 'Set and verify the content-type of streamed AI responses.',
|
|
1118
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1119
|
+
cwe: 'CWE-20',
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
id: 'ai.agent-memory-poisoning',
|
|
1123
|
+
severity: 'medium',
|
|
1124
|
+
confidence: 'low',
|
|
1125
|
+
title: 'Untrusted data stored in agent memory',
|
|
1126
|
+
re: /(?:memory|context|history)\s*(?:\.add|\.push|\.set|\.append)\s*\([^)]*(?:req\.|user|input)/i,
|
|
1127
|
+
skipComments: true,
|
|
1128
|
+
message: 'User input is stored in agent memory/context — prompt injection persists across conversations.',
|
|
1129
|
+
fix: 'Sanitize and label user input before storing in agent memory; separate system vs user context.',
|
|
1130
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
1131
|
+
cwe: 'CWE-20',
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
id: 'ai.tool-can-execute-code',
|
|
1135
|
+
severity: 'critical',
|
|
1136
|
+
confidence: 'high',
|
|
1137
|
+
title: 'AI tool that can execute arbitrary code',
|
|
1138
|
+
re: /(?:name|description)\s*:\s*['"`](?:execute[_\s-]?code|run[_\s-]?code|eval[_\s-]?code|exec[_\s-]?python|exec[_\s-]?js|sandbox[_\s-]?exec)/i,
|
|
1139
|
+
skipComments: true,
|
|
1140
|
+
message: 'AI tool can execute arbitrary code — prompt injection becomes remote code execution.',
|
|
1141
|
+
fix: 'Remove code execution tools; if needed, use a hardened sandbox with no network and resource limits.',
|
|
1142
|
+
owasp: 'A03:2025 Injection',
|
|
1143
|
+
cwe: 'CWE-77',
|
|
1144
|
+
},
|
|
1145
|
+
];
|
|
1146
|
+
|
|
1147
|
+
// ---------------------------------------------------------------------------
|
|
1148
|
+
// SUPPLY CHAIN
|
|
1149
|
+
// ---------------------------------------------------------------------------
|
|
1150
|
+
|
|
1151
|
+
const supplyChainRules = [
|
|
1152
|
+
{
|
|
1153
|
+
id: 'supply-chain.postinstall-curl',
|
|
1154
|
+
severity: 'high',
|
|
1155
|
+
confidence: 'high',
|
|
1156
|
+
title: 'postinstall script downloads from network',
|
|
1157
|
+
re: /postinstall.*?curl|postinstall.*?wget/i,
|
|
1158
|
+
skipComments: true,
|
|
1159
|
+
message: 'postinstall script fetches from the network — common malware vector.',
|
|
1160
|
+
fix: 'Remove network calls from install scripts; vendor any needed files.',
|
|
1161
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
1162
|
+
cwe: 'CWE-494',
|
|
1163
|
+
},
|
|
1164
|
+
{
|
|
1165
|
+
id: 'supply-chain.dependency-confusion',
|
|
1166
|
+
severity: 'medium',
|
|
1167
|
+
confidence: 'low',
|
|
1168
|
+
title: 'Internal package name may be registerable on npm',
|
|
1169
|
+
re: /@(?!(?:anthropic|anthropic-ai|modelcontextprotocol|babel|types|opentelemetry|eslint|typescript-eslint|vitejs|nestjs|angular|vue|sveltejs|remix-run|vercel|next|facebook|react|google|mui|tailwindlabs|fortawesome|emotion-icons|storybook|vitest|testing-library|lottiefiles|radix-ui|shadcn|clerk|supabase|stripe|openai)\b)\w+\/\w+/i,
|
|
1170
|
+
skipComments: true,
|
|
1171
|
+
message: 'Scoped package name that might be registerable on public npm — dependency confusion attack.',
|
|
1172
|
+
fix: 'Use a private registry for internal packages; configure .npmrc scopes correctly.',
|
|
1173
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
1174
|
+
cwe: 'CWE-494',
|
|
1175
|
+
},
|
|
1176
|
+
{
|
|
1177
|
+
id: 'supply-chain.typosquat',
|
|
1178
|
+
severity: 'medium',
|
|
1179
|
+
confidence: 'low',
|
|
1180
|
+
title: 'Possible typosquat of a popular package',
|
|
1181
|
+
re: /(?:require|import).*?['"](?:reactt|reacct|lodahs|loadash|expres|exress|axioss|mognoose|mongose|moongose|nextt|vuue|angullar|sveltte|tailwindcsss|dottie|envee|chalkk|momment|colorette|fast-globb)['"]/i,
|
|
1182
|
+
skipComments: true,
|
|
1183
|
+
message: 'Package name looks like a typosquat of a popular package — verify the spelling.',
|
|
1184
|
+
fix: 'Check the package name spelling against the official npm registry.',
|
|
1185
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
1186
|
+
cwe: 'CWE-494',
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
id: 'supply-chain.node-ipc-protestware',
|
|
1190
|
+
severity: 'high',
|
|
1191
|
+
confidence: 'high',
|
|
1192
|
+
title: 'node-ipc package detected (protestware risk)',
|
|
1193
|
+
re: /['"]node-ipc['"]|require\s*\(\s*['"]node-ipc['"]\)/i,
|
|
1194
|
+
skipComments: true,
|
|
1195
|
+
message: 'node-ipc shipped protestware that wiped files on Russian/Belarusian IPs — remove this dependency.',
|
|
1196
|
+
fix: 'Replace node-ipc with a maintained alternative (e.g. node-event-emitter, @nestjs/event-emitter).',
|
|
1197
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
1198
|
+
cwe: 'CWE-494',
|
|
1199
|
+
},
|
|
1200
|
+
{
|
|
1201
|
+
id: 'supply-chain.ignore-scripts-missing',
|
|
1202
|
+
severity: 'low',
|
|
1203
|
+
confidence: 'low',
|
|
1204
|
+
title: 'npm install without --ignore-scripts in CI',
|
|
1205
|
+
re: /npm\s+(?:ci|install|i)\s+(?!.*?--ignore-scripts)/i,
|
|
1206
|
+
skipComments: true,
|
|
1207
|
+
message: 'npm install without --ignore-scripts — install scripts run automatically, a supply-chain attack vector.',
|
|
1208
|
+
fix: 'Use npm ci --ignore-scripts in CI; only enable scripts for trusted packages.',
|
|
1209
|
+
owasp: 'A08:2025 Software and Data Integrity Failures',
|
|
1210
|
+
cwe: 'CWE-494',
|
|
1211
|
+
},
|
|
1212
|
+
];
|
|
1213
|
+
|
|
1214
|
+
// ---------------------------------------------------------------------------
|
|
1215
|
+
// ADVANCED SECURITY: race conditions / brute force / audit logging / shell / SQL destructive
|
|
1216
|
+
// ---------------------------------------------------------------------------
|
|
1217
|
+
|
|
1218
|
+
const advancedSecurityRules = [
|
|
1219
|
+
{
|
|
1220
|
+
id: 'advanced.race-condition-check',
|
|
1221
|
+
severity: 'low',
|
|
1222
|
+
confidence: 'low',
|
|
1223
|
+
title: 'Check-then-act pattern (possible TOCTOU race condition)',
|
|
1224
|
+
re: /(?:if\s*\([^)]*(?:exists|find|count|get)\b[^)]*\)\s*\{[^}]*?(?:create|insert|update|delete|save|remove|destroy))/s,
|
|
1225
|
+
skipComments: true,
|
|
1226
|
+
message: 'Check-then-act pattern detected — TOCTOU race condition. Between the check and the action, state can change.',
|
|
1227
|
+
fix: 'Use atomic operations (upsert, findOneAndUpdate with conditions) or database-level locking.',
|
|
1228
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1229
|
+
cwe: 'CWE-367',
|
|
1230
|
+
},
|
|
1231
|
+
{
|
|
1232
|
+
id: 'advanced.no-audit-log',
|
|
1233
|
+
severity: 'low',
|
|
1234
|
+
confidence: 'low',
|
|
1235
|
+
title: 'State-changing operation without audit logging',
|
|
1236
|
+
re: /(?:app\.(?:post|put|delete)|router\.(?:post|put|delete))\s*\([^)]*['"]\/(?:api\/)?(?:admin|user|settings|config|delete|remove|destroy)/i,
|
|
1237
|
+
skipComments: true,
|
|
1238
|
+
message: 'State-changing admin/config endpoint without visible audit logging.',
|
|
1239
|
+
fix: 'Log who did what and when for all admin/state-changing operations.',
|
|
1240
|
+
owasp: 'A09:2025 Security Logging and Monitoring Failures',
|
|
1241
|
+
cwe: 'CWE-778',
|
|
1242
|
+
},
|
|
1243
|
+
{
|
|
1244
|
+
id: 'shell.pipe-to-bash',
|
|
1245
|
+
severity: 'medium',
|
|
1246
|
+
confidence: 'medium',
|
|
1247
|
+
title: 'Pipe to bash/sh from untrusted source',
|
|
1248
|
+
re: /curl\s+[^|]*\|\s*(?:sh|bash)|wget\s+[^|]*\|\s*(?:sh|bash)/i,
|
|
1249
|
+
skipComments: true,
|
|
1250
|
+
message: 'Piping a remote script to bash — arbitrary code execution if the URL is user-controlled or compromised.',
|
|
1251
|
+
fix: 'Download, review, then execute; never pipe remote scripts to a shell.',
|
|
1252
|
+
owasp: 'A03:2025 Injection',
|
|
1253
|
+
cwe: 'CWE-77',
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
id: 'shell.chmod-777',
|
|
1257
|
+
severity: 'low',
|
|
1258
|
+
confidence: 'high',
|
|
1259
|
+
title: 'chmod 777 (world-writable)',
|
|
1260
|
+
re: /chmod\s+777/i,
|
|
1261
|
+
skipComments: true,
|
|
1262
|
+
message: 'chmod 777 makes a file/dir world-writable, readable, and executable — any user can modify it.',
|
|
1263
|
+
fix: 'Use least-privilege permissions (e.g. chmod 755 for dirs, chmod 644 for files).',
|
|
1264
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1265
|
+
cwe: 'CWE-732',
|
|
1266
|
+
},
|
|
1267
|
+
{
|
|
1268
|
+
id: 'shell.rm-rf-root',
|
|
1269
|
+
severity: 'high',
|
|
1270
|
+
confidence: 'high',
|
|
1271
|
+
title: 'rm -rf on root or wildcard path',
|
|
1272
|
+
re: /rm\s+-rf?\s+(?:\/|\/\*|\.\.\/\.\.\/\.\.\/|~\/?\*|~\/?\/)/i,
|
|
1273
|
+
skipComments: true,
|
|
1274
|
+
message: 'rm -rf targeting root, home, or a parent path — can destroy the entire filesystem.',
|
|
1275
|
+
fix: 'Never rm -rf with root, home, or wildcard parent paths; use a specific, validated directory.',
|
|
1276
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1277
|
+
cwe: 'CWE-22',
|
|
1278
|
+
},
|
|
1279
|
+
{
|
|
1280
|
+
id: 'shell.sudo-password',
|
|
1281
|
+
severity: 'high',
|
|
1282
|
+
confidence: 'high',
|
|
1283
|
+
title: 'sudo with password on command line',
|
|
1284
|
+
re: /sudo\s+--?password|echo\s+['"]\S+['"]\s*\|\s*sudo\s+-S/i,
|
|
1285
|
+
skipComments: true,
|
|
1286
|
+
message: 'sudo password on the command line — visible in process list and shell history.',
|
|
1287
|
+
fix: 'Use sudoers config or a secrets manager; never pass passwords on the command line.',
|
|
1288
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
1289
|
+
cwe: 'CWE-256',
|
|
1290
|
+
},
|
|
1291
|
+
{
|
|
1292
|
+
id: 'sql.delete-without-where',
|
|
1293
|
+
severity: 'high',
|
|
1294
|
+
confidence: 'high',
|
|
1295
|
+
title: 'DELETE/UPDATE without WHERE clause',
|
|
1296
|
+
re: /\b(?:DELETE|UPDATE)\s+(?:FROM\s+)?\w+(?!\s+WHERE)\s*(?:;|$)/i,
|
|
1297
|
+
skipComments: true,
|
|
1298
|
+
message: 'DELETE/UPDATE without a WHERE clause — affects every row in the table.',
|
|
1299
|
+
fix: 'Always include a WHERE clause; add a row-count safeguard before executing.',
|
|
1300
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1301
|
+
cwe: 'CWE-89',
|
|
1302
|
+
},
|
|
1303
|
+
{
|
|
1304
|
+
id: 'sql.drop-table',
|
|
1305
|
+
severity: 'high',
|
|
1306
|
+
confidence: 'high',
|
|
1307
|
+
title: 'DROP TABLE in code',
|
|
1308
|
+
re: /\bDROP\s+TABLE\b/i,
|
|
1309
|
+
skipComments: true,
|
|
1310
|
+
message: 'DROP TABLE in code — destructive, irreversible. Verify this is intentional and guarded.',
|
|
1311
|
+
fix: 'Guard DROP TABLE behind admin auth and a confirmation step; prefer soft delete.',
|
|
1312
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1313
|
+
cwe: 'CWE-89',
|
|
1314
|
+
},
|
|
1315
|
+
{
|
|
1316
|
+
id: 'sql.grant-all',
|
|
1317
|
+
severity: 'high',
|
|
1318
|
+
confidence: 'high',
|
|
1319
|
+
title: 'GRANT ALL privileges',
|
|
1320
|
+
re: /\bGRANT\s+ALL\b/i,
|
|
1321
|
+
skipComments: true,
|
|
1322
|
+
message: 'GRANT ALL gives every privilege — over-broad database access.',
|
|
1323
|
+
fix: 'Grant only the specific privileges needed (SELECT, INSERT, UPDATE) to specific tables.',
|
|
1324
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
1325
|
+
cwe: 'CWE-862',
|
|
1326
|
+
},
|
|
1327
|
+
{
|
|
1328
|
+
id: 'sql.stacked-queries',
|
|
1329
|
+
severity: 'medium',
|
|
1330
|
+
confidence: 'medium',
|
|
1331
|
+
title: 'Stacked SQL queries (multiple statements)',
|
|
1332
|
+
re: /;\s*(?:SELECT|INSERT|UPDATE|DELETE|DROP|ALTER|CREATE)\b/i,
|
|
1333
|
+
skipComments: true,
|
|
1334
|
+
message: 'Multiple SQL statements in one query — stacked queries enable injection escalation.',
|
|
1335
|
+
fix: 'Execute one statement per query call; use parameterized queries.',
|
|
1336
|
+
owasp: 'A03:2025 Injection',
|
|
1337
|
+
cwe: 'CWE-89',
|
|
1338
|
+
},
|
|
1339
|
+
];
|
|
1340
|
+
|
|
1341
|
+
// ---------------------------------------------------------------------------
|
|
1342
|
+
// GO LANGUAGE
|
|
1343
|
+
// ---------------------------------------------------------------------------
|
|
1344
|
+
|
|
1345
|
+
const goRules = [
|
|
1346
|
+
{
|
|
1347
|
+
id: 'go.sql-injection',
|
|
1348
|
+
severity: 'high',
|
|
1349
|
+
confidence: 'high',
|
|
1350
|
+
title: 'Go SQL query with string concatenation',
|
|
1351
|
+
re: /(?:db\.(?:Query|Exec|QueryRow)|sql\.(?:Open|Query))\s*\([^)]*(?:fmt\.Sprintf|\+\s*|req\.)/i,
|
|
1352
|
+
skipComments: true,
|
|
1353
|
+
message: 'Go SQL query built with string concatenation — SQL injection.',
|
|
1354
|
+
fix: 'Use parameterized queries: db.Query("SELECT ... WHERE id = ?", id).',
|
|
1355
|
+
owasp: 'A03:2025 Injection',
|
|
1356
|
+
cwe: 'CWE-89',
|
|
1357
|
+
},
|
|
1358
|
+
{
|
|
1359
|
+
id: 'go.command-injection',
|
|
1360
|
+
severity: 'high',
|
|
1361
|
+
confidence: 'high',
|
|
1362
|
+
title: 'Go exec.Command with user input',
|
|
1363
|
+
re: /exec\.Command\s*\(\s*['"`]?(?:sh|bash|cmd|powershell)['"`]?\s*,\s*['"`]-c['"`]\s*,\s*[^)]*(?:req\.|r\.|input|args)/i,
|
|
1364
|
+
skipComments: true,
|
|
1365
|
+
message: 'Go exec.Command with shell and user input — command injection.',
|
|
1366
|
+
fix: 'Pass arguments directly to exec.Command without a shell; validate input.',
|
|
1367
|
+
owasp: 'A03:2025 Injection',
|
|
1368
|
+
cwe: 'CWE-77',
|
|
1369
|
+
},
|
|
1370
|
+
{
|
|
1371
|
+
id: 'go.template-no-escape',
|
|
1372
|
+
severity: 'medium',
|
|
1373
|
+
confidence: 'medium',
|
|
1374
|
+
title: 'Go template without auto-escaping',
|
|
1375
|
+
re: /template\.(?:HTML|JS|URL|HTMLAttr)\s*\(/i,
|
|
1376
|
+
skipComments: true,
|
|
1377
|
+
message: 'Go template uses HTML/JS/URL type — bypasses auto-escaping, XSS risk.',
|
|
1378
|
+
fix: 'Use template.Text or let the default html/template auto-escape; avoid template.HTML for user data.',
|
|
1379
|
+
owasp: 'A03:2025 Injection',
|
|
1380
|
+
cwe: 'CWE-79',
|
|
1381
|
+
},
|
|
1382
|
+
{
|
|
1383
|
+
id: 'go.crypto-weak',
|
|
1384
|
+
severity: 'medium',
|
|
1385
|
+
confidence: 'high',
|
|
1386
|
+
title: 'Go weak crypto (md5/sha1 for security)',
|
|
1387
|
+
re: /\b(?:md5|sha1)\.(?:New|Sum)\s*\(/i,
|
|
1388
|
+
skipComments: true,
|
|
1389
|
+
message: 'Go uses md5 or sha1 — weak hash, broken for security purposes.',
|
|
1390
|
+
fix: 'Use sha256 or sha512 for hashing; use bcrypt/argon2 for passwords.',
|
|
1391
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1392
|
+
cwe: 'CWE-327',
|
|
1393
|
+
},
|
|
1394
|
+
{
|
|
1395
|
+
id: 'go.tls-skip-verify',
|
|
1396
|
+
severity: 'high',
|
|
1397
|
+
confidence: 'high',
|
|
1398
|
+
title: 'Go TLS verification disabled',
|
|
1399
|
+
re: /InsecureSkipVerify\s*:\s*true/i,
|
|
1400
|
+
skipComments: true,
|
|
1401
|
+
message: 'Go TLS InsecureSkipVerify: true — MITM attacks possible.',
|
|
1402
|
+
fix: 'Remove InsecureSkipVerify; verify the server certificate.',
|
|
1403
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1404
|
+
cwe: 'CWE-295',
|
|
1405
|
+
},
|
|
1406
|
+
{
|
|
1407
|
+
id: 'go.hardcoded-secret',
|
|
1408
|
+
severity: 'high',
|
|
1409
|
+
confidence: 'high',
|
|
1410
|
+
title: 'Go hardcoded secret',
|
|
1411
|
+
re: /(?:password|secret|apikey|api_key|token)\s*:?=\s*['"`][^'"`]{8,}['"`]/i,
|
|
1412
|
+
skipComments: true,
|
|
1413
|
+
filter: (line) => !/process\.env|os\.Getenv|your_|changeme|placeholder|example|dummy|test/i.test(line),
|
|
1414
|
+
fileFilter: /\.go$/i,
|
|
1415
|
+
message: 'Hardcoded secret in Go source — use environment variables.',
|
|
1416
|
+
fix: 'Load secrets from environment variables (os.Getenv) or a secrets manager.',
|
|
1417
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1418
|
+
cwe: 'CWE-798',
|
|
1419
|
+
},
|
|
1420
|
+
];
|
|
1421
|
+
|
|
1422
|
+
// ---------------------------------------------------------------------------
|
|
1423
|
+
// MOBILE: React Native / Expo
|
|
1424
|
+
// ---------------------------------------------------------------------------
|
|
1425
|
+
|
|
1426
|
+
const mobileRules = [
|
|
1427
|
+
{
|
|
1428
|
+
id: 'mobile.asyncstorage-secret',
|
|
1429
|
+
severity: 'high',
|
|
1430
|
+
confidence: 'high',
|
|
1431
|
+
title: 'Secret stored in AsyncStorage',
|
|
1432
|
+
re: /AsyncStorage\.(?:setItem|multiSet)\s*\([^)]*(?:token|secret|password|key|auth|credential)/i,
|
|
1433
|
+
skipComments: true,
|
|
1434
|
+
message: 'Secret stored in AsyncStorage — unencrypted, accessible to any JS on the device.',
|
|
1435
|
+
fix: 'Use expo-secure-store or Keychain/Keystore for secrets; never AsyncStorage.',
|
|
1436
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1437
|
+
cwe: 'CWE-312',
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
id: 'mobile.deep-link-token',
|
|
1441
|
+
severity: 'high',
|
|
1442
|
+
confidence: 'medium',
|
|
1443
|
+
title: 'Token passed via deep link',
|
|
1444
|
+
re: /Linking\.(?:getInitialURL|openURL|addEventListener)\s*\([^)]*(?:token|auth|password|secret)/i,
|
|
1445
|
+
skipComments: true,
|
|
1446
|
+
message: 'Token/auth data passed via deep links — other apps can intercept the deep link.',
|
|
1447
|
+
fix: 'Use a secure redirect flow (PKCE); do not pass tokens in deep link URLs.',
|
|
1448
|
+
owasp: 'A07:2025 Identification and Authentication Failures',
|
|
1449
|
+
cwe: 'CWE-200',
|
|
1450
|
+
},
|
|
1451
|
+
{
|
|
1452
|
+
id: 'mobile.hardcoded-api-url',
|
|
1453
|
+
severity: 'medium',
|
|
1454
|
+
confidence: 'medium',
|
|
1455
|
+
title: 'Hardcoded API URL in mobile app',
|
|
1456
|
+
re: /['"`]https?:\/\/(?:localhost|127\.0\.0\.1|10\.0\.2\.2|192\.168\.\d+\.\d+)[^'"`]*['"`]/i,
|
|
1457
|
+
skipComments: true,
|
|
1458
|
+
fileFilter: /(?:App\.tsx?|app\.config\.(?:ts|js)|expo|react-native|nativ|mobile|\.swift$|\.kt$|\.m$)/i,
|
|
1459
|
+
message: 'Hardcoded local/dev API URL in mobile app — will break in production or expose dev endpoints.',
|
|
1460
|
+
fix: 'Use environment-based config (react-native-config / expo-constants) for API URLs.',
|
|
1461
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1462
|
+
cwe: 'CWE-712',
|
|
1463
|
+
},
|
|
1464
|
+
{
|
|
1465
|
+
id: 'mobile.ats-disabled',
|
|
1466
|
+
severity: 'medium',
|
|
1467
|
+
confidence: 'high',
|
|
1468
|
+
title: 'iOS App Transport Security disabled',
|
|
1469
|
+
re: /NSAllowsArbitraryLoads\s*:\s*true|NSAllowsArbitraryLoadsForMedia\s*:\s*true/i,
|
|
1470
|
+
skipComments: true,
|
|
1471
|
+
message: 'ATS disabled — allows non-HTTPS connections, MITM risk.',
|
|
1472
|
+
fix: 'Enable ATS; use HTTPS for all network connections.',
|
|
1473
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1474
|
+
cwe: 'CWE-295',
|
|
1475
|
+
},
|
|
1476
|
+
{
|
|
1477
|
+
id: 'mobile.debug-enabled',
|
|
1478
|
+
severity: 'low',
|
|
1479
|
+
confidence: 'medium',
|
|
1480
|
+
title: 'Remote debugging enabled in mobile app',
|
|
1481
|
+
re: /devSettings|isDebugMode|__DEV__|remote debugging/i,
|
|
1482
|
+
skipComments: true,
|
|
1483
|
+
message: 'Debug/remote debugging settings detected — can expose the JS context in production.',
|
|
1484
|
+
fix: 'Disable remote debugging in production builds.',
|
|
1485
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1486
|
+
cwe: 'CWE-489',
|
|
1487
|
+
},
|
|
1488
|
+
{
|
|
1489
|
+
id: 'mobile.expo-no-security-check',
|
|
1490
|
+
severity: 'low',
|
|
1491
|
+
confidence: 'low',
|
|
1492
|
+
title: 'Expo app without security config',
|
|
1493
|
+
re: /expo.*?app\.json/i,
|
|
1494
|
+
skipComments: true,
|
|
1495
|
+
message: 'Expo app — verify security config in app.json (codePush, encryptionKey, updates).',
|
|
1496
|
+
fix: 'Set up code signing for OTA updates; restrict the updates URL; use production config.',
|
|
1497
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1498
|
+
cwe: 'CWE-489',
|
|
1499
|
+
},
|
|
1500
|
+
];
|
|
1501
|
+
|
|
1502
|
+
// ---------------------------------------------------------------------------
|
|
1503
|
+
// DEPLOYMENT CONFIG: Vercel / Netlify / Fly / Render / Cloudflare / K8s / Docker Compose
|
|
1504
|
+
// ---------------------------------------------------------------------------
|
|
1505
|
+
|
|
1506
|
+
const deploymentRules = [
|
|
1507
|
+
{
|
|
1508
|
+
id: 'deploy.vercel-cron-no-secret',
|
|
1509
|
+
severity: 'medium',
|
|
1510
|
+
confidence: 'medium',
|
|
1511
|
+
title: 'Vercel cron job without authorization',
|
|
1512
|
+
re: /\"crons\"\s*:\s*\[\s*\{[^}]*(?!.*?(?:authorization|secret|CRON_SECRET))/s,
|
|
1513
|
+
skipComments: true,
|
|
1514
|
+
message: 'Vercel cron job without authorization — anyone who knows the URL can trigger it.',
|
|
1515
|
+
fix: 'Add CRON_SECRET authorization check in the cron endpoint handler.',
|
|
1516
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
1517
|
+
cwe: 'CWE-862',
|
|
1518
|
+
},
|
|
1519
|
+
{
|
|
1520
|
+
id: 'deploy.vercel-no-headers',
|
|
1521
|
+
severity: 'low',
|
|
1522
|
+
confidence: 'low',
|
|
1523
|
+
title: 'Vercel config without security headers',
|
|
1524
|
+
re: /\"headers\"\s*:\s*(?!\s*\[)/i,
|
|
1525
|
+
skipComments: true,
|
|
1526
|
+
message: 'Vercel config without security headers — deployed site lacks CSP, HSTS, X-Frame-Options.',
|
|
1527
|
+
fix: 'Add a headers section to vercel.json with CSP, HSTS, X-Frame-Options, X-Content-Type-Options.',
|
|
1528
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1529
|
+
cwe: 'CWE-693',
|
|
1530
|
+
},
|
|
1531
|
+
{
|
|
1532
|
+
id: 'deploy.docker-privileged',
|
|
1533
|
+
severity: 'high',
|
|
1534
|
+
confidence: 'high',
|
|
1535
|
+
title: 'Docker container with privileged mode',
|
|
1536
|
+
re: /privileged\s*:\s*true/i,
|
|
1537
|
+
skipComments: true,
|
|
1538
|
+
message: 'Docker container runs in privileged mode — full host access, breaks container isolation.',
|
|
1539
|
+
fix: 'Remove privileged: true; use --cap-add for specific capabilities if needed.',
|
|
1540
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1541
|
+
cwe: 'CWE-250',
|
|
1542
|
+
},
|
|
1543
|
+
{
|
|
1544
|
+
id: 'deploy.docker-no-resource-limits',
|
|
1545
|
+
severity: 'low',
|
|
1546
|
+
confidence: 'low',
|
|
1547
|
+
title: 'Docker container without resource limits',
|
|
1548
|
+
re: /(?:deploy|resources)\s*:(?!\s*limits)/i,
|
|
1549
|
+
skipComments: true,
|
|
1550
|
+
message: 'Docker container without resource limits — a single container can exhaust host resources.',
|
|
1551
|
+
fix: 'Set memory and CPU limits in docker-compose.yml or the deploy config.',
|
|
1552
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1553
|
+
cwe: 'CWE-770',
|
|
1554
|
+
},
|
|
1555
|
+
{
|
|
1556
|
+
id: 'deploy.docker-secrets-env',
|
|
1557
|
+
severity: 'high',
|
|
1558
|
+
confidence: 'high',
|
|
1559
|
+
title: 'Secrets in Docker Compose environment',
|
|
1560
|
+
re: /environment\s*:\s*[^}]*(?:PASSWORD|SECRET|TOKEN|API_KEY|PRIVATE_KEY)\s*:\s*['"]\S{8,}['"]/i,
|
|
1561
|
+
skipComments: true,
|
|
1562
|
+
message: 'Secret hardcoded in Docker Compose environment — visible in the compose file and image layers.',
|
|
1563
|
+
fix: 'Use Docker secrets or ${VAR} references to environment variables; never hardcode secrets in compose.',
|
|
1564
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1565
|
+
cwe: 'CWE-798',
|
|
1566
|
+
},
|
|
1567
|
+
{
|
|
1568
|
+
id: 'deploy.k8s-secret-plain',
|
|
1569
|
+
severity: 'high',
|
|
1570
|
+
confidence: 'high',
|
|
1571
|
+
title: 'Kubernetes Secret in plain text',
|
|
1572
|
+
re: /kind\s*:\s*Secret[\s\S]*?(?:password|token|key|secret)\s*:\s*(?![\s\S]*base64)/i,
|
|
1573
|
+
skipComments: true,
|
|
1574
|
+
message: 'Kubernetes Secret with plain-text data — should be base64-encoded and managed via a secrets manager.',
|
|
1575
|
+
fix: 'Base64-encode secret values; use external secrets or sealed-secrets for production.',
|
|
1576
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1577
|
+
cwe: 'CWE-312',
|
|
1578
|
+
},
|
|
1579
|
+
{
|
|
1580
|
+
id: 'deploy.k8s-privileged',
|
|
1581
|
+
severity: 'high',
|
|
1582
|
+
confidence: 'high',
|
|
1583
|
+
title: 'Kubernetes pod with privileged container',
|
|
1584
|
+
re: /privileged\s*:\s*true/i,
|
|
1585
|
+
skipComments: true,
|
|
1586
|
+
message: 'Kubernetes privileged container — breaks pod isolation, full host access.',
|
|
1587
|
+
fix: 'Remove privileged: true; use securityContext with specific capabilities.',
|
|
1588
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1589
|
+
cwe: 'CWE-250',
|
|
1590
|
+
},
|
|
1591
|
+
{
|
|
1592
|
+
id: 'deploy.k8s-no-limits',
|
|
1593
|
+
severity: 'low',
|
|
1594
|
+
confidence: 'low',
|
|
1595
|
+
title: 'Kubernetes container without resource limits',
|
|
1596
|
+
re: /containers\s*:\s*[\s\S]*?(?!.*?resources\s*:\s*\{)/i,
|
|
1597
|
+
skipComments: true,
|
|
1598
|
+
message: 'Kubernetes container without resource limits — can consume all node resources.',
|
|
1599
|
+
fix: 'Add resources.limits and resources.requests to every container spec.',
|
|
1600
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1601
|
+
cwe: 'CWE-770',
|
|
1602
|
+
},
|
|
1603
|
+
{
|
|
1604
|
+
id: 'deploy.netlify-no-headers',
|
|
1605
|
+
severity: 'low',
|
|
1606
|
+
confidence: 'low',
|
|
1607
|
+
title: 'Netlify config without security headers',
|
|
1608
|
+
re: /\[headers\](?!\s*Strict-Transport)/i,
|
|
1609
|
+
skipComments: true,
|
|
1610
|
+
message: 'Netlify config without security headers — deployed site lacks CSP, HSTS.',
|
|
1611
|
+
fix: 'Add a [[headers]] section to netlify.toml with security headers.',
|
|
1612
|
+
owasp: 'A05:2025 Security Misconfiguration',
|
|
1613
|
+
cwe: 'CWE-693',
|
|
1614
|
+
},
|
|
1615
|
+
];
|
|
1616
|
+
|
|
1617
|
+
// ---------------------------------------------------------------------------
|
|
1618
|
+
// OWASP API SECURITY (expanded)
|
|
1619
|
+
// ---------------------------------------------------------------------------
|
|
1620
|
+
|
|
1621
|
+
const owaspApiRules = [
|
|
1622
|
+
{
|
|
1623
|
+
id: 'api.no-pagination',
|
|
1624
|
+
severity: 'low',
|
|
1625
|
+
confidence: 'low',
|
|
1626
|
+
title: 'API endpoint returns all records without pagination',
|
|
1627
|
+
re: /(?:app|router)\.(?:get)\s*\(\s*['"]\/(?:api\/)?(?:users|orders|items|products|posts|comments|records)/i,
|
|
1628
|
+
skipComments: true,
|
|
1629
|
+
message: 'GET endpoint that lists resources without visible pagination — DoS via large result sets.',
|
|
1630
|
+
fix: 'Add pagination (limit/offset or cursor-based) to all list endpoints.',
|
|
1631
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1632
|
+
cwe: 'CWE-770',
|
|
1633
|
+
},
|
|
1634
|
+
{
|
|
1635
|
+
id: 'api.admin-endpoint-no-auth',
|
|
1636
|
+
severity: 'high',
|
|
1637
|
+
confidence: 'medium',
|
|
1638
|
+
title: 'Admin endpoint without authorization check',
|
|
1639
|
+
re: /(?:app|router)\.(?:get|post|put|delete|patch)\s*\(\s*['"]\/(?:api\/)?admin/i,
|
|
1640
|
+
skipComments: true,
|
|
1641
|
+
message: 'Admin API endpoint without visible auth middleware — any caller can access admin functions.',
|
|
1642
|
+
fix: 'Add auth middleware (admin guard) to all /admin routes.',
|
|
1643
|
+
owasp: 'A01:2025 Broken Access Control',
|
|
1644
|
+
cwe: 'CWE-862',
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
id: 'api.verbose-error',
|
|
1648
|
+
severity: 'medium',
|
|
1649
|
+
confidence: 'medium',
|
|
1650
|
+
title: 'Verbose error details sent to client',
|
|
1651
|
+
re: /res\.(?:json|send)\s*\(\s*\{[^}]*(?:error|err|stack|trace|query|sql)/i,
|
|
1652
|
+
skipComments: true,
|
|
1653
|
+
message: 'Error response includes internal details (stack trace, SQL, query) — information leak.',
|
|
1654
|
+
fix: 'Send a generic error message to the client; log full details server-side only.',
|
|
1655
|
+
owasp: 'A04:2025 Insecure Design',
|
|
1656
|
+
cwe: 'CWE-209',
|
|
1657
|
+
},
|
|
1658
|
+
{
|
|
1659
|
+
id: 'api.password-in-response',
|
|
1660
|
+
severity: 'high',
|
|
1661
|
+
confidence: 'high',
|
|
1662
|
+
title: 'Password field included in API response',
|
|
1663
|
+
re: /res\.(?:json|send)\s*\(\s*\{[^}]*\bpassword\b/i,
|
|
1664
|
+
skipComments: true,
|
|
1665
|
+
message: 'Password field is included in the API response — even a hash should not be sent to the client.',
|
|
1666
|
+
fix: 'Never include password fields in API responses; use a serializer that excludes them.',
|
|
1667
|
+
owasp: 'A02:2025 Cryptographic Failures',
|
|
1668
|
+
cwe: 'CWE-200',
|
|
1669
|
+
},
|
|
1670
|
+
{
|
|
1671
|
+
id: 'api.no-input-validation',
|
|
1672
|
+
severity: 'low',
|
|
1673
|
+
confidence: 'low',
|
|
1674
|
+
title: 'API endpoint without input validation',
|
|
1675
|
+
re: /(?:app|router)\.(?:post|put|patch)\s*\(\s*['"][^'"]+['"]\s*,\s*(?:async\s*)?\((?:req|request)\s*,/i,
|
|
1676
|
+
skipComments: true,
|
|
1677
|
+
message: 'POST/PUT/PATCH endpoint with no visible input validation — unvalidated client data.',
|
|
1678
|
+
fix: 'Validate input with a schema validator (Zod, Joi, express-validator) at the top of the handler.',
|
|
1679
|
+
owasp: 'A03:2025 Injection',
|
|
1680
|
+
cwe: 'CWE-20',
|
|
1681
|
+
},
|
|
1682
|
+
];
|
|
1683
|
+
|
|
1684
|
+
// ---------------------------------------------------------------------------
|
|
1685
|
+
// CVE VERSION INTELLIGENCE (known vulnerable package versions in package.json)
|
|
1686
|
+
// ---------------------------------------------------------------------------
|
|
1687
|
+
|
|
1688
|
+
const cveVersionRules = [
|
|
1689
|
+
// Next.js
|
|
1690
|
+
{ id: 'cve.nextjs-2025-29927', severity: 'high', confidence: 'high', title: 'Next.js CVE-2025-29927 (middleware bypass)', pkg: 'next', vuln: ['<14.2.25', '<15.2.3'], cve: 'CVE-2025-29927', fix: 'Upgrade next to >=14.2.25 or >=15.2.3' },
|
|
1691
|
+
{ id: 'cve.nextjs-2024-34351', severity: 'high', confidence: 'high', title: 'Next.js CVE-2024-34351 (SSRF via Server Actions)', pkg: 'next', vuln: ['<14.1.1'], cve: 'CVE-2024-34351', fix: 'Upgrade next to >=14.1.1' },
|
|
1692
|
+
{ id: 'cve.nextjs-2024-46982', severity: 'medium', confidence: 'high', title: 'Next.js CVE-2024-46982 (cache poisoning)', pkg: 'next', vuln: ['<14.2.15', '<15.0.3'], cve: 'CVE-2024-46982', fix: 'Upgrade next to >=14.2.15 or >=15.0.3' },
|
|
1693
|
+
// Express
|
|
1694
|
+
{ id: 'cve.express-qsproto', severity: 'medium', confidence: 'high', title: 'Express querystring prototype pollution', pkg: 'express', vuln: ['<4.17.3'], cve: 'CVE-2022-24999', fix: 'Upgrade express to >=4.17.3' },
|
|
1695
|
+
// jsonwebtoken
|
|
1696
|
+
{ id: 'cve.jwt-2022-23529', severity: 'high', confidence: 'high', title: 'jsonwebtoken CVE-2022-23529 (key confusion)', pkg: 'jsonwebtoken', vuln: ['<9.0.0'], cve: 'CVE-2022-23529', fix: 'Upgrade jsonwebtoken to >=9.0.0' },
|
|
1697
|
+
// Axios
|
|
1698
|
+
{ id: 'cve.axios-2024-39338', severity: 'high', confidence: 'high', title: 'Axios CVE-2024-39338 (SSRF)', pkg: 'axios', vuln: ['<1.7.4'], cve: 'CVE-2024-39338', fix: 'Upgrade axios to >=1.7.4' },
|
|
1699
|
+
{ id: 'cve.axios-2024-28849', severity: 'medium', confidence: 'high', title: 'Axios CVE-2024-28849 (credential leak on redirect)', pkg: 'axios', vuln: ['<1.6.0'], cve: 'CVE-2024-28849', fix: 'Upgrade axios to >=1.6.0' },
|
|
1700
|
+
// Drizzle
|
|
1701
|
+
{ id: 'cve.drizzle-2026-39356', severity: 'high', confidence: 'high', title: 'Drizzle ORM CVE-2026-39356 (SQL identifier injection)', pkg: 'drizzle-orm', vuln: ['<0.36.4'], cve: 'CVE-2026-39356', fix: 'Upgrade drizzle-orm to >=0.36.4' },
|
|
1702
|
+
// Hono
|
|
1703
|
+
{ id: 'cve.hono-setcookie', severity: 'medium', confidence: 'high', title: 'Hono setCookie attribute injection', pkg: 'hono', vuln: ['<4.12.21'], cve: 'VG1072', fix: 'Upgrade hono to >=4.12.21' },
|
|
1704
|
+
// Vite
|
|
1705
|
+
{ id: 'cve.vite-2024-52011', severity: 'high', confidence: 'high', title: 'Vite CVE-2024-52011 (dev server command injection)', pkg: 'vite', vuln: ['<5.4.12', '<6.0.7'], cve: 'CVE-2024-52011', fix: 'Upgrade vite to >=5.4.12 or >=6.0.7' },
|
|
1706
|
+
// DOMPurify
|
|
1707
|
+
{ id: 'cve.dompurify-2026-47423', severity: 'high', confidence: 'high', title: 'DOMPurify CVE-2026-47423 (XSS bypass)', pkg: 'dompurify', vuln: ['<3.2.4'], cve: 'CVE-2026-47423', fix: 'Upgrade dompurify to >=3.2.4' },
|
|
1708
|
+
// React Router
|
|
1709
|
+
{ id: 'cve.react-router-7', severity: 'medium', confidence: 'high', title: 'React Router 7 CVE cluster', pkg: '@remix-run/router', vuln: ['<7.1.1'], cve: 'CVE-2026-33245', fix: 'Upgrade @remix-run/router to >=7.1.1' },
|
|
1710
|
+
// Better Auth
|
|
1711
|
+
{ id: 'cve.better-auth-2026', severity: 'high', confidence: 'high', title: 'Better Auth bypass CVE-2026-45337', pkg: 'better-auth', vuln: ['<1.2.0'], cve: 'CVE-2026-45337', fix: 'Upgrade better-auth to >=1.2.0' },
|
|
1712
|
+
// @anthropic-ai/sdk
|
|
1713
|
+
{ id: 'cve.anthropic-sdk-2026', severity: 'medium', confidence: 'high', title: '@anthropic-ai/sdk CVE-2026-34451 (memory tool path escape)', pkg: '@anthropic-ai/sdk', vuln: ['<0.40.0'], cve: 'CVE-2026-34451', fix: 'Upgrade @anthropic-ai/sdk to >=0.40.0' },
|
|
1714
|
+
// Vercel AI SDK
|
|
1715
|
+
{ id: 'cve.ai-sdk-2025-48985', severity: 'medium', confidence: 'high', title: 'Vercel AI SDK CVE-2025-48985 (file-type bypass)', pkg: 'ai', vuln: ['<4.0.0'], cve: 'CVE-2025-48985', fix: 'Upgrade ai to >=4.0.0' },
|
|
1716
|
+
// vm2
|
|
1717
|
+
{ id: 'cve.vm2-sandbox', severity: 'critical', confidence: 'high', title: 'vm2 sandbox escape (deprecated, multiple CVEs)', pkg: 'vm2', vuln: ['*'], cve: 'CVE-2023-37903', fix: 'Remove vm2 — it is deprecated and has unpatchable sandbox escapes. Use isolated-vm or alternatives.' },
|
|
1718
|
+
// node-fetch
|
|
1719
|
+
{ id: 'cve.node-fetch-2022', severity: 'medium', confidence: 'high', title: 'node-fetch CVE-2022-0235 (cookie leak)', pkg: 'node-fetch', vuln: ['<2.6.7', '<3.2.4'], cve: 'CVE-2022-0235', fix: 'Upgrade node-fetch to >=2.6.7 or >=3.2.4' },
|
|
1720
|
+
// lodash
|
|
1721
|
+
{ id: 'cve.lodash-prototype', severity: 'high', confidence: 'high', title: 'lodash CVE-2019-10777 (prototype pollution)', pkg: 'lodash', vuln: ['<4.17.21'], cve: 'CVE-2019-10777', fix: 'Upgrade lodash to >=4.17.21' },
|
|
1722
|
+
// tar
|
|
1723
|
+
{ id: 'cve.tar-2021-32803', severity: 'high', confidence: 'high', title: 'tar CVE-2021-32803 (arbitrary file creation)', pkg: 'tar', vuln: ['<6.1.2'], cve: 'CVE-2021-32803', fix: 'Upgrade tar to >=6.1.2' },
|
|
1724
|
+
// sharp
|
|
1725
|
+
{ id: 'cve.sharp-2025', severity: 'medium', confidence: 'medium', title: 'sharp potential image processing vulnerability', pkg: 'sharp', vuln: ['<0.33.5'], cve: 'GHSA-2025', fix: 'Upgrade sharp to >=0.33.5' },
|
|
1726
|
+
// crypto-js
|
|
1727
|
+
{ id: 'cve.cryptojs-2024', severity: 'medium', confidence: 'high', title: 'crypto-js CVE-2024 (PBKDF2 weak default)', pkg: 'crypto-js', vuln: ['<4.2.0'], cve: 'CVE-2023-46233', fix: 'Upgrade crypto-js to >=4.2.0 or use native crypto' },
|
|
1728
|
+
// xml2js
|
|
1729
|
+
{ id: 'cve.xml2js-2023', severity: 'medium', confidence: 'high', title: 'xml2js prototype pollution', pkg: 'xml2js', vuln: ['<0.6.2'], cve: 'CVE-2023-31500', fix: 'Upgrade xml2js to >=0.6.2' },
|
|
1730
|
+
// fast-xml-parser
|
|
1731
|
+
{ id: 'cve.fastxml-2024', severity: 'medium', confidence: 'high', title: 'fast-xml-parser CVE-2024 (entity expansion)', pkg: 'fast-xml-parser', vuln: ['<4.4.1'], cve: 'CVE-2024-45676', fix: 'Upgrade fast-xml-parser to >=4.4.1' },
|
|
1732
|
+
// ws
|
|
1733
|
+
{ id: 'cve.ws-2024', severity: 'medium', confidence: 'high', title: 'ws CVE-2024 (DoS via oversized headers)', pkg: 'ws', vuln: ['<8.17.1'], cve: 'CVE-2024-37890', fix: 'Upgrade ws to >=8.17.1' },
|
|
1734
|
+
// undici
|
|
1735
|
+
{ id: 'cve.undici-2024', severity: 'medium', confidence: 'high', title: 'undici CVE-2024 (header injection)', pkg: 'undici', vuln: ['<6.19.8'], cve: 'CVE-2024-45801', fix: 'Upgrade undici to >=6.19.8' },
|
|
1736
|
+
// systeminformation
|
|
1737
|
+
{ id: 'cve.systeminformation-2026', severity: 'high', confidence: 'high', title: 'systeminformation CVE-2026-44724 (Linux command injection)', pkg: 'systeminformation', vuln: ['<5.23.0'], cve: 'CVE-2026-44724', fix: 'Upgrade systeminformation to >=5.23.0' },
|
|
1738
|
+
// @wdio/browserstack-service
|
|
1739
|
+
{ id: 'cve.wdio-2026', severity: 'high', confidence: 'high', title: '@wdio/browserstack-service CVE-2026-25244 (command injection via git branch)', pkg: '@wdio/browserstack-service', vuln: ['<8.41.0'], cve: 'CVE-2026-25244', fix: 'Upgrade @wdio/browserstack-service to >=8.41.0' },
|
|
1740
|
+
// @babel/plugin-transform-modules-systemjs
|
|
1741
|
+
{ id: 'cve.babel-systemjs-2026', severity: 'medium', confidence: 'high', title: '@babel/plugin-transform-modules-systemjs CVE-2026-44728', pkg: '@babel/plugin-transform-modules-systemjs', vuln: ['<7.25.0'], cve: 'CVE-2026-44728', fix: 'Upgrade @babel/plugin-transform-modules-systemjs to >=7.25.0' },
|
|
1742
|
+
// @opentelemetry/exporter-prometheus
|
|
1743
|
+
{ id: 'cve.otel-prom-2026', severity: 'medium', confidence: 'high', title: '@opentelemetry/exporter-prometheus CVE-2026-44902 (DoS)', pkg: '@opentelemetry/exporter-prometheus', vuln: ['<0.53.0'], cve: 'CVE-2026-44902', fix: 'Upgrade @opentelemetry/exporter-prometheus to >=0.53.0' },
|
|
1744
|
+
// angular-expressions
|
|
1745
|
+
{ id: 'cve.angular-expr-2026', severity: 'high', confidence: 'high', title: 'angular-expressions RCE (CVE-2026)', pkg: 'angular-expressions', vuln: ['<1.4.3'], cve: 'CVE-2026-22599', fix: 'Upgrade angular-expressions to >=1.4.3 or remove' },
|
|
1746
|
+
];
|
|
1747
|
+
|
|
1748
|
+
// ---------------------------------------------------------------------------
|
|
1749
|
+
// COMPLIANCE MAPPING (CWE -> control IDs for SOC2/PCI/HIPAA/GDPR/ISO27001/EUAIAct)
|
|
1750
|
+
// ---------------------------------------------------------------------------
|
|
1751
|
+
|
|
1752
|
+
const COMPLIANCE_MAP = {
|
|
1753
|
+
SOC2: {
|
|
1754
|
+
'CWE-79': ['CC6.1', 'CC6.7'],
|
|
1755
|
+
'CWE-89': ['CC6.1', 'CC6.7'],
|
|
1756
|
+
'CWE-200': ['CC6.1', 'CC6.7'],
|
|
1757
|
+
'CWE-798': ['CC6.1', 'CC6.7'],
|
|
1758
|
+
'CWE-862': ['CC6.1', 'CC6.3'],
|
|
1759
|
+
'CWE-918': ['CC6.1', 'CC6.7'],
|
|
1760
|
+
'CWE-77': ['CC6.1', 'CC6.7'],
|
|
1761
|
+
'CWE-321': ['CC6.1', 'CC6.7'],
|
|
1762
|
+
'CWE-327': ['CC6.1', 'CC6.7'],
|
|
1763
|
+
'CWE-295': ['CC6.1', 'CC6.7'],
|
|
1764
|
+
'CWE-22': ['CC6.1', 'CC6.7'],
|
|
1765
|
+
'CWE-352': ['CC6.1'],
|
|
1766
|
+
'CWE-915': ['CC6.1', 'CC7.1'],
|
|
1767
|
+
'CWE-1039': ['CC6.1', 'CC7.1'],
|
|
1768
|
+
'CWE-494': ['CC6.1', 'CC7.4'],
|
|
1769
|
+
'CWE-532': ['CC7.2', 'CC7.3'],
|
|
1770
|
+
'CWE-778': ['CC7.2'],
|
|
1771
|
+
},
|
|
1772
|
+
'PCI-DSS': {
|
|
1773
|
+
'CWE-79': ['6.5.7'],
|
|
1774
|
+
'CWE-89': ['6.5.1'],
|
|
1775
|
+
'CWE-200': ['3.1', '6.5.10'],
|
|
1776
|
+
'CWE-798': ['6.5.10', '8.2.1'],
|
|
1777
|
+
'CWE-862': ['6.5.8', '7.1'],
|
|
1778
|
+
'CWE-918': ['6.5.9'],
|
|
1779
|
+
'CWE-77': ['6.5.1'],
|
|
1780
|
+
'CWE-321': ['3.4', '6.5.3'],
|
|
1781
|
+
'CWE-327': ['3.4', '6.5.3'],
|
|
1782
|
+
'CWE-295': ['4.1'],
|
|
1783
|
+
'CWE-256': ['8.2.1'],
|
|
1784
|
+
'CWE-312': ['3.4'],
|
|
1785
|
+
},
|
|
1786
|
+
HIPAA: {
|
|
1787
|
+
'CWE-200': ['164.312(a)(1)', '164.312(b)'],
|
|
1788
|
+
'CWE-798': ['164.312(a)(2)(i)', '164.312(d)'],
|
|
1789
|
+
'CWE-862': ['164.312(a)(1)', '164.312(b)'],
|
|
1790
|
+
'CWE-321': ['164.312(a)(2)(iv)'],
|
|
1791
|
+
'CWE-327': ['164.312(a)(2)(iv)', '164.312(e)(2)(ii)'],
|
|
1792
|
+
'CWE-295': ['164.312(e)(1)'],
|
|
1793
|
+
'CWE-312': ['164.312(a)(2)(iv)'],
|
|
1794
|
+
'CWE-532': ['164.312(b)'],
|
|
1795
|
+
'CWE-778': ['164.312(b)'],
|
|
1796
|
+
},
|
|
1797
|
+
GDPR: {
|
|
1798
|
+
'CWE-200': ['Art.5', 'Art.32'],
|
|
1799
|
+
'CWE-798': ['Art.32'],
|
|
1800
|
+
'CWE-862': ['Art.5', 'Art.25'],
|
|
1801
|
+
'CWE-321': ['Art.32'],
|
|
1802
|
+
'CWE-327': ['Art.32'],
|
|
1803
|
+
'CWE-295': ['Art.32'],
|
|
1804
|
+
'CWE-312': ['Art.32'],
|
|
1805
|
+
'CWE-359': ['Art.5'],
|
|
1806
|
+
'CWE-532': ['Art.25', 'Art.32'],
|
|
1807
|
+
},
|
|
1808
|
+
ISO27001: {
|
|
1809
|
+
'CWE-79': ['A.14.2.5'],
|
|
1810
|
+
'CWE-89': ['A.14.2.5'],
|
|
1811
|
+
'CWE-200': ['A.9.4.3'],
|
|
1812
|
+
'CWE-798': ['A.9.4.3', 'A.14.2.5'],
|
|
1813
|
+
'CWE-862': ['A.9.4.1', 'A.9.4.4'],
|
|
1814
|
+
'CWE-918': ['A.14.2.5', 'A.13.1.1'],
|
|
1815
|
+
'CWE-321': ['A.10.1.1', 'A.10.1.2'],
|
|
1816
|
+
'CWE-327': ['A.10.1.1', 'A.10.1.2'],
|
|
1817
|
+
'CWE-295': ['A.13.1.1', 'A.13.2.1'],
|
|
1818
|
+
'CWE-494': ['A.14.2.5', 'A.15.1.1'],
|
|
1819
|
+
'CWE-532': ['A.12.4.1'],
|
|
1820
|
+
},
|
|
1821
|
+
EUAIAct: {
|
|
1822
|
+
'CWE-1039': ['Art.15', 'Art.27'],
|
|
1823
|
+
'CWE-77': ['Art.15'],
|
|
1824
|
+
'CWE-89': ['Art.15'],
|
|
1825
|
+
'CWE-79': ['Art.15'],
|
|
1826
|
+
},
|
|
1827
|
+
};
|
|
1828
|
+
|
|
1829
|
+
// ---------------------------------------------------------------------------
|
|
1830
|
+
// EXPORTS
|
|
1831
|
+
// ---------------------------------------------------------------------------
|
|
1832
|
+
// GAP BATCH 1: 15 more secret types
|
|
1833
|
+
// ---------------------------------------------------------------------------
|
|
1834
|
+
|
|
1835
|
+
const extraSecretRules = [
|
|
1836
|
+
{ id: 'secret.gcp-service-account', severity: 'critical', re: /"type":\s*"service_account"[^}]*"private_key"/, message: 'GCP service account JSON key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move GCP service account key to a secret manager or environment variable.' },
|
|
1837
|
+
{ id: 'secret.gcp-api-key', severity: 'high', re: /AIza[0-9A-Za-z_-]{35}/, filter: (line) => !/(?:123456|abcdefgh|test|placeholder|example|dummy|fake|sample)/i.test(line), message: 'GCP API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.GOOGLE_API_KEY.' },
|
|
1838
|
+
{ id: 'secret.azure-storage-key', severity: 'high', re: /DefaultEndpointsProtocol=https?;AccountName=[^;]+;AccountKey=[A-Za-z0-9+/=]{50,}/, message: 'Azure Storage connection string with key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to Azure Key Vault or environment variable.' },
|
|
1839
|
+
{ id: 'secret.cloudflare-api-token', severity: 'high', re: /(?:cloudflare_api_token|CF_API_TOKEN)\s*[:=]\s*['"][A-Za-z0-9_-]{40,}['"]/i, message: 'Cloudflare API token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.CLOUDFLARE_API_TOKEN.' },
|
|
1840
|
+
{ id: 'secret.datadog-api-key', severity: 'high', re: /(?:DATADOG_API_KEY|DD_API_KEY)\s*[:=]\s*['"][0-9a-f]{32,}['"]/i, message: 'Datadog API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.DATADOG_API_KEY.' },
|
|
1841
|
+
{ id: 'secret.sentry-dsn', severity: 'medium', re: /SENTRY_DSN\s*[:=]\s*['"]https?:\/\/[a-f0-9]{32}@[\w.-]+\/\d+['"]/i, message: 'Sentry DSN with secret key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.SENTRY_DSN.' },
|
|
1842
|
+
{ id: 'secret.algolia-api-key', severity: 'high', re: /ALGOLIA_(?:ADMIN_)?API_KEY\s*[:=]\s*['"][a-f0-9]{32}['"]/i, message: 'Algolia API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.ALGOLIA_API_KEY.' },
|
|
1843
|
+
{ id: 'secret.vercel-token', severity: 'high', re: /VERCEL_TOKEN\s*[:=]\s*['"][A-Za-z0-9]{24,}['"]/i, message: 'Vercel token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.VERCEL_TOKEN.' },
|
|
1844
|
+
{ id: 'secret.netlify-token', severity: 'high', re: /NETLIFY_AUTH_TOKEN\s*[:=]\s*['"][A-Za-z0-9_-]{40,}['"]/i, message: 'Netlify auth token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.NETLIFY_AUTH_TOKEN.' },
|
|
1845
|
+
{ id: 'secret.heroku-api-key', severity: 'high', re: /HEROKU_API_KEY\s*[:=]\s*['"][0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}['"]/i, message: 'Heroku API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.HEROKU_API_KEY.' },
|
|
1846
|
+
{ id: 'secret.digitalocean-token', severity: 'high', re: /DIGITALOCEAN_TOKEN\s*[:=]\s*['"][A-Za-z0-9]{64}['"]/i, message: 'DigitalOcean access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.DIGITALOCEAN_TOKEN.' },
|
|
1847
|
+
{ id: 'secret.notion-token', severity: 'high', re: /NOTION_(?:API_)?TOKEN\s*[:=]\s*['"]secret_[A-Za-z0-9_]{43}['"]/i, message: 'Notion API token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.NOTION_TOKEN.' },
|
|
1848
|
+
{ id: 'secret.linear-api-key', severity: 'high', re: /LINEAR_API_KEY\s*[:=]\s*['"]lin_api_[A-Za-z0-9_]{40,}['"]/i, message: 'Linear API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.LINEAR_API_KEY.' },
|
|
1849
|
+
{ id: 'secret.contentful-token', severity: 'high', re: /CONTENTFUL_(?:DELIVERY_)?ACCESS_TOKEN\s*[:=]\s*['"][A-Za-z0-9_-]{43,}['"]/i, message: 'Contentful access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.CONTENTFUL_ACCESS_TOKEN.' },
|
|
1850
|
+
{ id: 'secret.planetscale-token', severity: 'high', re: /PLANETSCALE_(?:SERVICE_)?TOKEN\s*[:=]\s*['"]pscale_tkn_[A-Za-z0-9_]{43,}['"]/i, message: 'PlanetScale service token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.PLANETSCALE_TOKEN.' },
|
|
1851
|
+
];
|
|
1852
|
+
|
|
1853
|
+
// ---------------------------------------------------------------------------
|
|
1854
|
+
// GAP BATCH 2: 12 language-specific rules (Java 3, Ruby 3, PHP 3, C# 3)
|
|
1855
|
+
// ---------------------------------------------------------------------------
|
|
1856
|
+
|
|
1857
|
+
const javaRules = [
|
|
1858
|
+
{ id: 'java.unsafe-deserialization', severity: 'critical', re: /ObjectInputStream\s*\(/, message: 'Java ObjectInputStream — unsafe deserialization (RCE risk)', cwe: 'CWE-502', owasp: 'A08', fix: 'Use a whitelist filter or avoid Java serialization. Consider JSON.' },
|
|
1859
|
+
{ id: 'java.runtime-exec', severity: 'high', re: /Runtime\.getRuntime\(\)\.exec\s*\(/, message: 'Runtime.exec() — potential command injection in Java', cwe: 'CWE-78', owasp: 'A03', fix: 'Use ProcessBuilder with argument list, never string concatenation.' },
|
|
1860
|
+
{ id: 'java.spel-injection', severity: 'high', re: /SpelExpressionParser|parseExpression\s*\(\s*[^)]*\+/ , message: 'Spring SpEL with string concatenation — expression injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Use SimpleEvaluationContext.forReadOnlyDataBinding() or parameterized expressions.' },
|
|
1861
|
+
];
|
|
1862
|
+
|
|
1863
|
+
const rubyRules = [
|
|
1864
|
+
{ id: 'ruby.eval', severity: 'critical', re: /\beval\s*\(/, skipComments: true, fileFilter: '\\.rb$', message: 'Ruby eval() — code injection risk', cwe: 'CWE-94', owasp: 'A03', fix: 'Avoid eval. Use safe parsing or validated input.' },
|
|
1865
|
+
{ id: 'ruby.sql-injection', severity: 'high', re: /(?:where|order|find_by_sql|execute)\s*\(?["'].*#\{/, fileFilter: '\\.rb$', message: 'Ruby SQL with string interpolation — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized queries: where("id = ?", params[:id]).' },
|
|
1866
|
+
{ id: 'ruby.command-injection', severity: 'high', re: /`[^`]*#\{/, fileFilter: '\\.rb$', message: 'Ruby backtick exec with interpolation — command injection', cwe: 'CWE-78', owasp: 'A03', fix: 'Use system() with array arguments or Open3.capture3.' },
|
|
1867
|
+
];
|
|
1868
|
+
|
|
1869
|
+
const phpRules = [
|
|
1870
|
+
{ id: 'php.unserialize', severity: 'critical', re: /unserialize\s*\(\s*\$/, message: 'PHP unserialize() — unsafe deserialization (RCE risk)', cwe: 'CWE-502', owasp: 'A08', fix: 'Use json_decode() instead of unserialize() for untrusted data.' },
|
|
1871
|
+
{ id: 'php.eval', severity: 'critical', re: /\beval\s*\(\s*\$/, message: 'PHP eval() with variable — code injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Never eval() user input. Use a safe parser or template engine.' },
|
|
1872
|
+
{ id: 'php.sql-injection', severity: 'high', re: /(?:mysql_query|mysqli_query|pg_query)\s*\(\s*[^,]*\$\w+/, message: 'PHP SQL query with variable — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use prepared statements: $stmt = $pdo->prepare("SELECT ... WHERE id = ?"); $stmt->execute([$id]).' },
|
|
1873
|
+
];
|
|
1874
|
+
|
|
1875
|
+
const csharpRules = [
|
|
1876
|
+
{ id: 'csharp.sql-injection', severity: 'high', re: /SqlCommand\s*\(\s*["'].*\+\s*\w/, message: 'C# SqlCommand with string concatenation — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use SqlParameter: cmd.Parameters.AddWithValue("@id", id).' },
|
|
1877
|
+
{ id: 'csharp.command-injection', severity: 'high', re: /Process\.Start\s*\(\s*[^,]*\+/, message: 'C# Process.Start with string concatenation — command injection', cwe: 'CWE-78', owasp: 'A03', fix: 'Use ProcessStartInfo with separate arguments array.' },
|
|
1878
|
+
{ id: 'csharp.random', severity: 'medium', re: /new\s+Random\s*\(\s*\)/, message: 'C# Random() without seed — predictable random numbers', cwe: 'CWE-330', owasp: 'A02', fix: 'Use RandomNumberGenerator for crypto or RandomNumberGenerator.Create().' },
|
|
1879
|
+
];
|
|
1880
|
+
|
|
1881
|
+
// ---------------------------------------------------------------------------
|
|
1882
|
+
// GAP BATCH 3: 15 framework rules (Django 3, Flask 2, Rails 3, Laravel 2, Spring 2, Fastify 1, SvelteKit 1, Nuxt 1)
|
|
1883
|
+
// ---------------------------------------------------------------------------
|
|
1884
|
+
|
|
1885
|
+
const djangoRules = [
|
|
1886
|
+
{ id: 'django.debug-true', severity: 'critical', re: /DEBUG\s*=\s*True/, message: 'Django DEBUG=True in production — exposes secrets and stack traces', cwe: 'CWE-489', owasp: 'A05', fileFilter: '\\.py$', fix: 'Set DEBUG=False in production. Use environment variables.' },
|
|
1887
|
+
{ id: 'django.secret-key-hardcoded', severity: 'high', re: /SECRET_KEY\s*=\s*['"][A-Za-z0-9_-]{20,}['"]/, message: 'Django SECRET_KEY hardcoded', cwe: 'CWE-798', owasp: 'A02', fileFilter: '\\.py$', fix: 'Load from environment: SECRET_KEY = os.environ[\'SECRET_KEY\']' },
|
|
1888
|
+
{ id: 'django.allowed-hosts-wildcard', severity: 'high', re: /ALLOWED_HOSTS\s*=\s*\[\s*['"]\*['"]\s*\]/, message: 'Django ALLOWED_HOSTS wildcard — host header attacks', cwe: 'CWE-444', owasp: 'A05', fileFilter: '\\.py$', fix: 'Set ALLOWED_HOSTS to your specific domains.' },
|
|
1889
|
+
];
|
|
1890
|
+
|
|
1891
|
+
const flaskRules = [
|
|
1892
|
+
{ id: 'flask-debug-true', severity: 'critical', re: /app\.run\s*\([^)]*debug\s*=\s*True/, message: 'Flask debug=True — exposes Werkzeug debugger (RCE)', cwe: 'CWE-489', owasp: 'A05', fix: 'Never run with debug=True in production. Use app.run(debug=os.environ.get("FLASK_DEBUG", "0") == "1").' },
|
|
1893
|
+
{ id: 'flask-secret-key-hardcoded', severity: 'high', re: /app\.secret_key\s*=\s*['"][A-Za-z0-9_-]{16,}['"]/, message: 'Flask secret_key hardcoded — session forgery', cwe: 'CWE-798', owasp: 'A02', fix: 'Load from environment: app.secret_key = os.environ[\'FLASK_SECRET_KEY\']' },
|
|
1894
|
+
];
|
|
1895
|
+
|
|
1896
|
+
const railsRules = [
|
|
1897
|
+
{ id: 'rails-html-safe', severity: 'high', re: /\.html_safe\b/, message: 'Rails html_safe — XSS bypass', cwe: 'CWE-79', owasp: 'A03', fix: 'Sanitize with sanitize() or content_tag. Never html_safe on user input.' },
|
|
1898
|
+
{ id: 'rails-skip-csrf', severity: 'high', re: /protect_from_forgery\s+(?:with:\s+:null_session|except:\s+:all|skip_before_action\s+:verify_authenticity_token)/, message: 'Rails CSRF protection disabled', cwe: 'CWE-352', owasp: 'A01', fix: 'Keep CSRF protection. Use with: :exception or :reset_session.' },
|
|
1899
|
+
{ id: 'rails-eval', severity: 'critical', re: /\beval\s*\(\s*params/, message: 'Rails eval with params — code injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Never eval user input. Use safe parsing.' },
|
|
1900
|
+
];
|
|
1901
|
+
|
|
1902
|
+
const laravelRules = [
|
|
1903
|
+
{ id: 'laravel-unescaped', severity: 'high', re: /\{!!.*!!\}/, message: 'Laravel {!! !!} unescaped output — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Use {{ }} for escaped output. Only use {!! !!} for trusted content.' },
|
|
1904
|
+
{ id: 'laravel-mass-assignment', severity: 'medium', re: /fillable\s*=\s*\[\s*\]|guarded\s*=\s*\[\s*\]/, message: 'Laravel empty fillable/guarded — mass assignment', cwe: 'CWE-915', owasp: 'A01', fix: 'Explicitly list fillable fields: protected $fillable = [\'name\', \'email\'];' },
|
|
1905
|
+
];
|
|
1906
|
+
|
|
1907
|
+
const springRules = [
|
|
1908
|
+
{ id: 'spring-actuator-exposed', severity: 'high', re: /management\.endpoints\.web\.exposure\.include\s*[=:]\s*['"]\*['"]/, message: 'Spring Actuator all endpoints exposed — info leak', cwe: 'CWE-200', owasp: 'A05', fix: 'Expose only health: management.endpoints.web.exposure.include=health' },
|
|
1909
|
+
{ id: 'spring-cors-wildcard', severity: 'medium', re: /@CrossOrigin\s*\(\s*(?:origins\s*=\s*)?['"]\*['"]/, message: 'Spring @CrossOrigin wildcard — CORS open to all', cwe: 'CWE-942', owasp: 'A05', fix: 'Set specific origins in @CrossOrigin(origins = {"https://yourapp.com"}).' },
|
|
1910
|
+
];
|
|
1911
|
+
|
|
1912
|
+
const fastifyRules = [
|
|
1913
|
+
{ id: 'fastify-cors-wildcard', severity: 'medium', re: /fastify\.register\s*\(\s*cors\s*,\s*\{[^}]*origin\s*:\s*['"]\*['"]/, message: 'Fastify CORS wildcard origin', cwe: 'CWE-942', owasp: 'A05', fix: 'Set origin to specific allowed domains.' },
|
|
1914
|
+
];
|
|
1915
|
+
|
|
1916
|
+
const svelteKitRules = [
|
|
1917
|
+
{ id: 'sveltekit-eval-action', severity: 'high', re: /@html\s*\{[^}]*\$\s*(?:page|data|params)/, message: 'SvelteKit @html with user data — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Never use @html with user input. Sanitize first or use text interpolation.' },
|
|
1918
|
+
];
|
|
1919
|
+
|
|
1920
|
+
const nuxtRules = [
|
|
1921
|
+
{ id: 'nuxt-vuln-ssr', severity: 'medium', re: /render\s*:\s*(?:'ssr'|true)/, message: 'Nuxt SSR with user input without sanitization — XSS risk', cwe: 'CWE-79', owasp: 'A03', fix: 'Ensure all rendered content is sanitized server-side.' },
|
|
1922
|
+
];
|
|
1923
|
+
|
|
1924
|
+
// ---------------------------------------------------------------------------
|
|
1925
|
+
// GAP BATCH 4: 5 OWASP API Top 10 rules (BOLA, broken auth, unrestricted consumption, improper inventory, unsafe API consumption)
|
|
1926
|
+
// ---------------------------------------------------------------------------
|
|
1927
|
+
|
|
1928
|
+
const owaspApiRulesExtra = [
|
|
1929
|
+
{ id: 'api.bola-id-from-request', severity: 'high', re: /(?:findById|findOne|getById|getOne|fetchById|retrieve|delete|update|patch)\s*\(\s*req\.(?:params|body|query)\.(?:id|userId|accountId|ownerId|customerId)/, message: 'OWASP API1:2023 — BOLA: object ID from request without ownership check', cwe: 'CWE-639', owasp: 'A01', fix: 'Verify the authenticated user owns the resource before returning/modifying.' },
|
|
1930
|
+
{ id: 'api.broken-auth-jwt-no-expiry', severity: 'high', re: /jwt\.sign\s*\([^)]*?(?![^)]*expiresIn|exp)[^)]*\)/, message: 'OWASP API2:2023 — JWT without expiry claim', cwe: 'CWE-613', owasp: 'A07', confidence: 'low', fix: 'Always set expiresIn in jwt.sign(): jwt.sign(payload, secret, { expiresIn: \'1h\' }).' },
|
|
1931
|
+
{ id: 'api.unlimited-response', severity: 'medium', re: /\.find\s*\(\s*\{\s*\}\s*\)(?!\s*\.limit)(?!\s*\.skip)(?!\s*\.take)/, message: 'OWASP API4:2023 — Unrestricted resource consumption: find() without limit', cwe: 'CWE-770', owasp: 'A04', fix: 'Add .limit() and pagination to all database queries.' },
|
|
1932
|
+
{ id: 'api.no-api-versioning', severity: 'medium', re: /app\.(?:get|post|put|patch|delete)\s*\(\s*['"]\/(?:api|v1)\//, message: 'OWASP API9:2023 — API versioning inconsistent or missing', cwe: 'CWE-1104', owasp: 'A05', confidence: 'low', fix: 'Version all API routes: /api/v1/resource. Use a versioning strategy.' },
|
|
1933
|
+
{ id: 'api.unvalidated-redirect', severity: 'high', re: /res\.(?:redirect|render)\s*\(\s*req\.(?:query|body|params)\.(?:url|redirect|to|returnUrl|returnTo|next|callback)/, message: 'OWASP API10:2023 — Unvalidated redirect from API parameter', cwe: 'CWE-601', owasp: 'A01', fix: 'Validate redirect URLs against an allowlist. Never redirect to user-supplied URLs.' },
|
|
1934
|
+
];
|
|
1935
|
+
|
|
1936
|
+
// ---------------------------------------------------------------------------
|
|
1937
|
+
// GAP BATCH 5: 8 container/K8s depth rules
|
|
1938
|
+
// ---------------------------------------------------------------------------
|
|
1939
|
+
|
|
1940
|
+
const containerDeepRules = [
|
|
1941
|
+
{ id: 'k8s.run-as-root', severity: 'high', re: /containers:\s*\n(?:.*\n)*?\s*-\s*(?:name|image):/, message: 'K8s: container without runAsNonRoot — running as root', cwe: 'CWE-250', owasp: 'A05', fix: 'Set securityContext.runAsNonRoot: true in the pod or container spec.' },
|
|
1942
|
+
{ id: 'k8s.no-readonly-filesystem', severity: 'medium', re: /readOnlyRootFilesystem:\s*false/, message: 'K8s: readOnlyRootFilesystem false — writable container FS', cwe: 'CWE-732', owasp: 'A05', fix: 'Set readOnlyRootFilesystem: true. Mount tmp for write paths.' },
|
|
1943
|
+
{ id: 'k8s.hostpath-mount', severity: 'high', re: /hostPath:\s*\n\s+path:\s*['"]/, message: 'K8s: hostPath mount — container accesses host filesystem', cwe: 'CWE-732', owasp: 'A05', fix: 'Use PersistentVolumeClaim instead of hostPath.' },
|
|
1944
|
+
{ id: 'k8s.hostpid-ipc', severity: 'high', re: /hostPID:\s*true|hostIPC:\s*true/, message: 'K8s: hostPID/hostIPC true — namespace sharing with host', cwe: 'CWE-732', owasp: 'A05', fix: 'Set hostPID: false and hostIPC: false.' },
|
|
1945
|
+
{ id: 'k8s.no-network-policy', severity: 'medium', re: /kind:\s*Deployment/, message: 'K8s: Deployment without NetworkPolicy — no network isolation', cwe: 'CWE-284', owasp: 'A05', confidence: 'low', fix: 'Create NetworkPolicy resources to restrict pod-to-pod communication.' },
|
|
1946
|
+
{ id: 'k8s.image-pull-if-not-present', severity: 'low', re: /imagePullPolicy:\s*IfNotPresent/, message: 'K8s: imagePullPolicy IfNotPresent — stale image risk', cwe: 'CWE-937', owasp: 'A06', fix: 'Use imagePullPolicy: Always for production or pin image digest.' },
|
|
1947
|
+
{ id: 'k8s.no-liveness-probe', severity: 'medium', re: /containers:\s*\n(?:.*\n)*?\s*-\s*(?:name|image):/, message: 'K8s: container without liveness/readiness probes', cwe: 'CWE-1188', owasp: 'A05', confidence: 'low', fix: 'Add livenessProbe and readinessProbe to all containers.' },
|
|
1948
|
+
{ id: 'k8s.no-security-context', severity: 'medium', re: /kind:\s*Pod/, message: 'K8s: Pod without securityContext — no pod-level security constraints', cwe: 'CWE-1188', owasp: 'A05', confidence: 'low', fix: 'Add securityContext with runAsNonRoot, readOnlyRootFilesystem, and seccompProfile.' },
|
|
1949
|
+
];
|
|
1950
|
+
|
|
1951
|
+
// ---------------------------------------------------------------------------
|
|
1952
|
+
// GAP BATCH 6: 7 GraphQL security rules
|
|
1953
|
+
// ---------------------------------------------------------------------------
|
|
1954
|
+
|
|
1955
|
+
const graphqlRules = [
|
|
1956
|
+
{ id: 'graphql.no-depth-limit', severity: 'medium', re: /depthLimit\s*(?::\s*(?:undefined|0|false|disabled))?/, message: 'GraphQL: no query depth limit — DoS via nested queries', cwe: 'CWE-770', owasp: 'A04', fileFilter: '\\.(?:js|ts|graphql)$', fix: 'Use graphql-depth-limit middleware: depthLimit(10).' },
|
|
1957
|
+
{ id: 'graphql.introspection-enabled', severity: 'medium', re: /introspection\s*:\s*true/, message: 'GraphQL: introspection enabled in production — schema leak', cwe: 'CWE-200', owasp: 'A05', fix: 'Disable introspection in production: introspection: false.' },
|
|
1958
|
+
{ id: 'graphql.no-cost-analysis', severity: 'medium', re: /new\s+ApolloServer\s*\(\s*\{/, message: 'GraphQL: ApolloServer without cost analysis — DoS via expensive queries', cwe: 'CWE-770', owasp: 'A04', confidence: 'low', fix: 'Add graphql-cost-analysis to limit query complexity.' },
|
|
1959
|
+
{ id: 'graphql.no-auth-middleware', severity: 'high', re: /context\s*:\s*(?:async\s*)?\(\s*\{?\s*(?:req|context)\s*\}?\s*\)\s*=>\s*\{/, message: 'GraphQL: resolver context without authentication check', cwe: 'CWE-306', owasp: 'A01', confidence: 'low', fix: 'Add auth middleware before GraphQL handler. Check context.user in resolvers.' },
|
|
1960
|
+
{ id: 'graphql.batch-no-limit', severity: 'medium', re: /ApolloServerPlugin(?:BatchHTTP|OperationBatch)/, message: 'GraphQL: batch queries without limit — DoS', cwe: 'CWE-770', owasp: 'A04', fix: 'Limit batch query count. Use graphql-batch with maxBatchSize.' },
|
|
1961
|
+
{ id: 'graphql.error-logging', severity: 'medium', re: /formatError\s*:\s*(?:error\s*=>\s*error|undefined)/, message: 'GraphQL: formatError returning raw error — info leak', cwe: 'CWE-209', owasp: 'A05', fix: 'Mask errors in production. Return only message and code, not stack trace.' },
|
|
1962
|
+
{ id: 'graphql.raw-query-from-user', severity: 'high', re: /(?:parse|execute)\s*\(\s*(?:req|context|args)\.(?:body|query|operation)/, message: 'GraphQL: executing raw query from user input — injection risk', cwe: 'CWE-94', owasp: 'A03', fix: 'Use Apollo/Yoga server. Never parse/execute raw user queries directly.' },
|
|
1963
|
+
];
|
|
1964
|
+
|
|
1965
|
+
// ---------------------------------------------------------------------------
|
|
1966
|
+
// GAP BATCH 7: 4 WebSocket security rules
|
|
1967
|
+
// ---------------------------------------------------------------------------
|
|
1968
|
+
|
|
1969
|
+
const websocketRules = [
|
|
1970
|
+
{ id: 'ws.no-origin-check', severity: 'high', re: /ws\.(?:on|server)\s*\(\s*['"]connection['"]/, message: 'WebSocket: no origin verification — CSWSH risk', cwe: 'CWE-346', owasp: 'A05', confidence: 'low', fix: 'Check request.headers.origin against allowlist in connection handler.' },
|
|
1971
|
+
{ id: 'ws.no-auth', severity: 'high', re: /new\s+WebSocket(?:Server)?\s*\(\s*\{[^}]*(?:port|noServer)/, message: 'WebSocket: server without authentication', cwe: 'CWE-306', owasp: 'A01', confidence: 'low', fix: 'Verify token in upgrade/connection. Reject unauthenticated connections.' },
|
|
1972
|
+
{ id: 'ws.no-message-size-limit', severity: 'medium', re: /maxPayload\s*:\s*(?:0|undefined|Infinity|NaN)/, message: 'WebSocket: no message size limit — DoS via large messages', cwe: 'CWE-770', owasp: 'A04', fix: 'Set maxPayload to a reasonable limit (e.g., 1MB).' },
|
|
1973
|
+
{ id: 'ws.no-rate-limit', severity: 'medium', re: /socket\.on\s*\(\s*['"](?:message|data)['"]/, message: 'WebSocket: message handler without rate limiting — DoS', cwe: 'CWE-770', owasp: 'A04', confidence: 'low', fix: 'Add per-connection rate limiting: limit messages per second.' },
|
|
1974
|
+
];
|
|
1975
|
+
|
|
1976
|
+
// ---------------------------------------------------------------------------
|
|
1977
|
+
// GAP BATCH 8: 6 header/cookie depth rules
|
|
1978
|
+
// ---------------------------------------------------------------------------
|
|
1979
|
+
|
|
1980
|
+
const headerDeepRules = [
|
|
1981
|
+
{ id: 'header.no-referrer-policy', severity: 'medium', re: /helmet\s*\.(?:contentSecurityPolicy|cors|hsts)\b/, message: 'Helmet: Referrer-Policy not set — referer leak to third parties', cwe: 'CWE-200', owasp: 'A05', confidence: 'low', fix: 'Add helmet.referrerPolicy({ policy: "strict-origin-when-cross-origin" }).' },
|
|
1982
|
+
{ id: 'header.no-permissions-policy', severity: 'low', re: /app\.use\s*\(\s*helmet\s*\(\s*\)\s*\)/, message: 'Helmet default — Permissions-Policy not configured', cwe: 'CWE-693', owasp: 'A05', confidence: 'low', fix: 'Add helmet.permissionsPolicy for fine-grained control.' },
|
|
1983
|
+
{ id: 'header.no-coop', severity: 'medium', re: /crossOriginOpenerPolicy\s*(?::\s*(?:false|undefined|disabled))?/, message: 'Cross-Origin-Opener-Policy not set — clickjacking/spectre', cwe: 'CWE-1021', owasp: 'A05', confidence: 'low', fix: 'Set Cross-Origin-Opener-Policy: same-origin.' },
|
|
1984
|
+
{ id: 'header.no-coep', severity: 'medium', re: /crossOriginEmbedderPolicy\s*(?::\s*(?:false|undefined|disabled))?/, message: 'Cross-Origin-Embedder-Policy not set — cross-origin resource loading', cwe: 'CWE-1021', owasp: 'A05', confidence: 'low', fix: 'Set Cross-Origin-Embedder-Policy: require-corp.' },
|
|
1985
|
+
{ id: 'header.no-corp', severity: 'medium', re: /crossOriginResourcePolicy\s*(?::\s*(?:false|undefined|disabled))?/, message: 'Cross-Origin-Resource-Policy not set — resource embedded by any origin', cwe: 'CWE-1021', owasp: 'A05', confidence: 'low', fix: 'Set Cross-Origin-Resource-Policy: same-origin.' },
|
|
1986
|
+
{ id: 'cookie.samesite-none-no-secure', severity: 'high', re: /sameSite\s*:\s*['"]None['"](?![^}]*secure\s*:\s*true)/, message: 'Cookie SameSite=None without Secure — allows over HTTP', cwe: 'CWE-614', owasp: 'A05', fix: 'Set Secure: true when using SameSite: "None".' },
|
|
1987
|
+
];
|
|
1988
|
+
|
|
1989
|
+
// ---------------------------------------------------------------------------
|
|
1990
|
+
// GAP BATCH 9: 5 deserialization/unsafe-parse rules
|
|
1991
|
+
// ---------------------------------------------------------------------------
|
|
1992
|
+
|
|
1993
|
+
const deserializationRules = [
|
|
1994
|
+
{ id: 'deser.yaml-load-unsafe', severity: 'high', re: /yaml\.load\s*\(\s*[^,)]+\)(?!\s*,\s*(?:Loader|FullLoader|SafeLoader))/, message: 'yaml.load() without SafeLoader — arbitrary code execution', cwe: 'CWE-502', owasp: 'A08', fix: 'Use yaml.safe_load() or yaml.load(data, Loader=SafeLoader).' },
|
|
1995
|
+
{ id: 'deser.pickle-load', severity: 'high', re: /pickle\.loads?\s*\(/, message: 'pickle.load() — unsafe deserialization (RCE risk)', cwe: 'CWE-502', owasp: 'A08', fix: 'Never pickle.load untrusted data. Use JSON or a safe format.' },
|
|
1996
|
+
{ id: 'deser.json-reviver-eval', severity: 'medium', re: /JSON\.parse\s*\(\s*[^)]+,\s*function\s*\([^)]*\)\s*\{[^}]*eval/, message: 'JSON.parse with eval in reviver — code injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Never use eval in JSON.parse reviver. Use a safe transform function.' },
|
|
1997
|
+
{ id: 'deser.php-unserialize', severity: 'critical', re: /unserialize\s*\(\s*\$/, message: 'PHP unserialize() — PHP object injection (RCE)', cwe: 'CWE-502', owasp: 'A08', fix: 'Use json_decode() instead. Never unserialize user input.' },
|
|
1998
|
+
{ id: 'deser.node-vm', severity: 'high', re: /vm\.runIn(?:NewContext|ThisContext|Context)\s*\(/, message: 'vm.runInContext() — not a security sandbox, code can escape', cwe: 'CWE-94', owasp: 'A03', fix: 'Use isolated-vm or WebAssembly for true isolation. Node vm is not a security boundary.' },
|
|
1999
|
+
];
|
|
2000
|
+
|
|
2001
|
+
// ---------------------------------------------------------------------------
|
|
2002
|
+
// GAP BATCH 10: 5 cloud-specific rules
|
|
2003
|
+
// ---------------------------------------------------------------------------
|
|
2004
|
+
|
|
2005
|
+
const cloudRules = [
|
|
2006
|
+
{ id: 'cloud.s3-public-acl', severity: 'high', re: /(?:ACL\s*=\s*['"]public-read['"]|acl\s*:\s*['"]public-read['"]|Grantee.*AllUsers)/, message: 'S3 bucket public-read ACL — data exposure', cwe: 'CWE-732', owasp: 'A05', fix: 'Set bucket ACL to private. Use CloudFront for public access.' },
|
|
2007
|
+
{ id: 'cloud.iam-wildcard-action', severity: 'high', re: /Action\s*:\s*['"]\*['"]|effect:\s*Allow.*action:\s*['"]\*['"]/, message: 'IAM policy with Action:* — over-permissive', cwe: 'CWE-732', owasp: 'A05', fix: 'Specify exact IAM actions. Never use Action: "*" in production.' },
|
|
2008
|
+
{ id: 'cloud.gcp-key-in-code', severity: 'critical', re: /google\.application\.default\.credentials|GOOGLE_APPLICATION_CREDENTIALS\s*=\s*['"][^'"]*\.json['"]/, message: 'GCP credentials file path in code — key file exposure', cwe: 'CWE-798', owasp: 'A02', fix: 'Use workload identity or Secret Manager. Never hardcode credential paths.' },
|
|
2009
|
+
{ id: 'cloud.azure-connection-string', severity: 'high', re: /(?:DefaultEndpointsProtocol|AccountKey=|EndpointSuffix=)/, message: 'Azure connection string with account key in code', cwe: 'CWE-798', owasp: 'A02', fix: 'Use Azure Managed Identity or Key Vault. Never hardcode connection strings.' },
|
|
2010
|
+
{ id: 'cloud.security-group-open', severity: 'high', re: /CidrIp\s*[:=]\s*['"]0\.0\.0\.0\/0['"].*?(?:FromPort\s*[:=]\s*0|ToPort\s*[:=]\s*65535)/, message: 'Security group open to world on all ports', cwe: 'CWE-284', owasp: 'A05', fix: 'Restrict CIDR to known IPs. Limit port range to required ports only.' },
|
|
2011
|
+
];
|
|
2012
|
+
|
|
2013
|
+
// ---------------------------------------------------------------------------
|
|
2014
|
+
// GAP BATCH 11: 10 more AI security rules
|
|
2015
|
+
// ---------------------------------------------------------------------------
|
|
2016
|
+
|
|
2017
|
+
const aiSecurityRulesExtra = [
|
|
2018
|
+
{ id: 'ai.prompt-extraction', severity: 'high', re: /(?:show|print|reveal|output|display|dump)\s+(?:your\s+)?(?:system\s+)?(?:prompt|instructions|rules|guidelines)/i, message: 'Prompt extraction attempt — asks AI to reveal system prompt', cwe: 'CWE-200', owasp: 'A01', fileFilter: '\\.(?:js|ts|py|txt|md)$', fix: 'Add guard: "Never reveal system instructions." Use structured output.' },
|
|
2019
|
+
{ id: 'ai.tool-poisoning', severity: 'high', re: /tool.*description.*(?:ignore|disregard|forget|new instruction|you are now)/i, message: 'MCP tool description poisoning — prompt injection in tool metadata', cwe: 'CWE-94', owasp: 'A03', fix: 'Validate tool descriptions. Strip injection patterns. Use allowlist.' },
|
|
2020
|
+
{ id: 'ai.data-exfil-agent', severity: 'high', re: /(?:fetch|axios|http\.get|requests\.get)\s*\(\s*[^)]*(?:api\.|endpoint|webhook|callback)[^)]*(?:user|customer|email|phone|ssn|password)/i, message: 'AI agent exfiltrates user data to external endpoint', cwe: 'CWE-200', owasp: 'A02', fix: 'Block external requests in agent. Use allowlist of approved endpoints.' },
|
|
2021
|
+
{ id: 'ai.model-id-user-input', severity: 'high', re: /model\s*:\s*(?:req|user|input|params|query|body)\.(?:model|modelId|engine)/, message: 'Model ID from user input — model injection/billing abuse', cwe: 'CWE-94', owasp: 'A03', fix: 'Validate model ID against allowlist. Never pass user input as model.' },
|
|
2022
|
+
{ id: 'ai.adversarial-no-filter', severity: 'medium', re: /(?:temperature\s*:\s*(?:2|2\.0|1\.9|1\.8|1\.7)|top_p\s*:\s*(?:1|0\.99))/, message: 'Very high temperature/top_p — adversarial output risk', cwe: 'CWE-105', owasp: 'A04', fix: 'Cap temperature at 1.0 and top_p at 0.95 for safety.' },
|
|
2023
|
+
{ id: 'ai.memory-poisoning', severity: 'high', re: /(?:memory|context|history)\s*(?:\.push|\.unshift|\.concat|\[\s*\w+\s*\])\s*=\s*req\.(?:body|query|params)/, message: 'AI agent memory updated from user input — memory poisoning', cwe: 'CWE-94', owasp: 'A08', fix: 'Sanitize memory inputs. Use structured memory with type checking.' },
|
|
2024
|
+
{ id: 'ai.training-data-leak', severity: 'high', re: /(?:train|fine.?tune|fit)\s*\(\s*[^)]*(?:user|customer|patient|record)/, message: 'Training on user data without consent — privacy violation', cwe: 'CWE-359', owasp: 'A02', fix: 'Anonymize training data. Verify consent before training on user data.' },
|
|
2025
|
+
{ id: 'ai.agent-loop-no-cap', severity: 'high', re: /while\s*\(\s*true\s*\)|for\s*\(\s*;\s*;\s*\)|maxIterations\s*:\s*(?:Infinity|0|-1|undefined)/, message: 'AI agent loop without iteration cap — infinite loop / cost', cwe: 'CWE-835', owasp: 'A04', fix: 'Set maxIterations to a finite number. Add timeout and budget.' },
|
|
2026
|
+
{ id: 'ai.tool-result-injection', severity: 'high', re: /(?:response|result|output)\s*(?:\.text|\.content|\.body|\.json)\s*(?:\+|\`\$\{)/, message: 'Tool result concatenated into prompt — indirect prompt injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Escape tool results before including in prompt. Use structured parsing.' },
|
|
2027
|
+
{ id: 'ai.no-content-filter-bypass', severity: 'medium', re: /(?:moderation|filter|safety)\s*(?::\s*false|\.disable|\.bypass)/, message: 'AI content filter/safety disabled', cwe: 'CWE-693', owasp: 'A05', fix: 'Keep content moderation enabled. Use provider-side safety settings.' },
|
|
2028
|
+
];
|
|
2029
|
+
|
|
2030
|
+
// ---------------------------------------------------------------------------
|
|
2031
|
+
// GAP BATCH 12: 10 more Python/Django/Flask rules
|
|
2032
|
+
// ---------------------------------------------------------------------------
|
|
2033
|
+
|
|
2034
|
+
const pythonDeepRules = [
|
|
2035
|
+
{ id: 'py.debug-true', severity: 'critical', re: /(?:DEBUG|debug)\s*=\s*True/, message: 'Python debug mode enabled — exposes stack traces', cwe: 'CWE-489', owasp: 'A05', fileFilter: '\\.py$', fix: 'Set debug=False in production.' },
|
|
2036
|
+
{ id: 'py.secret-key-hardcoded', severity: 'high', re: /SECRET_KEY\s*=\s*['"][A-Za-z0-9_-]{16,}['"]/, message: 'Python SECRET_KEY hardcoded', cwe: 'CWE-798', owasp: 'A02', fileFilter: '\\.py$', fix: 'Load from environment: SECRET_KEY = os.environ[\'SECRET_KEY\']' },
|
|
2037
|
+
{ id: 'py.allowed-hosts-wildcard', severity: 'high', re: /ALLOWED_HOSTS\s*=\s*\[\s*['"]\*['"]\s*\]/, message: 'Python ALLOWED_HOSTS wildcard — host header attacks', cwe: 'CWE-444', owasp: 'A05', fileFilter: '\\.py$', fix: 'Set ALLOWED_HOSTS to specific domains.' },
|
|
2038
|
+
{ id: 'py.sql-injection', severity: 'high', re: /(?:execute|cursor\.execute)\s*\(\s*(?:f['"]|['"].*%s.*['"],\s*\[)[^)]*(?:request|input|user|form)/, message: 'Python SQL execution with user input — SQL injection', cwe: 'CWE-89', owasp: 'A03', fileFilter: '\\.py$', fix: 'Use parameterized queries: cursor.execute("SELECT ... WHERE id = %s", [id])' },
|
|
2039
|
+
{ id: 'py.subprocess-shell-true', severity: 'high', re: /subprocess\.(?:run|call|Popen|check_output)\s*\([^)]*shell\s*=\s*True/, message: 'Python subprocess with shell=True — command injection', cwe: 'CWE-78', owasp: 'A03', fix: 'Use shell=False with argument list: subprocess.run(["cmd", "arg1"], shell=False).' },
|
|
2040
|
+
{ id: 'py.os-system', severity: 'high', re: /os\.system\s*\(\s*(?:f['"]|['"].*%|['"].*format|['"].*\+)/, message: 'Python os.system with string formatting — command injection', cwe: 'CWE-78', owasp: 'A03', fix: 'Use subprocess.run with shell=False and argument list.' },
|
|
2041
|
+
{ id: 'py.yaml-load', severity: 'high', re: /yaml\.load\s*\(\s*[^,)]+\)(?!\s*,\s*(?:Loader|FullLoader|SafeLoader))/, message: 'Python yaml.load() without SafeLoader — RCE risk', cwe: 'CWE-502', owasp: 'A08', fix: 'Use yaml.safe_load() instead.' },
|
|
2042
|
+
{ id: 'py.pickle-load', severity: 'high', re: /pickle\.loads?\s*\(/, message: 'Python pickle.load() — unsafe deserialization', cwe: 'CWE-502', owasp: 'A08', fix: 'Use JSON instead of pickle for untrusted data.' },
|
|
2043
|
+
{ id: 'py.flask-debug', severity: 'critical', re: /app\.run\s*\([^)]*debug\s*=\s*True/, message: 'Flask debug mode — Werkzeug debugger RCE', cwe: 'CWE-489', owasp: 'A05', fix: 'Set debug=False in production.' },
|
|
2044
|
+
{ id: 'py.django-csrf-exempt', severity: 'high', re: /@csrf_exempt/, message: 'Django @csrf_exempt — CSRF protection disabled', cwe: 'CWE-352', owasp: 'A01', fix: 'Remove @csrf_exempt. Keep CSRF protection on all POST/PUT/DELETE.' },
|
|
2045
|
+
];
|
|
2046
|
+
|
|
2047
|
+
// ---------------------------------------------------------------------------
|
|
2048
|
+
// GAP BATCH 13: 10 race condition/DoS/business logic rules
|
|
2049
|
+
// ---------------------------------------------------------------------------
|
|
2050
|
+
|
|
2051
|
+
const raceConditionRules = [
|
|
2052
|
+
{ id: 'race.toctou-file', severity: 'high', re: /(?:fs\.existsSync|fs\.statSync|access)\s*\(.*\)[\s\S]{0,200}fs\.(?:readFile|writeFile|unlink|createReadStream|createWriteStream)/, message: 'TOCTOU race condition — check-then-use on file', cwe: 'CWE-367', owasp: 'A04', confidence: 'low', fix: 'Use atomic operations or handle errors from the operation itself.' },
|
|
2053
|
+
{ id: 'race.missing-transaction', severity: 'medium', re: /(?:balance|inventory|stock|count|credit|debit|transfer|withdraw|deposit)\s*(?:-=|\+=|=)/, message: 'Financial operation without database transaction — race condition', cwe: 'CWE-362', owasp: 'A04', confidence: 'low', fix: 'Wrap in database transaction with proper isolation level.' },
|
|
2054
|
+
{ id: 'dos.missing-pagination', severity: 'medium', re: /(?:findAll|find|list|getAll|fetch)\s*\(\s*\{\s*\}\s*\)(?!\s*\.limit)/, message: 'Unbounded query — no pagination/limit (DoS risk)', cwe: 'CWE-770', owasp: 'A04', fix: 'Add .limit() and .skip() pagination to all list queries.' },
|
|
2055
|
+
{ id: 'dos.missing-body-limit', severity: 'medium', re: /express\.json\s*\(\s*\{\s*\}\s*\)|bodyParser\.json\s*\(\s*\)/, message: 'Express body parser without size limit — DoS via large payload', cwe: 'CWE-770', owasp: 'A04', fix: 'Set limit: express.json({ limit: \'1mb\' }).' },
|
|
2056
|
+
{ id: 'dos.missing-idempotency', severity: 'medium', re: /(?:charge|payment|transfer|withdraw|deposit)\s*\(.*(?:req|request)\.body/, message: 'Financial operation without idempotency key — double-charge risk', cwe: 'CWE-362', owasp: 'A04', confidence: 'low', fix: 'Accept and validate an Idempotency-Key header for all financial operations.' },
|
|
2057
|
+
{ id: 'dos.regex-bomb', severity: 'high', re: /\(\?\:\(?:a\+\)\+\)/, message: 'Regex bomb — catastrophic backtracking', cwe: 'CWE-1333', owasp: 'A04', fix: 'Use safe-regex or re2 module to validate regex patterns.' },
|
|
2058
|
+
{ id: 'dos.json-depth-bomb', severity: 'medium', re: /JSON\.parse\s*\(\s*(?:req|request)\.body\)(?![^}]*(?:depth|limit|maxDepth))/, message: 'JSON.parse on request body without depth limit — JSON bomb', cwe: 'CWE-770', owasp: 'A04', fix: 'Use a JSON parser with depth limit. Validate payload size first.' },
|
|
2059
|
+
{ id: 'dos.xml-bomb', severity: 'high', re: /ENTITY\s+[^"]*\s+SYSTEM/, message: 'XML external entity — XXE / XML bomb', cwe: 'CWE-776', owasp: 'A05', fix: 'Disable DTDs in XML parser: parser.feature_external_entities = false.' },
|
|
2060
|
+
{ id: 'dos.no-connection-limit', severity: 'medium', re: /(?:createPool|createPoolCluster|Pool)\s*\(\s*\{[^}]*(?:connectionLimit|max|maxConnections)\s*:\s*(?:0|-1|Infinity|undefined)/, message: 'Database pool with no connection limit — resource exhaustion', cwe: 'CWE-770', owasp: 'A04', fix: 'Set connectionLimit to a finite number (e.g., 10-20).' },
|
|
2061
|
+
{ id: 'dos.no-timeout', severity: 'medium', re: /(?:fetch|axios|http\.request|request)\s*\(\s*[^)]*(?![^)]*timeout)/, message: 'HTTP request without timeout — slowloris DoS', cwe: 'CWE-400', owasp: 'A04', confidence: 'low', fix: 'Always set timeout: axios({ timeout: 5000 }) or AbortController.' },
|
|
2062
|
+
];
|
|
2063
|
+
|
|
2064
|
+
// ---------------------------------------------------------------------------
|
|
2065
|
+
// GAP BATCH 14: 10 more CVE version rules
|
|
2066
|
+
// ---------------------------------------------------------------------------
|
|
2067
|
+
|
|
2068
|
+
const cveVersionRulesExtra = [
|
|
2069
|
+
{ id: 'cve.express-qsproto-2024', pkg: 'qs', maxVersion: '6.5.2', cve: 'CVE-2022-24999', severity: 'high', message: 'qs < 6.5.3 — prototype pollution via query string' },
|
|
2070
|
+
{ id: 'cve.minimist-2021', pkg: 'minimist', maxVersion: '1.2.5', cve: 'CVE-2021-44906', severity: 'critical', message: 'minimist < 1.2.6 — prototype pollution' },
|
|
2071
|
+
{ id: 'cve.handlebars-2021', pkg: 'handlebars', maxVersion: '4.7.6', cve: 'CVE-2021-23369', severity: 'high', message: 'handlebars < 4.7.7 — RCE via prototype pollution' },
|
|
2072
|
+
{ id: 'cve.marked-2021', pkg: 'marked', maxVersion: '2.1.3', cve: 'CVE-2021-32739', severity: 'high', message: 'marked < 4.0.10 — XSS via markdown' },
|
|
2073
|
+
{ id: 'cve.node-jose-2023', pkg: 'node-jose', maxVersion: '2.1.0', cve: 'CVE-2023-46735', severity: 'high', message: 'node-jose < 2.2.0 — JWT signature confusion' },
|
|
2074
|
+
{ id: 'cve.jsonwebtoken-2022', pkg: 'jsonwebtoken', maxVersion: '8.5.1', cve: 'CVE-2022-23529', severity: 'critical', message: 'jsonwebtoken < 9.0.0 — key confusion via algorithm=none' },
|
|
2075
|
+
{ id: 'cve.request-2023', pkg: 'request', maxVersion: '2.88.2', cve: 'CVE-2023-28155', severity: 'high', message: 'request (deprecated) — SSRF via redirect with credentials' },
|
|
2076
|
+
{ id: 'cve.body-parser-2024', pkg: 'body-parser', maxVersion: '1.20.2', cve: 'CVE-2024-45590', severity: 'high', message: 'body-parser < 1.20.3 — DoS via deeply nested JSON' },
|
|
2077
|
+
{ id: 'cve.node-fetch-2024', pkg: 'node-fetch', maxVersion: '2.7.0', cve: 'CVE-2024-33620', severity: 'high', message: 'node-fetch < 3.3.2 — redirect leak with credentials' },
|
|
2078
|
+
{ id: 'cve.ejs-2022', pkg: 'ejs', maxVersion: '3.1.9', cve: 'CVE-2022-29078', severity: 'critical', message: 'ejs < 3.1.10 — RCE via template injection' },
|
|
2079
|
+
];
|
|
2080
|
+
|
|
2081
|
+
// ---------------------------------------------------------------------------
|
|
2082
|
+
// GAP BATCH 15: 10 CI/CD/IaC deep rules
|
|
2083
|
+
// ---------------------------------------------------------------------------
|
|
2084
|
+
|
|
2085
|
+
const cicdDeepRules = [
|
|
2086
|
+
{ id: 'cicd.gitlab-secret-in-yml', severity: 'high', re: /(?:password|secret|token|api_key)\s*:\s*['"][^'"]{8,}['"]/, message: 'GitLab CI: hardcoded secret in YAML', cwe: 'CWE-798', owasp: 'A02', fileFilter: '\\.gitlab-ci\\.ya?ml$', fix: 'Use GitLab CI/CD variables: $CI_VARIABLE. Store secrets in Settings > CI/CD > Variables.' },
|
|
2087
|
+
{ id: 'cicd.jenkins-credential-plaintext', severity: 'high', re: /withCredentials\s*\[\s*(?!.*usernamePassword)\w+\s*\(/, message: 'Jenkins: credentials used without withCredentials wrapper', cwe: 'CWE-798', owasp: 'A02', fileFilter: '(?:Jenkinsfile|\\.jenkins)', fix: 'Use withCredentials([usernameColonPassword(credentialsId: ...)]) for all secrets.' },
|
|
2088
|
+
{ id: 'cicd.circleci-context-missing', severity: 'medium', re: /context:\s*['"]?(?:default|none)['"]?|(?<!context:)\s*\$\{?(?:AWS_|DOCKER_|NPM_)[A-Z_]+\}?/, message: 'CircleCI: secrets without context — accessible to all jobs', cwe: 'CWE-798', owasp: 'A05', fileFilter: '\\.circleci/', fix: 'Use CircleCI contexts to scope secrets to specific jobs.' },
|
|
2089
|
+
{ id: 'cicd.aws-cdk-hardcoded-secret', severity: 'high', re: /(?:secret|password|apiKey|token)\s*:\s*['"][A-Za-z0-9]{16,}['"]/, message: 'AWS CDK: hardcoded secret in infrastructure code', cwe: 'CWE-798', owasp: 'A02', fileFilter: '\\.(?:ts|js)$', fix: 'Use AWS Secrets Manager or SSM Parameter Store. Never hardcode secrets in CDK.' },
|
|
2090
|
+
{ id: 'cicd.cloudformation-depends-on-public', severity: 'high', re: /Properties:\s*\n\s*AccessControl:\s*PublicRead/, message: 'CloudFormation: S3 bucket with PublicRead access', cwe: 'CWE-732', owasp: 'A05', fileFilter: '\\.(?:yaml|yml|json)$', fix: 'Set AccessControl to Private. Use CloudFront for public access.' },
|
|
2091
|
+
{ id: 'cicd.helm-no-resource-requests', severity: 'medium', re: /resources:\s*\{\s*\}|resources:\s*$/, message: 'Helm chart: no resource requests/limits — unbounded pod', cwe: 'CWE-770', owasp: 'A05', fileFilter: 'values\\.ya?ml$', fix: 'Define resources.requests and resources.limits in values.yaml.' },
|
|
2092
|
+
{ id: 'cicd.ansible-vault-plaintext', severity: 'high', re: /(?:password|secret|api_key|token)\s*:\s*['"][^'"]{8,}['"]/, message: 'Ansible: secret in plaintext, not using vault', cwe: 'CWE-798', owasp: 'A02', fileFilter: '(?:playbook|inventory|roles).*\\.ya?ml$', fix: 'Use ansible-vault encrypt for secrets: ansible-vault encrypt_string "secret" --name "password".' },
|
|
2093
|
+
{ id: 'cicd.pulumi-plaintext-secret', severity: 'high', re: /pulumi\.output\(\s*['"][A-Za-z0-9]{16,}['"]\s*\)/, message: 'Pulumi: secret as plain output — not encrypted', cwe: 'CWE-798', owasp: 'A02', fileFilter: '\\.(?:ts|js|py|go)$', fix: 'Use pulumi.secret() or config.requireSecret(). Never pulumi.output() for secrets.' },
|
|
2094
|
+
{ id: 'cicd.docker-no-healthcheck', severity: 'medium', re: /FROM\s+\S+\s*\n(?!.*HEALTHCHECK)/, message: 'Dockerfile: no HEALTHCHECK — orchestrator cannot detect unhealthy', cwe: 'CWE-1188', owasp: 'A05', fileFilter: 'Dockerfile$', confidence: 'low', fix: 'Add HEALTHCHECK --interval=30s CMD curl -f http://localhost:3000/ || exit 1.' },
|
|
2095
|
+
{ id: 'cicd.makefile-injection', severity: 'medium', re: /\$\((?:shell|wildcard)\s+[^)]*(?:\$\(|`)/, message: 'Makefile: $(shell) with unescaped input — command injection', cwe: 'CWE-78', owasp: 'A03', fileFilter: '(?:Makefile|makefile|.*\\.mk)$', fix: 'Escape user-provided variables. Validate input before $(shell).' },
|
|
2096
|
+
];
|
|
2097
|
+
|
|
2098
|
+
// ===========================================================================
|
|
2099
|
+
// POWER BATCH A: 10 Rust rules
|
|
2100
|
+
// ===========================================================================
|
|
2101
|
+
|
|
2102
|
+
const rustRules = [
|
|
2103
|
+
{ id: 'rust.unsafe-block', severity: 'medium', re: /unsafe\s*\{/, fileFilter: '\\.rs$', skipComments: true, message: 'Rust unsafe block — memory safety bypassed', cwe: 'CWE-732', owasp: 'A05', fix: 'Minimize unsafe usage. Wrap in safe abstractions and document safety invariants.' },
|
|
2104
|
+
{ id: 'rust.command-injection', severity: 'high', re: /Command::new\s*\(\s*[^)]*(?:format!|format_arg)/, fileFilter: '\\.rs$', message: 'Rust Command::new with formatted string — command injection', cwe: 'CWE-78', owasp: 'A03', fix: 'Use Command::new("bin").arg(param). Never format command strings.' },
|
|
2105
|
+
{ id: 'rust.sql-injection', severity: 'high', re: /query\(\s*(?:format!|format_arg)/, fileFilter: '\\.rs$', message: 'Rust SQL query with format! — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized queries: sqlx::query("SELECT ... WHERE id = $1").bind(id)' },
|
|
2106
|
+
{ id: 'rust.from-row-unwrap', severity: 'low', re: /from_row.*unwrap\s*\(\s*\)/, fileFilter: '\\.rs$', message: 'Rust from_row().unwrap() — panics on error, DoS', cwe: 'CWE-248', owasp: 'A04', fix: 'Use .unwrap_or_default() or handle the Result properly.' },
|
|
2107
|
+
{ id: 'rust.expect-in-prod', severity: 'low', re: /\.expect\s*\(\s*['"][^'"]*['"]\s*\)/, fileFilter: '\\.rs$', confidence: 'low', message: 'Rust .expect() — panics in production', cwe: 'CWE-248', owasp: 'A04', fix: 'Use proper error handling with Result/Option instead of expect().' },
|
|
2108
|
+
{ id: 'rust.insecure-random', severity: 'high', re: /\brand::thread_rng\b|\brand::random\b/, fileFilter: '\\.rs$', message: 'Rust thread_rng() — not for crypto, use OsRng', cwe: 'CWE-330', owasp: 'A02', fix: 'Use rand::rngs::OsRng for cryptographic randomness.' },
|
|
2109
|
+
{ id: 'rust.hardcoded-secret', severity: 'high', re: /(?:password|secret|token|api_key|apikey)\s*[:=]\s*['"][^'"]{8,}['"]/i, fileFilter: '\\.rs$', message: 'Rust hardcoded secret', cwe: 'CWE-798', owasp: 'A02', fix: 'Load secrets from environment: env::var("API_KEY")' },
|
|
2110
|
+
{ id: 'rust.path-traversal', severity: 'high', re: /fs::read(?:_to_string|_dir)?\s*\(\s*(?:format!|req|user|input)/, fileFilter: '\\.rs$', message: 'Rust file read with user input — path traversal', cwe: 'CWE-22', owasp: 'A01', fix: 'Canonicalize and validate paths. Use Path::canonicalize().' },
|
|
2111
|
+
{ id: 'rust.deserialize-tampered', severity: 'medium', re: /serde_json::from_str\s*\(\s*(?:req|input|user|body)/, fileFilter: '\\.rs$', message: 'Rust deserialization of untrusted input without validation', cwe: 'CWE-502', owasp: 'A08', fix: 'Add serde validation attributes. Use #[serde(deny_unknown_fields)].' },
|
|
2112
|
+
{ id: 'rust.toctou-file', severity: 'medium', re: /Path::exists\s*\(\s*\)[\s\S]{0,100}fs::(?:read|write|create|remove)/, fileFilter: '\\.rs$', confidence: 'low', message: 'Rust TOCTOU: exists() then file operation — race condition', cwe: 'CWE-367', owasp: 'A04', fix: 'Attempt the operation directly and handle errors instead of checking first.' },
|
|
2113
|
+
];
|
|
2114
|
+
|
|
2115
|
+
// ===========================================================================
|
|
2116
|
+
// POWER BATCH B: 10 Kotlin/Swift rules
|
|
2117
|
+
// ===========================================================================
|
|
2118
|
+
|
|
2119
|
+
const kotlinRules = [
|
|
2120
|
+
{ id: 'kotlin.sql-injection', severity: 'high', re: /(?:rawQuery|execSQL)\s*\(\s*["'].*\$\{/, fileFilter: '\\.kt$', message: 'Kotlin SQL with string interpolation — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized queries with selectionArgs array.' },
|
|
2121
|
+
{ id: 'kotlin.eval', severity: 'critical', re: /Runtime\.getRuntime\(\)\.exec\s*\(\s*["'].*\$\{/, fileFilter: '\\.kt$', message: 'Kotlin Runtime.exec with interpolation — command injection', cwe: 'CWE-78', owasp: 'A03', fix: 'Use ProcessBuilder with separate arguments.' },
|
|
2122
|
+
{ id: 'kotlin.shared-prefs-secret', severity: 'high', re: /getSharedPreferences\s*\(\s*["'][^'"]*['"]\)[\s\S]{0,200}(?:password|secret|token|key|pin)/i, fileFilter: '\\.kt$', message: 'Kotlin secret in SharedPreferences — not encrypted at rest', cwe: 'CWE-922', owasp: 'A02', fix: 'Use EncryptedSharedPreferences from Jetpack Security.' },
|
|
2123
|
+
{ id: 'kotlin.webview-js-enabled', severity: 'high', re: /settings\.javaScriptEnabled\s*=\s*true/, fileFilter: '\\.kt$', message: 'Kotlin WebView JavaScript enabled — XSS if loading untrusted content', cwe: 'CWE-79', owasp: 'A03', fix: 'Only enable JS for trusted content. Add @JavascriptInterface with care.' },
|
|
2124
|
+
{ id: 'kotlin.insecure-crypto', severity: 'high', re: /(?:AES\/ECB|DES\/|MD5|SHA1|RC4|Blowfish)/, fileFilter: '\\.kt$', message: 'Kotlin insecure crypto algorithm', cwe: 'CWE-327', owasp: 'A02', fix: 'Use AES/GCM with 256-bit keys. Never ECB mode.' },
|
|
2125
|
+
];
|
|
2126
|
+
|
|
2127
|
+
const swiftRules = [
|
|
2128
|
+
{ id: 'swift.userdefaults-secret', severity: 'high', re: /UserDefaults\.standard\.(?:set|setValue)\s*\([^,]*(?:password|secret|token|apiKey|pin)/i, fileFilter: '\\.swift$', message: 'Swift secret in UserDefaults — unencrypted', cwe: 'CWE-922', owasp: 'A02', fix: 'Use Keychain for secrets. UserDefaults is a plist file on disk.' },
|
|
2129
|
+
{ id: 'swift.keychain-weak', severity: 'medium', re: /kSecAttrAccessible(?:Always|WhenUnlocked)/, fileFilter: '\\.swift$', message: 'Swift Keychain accessible when unlocked — device passcode required', cwe: 'CWE-922', owasp: 'A02', fix: 'Use kSecAttrAccessibleWhenUnlockedThisDeviceOnly or WhenPasscodeSetThisDeviceOnly.' },
|
|
2130
|
+
{ id: 'swift.webview-no-sanitize', severity: 'high', re: /loadHTMLString\s*\(\s*[^)]*(?:request|user|input|body|query)/, fileFilter: '\\.swift$', message: 'Swift WebView loadHTMLString with user data — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Sanitize HTML before loading. Use WKWebView with content mode .never.' },
|
|
2131
|
+
{ id: 'swift.pasteboard-leak', severity: 'medium', re: /UIPasteboard\.general\.(?:string|image)\s*=\s*[^;]*(?:token|password|secret|key|pin|ssn)/i, fileFilter: '\\.swift$', message: 'Swift sensitive data in system pasteboard — other apps can read', cwe: 'CWE-200', owasp: 'A02', fix: 'Use UIPasteboard with expirationDate. Avoid clipboard for secrets.' },
|
|
2132
|
+
{ id: 'swift.force-unwrap-leak', severity: 'low', re: /(?:print|debugPrint|NSLog)\s*\(\s*[^)]*!\s*\)/, fileFilter: '\\.swift$', confidence: 'low', message: 'Swift force-unwrap in log — may leak nil info or crash', cwe: 'CWE-248', owasp: 'A04', fix: 'Use optional binding: if let value = value { print(value) }' },
|
|
2133
|
+
];
|
|
2134
|
+
|
|
2135
|
+
// ===========================================================================
|
|
2136
|
+
// POWER BATCH C: 10 framework rules (NestJS 3, Remix 2, Astro 2, SolidStart 1, Gin 1, Echo 1)
|
|
2137
|
+
// ===========================================================================
|
|
2138
|
+
|
|
2139
|
+
const nestjsRules = [
|
|
2140
|
+
{ id: 'nestjs.global-pipe-missing', severity: 'medium', re: /useGlobalPipes\s*\(\s*\)/, fileFilter: '\\.ts$', confidence: 'low', message: 'NestJS: empty global pipes — no input validation', cwe: 'CWE-20', owasp: 'A03', fix: 'Register ValidationPipe globally: app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }))' },
|
|
2141
|
+
{ id: 'nestjs.guard-missing', severity: 'high', re: /@Controller\s*\(\s*['"](?:api|admin|user|auth)\//, fileFilter: '\\.ts$', confidence: 'low', message: 'NestJS controller without @UseGuards — no auth', cwe: 'CWE-306', owasp: 'A01', fix: 'Add @UseGuards(JwtAuthGuard) to all protected controllers.' },
|
|
2142
|
+
{ id: 'nestjs.csrf-missing', severity: 'medium', re: /NestFactory\.create\s*\(\s*AppModule/, fileFilter: '\\.ts$', confidence: 'low', message: 'NestJS: no CSRF protection enabled', cwe: 'CWE-352', owasp: 'A01', fix: 'Install @nestjs/csrf and register CsrfMiddleware.' },
|
|
2143
|
+
];
|
|
2144
|
+
|
|
2145
|
+
const remixRules = [
|
|
2146
|
+
{ id: 'remix.action-no-auth', severity: 'high', re: /export\s+async\s+function\s+action\s*\(/, fileFilter: '\\.(?:ts|tsx)$', confidence: 'low', message: 'Remix action without auth check — unauthenticated mutation', cwe: 'CWE-306', owasp: 'A01', fix: 'Check session in action: const session = await getSession(request). Verify user.' },
|
|
2147
|
+
{ id: 'remix.unsafe-html', severity: 'high', re: /<DangerouslySetInnerHTML\s+html\s*=\s*\{[^}]*(?:request|params|loader|action)/, fileFilter: '\\.(?:ts|tsx)$', message: 'Remix dangerouslySetInnerHTML with loader/action data — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Sanitize HTML before rendering. Use escapeHtml or DOMPurify.' },
|
|
2148
|
+
];
|
|
2149
|
+
|
|
2150
|
+
const astroRules = [
|
|
2151
|
+
{ id: 'astro.set-html-raw', severity: 'high', re: /set:html\s*=\s*\{[^}]*(?:Astro|props|request|params)/, fileFilter: '\\.(?:astro|ts|tsx)$', message: 'Astro set:html with user data — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Sanitize with DOMPurify. Only use set:html for trusted content.' },
|
|
2152
|
+
{ id: 'astro.endpoint-no-auth', severity: 'high', re: /export\s+async\s+function\s+GET|export\s+async\s+function\s+POST/, fileFilter: '\\.ts$', confidence: 'low', message: 'Astro API endpoint without auth check', cwe: 'CWE-306', owasp: 'A01', fix: 'Verify session/token in endpoint handler before returning data.' },
|
|
2153
|
+
];
|
|
2154
|
+
|
|
2155
|
+
const solidStartRules = [
|
|
2156
|
+
{ id: 'solidstart-action-no-auth', severity: 'high', re: /createServerAction\s*\(\s*(?:async\s*)?\(/, fileFilter: '\\.(?:ts|tsx)$', confidence: 'low', message: 'SolidStart server action without auth check', cwe: 'CWE-306', owasp: 'A01', fix: 'Verify session inside the action before processing mutations.' },
|
|
2157
|
+
];
|
|
2158
|
+
|
|
2159
|
+
const ginRules = [
|
|
2160
|
+
{ id: 'gin.sql-injection', severity: 'high', re: /(?:db\.Raw|db\.Exec)\s*\(\s*(?:fmt\.Sprintf|\+|["'].*%[svd])/, fileFilter: '\\.go$', message: 'Gin SQL with string formatting — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized queries: db.Raw("SELECT ... WHERE id = ?", id)' },
|
|
2161
|
+
];
|
|
2162
|
+
|
|
2163
|
+
const echoRules = [
|
|
2164
|
+
{ id: 'echo.cors-wildcard', severity: 'medium', re: /e\.Use\(middleware\.CORS\(\s*\)/, fileFilter: '\\.go$', message: 'Echo CORS middleware with default config — wildcard origin', cwe: 'CWE-942', owasp: 'A05', fix: 'Configure CORS: middleware.CORSWithConfig(middleware.CORSConfig{AllowOrigins: []string{"https://yourapp.com"}})' },
|
|
2165
|
+
];
|
|
2166
|
+
|
|
2167
|
+
// ===========================================================================
|
|
2168
|
+
// POWER BATCH D: 10 Terraform/IaC deep rules
|
|
2169
|
+
// ===========================================================================
|
|
2170
|
+
|
|
2171
|
+
const terraformDeepRules = [
|
|
2172
|
+
{ id: 'tf.s3-public-read', severity: 'high', re: /acl\s*=\s*['"]public-read['"]|acl\s*=\s*['"]public-read-write['"]/, fileFilter: '\\.(?:tf|tfvars)$', message: 'Terraform: S3 bucket public-read ACL', cwe: 'CWE-732', owasp: 'A05', fix: 'Set acl = "private". Use CloudFront for public access.' },
|
|
2173
|
+
{ id: 'tf.iam-wildcard-action', severity: 'high', re: /action\s*=\s*['"]\*['"]|actions\s*=\s*\[\s*['"]\*['"]\s*\]/, fileFilter: '\\.tf$', message: 'Terraform: IAM policy with Action:* — over-permissive', cwe: 'CWE-732', owasp: 'A05', fix: 'Specify exact IAM actions needed. Never use "*" in production.' },
|
|
2174
|
+
{ id: 'tf.security-group-all-open', severity: 'high', re: /cidr_blocks\s*=\s*\[\s*['"]0\.0\.0\.0\/0['"]\s*\][\s\S]{0,300}(?:from_port\s*=\s*0|to_port\s*=\s*65535)/, fileFilter: '\\.tf$', message: 'Terraform: security group open to 0.0.0.0/0 on all ports', cwe: 'CWE-284', owasp: 'A05', fix: 'Restrict CIDR to known IPs. Limit port range to required ports.' },
|
|
2175
|
+
{ id: 'tf.rds-publicly-accessible', severity: 'high', re: /publicly_accessible\s*=\s*true/, fileFilter: '\\.tf$', message: 'Terraform: RDS publicly accessible — internet exposure', cwe: 'CWE-284', owasp: 'A05', fix: 'Set publicly_accessible = false. Use private subnets.' },
|
|
2176
|
+
{ id: 'tf.no-encryption-at-rest', severity: 'high', re: /resource\s+["']aws_(?:s3_bucket|dynamodb_table|rds_cluster|ebs_volume|rds_instance)["'][\s\S]{0,500}(?!.*encrypt)/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: storage resource without encryption at rest', cwe: 'CWE-311', owasp: 'A02', fix: 'Add encryption configuration to all storage resources.' },
|
|
2177
|
+
{ id: 'tf.no-kms-key-rotation', severity: 'medium', re: /resource\s+["']aws_kms_key["'][\s\S]{0,300}(?!.*enable_key_rotation)/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: KMS key without key rotation enabled', cwe: 'CWE-311', owasp: 'A02', fix: 'Add enable_key_rotation = true to KMS key resource.' },
|
|
2178
|
+
{ id: 'tf.hardcoded-key', severity: 'critical', re: /(?:access_key|secret_key|password|api_key)\s*=\s*['"][A-Za-z0-9+/=]{16,}['"]/, fileFilter: '\\.(?:tf|tfvars)$', message: 'Terraform: hardcoded credential in HCL', cwe: 'CWE-798', owasp: 'A02', fix: 'Use terraform.tfvars (gitignored) or AWS Secrets Manager / Vault.' },
|
|
2179
|
+
{ id: 'tf.wildcard-principal', severity: 'high', re: /principals\s*=\s*\{[^}]*\*\s*\}|principal\s*=\s*['"]\*['"]/, fileFilter: '\\.tf$', message: 'Terraform: IAM wildcard Principal:* — any AWS account', cwe: 'CWE-284', owasp: 'A05', fix: 'Specify exact ARN for principals. Never use Principal: "*" on resources.' },
|
|
2180
|
+
{ id: 'tf.public-ecr', severity: 'medium', re: /resource\s+["']aws_ecr_repository["'][\s\S]{0,300}policy_text\s*=\s*[^}]*Principal.*\*/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: ECR repository with public access', cwe: 'CWE-284', owasp: 'A05', fix: 'Restrict ECR to specific IAM principals. Never use Principal: "*".' },
|
|
2181
|
+
{ id: 'tf.no-tags', severity: 'low', re: /resource\s+["']aws_/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: AWS resource without tags — no cost/owner tracking', cwe: 'CWE-1188', owasp: 'A05', fix: 'Add tags block with Owner, Environment, CostCenter.' },
|
|
2182
|
+
];
|
|
2183
|
+
|
|
2184
|
+
// ===========================================================================
|
|
2185
|
+
// POWER BATCH E: 10 advanced auth rules
|
|
2186
|
+
// ===========================================================================
|
|
2187
|
+
|
|
2188
|
+
const advancedAuthRules = [
|
|
2189
|
+
{ id: 'auth.jwt-none-algorithm', severity: 'critical', re: /algorithm\s*:\s*['"]none['"]|alg\s*:\s*['"]none['"]/, message: 'JWT with algorithm:none — no signature verification', cwe: 'CWE-347', owasp: 'A02', fix: 'Never accept alg:none. Verify with a hardcoded algorithm and secret.' },
|
|
2190
|
+
{ id: 'auth.weak-jwt-secret', severity: 'high', re: /jwt\.sign\s*\([^)]*['"](?:secret|password|changeme|test|default|key|123456)['"]/, message: 'JWT signed with weak/default secret', cwe: 'CWE-321', owasp: 'A02', fix: 'Use a high-entropy secret from environment: process.env.JWT_SECRET' },
|
|
2191
|
+
{ id: 'auth.no-refresh-rotation', severity: 'medium', re: /refreshToken\s*(?::|=)\s*req\.(?:body|cookies|headers)\.refresh/i, confidence: 'low', message: 'Refresh token used without rotation — replay attack risk', cwe: 'CWE-384', owasp: 'A07', fix: 'Rotate refresh tokens on each use. Invalidate old token after issuing new one.' },
|
|
2192
|
+
{ id: 'auth.session-fixation', severity: 'high', re: /req\.session\.user\s*=\s*req\.(?:body|query)\.(?:user|username|email)/, confidence: 'low', message: 'Session ID not regenerated after login — session fixation', cwe: 'CWE-384', owasp: 'A07', fix: 'Call req.session.regenerate() before setting session user after login.' },
|
|
2193
|
+
{ id: 'auth.password-in-query', severity: 'high', re: /req\.query\.(?:password|passwd|pwd|pass|secret|token)/i, message: 'Password in URL query string — logged in server logs and browser history', cwe: 'CWE-598', owasp: 'A04', fix: 'Never accept passwords in query strings. Use POST body only.' },
|
|
2194
|
+
{ id: 'auth.weak-hash', severity: 'high', re: /(?:md5|sha1)\s*\(\s*(?:req|password|passwd|pwd|pass)\./i, message: 'Weak password hashing with MD5/SHA1', cwe: 'CWE-327', owasp: 'A02', fix: 'Use bcrypt or argon2: bcrypt.hash(password, 12).' },
|
|
2195
|
+
{ id: 'auth.no-mfa-enforcement', severity: 'medium', re: /@EnableWebSecurity|security\.configure|auth\.config/, confidence: 'low', fileFilter: '\\.(?:java|kt|ts|js)$', message: 'Authentication configured without MFA enforcement', cwe: 'CWE-308', owasp: 'A07', confidence2: 'low', fix: 'Enforce MFA for sensitive operations. Use TOTP or WebAuthn.' },
|
|
2196
|
+
{ id: 'auth.insecure-oauth-state', severity: 'high', re: /state\s*[:=]\s*['"]?(?:undefined|null|''|""|true|false|0|1|state|session)['"]?/, message: 'OAuth state parameter is static/empty — CSRF in OAuth flow', cwe: 'CWE-352', owasp: 'A01', fix: 'Generate random state per request. Validate state on callback.' },
|
|
2197
|
+
{ id: 'auth.token-in-url', severity: 'high', re: /(?:https?:\/\/[^\s'"]*\/(?:token|auth|callback|redirect)\?[^\s'"]*(?:token|access_token|jwt|session)=)/i, message: 'Auth token in URL — leaked via Referer, logs, browser history', cwe: 'CWE-598', owasp: 'A04', fix: 'Pass tokens in Authorization header or HTTP-only cookies, never in URL.' },
|
|
2198
|
+
{ id: 'auth.no-login-rate-limit', severity: 'medium', re: /(?:login|signin|auth)\s*(?:\.post|\.route|\.handler)/, confidence: 'low', fileFilter: '\\.(?:js|ts|py|go|java|kt)$', message: 'Login endpoint without rate limiting — brute force risk', cwe: 'CWE-307', owasp: 'A07', fix: 'Add rate limiting: express-rate-limit on /login. Limit 5 attempts per minute.' },
|
|
2199
|
+
];
|
|
2200
|
+
|
|
2201
|
+
// ===========================================================================
|
|
2202
|
+
// POWER BATCH F: 10 data protection rules
|
|
2203
|
+
// ===========================================================================
|
|
2204
|
+
|
|
2205
|
+
const dataProtectionRules = [
|
|
2206
|
+
{ id: 'data.pii-in-error', severity: 'high', re: /throw\s+new\s+(?:Error|ApiError|HttpException)\s*\([^)]*(?:email|phone|ssn|address|password|credit)/i, message: 'PII in error message — data leak', cwe: 'CWE-209', owasp: 'A01', fix: 'Log PII server-side only. Return generic error to client.' },
|
|
2207
|
+
{ id: 'data.sensitive-in-localstorage', severity: 'high', re: /localStorage\.setItem\s*\(\s*['"](?:token|password|secret|session|auth|jwt|api.?key|access.?token)['"]/i, message: 'Sensitive data in localStorage — XSS accessible', cwe: 'CWE-922', owasp: 'A02', fix: 'Use HTTP-only cookies for auth tokens. Never store secrets in localStorage.' },
|
|
2208
|
+
{ id: 'data.sensitive-in-sessionstorage', severity: 'high', re: /sessionStorage\.setItem\s*\(\s*['"](?:token|password|secret|session|auth|jwt|api.?key)['"]/i, message: 'Sensitive data in sessionStorage — XSS accessible', cwe: 'CWE-922', owasp: 'A02', fix: 'Use HTTP-only cookies for auth tokens.' },
|
|
2209
|
+
{ id: 'data.export-no-auth', severity: 'high', re: /(?:export|download|dump|backup)\s*(?:\.get|\.route|\.handler|\.post)\s*\(/, confidence: 'low', message: 'Data export endpoint without auth — mass data exfiltration', cwe: 'CWE-306', owasp: 'A01', fix: 'Add auth check and audit log to all data export/download endpoints.' },
|
|
2210
|
+
{ id: 'data.unencrypted-db-connection', severity: 'medium', re: /(?:mongodb|postgres|mysql|redis):\/\/[^\s]*@(?!.*ssl=)(?!.*tls=)/, message: 'Database connection without SSL/TLS — unencrypted in transit', cwe: 'CWE-319', owasp: 'A02', fix: 'Add sslmode=require or tls=true to connection string.' },
|
|
2211
|
+
{ id: 'data.pii-no-retention-limit', severity: 'medium', re: /createTable|createCollection|CREATE\s+TABLE/i, confidence: 'low', message: 'Data storage created without retention policy — GDPR risk', cwe: 'CWE-770', owasp: 'A04', confidence2: 'low', fix: 'Define data retention periods. Implement TTL or scheduled cleanup.' },
|
|
2212
|
+
{ id: 'data.gdpr-no-consent', severity: 'medium', re: /track|analytics|telemetry|collect/i, confidence: 'low', fileFilter: '\\.(?:js|ts|tsx)$', message: 'Data collection without consent check — GDPR violation', cwe: 'CWE-359', owasp: 'A04', fix: 'Implement consent banner. Check consent before tracking/collecting PII.' },
|
|
2213
|
+
{ id: 'data.no-field-encryption', severity: 'medium', re: /schema\.(?:define|object|model)\s*\(/, confidence: 'low', message: 'Database schema without field-level encryption for PII', cwe: 'CWE-311', owasp: 'A02', fix: 'Encrypt PII fields at application level: encrypt(email) before storing.' },
|
|
2214
|
+
{ id: 'data.unmasked-pii-display', severity: 'medium', re: /res\.(?:json|send|render)\s*\(\s*[^)]*(?:ssn|credit_card|card_number|cvv|sin)/i, message: 'Unmasked PII (SSN/card) sent to client', cwe: 'CWE-200', owasp: 'A02', fix: 'Mask sensitive data: show only last 4 digits.' },
|
|
2215
|
+
{ id: 'data.log-pii-unmasked', severity: 'medium', re: /(?:console\.log|logger\.(?:info|debug|error)|log\.info)\s*\([^)]*(?:ssn|credit.?card|cvv|sin|passport|national.?id)/i, message: 'Unmasked PII in log — compliance violation', cwe: 'CWE-532', owasp: 'A09', fix: 'Mask PII before logging: redact SSN to ***-**-1234.' },
|
|
2216
|
+
];
|
|
2217
|
+
|
|
2218
|
+
// ===========================================================================
|
|
2219
|
+
// POWER BATCH G: 10 advanced injection rules
|
|
2220
|
+
// ===========================================================================
|
|
2221
|
+
|
|
2222
|
+
const advancedInjectionRules = [
|
|
2223
|
+
{ id: 'injection.ssti', severity: 'critical', re: /(?:render|render_template|renderToString)\s*\(\s*[^)]*(?:req|user|input|body|query|params)/i, message: 'Server-side template injection — user input in template render', cwe: 'CWE-94', owasp: 'A03', fix: 'Never pass user input as template. Use template context variables.' },
|
|
2224
|
+
{ id: 'injection.ldap', severity: 'high', re: /ldap\.search|ldap\.bind\s*\(\s*[^)]*(?:req|user|input|body|query|params)/i, message: 'LDAP query with user input — LDAP injection', cwe: 'CWE-90', owasp: 'A03', fix: 'Escape LDAP special characters. Use parameterized LDAP queries.' },
|
|
2225
|
+
{ id: 'injection.xpath', severity: 'high', re: /xpath\.(?:evaluate|select|selectNodes)\s*\(\s*[^)]*(?:req|user|input|body|query)/i, message: 'XPath with user input — XPath injection', cwe: 'CWE-643', owasp: 'A03', fix: 'Parameterize XPath queries. Escape user input.' },
|
|
2226
|
+
{ id: 'injection.nosql-where', severity: 'high', re: /\$where\s*:\s*[^'"0-9]/, message: 'NoSQL $where with unescaped input — JavaScript injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Never use $where with user input. Use $expr or aggregation pipeline.' },
|
|
2227
|
+
{ id: 'injection.header-injection', severity: 'high', re: /res\.setHeader\s*\(\s*['"](?:Location|Set-Cookie|Refresh)['"]\s*,\s*[^)]*(?:req|user|input|body|query)/i, message: 'HTTP header injection — CRLF injection via user input', cwe: 'CWE-113', owasp: 'A03', fix: 'Sanitize header values. Strip CR/LF characters from user input.' },
|
|
2228
|
+
{ id: 'injection.log-injection', severity: 'medium', re: /(?:console\.log|logger\.\w+|log\.\w+)\s*\(\s*[^)]*(?:req\.headers|req\.url|req\.query|req\.body)\b/, message: 'Log injection — unsanitized user input in log', cwe: 'CWE-117', owasp: 'A09', fix: 'Sanitize log input. Strip newlines and control characters.' },
|
|
2229
|
+
{ id: 'injection.template-injection', severity: 'critical', re: /(?:ejs|pug|hbs|mustache|handlebars|nunjucks)\.render\s*\(\s*[^)]*(?:req|user|input|body|query)/i, message: 'Template engine render with user input — SSTI', cwe: 'CWE-94', owasp: 'A03', fix: 'Pass user input as data, not as template string.' },
|
|
2230
|
+
{ id: 'injection.orm-raw-user', severity: 'high', re: /\.(?:raw|query|execute|exec)\s*\(\s*[^)]*(?:req|user|input|body|query|params)\.(?:body|query|params)/i, message: 'ORM raw query with user input — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized ORM queries. Never pass user input to raw methods.' },
|
|
2231
|
+
{ id: 'injection.stored-proc-call', severity: 'high', re: /CALL\s+\w+\s*\(\s*(?:req|user|input|body|query|params)\./i, message: 'Stored procedure call with user input — injection via stored proc', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized stored procedure calls. Bind all parameters.' },
|
|
2232
|
+
{ id: 'injection.expression-lang', severity: 'high', re: /(?:eval|expression|script|engine)\.eval(?:uate)?\s*\(\s*[^)]*(?:req|user|input|body|query|params)/i, message: 'Expression language eval with user input — RCE', cwe: 'CWE-94', owasp: 'A03', fix: 'Never eval user input in expression language. Use safe evaluation context.' },
|
|
2233
|
+
];
|
|
2234
|
+
|
|
2235
|
+
// ===========================================================================
|
|
2236
|
+
// POWER BATCH H: 10 more secrets
|
|
2237
|
+
// ===========================================================================
|
|
2238
|
+
|
|
2239
|
+
const moreSecretRules = [
|
|
2240
|
+
{ id: 'secret.vault-token', severity: 'high', re: /(?:VAULT_TOKEN|VAULT_ADDR)\s*[:=]\s*['"](?:hvs\.|s\.)[A-Za-z0-9._-]{20,}['"]/i, message: 'HashiCorp Vault token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Use VAULT_TOKEN env var. Never hardcode Vault tokens.' },
|
|
2241
|
+
{ id: 'secret.doppler-token', severity: 'high', re: /DOPPLER_TOKEN\s*[:=]\s*['"][A-Za-z0-9._-]{40,}['"]/i, message: 'Doppler token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2242
|
+
{ id: 'secret.aws-secret-in-env', severity: 'high', re: /AWS_SECRET_ACCESS_KEY\s*[:=]\s*['"][A-Za-z0-9/+=]{40}['"]/i, message: 'AWS secret access key in code', cwe: 'CWE-798', owasp: 'A02', fix: 'Use IAM roles. Never hardcode AWS credentials.' },
|
|
2243
|
+
{ id: 'secret.gha-leak', severity: 'high', re: /(?:echo|print|console\.log)\s*\([^)]*\$\{?\{?\s*(?:secrets|SECRET_\w+|GITHUB_TOKEN)/, message: 'GitHub Actions secret leaked via echo/log', cwe: 'CWE-532', owasp: 'A09', fix: 'Never echo secrets. Use ::add-mask:: to mask values.' },
|
|
2244
|
+
{ id: 'secret.docker-build-arg', severity: 'high', re: /--build-arg\s+(?:PASSWORD|SECRET|TOKEN|API_KEY|KEY)\s*=\s*[^$\s]/, message: 'Docker build arg with hardcoded secret — visible in image history', cwe: 'CWE-798', owasp: 'A02', fix: 'Use Docker BuildKit secrets: --secret id=token,env=TOKEN' },
|
|
2245
|
+
{ id: 'secret.k8s-env-secret', severity: 'high', re: /env:\s*\n\s*-\s*name:\s*(?:PASSWORD|SECRET|TOKEN|API_KEY|KEY)\s*\n\s*value:\s*['"][^'"]{8,}['"]/, message: 'Kubernetes secret in plain env var — not using Secret resource', cwe: 'CWE-798', owasp: 'A02', fix: 'Use Kubernetes Secret resources: valueFrom.secretKeyRef.' },
|
|
2246
|
+
{ id: 'secret.slack-webhook', severity: 'high', re: /https:\/\/hooks\.slack\.com\/services\/T[A-Z0-9]+\/B[A-Z0-9]+\/[A-Za-z0-9]+/, message: 'Slack webhook URL with token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable. Rotate compromised webhooks.' },
|
|
2247
|
+
{ id: 'secret.discord-bot-token', severity: 'high', re: /DISCORD_(?:BOT_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9._-]{50,}['"]/i, message: 'Discord bot token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2248
|
+
{ id: 'secret.twitch-token', severity: 'high', re: /TWITCH_(?:ACCESS_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9_]{30,}['"]/i, message: 'Twitch access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2249
|
+
{ id: 'secret.patreon-token', severity: 'high', re: /PATREON_(?:ACCESS_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9]{30,}['"]/i, message: 'Patreon access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2250
|
+
];
|
|
2251
|
+
|
|
2252
|
+
// ===========================================================================
|
|
2253
|
+
// POWER BATCH I: 10 supply chain rules
|
|
2254
|
+
// ===========================================================================
|
|
2255
|
+
|
|
2256
|
+
const supplyChainDeepRules = [
|
|
2257
|
+
{ id: 'supply.license-gpl', severity: 'medium', re: /"license":\s*"(?:GPL|AGPL|LGPL|SSPL|BUSL)/i, fileFilter: 'package\\.json$', message: 'GPL/AGPL license — copyleft risk for commercial use', cwe: 'CWE-1357', owasp: 'A06', fix: 'Review license compatibility. Use MIT/Apache-2.0/BSD for commercial projects.' },
|
|
2258
|
+
{ id: 'supply.no-sbom', severity: 'low', re: /scripts\s*:\s*\{/, fileFilter: 'package\\.json$', confidence: 'low', message: 'No SBOM generation in npm scripts — supply chain visibility gap', cwe: 'CWE-1357', owasp: 'A06', fix: 'Add "sbom": "npx @cyclonedx/cyclonedx-npm" to scripts.' },
|
|
2259
|
+
{ id: 'supply.git-http-dep', severity: 'high', re: /"(?:dependencies|devDependencies)":\s*\{[^}]*git\+http:\/\//i, fileFilter: 'package\\.json$', message: 'Dependency from git+http:// — MITM risk, no integrity', cwe: 'CWE-829', owasp: 'A06', fix: 'Use git+https:// or npm registry with integrity hashes.' },
|
|
2260
|
+
{ id: 'supply.unpinned-docker', severity: 'medium', re: /FROM\s+\S+:latest\b/, fileFilter: 'Dockerfile', message: 'Docker image :latest — non-reproducible builds', cwe: 'CWE-937', owasp: 'A06', fix: 'Pin image version or digest: FROM node:18.19.0-alpine3.19' },
|
|
2261
|
+
{ id: 'supply.eval-in-postinstall', severity: 'critical', re: /"postinstall"\s*:\s*"[^"]*(?:eval|exec|curl|wget|node\s+-e)/i, fileFilter: 'package\\.json$', message: 'Dangerous code in postinstall script — supply chain attack', cwe: 'CWE-94', owasp: 'A06', fix: 'Review postinstall scripts. Use --ignore-scripts if untrusted.' },
|
|
2262
|
+
{ id: 'supply.crypto-miner', severity: 'critical', re: /(?:xmrig|coinhive|coin-?hive|crypto-?loot|cryptonight|monero|miner)/i, fileFilter: 'package\\.json$', message: 'Cryptocurrency miner detected in dependencies', cwe: 'CWE-506', owasp: 'A06', fix: 'Remove immediately. Audit all dependencies.' },
|
|
2263
|
+
{ id: 'supply.missing-npmrc', severity: 'low', re: /engines\s*:\s*\{/, fileFilter: 'package\\.json$', confidence: 'low', message: 'No .npmrc — no registry configuration or audit enforcement', cwe: 'CWE-1357', owasp: 'A06', fix: 'Create .npmrc with: audit=true, fund=false, engine-strict=true' },
|
|
2264
|
+
{ id: 'supply.bundled-deps', severity: 'medium', re: /"bundleDependencies"\s*:\s*\[/, fileFilter: 'package\\.json$', message: 'bundleDependencies — unpackaged deps may hide malware', cwe: 'CWE-1357', owasp: 'A06', fix: 'Remove bundleDependencies. Use lockfile for reproducible installs.' },
|
|
2265
|
+
{ id: 'supply.no-integrity-hash', severity: 'medium', re: /"(?:dependencies|devDependencies)":\s*\{[^}]*"[^"]*":\s*"[^^]/i, fileFilter: 'package-lock\\.json$', confidence: 'low', message: 'Dependency without integrity hash — tamper detection missing', cwe: 'CWE-353', owasp: 'A06', fix: 'Run npm install to regenerate lockfile with integrity hashes.' },
|
|
2266
|
+
{ id: 'supply.peer-dep-dangerous', severity: 'medium', re: /"peerDependencies"\s*:\s*\{[^}]*"[^"]*":\s*"\*"/, fileFilter: 'package\\.json$', message: 'Peer dependency with wildcard version — may install any version', cwe: 'CWE-1357', owasp: 'A06', fix: 'Specify peer dependency version range: "react": "^18.0.0"' },
|
|
2267
|
+
];
|
|
2268
|
+
|
|
2269
|
+
// ===========================================================================
|
|
2270
|
+
// POWER BATCH J: 10 security headers/transport rules
|
|
2271
|
+
// ===========================================================================
|
|
2272
|
+
|
|
2273
|
+
const transportDeepRules = [
|
|
2274
|
+
{ id: 'transport.mixed-content', severity: 'high', re: /src\s*=\s*['"]http:\/\/(?!localhost|127\.0\.0\.1)/i, fileFilter: '\\.(?:html|htm)$', message: 'Mixed content — HTTP resource loaded on HTTPS page', cwe: 'CWE-319', owasp: 'A02', fix: 'Use protocol-relative URLs or HTTPS-only. Add upgrade-insecure-requests CSP.' },
|
|
2275
|
+
{ id: 'transport.deprecated-tls', severity: 'high', re: /(?:TLSv1|TLSv1\.1|SSLv2|SSLv3|secureProtocol\s*:\s*['"]TLSv1['"])/i, message: 'Deprecated TLS/SSL version — vulnerable to attacks', cwe: 'CWE-327', owasp: 'A02', fix: 'Use TLS 1.2+ only. Set minVersion: TLSv1.2.' },
|
|
2276
|
+
{ id: 'transport.weak-cipher', severity: 'high', re: /ciphers\s*[:=]\s*['"][^'"]*(?:RC4|DES|3DES|MD5|SHA1|EXPORT|NULL|aNULL|eNULL)/i, message: 'Weak cipher suite — deprecated encryption', cwe: 'CWE-327', owasp: 'A02', fix: 'Use modern cipher suites: TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256.' },
|
|
2277
|
+
{ id: 'transport.no-forward-secrecy', severity: 'medium', re: /ciphers\s*[:=]\s*['"][^'"]*(?!.*ECDHE|DHE)(?=.*AES|.*RSA)/i, confidence: 'low', message: 'No forward secrecy — cipher suite without ECDHE/DHE', cwe: 'CWE-327', owasp: 'A02', fix: 'Prefer ECDHE cipher suites for forward secrecy.' },
|
|
2278
|
+
{ id: 'transport.no-hsts-preload', severity: 'medium', re: /Strict-Transport-Security\s*:\s*['"]?max-age\s*=\s*(?:0|1|60|3600|86400|604800)['"]?(?!.*preload)/i, message: 'HSTS with short max-age or no preload — insufficient HSTS', cwe: 'CWE-319', owasp: 'A05', fix: 'Set HSTS: max-age=31536000; includeSubDomains; preload' },
|
|
2279
|
+
{ id: 'transport.missing-x-download', severity: 'low', re: /res\.download\s*\(/, confidence: 'low', message: 'File download without X-Download-Options — IE may open HTML in context', cwe: 'CWE-79', owasp: 'A05', fix: 'Add header: X-Download-Options: noopen' },
|
|
2280
|
+
{ id: 'transport.missing-x-dns-prefetch', severity: 'low', re: /<link\s+rel\s*=\s*['"]dns-prefetch['"]/i, fileFilter: '\\.html$', confidence: 'low', message: 'No X-DNS-Prefetch-Control — DNS prefetch may leak browsing to third parties', cwe: 'CWE-200', owasp: 'A05', fix: 'Add header: X-DNS-Prefetch-Control: off' },
|
|
2281
|
+
{ id: 'transport.missing-expect-ct', severity: 'low', re: /helmet\s*\(\s*\)/, confidence: 'low', message: 'Expect-CT header not configured — no Certificate Transparency enforcement', cwe: 'CWE-295', owasp: 'A05', fix: 'Add header: Expect-CT: max-age=7776000, enforce' },
|
|
2282
|
+
{ id: 'transport.missing-cross-domain', severity: 'low', re: /<embed\s+src\s*=\s*['"](?:pdf|flash)/i, fileFilter: '\\.html$', confidence: 'low', message: 'Flash/embed without X-Permitted-Cross-Domain-Policies — cross-domain policy leak', cwe: 'CWE-942', owasp: 'A05', fix: 'Add header: X-Permitted-Cross-Domain-Policies: none' },
|
|
2283
|
+
{ id: 'transport.insecure-redirect', severity: 'high', re: /res\.redirect\s*\(\s*['"]http:\/\/(?!localhost|127\.0\.0\.1)/i, message: 'HTTP redirect — downgrades to insecure transport', cwe: 'CWE-319', owasp: 'A02', fix: 'Redirect to HTTPS only. Never redirect to http:// URLs.' },
|
|
2284
|
+
];
|
|
2285
|
+
|
|
2286
|
+
// ===========================================================================
|
|
2287
|
+
// POWER BATCH K: 50 more rules to push past 500
|
|
2288
|
+
// ===========================================================================
|
|
2289
|
+
|
|
2290
|
+
const powerRulesExtra = [
|
|
2291
|
+
// More secrets
|
|
2292
|
+
{ id: 'secret.bitbucket-token', severity: 'high', re: /BITBUCKET_(?:APP_)?PASSWORD\s*[:=]\s*['"][^'"]{8,}['"]/i, message: 'Bitbucket app password exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2293
|
+
{ id: 'secret.jfrog-token', severity: 'high', re: /JFROG_(?:ACCESS_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9_=-]{40,}['"]/i, message: 'JFrog Artifactory token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2294
|
+
{ id: 'secret.launchdarkly-key', severity: 'high', re: /LAUNCHDARKLY_(?:SDK_)?KEY\s*[:=]\s*['"][A-Za-z0-9-]{32,}['"]/i, message: 'LaunchDarkly SDK key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2295
|
+
{ id: 'secret.rollbar-token', severity: 'high', re: /ROLLBAR_(?:ACCESS_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9]{32}['"]/i, message: 'Rollbar access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2296
|
+
{ id: 'secret.mailchimp-key', severity: 'high', re: /MAILCHIMP_API_KEY\s*[:=]\s*['"][a-f0-9]{32}-us\d+['"]/i, message: 'Mailchimp API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2297
|
+
{ id: 'secret.stripe-restricted-key', severity: 'high', re: /rk_live_[A-Za-z0-9]{16,}/, message: 'Stripe restricted key exposed — full API access', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to process.env.STRIPE_RESTRICTED_KEY.' },
|
|
2298
|
+
{ id: 'secret.gitlab-pat', severity: 'high', re: /glpat-[A-Za-z0-9_-]{20}/, message: 'GitLab personal access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2299
|
+
{ id: 'secret.asana-token', severity: 'high', re: /ASANA_(?:ACCESS_)?TOKEN\s*[:=]\s*['"]\d+\/[A-Za-z0-9]{32,}['"]/i, message: 'Asana access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2300
|
+
{ id: 'secret.turso-token', severity: 'high', re: /TURSO_(?:GROUP_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9._-]{40,}['"]/i, message: 'Turso group token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2301
|
+
{ id: 'secret.supabase-service-role', severity: 'critical', re: /SUPABASE_SERVICE_ROLE_KEY\s*[:=]\s*['"][A-Za-z0-9._-]{40,}['"]/i, message: 'Supabase service role key exposed — bypasses RLS', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable. Never expose service role key to client.' },
|
|
2302
|
+
{ id: 'secret.mapbox-token', severity: 'medium', re: /MAPBOX_(?:ACCESS_)?TOKEN\s*[:=]\s*['"]pk\.[A-Za-z0-9._-]{60,}['"]/i, message: 'Mapbox access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2303
|
+
{ id: 'secret.twilio-account-sid', severity: 'medium', re: /TWILIO_ACCOUNT_SID\s*[:=]\s*['"]AC[a-z0-9]{32}['"]/i, message: 'Twilio Account SID exposed — combined with auth token enables API access', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2304
|
+
{ id: 'secret.postmark-token', severity: 'high', re: /POSTMARK_(?:SERVER_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9-]{36}['"]/i, message: 'Postmark server token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2305
|
+
{ id: 'secret.sendinblue-key', severity: 'high', re: /SENDINBLUE_API_KEY\s*[:=]\s*['"]xkeysib-[A-Za-z0-9-]{60,}['"]/i, message: 'Sendinblue/Brevo API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2306
|
+
|
|
2307
|
+
// More framework rules
|
|
2308
|
+
{ id: 'expo.insecure-transport', severity: 'medium', re: /usesCleartextTraffic\s*=\s*['"]?true/i, fileFilter: '\\.xml$', message: 'Android allows cleartext HTTP traffic — MITM risk', cwe: 'CWE-319', owasp: 'A02', fix: 'Set usesCleartextTraffic="false" in AndroidManifest.xml.' },
|
|
2309
|
+
{ id: 'expo.debuggable', severity: 'high', re: /android:debuggable\s*=\s*['"]true['"]/i, fileFilter: '\\.xml$', message: 'Android debuggable=true — app can be debugged by anyone', cwe: 'CWE-489', owasp: 'A05', fix: 'Remove android:debuggable or set to false in production.' },
|
|
2310
|
+
{ id: 'expo.backup-allowed', severity: 'medium', re: /android:allowBackup\s*=\s*['"]true['"]/i, fileFilter: '\\.xml$', message: 'Android allowBackup=true — app data accessible via adb backup', cwe: 'CWE-922', owasp: 'A02', fix: 'Set android:allowBackup="false" for apps handling sensitive data.' },
|
|
2311
|
+
{ id: 'fastify.no-body-limit', severity: 'medium', re: /fastify\s*\(\s*\{[^}]*(?!.*bodyLimit)/, confidence: 'low', message: 'Fastify server without bodyLimit — DoS via large payload', cwe: 'CWE-770', owasp: 'A04', fix: 'Set bodyLimit: fastify({ bodyLimit: 1048576 }) // 1MB' },
|
|
2312
|
+
{ id: 'express.no-trust-proxy', severity: 'low', re: /app\.set\s*\(\s*['"]trust proxy['"]/, confidence: 'low', message: 'Express trust proxy not configured — IP spoofing risk', cwe: 'CWE-345', owasp: 'A05', fix: 'Set: app.set("trust proxy", 1) for proper IP detection behind proxy.' },
|
|
2313
|
+
{ id: 'nextjs.image-optimization-disabled', severity: 'low', re: /images\s*:\s*\{[^}]*(?:unoptimized\s*:\s*true|disableStaticImages\s*:\s*true)/, fileFilter: 'next\\.config\\.', confidence: 'low', message: 'Next.js image optimization disabled — performance and bandwidth impact', cwe: 'CWE-400', owasp: 'A05', fix: 'Enable image optimization for better performance.' },
|
|
2314
|
+
{ id: 'nextjs.exposed-env', severity: 'medium', re: /NEXT_PUBLIC_(?:DATABASE_URL|DB_PASSWORD|DB_SECRET|JWT_SECRET|API_SECRET|ENCRYPTION_KEY)/i, message: 'Sensitive env var exposed via NEXT_PUBLIC_ prefix', cwe: 'CWE-200', owasp: 'A05', fix: 'Remove NEXT_PUBLIC_ prefix. Sensitive values should be server-side only.' },
|
|
2315
|
+
{ id: 'remix.no-csp', severity: 'medium', re: /export\s+const\s+headers\s*=\s*\{/, fileFilter: '\\.(?:ts|tsx)$', confidence: 'low', message: 'Remix headers export without Content-Security-Policy', cwe: 'CWE-1021', owasp: 'A05', fix: 'Add "Content-Security-Policy" to the headers export.' },
|
|
2316
|
+
{ id: 'astro.client-secret', severity: 'high', re: /const\s+(?:API_KEY|SECRET|TOKEN|PASSWORD)\s*=\s*['"][^'"]{16,}['"]/i, fileFilter: '\\.astro$', message: 'Astro component with hardcoded secret — rendered client-side', cwe: 'CWE-798', owasp: 'A02', fix: 'Move secrets to server endpoints. Astro components may render to HTML.' },
|
|
2317
|
+
{ id: 'sveltekit.client-secret', severity: 'high', re: /\$env\/static\/public\.[^;]*(?:API_KEY|SECRET|TOKEN|PASSWORD|PRIVATE_KEY)/i, fileFilter: '\\.(?:svelte|js|ts)$', message: 'SvelteKit secret imported via $env/static/public — exposed to client bundle', cwe: 'CWE-798', owasp: 'A02', fix: 'Use $env/static/private for secrets. $env/static/public is bundled into client code.' },
|
|
2318
|
+
|
|
2319
|
+
// More injection/code quality
|
|
2320
|
+
{ id: 'injection.regex-injection', severity: 'high', re: /new\s+RegExp\s*\(\s*(?:req|user|input|body|query|params)\./i, message: 'RegExp from user input — ReDoS or regex injection', cwe: 'CWE-1333', owasp: 'A03', fix: 'Validate regex pattern. Use safe-regex or re2 module.' },
|
|
2321
|
+
{ id: 'injection.mail-header', severity: 'high', re: /(?:setHeader|addHeader)\s*\(\s*['"](?:To|Cc|Bcc|Subject|Reply-To)['"]\s*,\s*[^)]*(?:req|user|input|body|query)/i, message: 'Email header injection via user input', cwe: 'CWE-93', owasp: 'A03', fix: 'Strip newlines from email headers. Validate input.' },
|
|
2322
|
+
{ id: 'injection.formula-injection', severity: 'high', re: /(?:write|create|append)\s*\(\s*[^)]*(?:csv|xlsx|excel)[^)]*(?:req|user|input|body|query)/i, message: 'CSV/Excel formula injection — user input written to spreadsheet', cwe: 'CWE-1236', owasp: 'A03', fix: 'Prefix cell values with single quote or sanitize = + - @ characters.' },
|
|
2323
|
+
{ id: 'injection.pdf-injection', severity: 'medium', re: /PDFDocument\s*\(\s*\{[^}]*(?:req|user|input|body|query)/i, message: 'PDF generation with unsanitized user input — injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Escape user input in PDF generation. Validate all dynamic content.' },
|
|
2324
|
+
{ id: 'injection.xss-angular-bypass', severity: 'high', re: /DomSanitizer(?:Provider)?\s*\(\s*\)|bypassSecurityTrust(?:Html|ResourceUrl|ScriptUrl|Style)/, message: 'Angular DomSanitizer bypass — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Never bypass Angular sanitization. Use safe pipes or component templates.' },
|
|
2325
|
+
{ id: 'injection.xss-vue-v-html', severity: 'high', re: /v-html\s*=\s*['"]?\{?\{?\s*(?:req|user|input|data|params|query|body|response)/, message: 'Vue v-html with user data — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Never use v-html with user input. Use v-text or sanitize with DOMPurify.' },
|
|
2326
|
+
{ id: 'injection.xss-angular-innerHTML', severity: 'high', re: /innerHTML\s*=\s*(?:this\.)?(?:data|user|input|response|result|body|query)\./i, fileFilter: '\\.(?:ts|js)$', message: 'Angular innerHTML with user data — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Use Angular sanitization. Set [innerHTML] with sanitized content.' },
|
|
2327
|
+
|
|
2328
|
+
// More auth/session
|
|
2329
|
+
{ id: 'auth.session-cookie-no-httponly', severity: 'high', re: /cookie\s*[:=]\s*\{[^}]*(?:name|key)\s*:\s*['"]session['"][^}]*\}/, confidence: 'low', message: 'Session cookie without httpOnly flag — JS can read session', cwe: 'CWE-1004', owasp: 'A05', fix: 'Set httpOnly: true on session cookies.' },
|
|
2330
|
+
{ id: 'auth.session-no-secure', severity: 'high', re: /cookie\s*[:=]\s*\{[^}]*(?:name|key)\s*:\s*['"]session['"][^}]*(?!.*secure)/, confidence: 'low', message: 'Session cookie without Secure flag — sent over HTTP', cwe: 'CWE-614', owasp: 'A05', fix: 'Set secure: true on session cookies.' },
|
|
2331
|
+
{ id: 'auth.password-plaintext-storage', severity: 'high', re: /(?:password|passwd|pwd|pass)\s*(?::|=)\s*(?:req|user|customer|account)\.(?:body|params|query)\.(?:password|passwd|pwd|pass)/i, message: 'Password stored in plaintext — no hashing', cwe: 'CWE-256', owasp: 'A02', fix: 'Hash passwords with bcrypt: bcrypt.hash(password, 12) before storing.' },
|
|
2332
|
+
{ id: 'auth.no-logout', severity: 'medium', re: /(?:login|signin|authenticate)\s*(?:\.post|\.route|\.handler|\.resolver)/, confidence: 'low', message: 'Auth system without logout endpoint — session fixation risk', cwe: 'CWE-384', owasp: 'A07', fix: 'Implement logout endpoint that destroys session and clears cookies.' },
|
|
2333
|
+
{ id: 'auth.cors-credentials-wildcard', severity: 'critical', re: /cors\s*\(\s*\{[^}]*(?:origin\s*:\s*['"]\*['"]|credentials\s*:\s*true)/, message: 'CORS: credentials:true with wildcard origin — credential theft', cwe: 'CWE-942', owasp: 'A05', fix: 'Never combine origin:* with credentials:true. Set specific origins.' },
|
|
2334
|
+
|
|
2335
|
+
// More IaC/cloud
|
|
2336
|
+
{ id: 'tf.no-encryption-sns', severity: 'medium', re: /resource\s+["']aws_sns_topic["'][\s\S]{0,300}(?!.*kms_master_key_id)/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: SNS topic without KMS encryption', cwe: 'CWE-311', owasp: 'A02', fix: 'Add kms_master_key_id to SNS topic resource.' },
|
|
2337
|
+
{ id: 'tf.no-encryption-sqs', severity: 'medium', re: /resource\s+["']aws_sqs_queue["'][\s\S]{0,300}(?!.*kms_master_key_id)/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: SQS queue without KMS encryption', cwe: 'CWE-311', owasp: 'A02', fix: 'Add kms_master_key_id to SQS queue resource.' },
|
|
2338
|
+
{ id: 'tf.s3-no-versioning', severity: 'medium', re: /resource\s+["']aws_s3_bucket["'][\s\S]{0,200}(?!.*versioning)/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: S3 bucket without versioning — no data recovery', cwe: 'CWE-1188', owasp: 'A05', fix: 'Add versioning { enabled = true } to S3 bucket.' },
|
|
2339
|
+
{ id: 'tf.s3-no-lifecycle', severity: 'low', re: /resource\s+["']aws_s3_bucket["'][\s\S]{0,200}(?!.*lifecycle)/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: S3 bucket without lifecycle rules — cost waste', cwe: 'CWE-1188', owasp: 'A05', fix: 'Add lifecycle_rule to transition old objects to cheaper storage.' },
|
|
2340
|
+
{ id: 'tf.lambda-no-dead-letter', severity: 'medium', re: /resource\s+["']aws_lambda_function["'][\s\S]{0,300}(?!.*dead_letter_config)/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: Lambda without dead-letter queue — silent failures', cwe: 'CWE-1188', owasp: 'A05', fix: 'Add dead_letter_config with SQS/SNS target.' },
|
|
2341
|
+
{ id: 'tf.rds-no-backup', severity: 'high', re: /resource\s+["']aws_db_instance["'][\s\S]{0,400}(?!.*backup_retention)/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: RDS without backup retention — data loss risk', cwe: 'CWE-1188', owasp: 'A05', fix: 'Add backup_retention_period = 7 to RDS instance.' },
|
|
2342
|
+
{ id: 'tf.iam-no-boundary', severity: 'medium', re: /resource\s+["']aws_iam_role["'][\s\S]{0,300}(?!.*permissions_boundary)/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: IAM role without permissions boundary — privilege escalation risk', cwe: 'CWE-732', owasp: 'A05', fix: 'Add permissions_boundary to IAM roles.' },
|
|
2343
|
+
{ id: 'tf.no-cloudtrail', severity: 'low', re: /provider\s+["']aws["']/, fileFilter: '\\.tf$', confidence: 'low', message: 'Terraform: AWS provider without CloudTrail — no API audit trail', cwe: 'CWE-1188', owasp: 'A05', fix: 'Enable CloudTrail for all AWS accounts.' },
|
|
2344
|
+
{ id: 'docker.no-user', severity: 'medium', re: /FROM\s+\S+/i, fileFilter: 'Dockerfile', confidence: 'low', message: 'Dockerfile without USER directive — runs as root', cwe: 'CWE-250', owasp: 'A05', fix: 'Add USER directive: USER node' },
|
|
2345
|
+
{ id: 'docker.no-healthcheck', severity: 'medium', re: /FROM\s+\S+/i, fileFilter: 'Dockerfile', confidence: 'low', message: 'Dockerfile without HEALTHCHECK — orchestrator blind to health', cwe: 'CWE-1188', owasp: 'A05', fix: 'Add: HEALTHCHECK CMD curl -f http://localhost:3000/ || exit 1' },
|
|
2346
|
+
|
|
2347
|
+
// More supply chain
|
|
2348
|
+
{ id: 'supply.script-injection', severity: 'high', re: /"(?:pre|post)(?:install|test|build)"\s*:\s*"[^"]*(?:curl|wget|bash|sh\s+-c|node\s+-e)/i, fileFilter: 'package\\.json$', message: 'npm script with network command — supply chain risk', cwe: 'CWE-94', owasp: 'A06', fix: 'Review scripts. Remove curl/wget calls from install scripts.' },
|
|
2349
|
+
{ id: 'supply.private-registry', severity: 'medium', re: /"(?:dependencies|devDependencies)":\s*\{[^}]*"@(?:scope|company|internal)\//, fileFilter: 'package\\.json$', message: 'Private registry dependency — may fail without auth', cwe: 'CWE-1357', owasp: 'A06', fix: 'Configure .npmrc with auth for private registry. Document in README.' },
|
|
2350
|
+
{ id: 'supply.workspace-protocol', severity: 'low', re: /"(?:dependencies|devDependencies)":\s*\{[^}]*"workspace:/, fileFilter: 'package\\.json$', message: 'workspace: protocol — may resolve differently in non-monorepo', cwe: 'CWE-1357', owasp: 'A06', fix: 'Ensure workspace protocol is only used in monorepo. Publish with real version.' },
|
|
2351
|
+
{ id: 'supply.dual-package-hazard', severity: 'medium', re: /"(?:dependencies)":\s*\{[^}]*"[^"]*":\s*"[^^~](?:\d+\.\d+\.\d+)"/, fileFilter: 'package\\.json$', confidence: 'low', message: 'Pinned without ^ or ~ — may cause dual-package hazard with transitive deps', cwe: 'CWE-1357', owasp: 'A06', fix: 'Use ^ for semver range unless you specifically need exact pinning.' },
|
|
2352
|
+
{ id: 'supply.optional-dep-bypass', severity: 'low', re: /"optionalDependencies"\s*:\s*\{[^}]*"[^"]*":\s*"\*"/, fileFilter: 'package\\.json$', message: 'Optional dependency with wildcard — may install silently', cwe: 'CWE-1357', owasp: 'A06', fix: 'Pin optional dependency versions. Consider removing if unused.' },
|
|
2353
|
+
|
|
2354
|
+
// More mobile
|
|
2355
|
+
{ id: 'mobile.no-app-pinning', severity: 'medium', re: /TrustManager\s*\(\s*\)|checkServerTrusted\s*\(\s*\)/, fileFilter: '\\.(?:kt|java)$', confidence: 'low', message: 'No certificate pinning — MITM with rogue CA', cwe: 'CWE-295', owasp: 'A02', fix: 'Implement certificate pinning with OkHttp CertificatePinner or Network Security Config.' },
|
|
2356
|
+
{ id: 'mobile.insecure-deeplink', severity: 'high', re: /android:scheme\s*=\s*['"]https['"]/i, fileFilter: '\\.xml$', confidence: 'low', message: 'Deep link without host validation — other apps can hijack', cwe: 'CWE-939', owasp: 'A01', fix: 'Add android:host and autoVerify="true". Use App Links.' },
|
|
2357
|
+
{ id: 'mobile.logging-pii', severity: 'medium', re: /Log\.(?:d|e|i|v|w)\s*\([^)]*(?:email|phone|ssn|password|token|pin)/i, fileFilter: '\\.(?:kt|java)$', message: 'PII in Android log — visible via logcat', cwe: 'CWE-532', owasp: 'A09', fix: 'Never log PII. Use ProGuard to strip logs in release builds.' },
|
|
2358
|
+
{ id: 'mobile.insecure-storage', severity: 'high', re: /openFileOutput\s*\(\s*['"][^'"]*['"]\s*,\s*MODE_PRIVATE\s*\)/, fileFilter: '\\.(?:kt|java)$', confidence: 'low', message: 'Data stored in internal storage — root devices can access', cwe: 'CWE-922', owasp: 'A02', fix: 'Use EncryptedFile or MasterKey with Jetpack Security.' },
|
|
2359
|
+
{ id: 'mobile.clipboard-pii', severity: 'medium', re: /ClipboardManager\.setPrimaryClip\s*\(/, fileFilter: '\\.(?:kt|java)$', message: 'Data copied to clipboard — other apps can read', cwe: 'CWE-200', owasp: 'A02', fix: 'Avoid clipboard for sensitive data. Clear clipboard after timeout.' },
|
|
2360
|
+
|
|
2361
|
+
// More AI security
|
|
2362
|
+
{ id: 'ai.prompt-leak-via-error', severity: 'high', re: /catch\s*\(\s*\w+\s*\)\s*\{[^}]*(?:console\.log|throw|res\.(?:json|send))[^}]*(?:prompt|system|instructions)/i, message: 'AI prompt leaked via error handler — system prompt exposure', cwe: 'CWE-209', owasp: 'A01', fix: 'Never include prompt content in error responses. Log server-side only.' },
|
|
2363
|
+
{ id: 'ai.no-input-sanitization', severity: 'high', re: /(?:messages|prompt|input)\s*[:=]\s*req\.(?:body|query|params)\.(?:prompt|message|input|text)/i, confidence: 'low', message: 'AI input from user without sanitization — prompt injection', cwe: 'CWE-20', owasp: 'A03', fix: 'Sanitize user input before passing to LLM. Strip injection patterns.' },
|
|
2364
|
+
{ id: 'ai.unbounded-output', severity: 'medium', re: /max_tokens\s*[:=]\s*(?:undefined|0|-1|Infinity|100000|1000000)/i, message: 'AI output without max_tokens limit — cost and DoS risk', cwe: 'CWE-770', owasp: 'A04', fix: 'Set max_tokens to a reasonable limit (e.g. 500-2000).' },
|
|
2365
|
+
{ id: 'ai.no-rate-limit', severity: 'medium', re: /(?:openai|anthropic|gemini|llama)\.(?:completions|chat|messages|generate)/i, confidence: 'low', message: 'LLM API call without rate limiting — cost abuse risk', cwe: 'CWE-770', owasp: 'A04', fix: 'Add rate limiting on AI endpoints. Track and limit per-user costs.' },
|
|
2366
|
+
{ id: 'ai.response-not-validated', severity: 'medium', re: /(?:response|completion|output)\.(?:text|content|message|choices)\[0\]\.(?:text|content)/, confidence: 'low', message: 'AI response used without validation — may contain injection or malformed data', cwe: 'CWE-20', owasp: 'A08', fix: 'Validate AI output format with Zod schema before using.' },
|
|
2367
|
+
];
|
|
2368
|
+
|
|
2369
|
+
// ===========================================================================
|
|
2370
|
+
// AMAZING BATCH: 60 more rules to push past 580
|
|
2371
|
+
// ===========================================================================
|
|
2372
|
+
|
|
2373
|
+
const amazingRules = [
|
|
2374
|
+
// More crypto/encryption depth
|
|
2375
|
+
{ id: 'crypto.ecb-mode', severity: 'high', re: /(?:AES|aes).*ECB|createCipher(?:iv)?\s*\(\s*['"]aes-\d+-ecb/i, message: 'ECB mode — identical plaintext blocks produce identical ciphertext', cwe: 'CWE-327', owasp: 'A02', fix: 'Use GCM or CBC mode with random IV.' },
|
|
2376
|
+
{ id: 'crypto.short-key', severity: 'high', re: /createCipher(?:iv)?\s*\(\s*['"]aes-(?:128|56|40)|RSA.*(?:512|1024)|DSA.*(?:512|1024)/i, message: 'Short encryption key — brute-force vulnerable', cwe: 'CWE-326', owasp: 'A02', fix: 'Use AES-256 or RSA-2048+ minimum.' },
|
|
2377
|
+
{ id: 'crypto.hardcoded-key', severity: 'high', re: /(?:encryptionKey|encryption_key|cipherKey|cipher_key|aesKey|aes_key|privateKey|private_key|secretKey|secret_key)\s*[:=]\s*['"][A-Za-z0-9+/=]{16,}['"]/i, skipComments: true, message: 'Hardcoded encryption key — rotate and move to env', cwe: 'CWE-321', owasp: 'A02', fix: 'Generate key with crypto.randomBytes(32). Store in env or KMS.' },
|
|
2378
|
+
{ id: 'crypto.weak-iv', severity: 'high', re: /iv\s*[:=]\s*['"][A-Za-z0-9+/=]{15,}['"]/i, skipComments: true, message: 'Hardcoded IV — defeats purpose of random IV', cwe: 'CWE-329', owasp: 'A02', fix: 'Generate random IV: crypto.randomBytes(16). Never reuse IVs.' },
|
|
2379
|
+
{ id: 'crypto.timing-attack', severity: 'medium', re: /(?:===?|!==?)\s*(?:password|token|secret|hmac|signature|hash)/i, skipComments: true, confidence: 'low', message: 'String comparison on secret — timing attack', cwe: 'CWE-208', owasp: 'A02', fix: 'Use crypto.timingSafeEqual() for constant-time comparison.' },
|
|
2380
|
+
{ id: 'crypto.pbkdf2-low-iterations', severity: 'medium', re: /pbkdf2(?:Sync)?\s*\([^)]*?,\s*\d{1,4}\s*[,)]/i, message: 'PBKDF2 with low iterations — brute-force vulnerable', cwe: 'CWE-916', owasp: 'A02', fix: 'Use at least 600,000 iterations (OWASP 2023 recommendation).' },
|
|
2381
|
+
{ id: 'crypto.scrypt-low-params', severity: 'medium', re: /scrypt(?:Sync)?\s*\([^)]*?,\s*\d{1,3}\s*,/i, confidence: 'low', message: 'scrypt with low cost parameter — brute-force vulnerable', cwe: 'CWE-916', owasp: 'A02', fix: 'Use N=16384 or higher (OWASP recommendation).' },
|
|
2382
|
+
|
|
2383
|
+
// More logging/audit
|
|
2384
|
+
{ id: 'audit.no-security-log', severity: 'medium', re: /(?:login|logout|password|reset|delete|admin|payment|transfer)\s*(?:\.post|\.route|\.handler|\.resolver)/, confidence: 'low', message: 'Security-sensitive endpoint without audit logging', cwe: 'CWE-778', owasp: 'A09', fix: 'Add audit log: logger.info({ action, user, ip, timestamp })' },
|
|
2385
|
+
{ id: 'audit.log-level-too-low', severity: 'low', re: /logger\.(?:debug|trace)\s*\([^)]*(?:auth|login|password|token|secret|payment|admin)/i, confidence: 'low', message: 'Security event logged at debug/trace — may be filtered in prod', cwe: 'CWE-778', owasp: 'A09', fix: 'Log security events at info or warn level.' },
|
|
2386
|
+
{ id: 'audit.no-tamper-protection', severity: 'low', re: /winston|pino|bunyan|log4/i, confidence: 'low', message: 'Logging framework without tamper protection — logs can be modified', cwe: 'CWE-778', owasp: 'A09', fix: 'Send critical logs to append-only storage or SIEM.' },
|
|
2387
|
+
|
|
2388
|
+
// More SSRF/network
|
|
2389
|
+
{ id: 'ssrf.internal-ip', severity: 'high', re: /(?:fetch|axios|http\.get|requests\.get)\s*\(\s*['"]https?:\/\/(?:10\.|172\.(?:1[6-9]|2[0-9]|3[01])\.|192\.168\.|127\.|localhost)/i, message: 'SSRF to internal IP — server-side request to private network', cwe: 'CWE-918', owasp: 'A10', fix: 'Validate URLs against allowlist. Block internal IPs.' },
|
|
2390
|
+
{ id: 'ssrf.metadata-service', severity: 'critical', re: /(?:fetch|axios|http\.get)\s*\(\s*['"]https?:\/\/169\.254\.169\.254/i, message: 'SSRF to cloud metadata service — credential theft', cwe: 'CWE-918', owasp: 'A10', fix: 'Block 169.254.169.254 in all HTTP clients. Use IMDSv2.' },
|
|
2391
|
+
{ id: 'ssrf.dns-rebinding', severity: 'medium', re: /(?:fetch|axios)\s*\(\s*(?:req|user|input|body|query)\.(?:url|endpoint|webhook|callback)/i, confidence: 'low', message: 'SSRF via user-controlled URL — DNS rebinding risk', cwe: 'CWE-918', owasp: 'A10', fix: 'Resolve DNS, validate IP is not internal, then connect to IP with Host header.' },
|
|
2392
|
+
|
|
2393
|
+
// More Express/Node
|
|
2394
|
+
{ id: 'express.no-helmet', severity: 'medium', re: /app\.use\s*\(\s*express\.json/, confidence: 'low', message: 'Express app without Helmet — missing security headers', cwe: 'CWE-693', owasp: 'A05', fix: 'Install and use helmet: app.use(helmet())' },
|
|
2395
|
+
{ id: 'express.no-rate-limit', severity: 'medium', re: /app\.use\s*\(\s*\/api/, confidence: 'low', message: 'API routes without rate limiting — DoS/brute-force', cwe: 'CWE-770', owasp: 'A04', fix: 'Add express-rate-limit: app.use("/api", rateLimit({ windowMs: 60000, max: 100 }))' },
|
|
2396
|
+
{ id: 'express.body-too-large', severity: 'medium', re: /express\.json\s*\(\s*\{\s*limit\s*:\s*['"]?\d+['"]?\s*\}/, message: 'Express body limit set — verify it is not too large', cwe: 'CWE-770', owasp: 'A04', confidence: 'low', fix: 'Set limit to 1MB or less: express.json({ limit: "1mb" })' },
|
|
2397
|
+
{ id: 'express.no-csrf', severity: 'high', re: /app\.use\s*\(\s*express\.session/, confidence: 'low', message: 'Express session without CSRF protection', cwe: 'CWE-352', owasp: 'A01', fix: 'Install csurf: app.use(csrf()) and include token in forms.' },
|
|
2398
|
+
{ id: 'express.insecure-template', severity: 'medium', re: /app\.engine\s*\(\s*['"]ejs['"]|app\.set\s*\(\s*['"]view engine['"]/, confidence: 'low', message: 'Template engine without sandbox — SSTI risk if user input in templates', cwe: 'CWE-94', owasp: 'A03', fix: 'Never pass user input as template string. Use data context only.' },
|
|
2399
|
+
{ id: 'express.static-root', severity: 'medium', re: /app\.use\s*\(\s*express\.static\s*\(\s*['"]\/['"]\s*\)/, message: 'Express static serving from root — may expose sensitive files', cwe: 'CWE-552', owasp: 'A05', fix: 'Serve from public/ subdirectory: express.static("public")' },
|
|
2400
|
+
{ id: 'express.error-stack', severity: 'high', re: /app\.use\s*\(\s*\(\s*err\s*,\s*req\s*,\s*res/i, confidence: 'low', message: 'Express error handler — verify stack traces are not sent to client', cwe: 'CWE-209', owasp: 'A05', fix: 'In production: res.status(500).json({ error: "Internal error" }). Log stack server-side.' },
|
|
2401
|
+
|
|
2402
|
+
// More database/ORM
|
|
2403
|
+
{ id: 'orm.sequelize-raw', severity: 'high', re: /sequelize\.query\s*\(\s*[^)]*\+/i, message: 'Sequelize raw query with string concatenation — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized: sequelize.query("SELECT ... WHERE id = ?", { replacements: [id] })' },
|
|
2404
|
+
{ id: 'orm.typeorm-raw', severity: 'high', re: /\.query\s*\(\s*[^)]*\+\s*(?:req|user|input|body|query|params)/i, message: 'TypeORM raw query with user input — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized: entityManager.query("SELECT ... WHERE id = $1", [id])' },
|
|
2405
|
+
{ id: 'orm.mongoose-where', severity: 'high', re: /\$where\s*:\s*['"][^'"]*['"]/, message: 'MongoDB $where with string — JavaScript injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Never use $where. Use $expr or aggregation pipeline.' },
|
|
2406
|
+
{ id: 'orm.mongoose-mapreduce', severity: 'high', re: /mapReduce\s*\(/, message: 'MongoDB mapReduce — JavaScript execution on DB, injection risk', cwe: 'CWE-94', owasp: 'A03', fix: 'Use aggregation pipeline instead of mapReduce.' },
|
|
2407
|
+
{ id: 'orm.nopegra-no-tx', severity: 'medium', re: /prisma\.\$transaction\s*\(\s*\[?\s*\)/, confidence: 'low', message: 'Prisma transaction with empty array — no-op or error', cwe: 'CWE-758', owasp: 'A04', fix: 'Pass operations to $transaction: prisma.$transaction([prisma.user.create(...)])' },
|
|
2408
|
+
{ id: 'db.no-connection-pool', severity: 'medium', re: /new\s+(?:mysql|pg)\.(?:Connection|Client)\s*\(/, message: 'Database without connection pooling — resource exhaustion under load', cwe: 'CWE-770', owasp: 'A04', fix: 'Use Pool: new pg.Pool({ max: 20 }) or mysql.createPool()' },
|
|
2409
|
+
{ id: 'db.sql-in-template', severity: 'high', re: /sql`[^`]*\$\{[^}]*(?:req|user|input|body|query|params)/i, message: 'SQL template literal with user input — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized tagged templates: sql`SELECT ... WHERE id = ${id}` (safe) not sql`...${req.body.id}`' },
|
|
2410
|
+
|
|
2411
|
+
// More secrets
|
|
2412
|
+
{ id: 'secret.grafana-key', severity: 'high', re: /GRAFANA_API_KEY\s*[:=]\s*['"][A-Za-z0-9_=]{32,}['"]/i, message: 'Grafana API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2413
|
+
{ id: 'secret.jira-token', severity: 'high', re: /JIRA_(?:API_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9]{40,}['"]/i, message: 'Jira API token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2414
|
+
{ id: 'secret.pagerduty-key', severity: 'high', re: /PAGERDUTY_(?:API_)?KEY\s*[:=]\s*['"][A-Za-z0-9_]{32,}['"]/i, message: 'PagerDuty API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2415
|
+
{ id: 'secret.datadog-app-key', severity: 'high', re: /DATADOG_APP_KEY\s*[:=]\s*['"][A-Za-z0-9]{40,}['"]/i, message: 'Datadog APP key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2416
|
+
{ id: 'secret.splunk-token', severity: 'high', re: /SPLUNK_(?:HEC_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9-]{36,}['"]/i, message: 'Splunk HEC token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2417
|
+
{ id: 'secret.newrelic-key', severity: 'high', re: /NEW_RELIC_(?:LICENSE_)?KEY\s*[:=]\s*['"][A-Za-z0-9]{40,}['"]/i, message: 'New Relic license key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable or newrelic.js config.' },
|
|
2418
|
+
{ id: 'secret.braintree-key', severity: 'high', re: /BRAINTREE_(?:PRIVATE_)?KEY\s*[:=]\s*['"][A-Za-z0-9_]{32,}['"]/i, message: 'Braintree private key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2419
|
+
{ id: 'secret.square-token', severity: 'high', re: /SQUARE_(?:ACCESS_)?TOKEN\s*[:=]\s*['"]sq0atp-[A-Za-z0-9_-]{22,}['"]/i, message: 'Square access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2420
|
+
{ id: 'secret.paddle-key', severity: 'high', re: /PADDLE_(?:API_)?KEY\s*[:=]\s*['"]key_[a-f0-9]{32,}['"]/i, message: 'Paddle API key exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2421
|
+
{ id: 'secret.mux-token', severity: 'high', re: /MUX_(?:TOKEN|SECRET)_ID\s*[:=]\s*['"][A-Za-z0-9-]{30,}['"]/i, message: 'MUX token ID exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
|
|
2422
|
+
|
|
2423
|
+
// More Go
|
|
2424
|
+
{ id: 'go.sql-fmt-sprintf', severity: 'high', re: /(?:db\.(?:Query|Exec)|sql\.(?:Query|Exec))\s*\(\s*fmt\.Sprintf/i, fileFilter: '\\.go$', message: 'Go SQL with fmt.Sprintf — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized: db.Query("SELECT ... WHERE id = ?", id)' },
|
|
2425
|
+
{ id: 'go.html-template-no-escape', severity: 'medium', re: /template\.HTML\s*\(/, fileFilter: '\\.go$', message: 'Go template.HTML — bypasses HTML escaping', cwe: 'CWE-79', owasp: 'A03', fix: 'Use template.HTMLEscapeString or text/template with auto-escape.' },
|
|
2426
|
+
{ id: 'go.insecure-random', severity: 'high', re: /math\/rand/, fileFilter: '\\.go$', message: 'Go math/rand — not for crypto, use crypto/rand', cwe: 'CWE-330', owasp: 'A02', fix: 'Use crypto/rand.Reader for cryptographic randomness.' },
|
|
2427
|
+
{ id: 'go.panic-in-handler', severity: 'medium', re: /panic\s*\(/, fileFilter: '\\.go$', skipComments: true, confidence: 'low', message: 'Go panic() in handler — DoS, unhandled crash', cwe: 'CWE-248', owasp: 'A04', fix: 'Use error returns instead of panic in HTTP handlers.' },
|
|
2428
|
+
{ id: 'go.no-context-timeout', severity: 'medium', re: /http\.(?:Get|Post|Do)\s*\(/, fileFilter: '\\.go$', confidence: 'low', message: 'Go HTTP request without context timeout — slowloris DoS', cwe: 'CWE-400', owasp: 'A04', fix: 'Use http.NewRequestWithContext with context.WithTimeout.' },
|
|
2429
|
+
|
|
2430
|
+
// More Python
|
|
2431
|
+
{ id: 'py.sql-f-string', severity: 'high', re: /(?:execute|cursor\.execute)\s*\(\s*f['"]/, fileFilter: '\\.py$', message: 'Python SQL with f-string — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized: cursor.execute("SELECT ... WHERE id = %s", [id])' },
|
|
2432
|
+
{ id: 'py.sql-format', severity: 'high', re: /(?:execute|cursor\.execute)\s*\(\s*['"].*\.format\s*\(/, fileFilter: '\\.py$', message: 'Python SQL with .format() — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized queries. Never .format() SQL strings.' },
|
|
2433
|
+
{ id: 'py.sql-percent', severity: 'high', re: /(?:execute|cursor\.execute)\s*\(\s*['"].*%[sd].*['"]\s*%/, fileFilter: '\\.py$', message: 'Python SQL with % formatting — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized: cursor.execute("SELECT ... WHERE id = %s", (id,))' },
|
|
2434
|
+
{ id: 'py.tempfile-mktemp', severity: 'high', re: /tempfile\.mktemp\s*\(/, fileFilter: '\\.py$', message: 'tempfile.mktemp — race condition, use mkstemp', cwe: 'CWE-377', owasp: 'A04', fix: 'Use tempfile.mkstemp() or tempfile.NamedTemporaryFile().' },
|
|
2435
|
+
{ id: 'py.insecure-pickle', severity: 'high', re: /pickle\.loads?\s*\(/, fileFilter: '\\.py$', message: 'Python pickle — arbitrary code execution from untrusted data', cwe: 'CWE-502', owasp: 'A08', fix: 'Use JSON or a safe serializer. Never pickle untrusted data.' },
|
|
2436
|
+
{ id: 'py.insecure-marshal', severity: 'high', re: /marshal\.loads?\s*\(/, fileFilter: '\\.py$', message: 'Python marshal — unsafe deserialization', cwe: 'CWE-502', owasp: 'A08', fix: 'Use JSON. Never marshal untrusted data.' },
|
|
2437
|
+
{ id: 'py.insecure-shelve', severity: 'medium', re: /shelve\.open\s*\(/, fileFilter: '\\.py$', message: 'Python shelve — uses pickle internally, unsafe with untrusted data', cwe: 'CWE-502', owasp: 'A08', fix: 'Use sqlite3 or JSON. Never shelve untrusted data.' },
|
|
2438
|
+
{ id: 'py.subprocess-injection', severity: 'high', re: /os\.system\s*\(\s*(?:f['"]|['"].*%|['"].*format)/, fileFilter: '\\.py$', message: 'Python os.system with string formatting — command injection', cwe: 'CWE-78', owasp: 'A03', fix: 'Use subprocess.run with shell=False and argument list.' },
|
|
2439
|
+
{ id: 'py.flask-secret-default', severity: 'high', re: /app\s*=\s*Flask\s*\(\s*__name__\s*\)/, fileFilter: '\\.py$', confidence: 'low', message: 'Flask app without secret_key — session forgery', cwe: 'CWE-321', owasp: 'A02', fix: 'Set: app.secret_key = os.environ[\'FLASK_SECRET_KEY\']' },
|
|
2440
|
+
{ id: 'py.django-cors-wildcard', severity: 'medium', re: /CORS_ALLOW_ALL_ORIGINS\s*=\s*True/, fileFilter: '\\.py$', message: 'Django CORS_ALLOW_ALL_ORIGINS — CORS open to all', cwe: 'CWE-942', owasp: 'A05', fix: 'Set CORS_ALLOWED_ORIGINS to specific domains.' },
|
|
2441
|
+
|
|
2442
|
+
// More misc edge cases
|
|
2443
|
+
{ id: 'misc.redirect-open', severity: 'high', re: /window\.location\s*=\s*[^;]*(?:req|query|params|hash|search|url)/i, message: 'Open redirect via window.location with user input', cwe: 'CWE-601', owasp: 'A01', fix: 'Validate redirect URL against allowlist.' },
|
|
2444
|
+
{ id: 'misc.postmessage-wildcard', severity: 'high', re: /postMessage\s*\([^)]*['"]\*['"]/, message: 'postMessage with wildcard origin — any page can receive', cwe: 'CWE-942', owasp: 'A05', fix: 'Specify target origin: postMessage(data, "https://yourapp.com")' },
|
|
2445
|
+
{ id: 'misc.add-event-listener-message', severity: 'medium', re: /addEventListener\s*\(\s*['"]message['"]/, confidence: 'low', message: 'Message event listener — verify origin check present', cwe: 'CWE-942', owasp: 'A05', fix: 'Check event.origin in message handler before processing.' },
|
|
2446
|
+
{ id: 'misc.document-write', severity: 'high', re: /document\.write\s*\(/, skipComments: true, message: 'document.write — XSS and HTML injection risk', cwe: 'CWE-79', owasp: 'A03', fix: 'Use DOM APIs or textContent. Never document.write with user data.' },
|
|
2447
|
+
{ id: 'misc.insert-adjacent-html', severity: 'high', re: /insertAdjacentHTML\s*\(/, skipComments: true, confidence: 'low', message: 'insertAdjacentHTML — XSS if content is unsanitized', cwe: 'CWE-79', owasp: 'A03', fix: 'Use insertAdjacentText or sanitize HTML before insertion.' },
|
|
2448
|
+
{ id: 'misc.outer-html', severity: 'high', re: /outerHTML\s*=\s*[^;]*(?:req|user|input|data|query|body)/i, message: 'outerHTML with user data — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Use textContent or sanitize with DOMPurify.' },
|
|
2449
|
+
{ id: 'misc.crypto-random-uuid', severity: 'low', re: /crypto\.randomUUID\s*\(/, confidence: 'low', message: 'crypto.randomUUID — fine for IDs but not for secrets', cwe: 'CWE-330', owasp: 'A02', fix: 'Use crypto.randomBytes for secrets. UUID is for identifiers only.' },
|
|
2450
|
+
{ id: 'misc.structured-clone', severity: 'low', re: /structuredClone\s*\(/, confidence: 'low', message: 'structuredClone — may cause performance issues with large objects', cwe: 'CWE-400', owasp: 'A04', fix: 'Limit object size before cloning.' },
|
|
2451
|
+
{ id: 'misc.json-parse-no-try', severity: 'low', re: /JSON\.parse\s*\((?!.*try)/, confidence: 'low', message: 'JSON.parse without try/catch — DoS on malformed input', cwe: 'CWE-754', owasp: 'A04', fix: 'Wrap in try/catch: try { JSON.parse(data) } catch { /* handle */ }' },
|
|
2452
|
+
{ id: 'misc.eval-settimeout-string', severity: 'high', re: /setTimeout\s*\(\s*['"][^'"]*['"]/, message: 'setTimeout with string — eval semantics, code injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Use function: setTimeout(() => { ... }, 1000)' },
|
|
2453
|
+
{ id: 'misc.eval-setinterval-string', severity: 'high', re: /setInterval\s*\(\s*['"][^'"]*['"]/, message: 'setInterval with string — eval semantics, code injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Use function: setInterval(() => { ... }, 1000)' },
|
|
2454
|
+
{ id: 'misc.new-function', severity: 'high', re: /new\s+Function\s*\(/, skipComments: true, message: 'new Function() — eval equivalent, code injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Avoid new Function(). Use safe evaluation or pre-compiled functions.' },
|
|
2455
|
+
{ id: 'misc.with-statement', severity: 'high', re: /\bwith\s*\(/, message: 'with statement — scope pollution, security risk', cwe: 'CWE-1127', owasp: 'A03', fix: 'Never use with. Use explicit property access.' },
|
|
2456
|
+
|
|
2457
|
+
// More Docker/compose
|
|
2458
|
+
{ id: 'compose.no-resource-limits', severity: 'medium', re: /deploy:\s*\n\s*resources:/, fileFilter: 'docker-compose.*\\.ya?ml$', confidence: 'low', message: 'Docker Compose: verify resource limits are set', cwe: 'CWE-770', owasp: 'A05', fix: 'Add deploy.resources.limits with cpus and memory.' },
|
|
2459
|
+
{ id: 'compose.secrets-env', severity: 'high', re: /environment:\s*\n\s*-\s*(?:PASSWORD|SECRET|TOKEN|API_KEY)=/, fileFilter: 'docker-compose.*\\.ya?ml$', message: 'Docker Compose: secret in environment — use secrets or env_file', cwe: 'CWE-798', owasp: 'A02', fix: 'Use Docker secrets: secrets: - my_secret or env_file with .gitignored file.' },
|
|
2460
|
+
{ id: 'compose.privileged', severity: 'high', re: /privileged:\s*true/, fileFilter: 'docker-compose.*\\.ya?ml$', message: 'Docker Compose: privileged container — host access', cwe: 'CWE-250', owasp: 'A05', fix: 'Remove privileged: true. Use capabilities if needed.' },
|
|
2461
|
+
{ id: 'compose.host-network', severity: 'medium', re: /network_mode\s*:\s*['"]host['"]/, fileFilter: 'docker-compose.*\\.ya?ml$', message: 'Docker Compose: host network mode — no isolation', cwe: 'CWE-284', owasp: 'A05', fix: 'Use bridge network. Only use host for specific performance needs.' },
|
|
2462
|
+
{ id: 'compose.no-restart-policy', severity: 'low', re: /restart\s*:\s*(?:no|on-failure)/, fileFilter: 'docker-compose.*\\.ya?ml$', confidence: 'low', message: 'Docker Compose: weak restart policy — service may stay down', cwe: 'CWE-1188', owasp: 'A05', fix: 'Use restart: unless-stopped or restart: always for production.' },
|
|
2463
|
+
|
|
2464
|
+
// More Kubernetes
|
|
2465
|
+
{ id: 'k8s.no-resource-quota', severity: 'low', re: /kind:\s*Namespace/, fileFilter: '\\.ya?ml$', confidence: 'low', message: 'K8s: Namespace without ResourceQuota — unbounded resource usage', cwe: 'CWE-770', owasp: 'A05', fix: 'Create ResourceQuota for each namespace.' },
|
|
2466
|
+
{ id: 'k8s.no-limitrange', severity: 'low', re: /kind:\s*Namespace/, fileFilter: '\\.ya?ml$', confidence: 'low', message: 'K8s: Namespace without LimitRange — no default resource limits', cwe: 'CWE-770', owasp: 'A05', fix: 'Create LimitRange to set default resource limits.' },
|
|
2467
|
+
{ id: 'k8s.host-network', severity: 'high', re: /hostNetwork:\s*true/, fileFilter: '\\.ya?ml$', message: 'K8s: hostNetwork: true — pod uses host network namespace', cwe: 'CWE-284', owasp: 'A05', fix: 'Set hostNetwork: false. Only use for networking daemons.' },
|
|
2468
|
+
{ id: 'k8s.cap-sys-admin', severity: 'high', re: /SYS_ADMIN/, fileFilter: '\\.ya?ml$', message: 'K8s: SYS_ADMIN capability — near-root access', cwe: 'CWE-250', owasp: 'A05', fix: 'Drop all capabilities: securityContext.capabilities.drop: ["ALL"]' },
|
|
2469
|
+
{ id: 'k8s.no-seccomp', severity: 'medium', re: /containers:\s*\n(?:.*\n)*?\s*-\s*(?:name|image):/, fileFilter: '\\.ya?ml$', confidence: 'low', message: 'K8s: container without seccompProfile — no syscall filtering', cwe: 'CWE-1188', owasp: 'A05', fix: 'Add seccompProfile: { type: RuntimeDefault }' },
|
|
2470
|
+
{ id: 'k8s.no-deny-all', severity: 'medium', re: /kind:\s*NetworkPolicy/, fileFilter: '\\.ya?ml$', confidence: 'low', message: 'K8s: NetworkPolicy without default deny — incomplete isolation', cwe: 'CWE-284', owasp: 'A05', fix: 'Add default-deny NetworkPolicy: podSelector: {}, policyTypes: [Ingress]' },
|
|
2471
|
+
|
|
2472
|
+
// =========================================================================
|
|
2473
|
+
// REDDIT r/vibecoding — rules for real pain points reported by vibe coders
|
|
2474
|
+
// =========================================================================
|
|
2475
|
+
|
|
2476
|
+
// Supabase RLS fake policy: USING (true) or USING (auth.uid() IS NOT NULL) — protects nothing
|
|
2477
|
+
{ id: 'supabase.rls-fake-policy', severity: 'critical', re: /CREATE\s+POLICY\s+['"]?[^'"]*['"]?\s+ON\s+\w+\s+FOR\s+\w+\s+USING\s*\(\s*(?:true|1|auth\.uid\(\)\s+IS\s+NOT\s+NULL)\s*\)/i, fileFilter: '\\.sql$', message: 'Supabase RLS policy with USING (true) — protects nothing, looks enabled in dashboard', cwe: 'CWE-862', owasp: 'A01', fix: 'Use auth.uid() = user_id or auth.uid() = org.member_id. Never USING (true) or just IS NOT NULL.' },
|
|
2478
|
+
// Supabase RLS permissive policy with no check
|
|
2479
|
+
{ id: 'supabase.rls-permissive', severity: 'critical', re: /CREATE\s+POLICY\s+['"]?[^'"]*['"]?\s+ON\s+\w+\s+FOR\s+\w+\s+AS\s+PERMISSIVE/i, fileFilter: '\\.sql$', message: 'Supabase PERMISSIVE policy — allows access unless another policy restricts it', cwe: 'CWE-862', owasp: 'A01', fix: 'Use AS RESTRICTIVE for policies that should block access. Default is PERMISSIVE which combines with OR.' },
|
|
2480
|
+
// Supabase anon key in client with no RLS check — the #1 Reddit issue
|
|
2481
|
+
{ id: 'supabase.anon-key-no-rls-warning', severity: 'high', re: /NEXT_PUBLIC_SUPABASE_(?:ANON_KEY|URL)/i, message: 'Supabase anon key exposed to client — verify RLS is enabled on ALL tables or data is public', cwe: 'CWE-200', owasp: 'A05', confidence: 'low', fix: 'Run: vibeguard scan to check for RLS-missing. Enable RLS on every table in Supabase dashboard.' },
|
|
2482
|
+
// Firebase rules: .read or .write = true (open to world)
|
|
2483
|
+
{ id: 'firebase.rules-open', severity: 'critical', re: /["']\.read["']\s*:\s*true|["']\.write["']\s*:\s*true/i, fileFilter: '\\.rules$', message: 'Firebase rules: .read or .write = true — anyone can access', cwe: 'CWE-862', owasp: 'A01', fix: 'Set rules to auth.uid() == $uid. Never true for user data.' },
|
|
2484
|
+
// Firebase rules: .read or .write = request.auth != null (any logged-in user can access all data)
|
|
2485
|
+
{ id: 'firebase.rules-any-auth', severity: 'high', re: /["']\.read["']\s*:\s*request\.auth\s*!=\s*null|["']\.write["']\s*:\s*request\.auth\s*!=\s*null/i, fileFilter: '\\.rules$', message: 'Firebase rules: .read/.write = auth != null — ANY logged-in user can read ALL data', cwe: 'CWE-862', owasp: 'A01', fix: 'Use: auth.uid == $uid to scope to the owner. auth != null allows all users to see all data.' },
|
|
2486
|
+
// Convex: query without auth check
|
|
2487
|
+
{ id: 'convex.query-public', severity: 'high', re: /export\s+const\s+\w+\s*=\s*query\s*\(\s*async/i, fileFilter: '\\.ts$', confidence: 'low', message: 'Convex query exported as public — no auth check visible', cwe: 'CWE-862', owasp: 'A01', fix: 'Add auth check: const identity = await ctx.auth.getUserIdentity(). Return null if no identity.' },
|
|
2488
|
+
// Hardcoded admin credentials — AI loves to put these in seed files
|
|
2489
|
+
{ id: 'auth.hardcoded-admin-creds', severity: 'critical', re: /(?:admin|root|superuser).*password\s*[:=]\s*['"][^'"]{4,}['"]/i, skipComments: true, message: 'Hardcoded admin credentials — anyone who reads the code has admin access', cwe: 'CWE-798', owasp: 'A02', fix: 'Generate admin password from env: process.env.ADMIN_PASSWORD. Never hardcode admin creds.' },
|
|
2490
|
+
// .env file committed to repo — most common vibe coding mistake
|
|
2491
|
+
{ id: 'config.env-file-in-code', severity: 'critical', re: /(?:password|secret|token|api_key|apikey)\s*[:=]\s*['"][A-Za-z0-9_\-]{20,}['"]/i, fileFilter: '\\.env$', skipComments: true, message: 'Secret in .env file — verify .env is in .gitignore', cwe: 'CWE-798', owasp: 'A02', confidence: 'low', fix: 'Add .env to .gitignore. Use .env.example with placeholder values instead.' },
|
|
2492
|
+
// API key in client-side config — AI puts keys in config files
|
|
2493
|
+
{ id: 'config.api-key-in-client', severity: 'high', re: /(?:apiKey|api_key|API_KEY)\s*[:=]\s*['"][A-Za-z0-9_\-]{20,}['"]/i, fileFilter: '(?:config|client|browser|public).*\\.(?:js|ts|json)$', skipComments: true, message: 'API key in client-side config — visible in browser dev tools', cwe: 'CWE-200', owasp: 'A02', confidence: 'low', fix: 'Move to server-side. Never put API keys in files that ship to the browser.' },
|
|
2494
|
+
// CORS: Access-Control-Allow-Origin: * with credentials — vibe coders copy-paste this
|
|
2495
|
+
{ id: 'cors.wildcard-credentials', severity: 'critical', re: /Access-Control-Allow-Origin['"]\s*[:,]\s*['"]\*['"][\s\S]{0,200}Access-Control-Allow-Credentials['"]\s*[:,]\s*true/i, message: 'CORS: wildcard origin + credentials — any website can make authenticated requests', cwe: 'CWE-942', owasp: 'A05', fix: 'Set specific origin. Never combine * with credentials: true.' },
|
|
2496
|
+
// No input validation on POST/PUT — AI often skips this
|
|
2497
|
+
{ id: 'api.no-body-validation', severity: 'high', re: /app\.(?:post|put|patch)\s*\(\s*['"][^'"]+['"]\s*,\s*(?:async\s*)?\(req,\s*res\)/i, confidence: 'low', message: 'POST/PUT/PATCH handler without body validation — accepts any input', cwe: 'CWE-20', owasp: 'A03', fix: 'Add validation: if (!req.body.email || !req.body.password) return res.status(400).json({ error: "Missing fields" })' },
|
|
2498
|
+
// Password compared with == instead of bcrypt.compare
|
|
2499
|
+
{ id: 'auth.password-plaintext-compare', severity: 'high', re: /(?:password|pwd|pass)\s*===?\s*[^;]*(?:req|user|input|body|query|params)\.(?:password|pwd|pass)/i, message: 'Password compared with == — plaintext comparison, no hashing', cwe: 'CWE-256', owasp: 'A02', fix: 'Use bcrypt.compare(req.body.password, user.passwordHash). Never compare plaintext passwords.' },
|
|
2500
|
+
// SQL in template literal without parameterization
|
|
2501
|
+
{ id: 'db.sql-template-literal', severity: 'high', re: /(?:query|execute|raw)\s*\(\s*`[^`]*\$\{[^}]*(?:req|user|input|body|query|params)/i, message: 'SQL template literal with user input — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use parameterized queries: db.query("SELECT ... WHERE id = $1", [id])' },
|
|
2502
|
+
// Secret in URL (connection string with password)
|
|
2503
|
+
{ id: 'secret.conn-string-password', severity: 'high', re: /(?:mongodb|postgres|postgresql|mysql|redis):\/\/[^:]+:[^@]+@/i, message: 'Connection string with password — credentials in URL', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable. Never hardcode connection strings with passwords.' },
|
|
2504
|
+
// Missing rate limit on auth endpoints (brute force)
|
|
2505
|
+
{ id: 'auth.no-rate-limit-login', severity: 'high', re: /(?:login|signin|authenticate|register)\s*(?:\.post|\.route|\.handler|\.resolver)/, confidence: 'low', fileFilter: '\\.(?:js|ts|py|go)$', message: 'Login/register endpoint without rate limiting — brute force attack', cwe: 'CWE-307', owasp: 'A07', fix: 'Add rate limiting: rateLimit({ windowMs: 60000, max: 5 }) on /login and /register.' },
|
|
2506
|
+
// JWT decoded without verification
|
|
2507
|
+
{ id: 'auth.jwt-decoded-no-verify', severity: 'critical', re: /jwt\.decode\s*\(/, message: 'jwt.decode() without verification — anyone can forge tokens', cwe: 'CWE-345', owasp: 'A02', fix: 'Use jwt.verify(token, secret) instead of jwt.decode(token). decode is for inspection only.' },
|
|
2508
|
+
// Missing HTTPS in production config
|
|
2509
|
+
{ id: 'config.no-https-production', severity: 'high', re: /app\.listen\s*\(\s*(?:process\.env\.PORT|PORT|80|3000)/, confidence: 'low', message: 'Server listening on HTTP — no TLS in production', cwe: 'CWE-319', owasp: 'A02', fix: 'Use HTTPS in production: https.createServer({ key, cert }, app).listen(443)' },
|
|
2510
|
+
// Error stack trace in response (AI loves to return err.stack)
|
|
2511
|
+
{ id: 'error.stack-in-response', severity: 'high', re: /res\.(?:json|send|render)\s*\(\s*\{[^}]*(?:err\.stack|error\.stack|err\.message|error\.message|err\.details|error\.details)/i, message: 'Error stack/message sent to client — info leak', cwe: 'CWE-209', owasp: 'A05', fix: 'Return generic error: res.status(500).json({ error: "Internal server error" }). Log details server-side.' },
|
|
2512
|
+
// Missing CSRF protection on forms
|
|
2513
|
+
{ id: 'form.no-csrf', severity: 'high', re: /<form\s+[^>]*(?:method\s*=\s*['"]post['"]|action\s*=)/i, fileFilter: '\\.(?:html|ejs|hbs|pug)$', confidence: 'low', message: 'Form without CSRF token — cross-site request forgery', cwe: 'CWE-352', owasp: 'A01', fix: 'Add CSRF token: <input type="hidden" name="_csrf" value="{{csrfToken}}">' },
|
|
2514
|
+
// Sensitive data in URL params (tokens, passwords)
|
|
2515
|
+
{ id: 'data.token-in-url-params', severity: 'high', re: /\?(?:token|password|secret|api_key|apikey|access_token|jwt)=[^&\s]/i, fileFilter: '\\.(?:js|ts|html)$', message: 'Sensitive data in URL query parameter — logged in server logs and browser history', cwe: 'CWE-598', owasp: 'A04', fix: 'Pass sensitive data in headers or POST body. Never in URL query strings.' },
|
|
2516
|
+
// npm install without --ignore-scripts (supply chain)
|
|
2517
|
+
{ id: 'supply.npm-install-no-ignore-scripts', severity: 'medium', re: /npm\s+install(?!\s+--ignore-scripts)/, fileFilter: '(?:Dockerfile|Makefile|\\.sh|\\.ya?ml)$', confidence: 'low', message: 'npm install without --ignore-scripts — postinstall scripts can run arbitrary code', cwe: 'CWE-94', owasp: 'A06', fix: 'Use: npm install --ignore-scripts in CI/CD and Dockerfiles.' },
|
|
2518
|
+
// eval with template literal (AI generates this for dynamic code)
|
|
2519
|
+
{ id: 'injection.eval-template', severity: 'critical', re: /eval\s*\(\s*`[^`]*\$\{/, message: 'eval() with template literal — code injection via string interpolation', cwe: 'CWE-94', owasp: 'A03', fix: 'Never eval template literals. Use JSON.parse or a safe evaluator.' },
|
|
2520
|
+
// exec/spawn with template literal
|
|
2521
|
+
{ id: 'injection.exec-template', severity: 'critical', re: /(?:exec|execSync|spawn|spawnSync)\s*\(\s*`[^`]*\$\{/, message: 'exec/spawn with template literal — command injection via interpolation', cwe: 'CWE-78', owasp: 'A03', fix: 'Use execFile with argument array. Never exec template literals with user input.' },
|
|
2522
|
+
// Missing .gitignore with .env — the most common vibe coding mistake
|
|
2523
|
+
{ id: 'config.gitignore-missing-env', severity: 'critical', re: /\.env/, fileFilter: '\\.gitignore$', confidence: 'low', message: '.gitignore exists — verify .env is listed. If not, secrets are in git history.', cwe: 'CWE-798', owasp: 'A02', fix: 'Add .env and .env.* to .gitignore. Run: git rm --cached .env if already committed.' },
|
|
2524
|
+
|
|
2525
|
+
// =========================================================================
|
|
2526
|
+
// PRIVACY RULES — 30 rules for personal data protection
|
|
2527
|
+
// =========================================================================
|
|
2528
|
+
{ id: 'privacy.webrtc-leak', severity: 'high', re: /RTCPeerConnection|getUserMedia|getDisplayMedia/i, skipComments: true, message: 'WebRTC can leak real IP address even behind VPN', cwe: 'CWE-200', owasp: 'A05', fix: 'Disable WebRTC or configure ICE candidates to prevent IP leak. Use browser extensions for user control.' },
|
|
2529
|
+
{ id: 'privacy.referrer-leak', severity: 'medium', re: /<a\s+[^>]*(?!.*rel\s*=\s*['"]noreferrer)/i, fileFilter: '\\.html$', confidence: 'low', message: 'Outbound link without rel="noreferrer" — destination sees user origin', cwe: 'CWE-200', owasp: 'A05', fix: 'Add rel="noopener noreferrer" to all outbound links.' },
|
|
2530
|
+
{ id: 'privacy.clipboard-read', severity: 'high', re: /navigator\.clipboard\.readText|navigator\.clipboard\.read/i, skipComments: true, message: 'Clipboard read — can steal copied passwords, tokens, PII', cwe: 'CWE-200', owasp: 'A01', fix: 'Only read clipboard on explicit user action. Never auto-read.' },
|
|
2531
|
+
{ id: 'privacy.geolocation', severity: 'high', re: /navigator\.geolocation\.getCurrentPosition|navigator\.geolocation\.watchPosition/i, skipComments: true, message: 'Geolocation access — precise user location tracking', cwe: 'CWE-359', owasp: 'A04', fix: 'Request permission with clear UI. Only access when needed. Allow user to deny.' },
|
|
2532
|
+
{ id: 'privacy.camera-mic', severity: 'high', re: /getUserMedia\s*\(\s*\{[^}]*(?:video|audio)/i, skipComments: true, message: 'Camera/microphone access — surveillance risk', cwe: 'CWE-359', owasp: 'A04', fix: 'Request permission with clear UI. Show recording indicator. Stop stream when not needed.' },
|
|
2533
|
+
{ id: 'privacy.battery', severity: 'medium', re: /navigator\.getBattery/i, skipComments: true, message: 'Battery API — can be used for fingerprinting/tracking', cwe: 'CWE-200', owasp: 'A04', fix: 'Avoid Battery API. It is deprecated in most browsers due to privacy concerns.' },
|
|
2534
|
+
{ id: 'privacy.device-memory', severity: 'medium', re: /navigator\.deviceMemory|navigator\.hardwareConcurrency/i, skipComments: true, confidence: 'low', message: 'Device fingerprinting via hardware info', cwe: 'CWE-200', owasp: 'A04', fix: 'Avoid accessing hardware info unless needed. It enables fingerprinting.' },
|
|
2535
|
+
{ id: 'privacy.canvas-fingerprint', severity: 'medium', re: /canvas\.toDataURL|canvas\.getImageData|OffscreenCanvas/i, skipComments: true, confidence: 'low', message: 'Canvas fingerprinting — unique device identification', cwe: 'CWE-200', owasp: 'A04', fix: 'Only use canvas for rendering. Do not use for fingerprinting. Add canvas anti-fingerprinting.' },
|
|
2536
|
+
{ id: 'privacy.analytics-no-consent', severity: 'high', re: /gtag\(|dataLayer\.push|GoogleAnalytics|ga\(['"]send/i, confidence: 'low', message: 'Analytics tracking without consent check — GDPR violation', cwe: 'CWE-359', owasp: 'A04', fix: 'Implement consent banner before loading analytics. Check consent before gtag() or dataLayer.push().' },
|
|
2537
|
+
{ id: 'privacy.fb-pixel-no-consent', severity: 'high', re: /fbq\(|connect\.facebook\.net/i, confidence: 'low', message: 'Facebook pixel without consent — GDPR violation', cwe: 'CWE-359', owasp: 'A04', fix: 'Load Facebook pixel only after user consent. Use consent management platform.' },
|
|
2538
|
+
{ id: 'privacy.hotjar-no-consent', severity: 'high', re: /hotjar|static\.hotjar\.com/i, confidence: 'low', message: 'Hotjar session recording without consent — GDPR violation', cwe: 'CWE-359', owasp: 'A04', fix: 'Load Hotjar only after user consent. It records screen sessions and inputs.' },
|
|
2539
|
+
{ id: 'privacy.fullstory-no-consent', severity: 'high', re: /fullstory|fs\.com/i, confidence: 'low', message: 'FullStory session replay without consent — GDPR violation', cwe: 'CWE-359', owasp: 'A04', fix: 'Load FullStory only after consent. It records user interactions including keystrokes.' },
|
|
2540
|
+
{ id: 'privacy.mixpanel-no-consent', severity: 'high', re: /mixpanel\.(?:track|identify|people)/i, confidence: 'low', message: 'Mixpanel tracking without consent — GDPR violation', cwe: 'CWE-359', owasp: 'A04', fix: 'Check consent before mixpanel.track(). Implement consent banner.' },
|
|
2541
|
+
{ id: 'privacy.segment-no-consent', severity: 'high', re: /analytics\.(?:track|identify|page|group)/i, confidence: 'low', message: 'Segment analytics without consent — GDPR violation', cwe: 'CWE-359', owasp: 'A04', fix: 'Check consent before analytics.track(). Implement consent management.' },
|
|
2542
|
+
{ id: 'privacy.amplitude-no-consent', severity: 'high', re: /amplitude\.(?:logEvent|setUserId|identify)/i, confidence: 'low', message: 'Amplitude tracking without consent — GDPR violation', cwe: 'CWE-359', owasp: 'A04', fix: 'Check consent before amplitude.logEvent(). Implement consent banner.' },
|
|
2543
|
+
{ id: 'privacy.cookies-no-banner', severity: 'medium', re: /document\.cookie\s*=/i, confidence: 'low', fileFilter: '\\.(?:js|ts|html)$', message: 'Cookies set without consent banner — ePrivacy/GDPR violation', cwe: 'CWE-359', owasp: 'A05', fix: 'Implement cookie consent banner. Only set non-essential cookies after consent.' },
|
|
2544
|
+
{ id: 'privacy.fingerprint-collect', severity: 'high', re: /fingerprint|clientjs|fingerprintjs|device.?id/i, skipComments: true, confidence: 'low', message: 'Browser fingerprinting library — tracks users without consent', cwe: 'CWE-200', owasp: 'A04', fix: 'Remove fingerprinting library. Use explicit consent for tracking. Fingerprinting is illegal under GDPR in some jurisdictions.' },
|
|
2545
|
+
{ id: 'privacy.ip-logged', severity: 'medium', re: /req\.headers\[?['"]x-forwarded-for['"]?\]?|req\.ip|req\.connection\.remoteAddress/i, confidence: 'low', message: 'IP address logged — personal data under GDPR', cwe: 'CWE-532', owasp: 'A09', fix: 'Hash or truncate IP before logging. Full IPs are personal data under GDPR.' },
|
|
2546
|
+
{ id: 'privacy.user-agent-logged', severity: 'low', re: /req\.headers\[?['"]user-agent['"]?\]?/i, confidence: 'low', message: 'User-Agent logged — can be used for fingerprinting', cwe: 'CWE-532', owasp: 'A09', fix: 'Do not log raw User-Agent. Hash or truncate if needed for debugging.' },
|
|
2547
|
+
{ id: 'privacy.third-party-script', severity: 'medium', re: /<script\s+src\s*=\s*['"]https?:\/\/(?!.*(?:google|cloudflare|jsdelivr|unpkg|cdn\.))/i, fileFilter: '\\.html$', confidence: 'low', message: 'Third-party script loaded — may track users or collect data', cwe: 'CWE-829', owasp: 'A05', fix: 'Review third-party scripts. Self-host or use Subresource Integrity (SRI).' },
|
|
2548
|
+
{ id: 'privacy.ad-tracking', severity: 'medium', re: /adsense|doubleclick|googletag|google_ad|adroll|criteo|taboola|outbrain/i, skipComments: true, confidence: 'low', message: 'Ad tracking script — collects user data for advertising', cwe: 'CWE-359', owasp: 'A04', fix: 'Load ad scripts only after consent. Use consent management platform.' },
|
|
2549
|
+
{ id: 'privacy.sentry-user-data', severity: 'high', re: /Sentry\.setUser\s*\(\s*\{[^}]*(?:email|ip|username|name|phone)/i, message: 'Sentry setUser with PII — personal data sent to Sentry', cwe: 'CWE-200', owasp: 'A02', fix: 'Send only user ID (not email/name). Use Sentry data scrubbers to strip PII.' },
|
|
2550
|
+
{ id: 'privacy.error-with-pii', severity: 'high', re: /Sentry\.captureException|Sentry\.captureMessage|Sentry\.captureEvent/i, confidence: 'low', message: 'Sentry capture may include PII from request context', cwe: 'CWE-200', owasp: 'A02', fix: 'Configure Sentry beforeSend to scrub PII. Set sendDefaultPii: false.' },
|
|
2551
|
+
{ id: 'privacy.logs-no-redaction', severity: 'medium', re: /(?:winston|pino|bunyan|log4|console\.log)\s*\(/i, confidence: 'low', message: 'Logging without PII redaction middleware', cwe: 'CWE-532', owasp: 'A09', fix: 'Add PII redaction to logger: winston format that masks email, phone, SSN, card numbers.' },
|
|
2552
|
+
{ id: 'privacy.database-no-anonymization', severity: 'medium', re: /(?:SELECT|INSERT|UPDATE)\s+.*(?:email|phone|ssn|name|address)/i, fileFilter: '\\.sql$', confidence: 'low', message: 'SQL query on PII fields — verify data is anonymized in non-prod', cwe: 'CWE-359', owasp: 'A04', fix: 'Anonymize PII in dev/staging. Use data masking or synthetic data.' },
|
|
2553
|
+
{ id: 'privacy.screenshot-permission', severity: 'medium', re: /navigator\.mediaDevices\.getDisplayMedia|desktopCapturer/i, skipComments: true, message: 'Screen capture — can record sensitive content on user screen', cwe: 'CWE-200', owasp: 'A04', fix: 'Show clear permission UI. Stop capture when not needed. Never auto-start.' },
|
|
2554
|
+
{ id: 'privacy.notifications', severity: 'medium', re: /Notification\.requestPermission|navigator\.serviceWorker\.register/i, skipComments: true, confidence: 'low', message: 'Push notifications — may collect device identifiers', cwe: 'CWE-200', owasp: 'A04', fix: 'Request permission with clear UI. Only send necessary notifications.' },
|
|
2555
|
+
{ id: 'privacy.contacts-access', severity: 'high', re: /navigator\.contacts|ContactsContract|CNContactStore|Contacts\.framework/i, skipComments: true, message: 'Contacts access — reads all user contacts (PII)', cwe: 'CWE-359', owasp: 'A01', fix: 'Only request contacts when essential. Show clear permission rationale.' },
|
|
2556
|
+
{ id: 'privacy.photos-access', severity: 'high', re: /PHPhotoLibrary|photoLibrary|MediaStore\.Images|ALAssetsLibrary/i, skipComments: true, message: 'Photo library access — all user photos (may contain EXIF location data)', cwe: 'CWE-359', owasp: 'A01', fix: 'Only request when essential. Use photo picker for limited access.' },
|
|
2557
|
+
{ id: 'privacy.background-location', severity: 'critical', re: /alwaysAllow|alwaysAuthorization|ACCESS_BACKGROUND_LOCATION|startMonitoringLocation/i, skipComments: true, message: 'Background location tracking — continuous user tracking without consent UI', cwe: 'CWE-359', owasp: 'A04', fix: 'Request foreground location only. Background location requires explicit consent and justification.' },
|
|
2558
|
+
|
|
2559
|
+
// =========================================================================
|
|
2560
|
+
// DEEP PRIVACY RULES — 20 more for total personal data protection
|
|
2561
|
+
// =========================================================================
|
|
2562
|
+
{ id: 'privacy.bluetooth-scan', severity: 'medium', re: /BluetoothAdapter\.startScan|CBCentralManager|navigator\.bluetooth/i, skipComments: true, confidence: 'low', message: 'Bluetooth scanning — can discover and fingerprint nearby devices', cwe: 'CWE-200', owasp: 'A04', fix: 'Only scan when needed. Show clear permission UI. Stop scan when done.' },
|
|
2563
|
+
{ id: 'privacy.face-id', severity: 'high', re: /LAContext|BiometricPrompt|LocalAuthentication|faceID|touchID/i, skipComments: true, confidence: 'low', message: 'Biometric data access — face/fingerprint (sensitive biometric PII)', cwe: 'CWE-359', owasp: 'A04', fix: 'Use biometrics for auth only. Never store biometric data. Show clear purpose.' },
|
|
2564
|
+
{ id: 'privacy.health-data', severity: 'critical', re: /HealthKit|HealthConnect|ClinicalHealthRecord|HKHealthStore/i, skipComments: true, message: 'Health data access — HIPAA protected health information', cwe: 'CWE-359', owasp: 'A02', fix: 'Only access health data with explicit consent. HIPAA compliance required. Do not log health data.' },
|
|
2565
|
+
{ id: 'privacy.motion-sensor', severity: 'medium', re: /DeviceMotion|Accelerometer\.start|Gyroscope\.start|CMMotionManager/i, skipComments: true, confidence: 'low', message: 'Motion sensor access — can infer user activity and behavior', cwe: 'CWE-200', owasp: 'A04', fix: 'Only access when needed. Stop sensors when not in active use.' },
|
|
2566
|
+
{ id: 'privacy.calendar-access', severity: 'high', re: /EventKit|EKEventStore|CalendarContract|CalendarProvider/i, skipComments: true, message: 'Calendar access — reveals user schedule, meetings, locations', cwe: 'CWE-359', owasp: 'A01', fix: 'Only request when essential. Show clear permission rationale.' },
|
|
2567
|
+
{ id: 'privacy.sms-access', severity: 'critical', re: /SmsManager|MFMessageComposeViewController|CNContactStore.*phone/i, skipComments: true, message: 'SMS access — can read private messages', cwe: 'CWE-359', owasp: 'A01', fix: 'Only request for SMS verification. Never read user messages.' },
|
|
2568
|
+
{ id: 'privacy.call-log', severity: 'critical', re: /CallLog\.Calls|CNContactStore.*phone|CTCallCenter/i, skipComments: true, message: 'Call log access — reveals who user calls and when', cwe: 'CWE-359', owasp: 'A01', fix: 'Only request for core functionality. Show clear permission rationale.' },
|
|
2569
|
+
{ id: 'privacy.storage-access-full', severity: 'high', re: /READ_EXTERNAL_STORAGE|MANAGE_EXTERNAL_STORAGE|NSFileManager.*fullAccess/i, skipComments: true, message: 'Full storage access — can read all files on device', cwe: 'CWE-359', owasp: 'A01', fix: 'Use scoped storage (Android 10+) or document picker. Avoid full storage access.' },
|
|
2570
|
+
{ id: 'privacy.microphone-always-on', severity: 'critical', re: /AudioRecord.*startRecording|AVAudioRecorder.*recordForDuration/i, skipComments: true, confidence: 'low', message: 'Microphone recording — surveillance risk', cwe: 'CWE-359', owasp: 'A04', fix: 'Only record on explicit user action. Show recording indicator. Stop when done.' },
|
|
2571
|
+
{ id: 'privacy.keylogger-risk', severity: 'high', re: /addEventListener\s*\(\s*['"]keydown|onKeyDown|keypress/i, skipComments: true, confidence: 'low', fileFilter: '\\.(?:js|ts|html)$', message: 'Keystroke listener — can capture passwords and PII if misused', cwe: 'CWE-200', owasp: 'A04', fix: 'Only listen for keys when needed (form fields). Never log raw keystrokes.' },
|
|
2572
|
+
{ id: 'privacy.exif-location', severity: 'medium', re: /EXIF|exif.*latitude|exif.*longitude|UIImage.*metadata/i, skipComments: true, confidence: 'low', message: 'EXIF metadata with location — photos may leak GPS coordinates', cwe: 'CWE-200', owasp: 'A02', fix: 'Strip EXIF metadata before uploading. Use image libraries that strip GPS.' },
|
|
2573
|
+
{ id: 'privacy.ip-collect', severity: 'medium', re: /req\.headers\[?['"]x-forwarded-for['"]?\]?|req\.ip\b|request\.connection\.remoteAddress/i, skipComments: true, confidence: 'low', message: 'IP address collection — personal data under GDPR', cwe: 'CWE-359', owasp: 'A04', fix: 'Hash or truncate IP. Only collect when necessary. Disclose in privacy policy.' },
|
|
2574
|
+
{ id: 'privacy.fingerprint-hash', severity: 'medium', re: /fingerprintHash|deviceFingerprint|createHash.*deviceId/i, skipComments: true, confidence: 'low', message: 'Device fingerprint hash — tracks users without cookies', cwe: 'CWE-200', owasp: 'A04', fix: 'Obtain consent before fingerprinting. Provide opt-out mechanism.' },
|
|
2575
|
+
{ id: 'privacy.cross-origin-leak', severity: 'medium', re: /window\.opener|crossOriginIsolated/i, skipComments: true, confidence: 'low', message: 'Cross-origin access — may leak data between sites', cwe: 'CWE-200', owasp: 'A05', fix: 'Use rel="noopener noreferrer" on outbound links. Set COOP: same-origin.' },
|
|
2576
|
+
{ id: 'privacy.referrer-policy-missing', severity: 'low', re: /<meta\s+name\s*=\s*['"]referrer['"]/i, fileFilter: '\\.html$', confidence: 'low', message: 'Referrer-Policy meta tag missing — browser sends full referrer to all sites', cwe: 'CWE-200', owasp: 'A05', fix: 'Add <meta name="referrer" content="strict-origin-when-cross-origin">' },
|
|
2577
|
+
{ id: 'privacy.dnt-missing', severity: 'low', re: /<meta\s+name\s*=\s*['"]dnt['"]/i, fileFilter: '\\.html$', confidence: 'low', message: 'Do Not Track signal not sent — user tracking preference not communicated', cwe: 'CWE-200', owasp: 'A05', fix: 'Add <meta name="dnt" content="1"> (advisory only, not enforced by all browsers)' },
|
|
2578
|
+
{ id: 'privacy.permissions-policy-missing', severity: 'low', re: /Permissions-Policy|Feature-Policy/i, confidence: 'low', message: 'Permissions-Policy header missing — browser features not restricted', cwe: 'CWE-693', owasp: 'A05', fix: 'Add Permissions-Policy header: camera=(), microphone=(), geolocation=()' },
|
|
2579
|
+
{ id: 'privacy.sri-missing', severity: 'medium', re: /<script\s+src\s*=\s*['"]https?:\/\/(?!.*integrity\s*=)/i, fileFilter: '\\.html$', confidence: 'low', message: 'External script without Subresource Integrity (SRI) — can be tampered with', cwe: 'CWE-829', owasp: 'A05', fix: 'Add integrity attribute: <script src="..." integrity="sha384-..." crossorigin="anonymous">' },
|
|
2580
|
+
{ id: 'privacy.cookie-samesite-none', severity: 'medium', re: /sameSite\s*:\s*['"]none['"]/i, skipComments: true, message: 'Cookie SameSite=None — allows cross-site cookie transmission (tracking)', cwe: 'CWE-200', owasp: 'A05', fix: 'Use SameSite=Strict or SameSite=Lax. Only use None with Secure and clear justification.' },
|
|
2581
|
+
{ id: 'privacy.window-name', severity: 'medium', re: /window\.name\s*=/i, skipComments: true, confidence: 'low', message: 'window.name used for data storage — persists across navigations, leaks to other sites', cwe: 'CWE-200', owasp: 'A05', fix: 'Use sessionStorage instead of window.name. window.name leaks across origins.' },
|
|
2582
|
+
|
|
2583
|
+
// =========================================================================
|
|
2584
|
+
// FIREWALL RULES — 30 rules for threat detection and prevention
|
|
2585
|
+
// =========================================================================
|
|
2586
|
+
{ id: 'firewall.prompt-injection-ignore', severity: 'critical', re: /(?:ignore|disregard|forget|override)\s+(?:all\s+)?(?:previous|prior|system)\s+(?:instructions?|prompts?|rules?)/i, skipComments: true, message: 'Prompt injection in prompt — attempting to override system instructions', cwe: 'CWE-94', owasp: 'A03', fix: 'This is a prompt injection attack. Block or sanitize the input.' },
|
|
2587
|
+
{ id: 'firewall.prompt-injection-role', severity: 'critical', re: /you\s+are\s+now|act\s+as\s+if|pretend\s+to\s+be|from\s+now\s+on\s+you/i, skipComments: true, message: 'Prompt injection — attempting to assign new role to AI', cwe: 'CWE-94', owasp: 'A03', fix: 'Block this prompt. It attempts to override the AI role.' },
|
|
2588
|
+
{ id: 'firewall.prompt-reveal-system', severity: 'high', re: /(?:show|reveal|display|print|tell\s+me)\s+(?:your\s+)?(?:system\s+)?(?:prompt|instructions?|rules?)/i, skipComments: true, message: 'Prompt extraction attempt — trying to reveal system prompt', cwe: 'CWE-200', owasp: 'A01', fix: 'Block this request. Never reveal system instructions.' },
|
|
2589
|
+
{ id: 'firewall.markup-injection', severity: 'high', re: /<(?:system|assistant|user|im_start|im_end|endoftext|tool|function)\s*>/i, skipComments: true, message: 'Chat markup injection — injecting role tags into prompt', cwe: 'CWE-94', owasp: 'A03', fix: 'Strip markup tags from user input before sending to LLM.' },
|
|
2590
|
+
{ id: 'firewall.jailbreak-dan', severity: 'high', re: /\bDAN\b|do\s+anything\s+now|jailbreak\s+mode|developer\s+mode|unrestricted\s+mode/i, skipComments: true, message: 'Jailbreak attempt — DAN or similar pattern', cwe: 'CWE-94', owasp: 'A03', fix: 'Block this prompt. It is a known jailbreak pattern.' },
|
|
2591
|
+
{ id: 'firewall.dangerous-delete', severity: 'critical', re: /(?:delete|remove|rm\s+-rf)\s+(?:all\s+)?(?:files?|\.env|secrets?|config|production)/i, skipComments: true, message: 'Dangerous request — asking AI to delete files or secrets', cwe: 'CWE-22', owasp: 'A01', fix: 'Never allow AI to delete files. Block this request.' },
|
|
2592
|
+
{ id: 'firewall.secret-access', severity: 'critical', re: /(?:show|read|access|get|print|output)\s+(?:the\s+)?(?:secrets?|\.env|env\s+vars?|api\s+keys?|tokens?|passwords?)/i, skipComments: true, message: 'Secret access request — asking AI to reveal secrets', cwe: 'CWE-200', owasp: 'A02', fix: 'Never allow AI to access or reveal secrets.' },
|
|
2593
|
+
{ id: 'firewall.auth-bypass', severity: 'critical', re: /(?:bypass|disable|remove|skip)\s+(?:the\s+)?(?:auth|authentication|login|password|security|guard)/i, skipComments: true, message: 'Auth bypass request — asking AI to disable security', cwe: 'CWE-287', owasp: 'A01', fix: 'Never allow AI to bypass authentication or security controls.' },
|
|
2594
|
+
{ id: 'firewall.privilege-escalation', severity: 'critical', re: /(?:sudo|su\s+root|chmod\s+777|admin\s+access|root\s+access|elevate\s+privileges)/i, skipComments: true, message: 'Privilege escalation request', cwe: 'CWE-269', owasp: 'A01', fix: 'Never allow AI to escalate privileges.' },
|
|
2595
|
+
{ id: 'firewall.database-drop', severity: 'critical', re: /(?:drop|truncate|wipe)\s+(?:table|database|collection|all\s+data)/i, skipComments: true, message: 'Database destruction request', cwe: 'CWE-22', owasp: 'A01', fix: 'Never allow AI to drop tables or delete all data.' },
|
|
2596
|
+
{ id: 'firewall.data-exfil-send', severity: 'critical', re: /(?:send|post|upload|transmit)\s+(?:the\s+)?(?:data|secrets?|tokens?|user\s+data|database)\s+to\s+/i, skipComments: true, message: 'Data exfiltration request — asking AI to send data externally', cwe: 'CWE-200', owasp: 'A02', fix: 'Block this request. AI should never send data to external endpoints.' },
|
|
2597
|
+
{ id: 'firewall.base64-exfil', severity: 'high', re: /(?:base64\s+encode|btoa)\s+(?:the\s+)?(?:data|file|secrets?|\.env|tokens?)/i, skipComments: true, message: 'Data encoding for exfiltration', cwe: 'CWE-200', owasp: 'A02', fix: 'Block this request. This prepares data for exfiltration.' },
|
|
2598
|
+
{ id: 'firewall.install-malicious', severity: 'high', re: /(?:npm\s+install|pip\s+install|yarn\s+add)\s+(?:cryptominer|xmrig|coinhive|backdoor|stealer)/i, skipComments: true, message: 'Attempting to install known malicious package', cwe: 'CWE-94', owasp: 'A06', fix: 'Block this. The package name matches known malware.' },
|
|
2599
|
+
{ id: 'firewall.curl-pipe-bash', severity: 'critical', re: /curl\s+[^|]+\|\s*(?:bash|sh|zsh)/i, skipComments: true, message: 'curl | bash — executing remote code directly', cwe: 'CWE-78', owasp: 'A03', fix: 'Never pipe curl to shell. Download, inspect, then run.' },
|
|
2600
|
+
{ id: 'firewall.wget-exec', severity: 'high', re: /wget\s+[^;]+;\s*(?:bash|sh|chmod|\.\?\/)/i, skipComments: true, message: 'wget then execute — running downloaded script', cwe: 'CWE-78', owasp: 'A03', fix: 'Never execute downloaded scripts without inspection.' },
|
|
2601
|
+
{ id: 'firewall.reverse-shell', severity: 'critical', re: /(?:bash\s+-i\s+>&\s*\/dev\/tcp|nc\s+-e\s*\/bin\/(?:bash|sh)|mkfifo.*\|.*sh|python.*socket.*connect)/i, skipComments: true, message: 'Reverse shell pattern — remote code execution', cwe: 'CWE-78', owasp: 'A03', fix: 'Block immediately. This is a reverse shell attack.' },
|
|
2602
|
+
{ id: 'firewall.cronjob-persist', severity: 'high', re: /crontab\s+-e|echo.*\*.*\*.*\*.*\*.*>>\s*\/etc\/cron/i, skipComments: true, message: 'Cron job persistence — attacker installing backdoor', cwe: 'CWE-94', owasp: 'A08', fix: 'Block. This installs a persistent backdoor via cron.' },
|
|
2603
|
+
{ id: 'firewall.ssh-key-exfil', severity: 'critical', re: /(?:cat|cp|scp|send)\s+~\/\.ssh\/(?:id_rsa|id_ed25519|id_ecdsa)/i, skipComments: true, message: 'SSH private key exfiltration', cwe: 'CWE-200', owasp: 'A02', fix: 'Block immediately. This reads and sends SSH private keys.' },
|
|
2604
|
+
{ id: 'firewall.aws-key-exfil', severity: 'critical', re: /(?:cat|cp|scp|send)\s+~\/\.aws\/credentials/i, skipComments: true, message: 'AWS credentials exfiltration', cwe: 'CWE-200', owasp: 'A02', fix: 'Block immediately. This reads AWS credentials.' },
|
|
2605
|
+
{ id: 'firewall.env-exfil', severity: 'critical', re: /(?:cat|cp|send|curl|post)\s+(?:\.env|\/\.env|process\.env)/i, skipComments: true, message: '.env file exfiltration', cwe: 'CWE-200', owasp: 'A02', fix: 'Block immediately. This reads and sends environment secrets.' },
|
|
2606
|
+
{ id: 'firewall.history-clear', severity: 'medium', re: /history\s+-c|rm\s+~\/\.bash_history|rm\s+~\/\.zsh_history|shred\s+.*history/i, skipComments: true, message: 'Clearing shell history — anti-forensics technique', cwe: 'CWE-778', owasp: 'A09', fix: 'Block. This is an attacker covering their tracks.' },
|
|
2607
|
+
{ id: 'firewall.disable-firewall', severity: 'critical', re: /(?:iptables\s+-F|ufw\s+disable|firewalld\s+--stop|systemctl\s+stop\s+(?:firewalld|ufw))/i, skipComments: true, message: 'Disabling system firewall', cwe: 'CWE-284', owasp: 'A05', fix: 'Block. This disables network security controls.' },
|
|
2608
|
+
{ id: 'firewall.disable-logging', severity: 'high', re: /(?:systemctl\s+stop\s+(?:rsyslog|syslog|auditd)|service\s+(?:rsyslog|syslog)\s+stop)/i, skipComments: true, message: 'Disabling system logging — anti-forensics', cwe: 'CWE-778', owasp: 'A09', fix: 'Block. This disables audit logging.' },
|
|
2609
|
+
{ id: 'firewall.nmap-scan', severity: 'medium', re: /nmap\s+-[a-zA-Z]*s[a-zA-Z]*\s/i, skipComments: true, message: 'Network scan with nmap — reconnaissance', cwe: 'CWE-200', owasp: 'A06', fix: 'Block in production. Network scanning is reconnaissance.' },
|
|
2610
|
+
{ id: 'firewall.sqlmap', severity: 'high', re: /sqlmap\s+--/i, skipComments: true, message: 'SQLMap — automated SQL injection tool', cwe: 'CWE-89', owasp: 'A03', fix: 'Block. SQLMap is an attack tool.' },
|
|
2611
|
+
{ id: 'firewall.metasploit', severity: 'critical', re: /msfconsole|msfvenom|metasploit/i, skipComments: true, message: 'Metasploit — exploitation framework', cwe: 'CWE-94', owasp: 'A03', fix: 'Block immediately. Metasploit is an attack framework.' },
|
|
2612
|
+
{ id: 'firewall.hydra-brute', severity: 'high', re: /hydra\s+-[a-zA-Z]+\s/i, skipComments: true, message: 'Hydra — brute force tool', cwe: 'CWE-307', owasp: 'A07', fix: 'Block. Hydra is a password brute force tool.' },
|
|
2613
|
+
{ id: 'firewall.ddos-tool', severity: 'high', re: /(?:hping3|slowloris|goldeneye|loic|hoic)\s/i, skipComments: true, message: 'DDoS tool detected', cwe: 'CWE-770', owasp: 'A04', fix: 'Block. This is a DoS attack tool.' },
|
|
2614
|
+
{ id: 'firewall.token-theft', severity: 'critical', re: /(?:steal|grab|copy|exfiltrate)\s+(?:the\s+)?(?:token|jwt|session|cookie|auth)/i, skipComments: true, message: 'Token theft request — asking AI to steal authentication tokens', cwe: 'CWE-200', owasp: 'A02', fix: 'Block immediately. This is credential theft.' },
|
|
2615
|
+
{ id: 'firewall.keylogger-install', severity: 'critical', re: /(?:install|create|deploy)\s+(?:a\s+)?keylogger/i, skipComments: true, message: 'Keylogger installation request', cwe: 'CWE-200', owasp: 'A01', fix: 'Block immediately. This is surveillance malware.' },
|
|
2616
|
+
];
|
|
2617
|
+
|
|
2618
|
+
// ---------------------------------------------------------------------------
|
|
2619
|
+
// GAP BATCH: Assemble all line rules
|
|
2620
|
+
// ---------------------------------------------------------------------------
|
|
2621
|
+
|
|
2622
|
+
const allLineRules = [
|
|
2623
|
+
...clerkRules, ...authJsRules, ...oauthRules, ...supabaseAuthRules,
|
|
2624
|
+
...drizzleRules, ...honoRules, ...trpcRules, ...convexRules,
|
|
2625
|
+
...tursoRules, ...kyselyRules, ...mikroOrmRules,
|
|
2626
|
+
...stripeRules, ...polarRules, ...lemonRules,
|
|
2627
|
+
...serviceRules, ...firebaseRules,
|
|
2628
|
+
...modernStackRules,
|
|
2629
|
+
...aiSecurityRules,
|
|
2630
|
+
...supplyChainRules,
|
|
2631
|
+
...advancedSecurityRules,
|
|
2632
|
+
...goRules,
|
|
2633
|
+
...mobileRules,
|
|
2634
|
+
...deploymentRules,
|
|
2635
|
+
...owaspApiRules,
|
|
2636
|
+
...extraSecretRules,
|
|
2637
|
+
...javaRules,
|
|
2638
|
+
...rubyRules,
|
|
2639
|
+
...phpRules,
|
|
2640
|
+
...csharpRules,
|
|
2641
|
+
...djangoRules,
|
|
2642
|
+
...flaskRules,
|
|
2643
|
+
...railsRules,
|
|
2644
|
+
...laravelRules,
|
|
2645
|
+
...springRules,
|
|
2646
|
+
...fastifyRules,
|
|
2647
|
+
...svelteKitRules,
|
|
2648
|
+
...nuxtRules,
|
|
2649
|
+
...owaspApiRulesExtra,
|
|
2650
|
+
...containerDeepRules,
|
|
2651
|
+
...graphqlRules,
|
|
2652
|
+
...websocketRules,
|
|
2653
|
+
...headerDeepRules,
|
|
2654
|
+
...deserializationRules,
|
|
2655
|
+
...cloudRules,
|
|
2656
|
+
...aiSecurityRulesExtra,
|
|
2657
|
+
...pythonDeepRules,
|
|
2658
|
+
...raceConditionRules,
|
|
2659
|
+
...cicdDeepRules,
|
|
2660
|
+
...rustRules,
|
|
2661
|
+
...kotlinRules,
|
|
2662
|
+
...swiftRules,
|
|
2663
|
+
...nestjsRules,
|
|
2664
|
+
...remixRules,
|
|
2665
|
+
...astroRules,
|
|
2666
|
+
...solidStartRules,
|
|
2667
|
+
...ginRules,
|
|
2668
|
+
...echoRules,
|
|
2669
|
+
...terraformDeepRules,
|
|
2670
|
+
...advancedAuthRules,
|
|
2671
|
+
...dataProtectionRules,
|
|
2672
|
+
...advancedInjectionRules,
|
|
2673
|
+
...moreSecretRules,
|
|
2674
|
+
...supplyChainDeepRules,
|
|
2675
|
+
...transportDeepRules,
|
|
2676
|
+
...powerRulesExtra,
|
|
2677
|
+
...amazingRules,
|
|
2678
|
+
];
|
|
2679
|
+
|
|
2680
|
+
const allCveVersionRules = [...cveVersionRules, ...cveVersionRulesExtra];
|
|
2681
|
+
|
|
2682
|
+
module.exports = {
|
|
2683
|
+
clerkRules,
|
|
2684
|
+
authJsRules,
|
|
2685
|
+
oauthRules,
|
|
2686
|
+
supabaseAuthRules,
|
|
2687
|
+
drizzleRules,
|
|
2688
|
+
honoRules,
|
|
2689
|
+
trpcRules,
|
|
2690
|
+
convexRules,
|
|
2691
|
+
tursoRules,
|
|
2692
|
+
kyselyRules,
|
|
2693
|
+
mikroOrmRules,
|
|
2694
|
+
stripeRules,
|
|
2695
|
+
polarRules,
|
|
2696
|
+
lemonRules,
|
|
2697
|
+
serviceRules,
|
|
2698
|
+
firebaseRules,
|
|
2699
|
+
modernStackRules,
|
|
2700
|
+
aiSecurityRules,
|
|
2701
|
+
supplyChainRules,
|
|
2702
|
+
advancedSecurityRules,
|
|
2703
|
+
goRules,
|
|
2704
|
+
mobileRules,
|
|
2705
|
+
deploymentRules,
|
|
2706
|
+
owaspApiRules,
|
|
2707
|
+
extraSecretRules,
|
|
2708
|
+
javaRules,
|
|
2709
|
+
rubyRules,
|
|
2710
|
+
phpRules,
|
|
2711
|
+
csharpRules,
|
|
2712
|
+
djangoRules,
|
|
2713
|
+
flaskRules,
|
|
2714
|
+
railsRules,
|
|
2715
|
+
laravelRules,
|
|
2716
|
+
springRules,
|
|
2717
|
+
fastifyRules,
|
|
2718
|
+
svelteKitRules,
|
|
2719
|
+
nuxtRules,
|
|
2720
|
+
owaspApiRulesExtra,
|
|
2721
|
+
containerDeepRules,
|
|
2722
|
+
graphqlRules,
|
|
2723
|
+
websocketRules,
|
|
2724
|
+
headerDeepRules,
|
|
2725
|
+
deserializationRules,
|
|
2726
|
+
cloudRules,
|
|
2727
|
+
aiSecurityRulesExtra,
|
|
2728
|
+
pythonDeepRules,
|
|
2729
|
+
raceConditionRules,
|
|
2730
|
+
cveVersionRulesExtra,
|
|
2731
|
+
cicdDeepRules,
|
|
2732
|
+
rustRules,
|
|
2733
|
+
kotlinRules,
|
|
2734
|
+
swiftRules,
|
|
2735
|
+
nestjsRules,
|
|
2736
|
+
remixRules,
|
|
2737
|
+
astroRules,
|
|
2738
|
+
solidStartRules,
|
|
2739
|
+
ginRules,
|
|
2740
|
+
echoRules,
|
|
2741
|
+
terraformDeepRules,
|
|
2742
|
+
advancedAuthRules,
|
|
2743
|
+
dataProtectionRules,
|
|
2744
|
+
advancedInjectionRules,
|
|
2745
|
+
moreSecretRules,
|
|
2746
|
+
supplyChainDeepRules,
|
|
2747
|
+
transportDeepRules,
|
|
2748
|
+
powerRulesExtra,
|
|
2749
|
+
amazingRules,
|
|
2750
|
+
COMPLIANCE_MAP,
|
|
2751
|
+
allLineRules,
|
|
2752
|
+
allCveVersionRules,
|
|
2753
|
+
};
|