guardvibe 3.1.4 → 3.1.6
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.
|
@@ -47,7 +47,11 @@ export const advancedSecurityRules = [
|
|
|
47
47
|
severity: "high",
|
|
48
48
|
owasp: "A04:2025 Insecure Design",
|
|
49
49
|
description: "Code reads a value, checks a condition, then updates based on the check — without a database transaction. Two concurrent requests can both pass the check before either writes, leading to double-spending, overselling, or duplicate operations.",
|
|
50
|
-
|
|
50
|
+
// Negative lookahead at the start of the if-body skips the 404-mapping shape
|
|
51
|
+
// (`if (!x) { return …; }`). Without it, the engine's backtracking matched updates
|
|
52
|
+
// that lived OUTSIDE the if-block (within 500-char window after the brace), making
|
|
53
|
+
// every `findUnique → if(!x) 404 → update` admin route a false hit.
|
|
54
|
+
pattern: /(?:findUnique|findFirst|findOne|findById)\s*\([\s\S]{0,200}?\)\s*;?\s*\n[\s\S]{0,300}?if\s*\([\s\S]{0,200}?\)\s*\{(?!\s*(?:return\b|throw\b|res\.\w+\(|response\.\w+\(|next\.\w+\(|NextResponse\.))[\s\S]{0,500}?(?:\.update\s*\(|\.delete\s*\(|\.decrement|\.increment)(?:(?!\$transaction|\.transaction|BEGIN|SERIALIZABLE|FOR UPDATE|NOWAIT)[\s\S]){0,300}?\}/g,
|
|
51
55
|
languages: ["javascript", "typescript"],
|
|
52
56
|
fix: "Wrap check-then-act sequences in a database transaction, or use atomic operations (e.g., UPDATE WHERE balance >= amount).",
|
|
53
57
|
fixCode: '// BAD: race condition\nconst account = await db.account.findUnique({ where: { id } });\nif (account.balance >= 100) {\n await db.account.update({ where: { id }, data: { balance: { decrement: 100 } } });\n}\n\n// GOOD: atomic transaction\nawait db.$transaction(async (tx) => {\n const account = await tx.account.findUnique({ where: { id } });\n if (account.balance < 100) throw new Error("Insufficient");\n await tx.account.update({ where: { id }, data: { balance: { decrement: 100 } } });\n});',
|
|
@@ -96,7 +96,12 @@ export const aiToolRuntimeRules = [
|
|
|
96
96
|
severity: "high",
|
|
97
97
|
owasp: "A05:2025 Security Misconfiguration",
|
|
98
98
|
description: "AI tool / MCP tool parameter schema (`z.enum(...)`, JSON Schema `enum`) is constructed at runtime from user input, fetched data, or a mutable variable. Runtime-mutable schemas defeat the safety guarantees the LLM relies on — an attacker can widen the accepted enum set or inject schema fields by poisoning the input.",
|
|
99
|
-
|
|
99
|
+
// Lowercase-start identifier required: PascalCase (`FraudAlertStatus`) and SCREAMING_SNAKE
|
|
100
|
+
// (`STATUSES`) are TypeScript enum imports / module-level const arrays — compile-time
|
|
101
|
+
// static, not user-mutable. Real attack shape uses lowercase variable names
|
|
102
|
+
// (`allowedActions`, `userActions`, `...userInput`). Template-literal interpolation in
|
|
103
|
+
// the JSON-schema branch (`enum: \`...${x}...\``) stays matched — that IS a real risk.
|
|
104
|
+
pattern: /(?:z\.enum\s*\(\s*(?!\[\s*["'])(?:[a-z_$][\w$]*|\.\.\.[a-z_$]\w*)|["']enum["']\s*:\s*(?!\[\s*(?:["']|true|false|null|\d))(?:[a-z_$][\w$]*\b|`[^`]*\$\{))/g,
|
|
100
105
|
languages: ["javascript", "typescript"],
|
|
101
106
|
fix: "Define enum values as static literal arrays in source. Never compute schema enums from runtime data.",
|
|
102
107
|
fixCode: '// SAFE:\nparameters: z.object({\n action: z.enum(["read", "list"]),\n})\n\n// UNSAFE — user controls allowed actions:\n// parameters: z.object({ action: z.enum(allowedActions) })',
|
|
@@ -351,7 +351,32 @@ export function analyzeCode(code, language, framework, filePath, configDir, rule
|
|
|
351
351
|
// agent.get('/?q=' + sqlPayload) which match the regex but aren't database calls
|
|
352
352
|
// - VG042/VG678: HTTP-response/security-header rules (tests don't serve to real users)
|
|
353
353
|
const isTestFile = filePath && /(?:\.(?:[\w-]+-)?(?:spec|test|e2e|stories|cy)\.(?:ts|tsx|js|jsx|mjs|cjs)$|\/__tests__\/|\/tests?\/|\/cypress\/|\/playwright\/)/i.test(filePath);
|
|
354
|
-
if (isTestFile && ["VG001", "VG062", "VG010", "VG011", "VG013", "VG014", "VG042", "VG130", "VG678"].includes(rule.id))
|
|
354
|
+
if (isTestFile && ["VG001", "VG062", "VG010", "VG011", "VG013", "VG014", "VG042", "VG130", "VG678", "VG955", "VG133", "VG1021"].includes(rule.id))
|
|
355
|
+
continue;
|
|
356
|
+
// VG955 (Missing Pagination on List Endpoint): only fire on actual request-handling
|
|
357
|
+
// surfaces — API routes, App Router `route.{ts,tsx}`, pages/api, or Server Actions.
|
|
358
|
+
// Library helpers, getStaticProps, internal _utils, and lib/handler test fixtures
|
|
359
|
+
// also use `findMany` but aren't list endpoints serving paginated client requests.
|
|
360
|
+
if (rule.id === "VG955" && filePath) {
|
|
361
|
+
const isRouteFile = /(?:\/api\/|\/route\.(?:ts|tsx|js|jsx)$|\/pages\/api\/|\/app\/api\/)/.test(filePath);
|
|
362
|
+
const isServerAction = /^\s*['"]use server['"];?\s*$/m.test(code.slice(0, 500));
|
|
363
|
+
const isStaticBuildHelper = /(?:getStaticProps|getStaticPaths|generateStaticParams|buildLegacy|getServerSideProps)/.test(filePath);
|
|
364
|
+
if (!isRouteFile && !isServerAction)
|
|
365
|
+
continue;
|
|
366
|
+
if (isStaticBuildHelper)
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
// VG506 (Hardcoded Secret in Vercel Config): the rule's intent is `vercel.json`
|
|
370
|
+
// specifically — its `_KEY`/`_SECRET`/`_TOKEN` regex unintentionally matched
|
|
371
|
+
// translation values in i18n locale JSONs (`packages/i18n/locales/da/common.json`
|
|
372
|
+
// etc. with strings like "user_secret_phrase": "<long Danish text>"). Restrict to
|
|
373
|
+
// actual Vercel config files.
|
|
374
|
+
if (rule.id === "VG506" && filePath && !/(?:^|\/)vercel\.json$/.test(filePath))
|
|
375
|
+
continue;
|
|
376
|
+
// VG041 (Debug mode in production): playground/demo/example paths are explicitly
|
|
377
|
+
// debug-mode showcases — `DEBUG = true` is the entire point of the file. Skip
|
|
378
|
+
// those paths to avoid swamping the report.
|
|
379
|
+
if (rule.id === "VG041" && filePath && /\/(?:playground|demos?|examples?|sandbox)\//i.test(filePath))
|
|
355
380
|
continue;
|
|
356
381
|
// Skip Expo-specific rule (VG708) when project is not an Expo app.
|
|
357
382
|
// The rule's regex incorrectly matches the literal strings "app.json"/"app.config.ts"
|
|
@@ -841,6 +866,8 @@ export function analyzeCode(code, language, framework, filePath, configDir, rule
|
|
|
841
866
|
const matched = match[0];
|
|
842
867
|
if (/\bin\s*:\s*\[/i.test(matched))
|
|
843
868
|
continue; // where: { x: { in: [...] } }
|
|
869
|
+
if (/\bin\s*:\s*[a-zA-Z_$]/i.test(matched))
|
|
870
|
+
continue; // where: { x: { in: someArray } } — variable-spread is also caller-bounded
|
|
844
871
|
if (/\b(?:id|[a-zA-Z]+Id)\s*:\s*\{?\s*in\s*:/i.test(matched))
|
|
845
872
|
continue; // where: { partnerId: { in: ids } }
|
|
846
873
|
if (/\b(?:id|[a-zA-Z]+Id)\s*:\s*[a-zA-Z_$]/i.test(matched))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "guardvibe",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"mcpName": "io.github.goklab/guardvibe",
|
|
5
5
|
"description": "Security MCP for vibe coding. 390 rules, 36 tools, CLI + doctor. Host security, auth coverage mapping, LLM-powered deep scan (IDOR/business logic), taint analysis, +25 AI-native rules (MCP supply-chain, RAG/vector poisoning, agent loop DoS, public-prefix LLM keys, sandbox bypass). Plus Next.js, Supabase, Clerk, Stripe, Prisma, tRPC, Hono, GraphQL, Convex, Turso, Uploadthing, AI SDK, and the full AI-generated stack.",
|
|
6
6
|
"type": "module",
|