guardvibe 1.8.7 → 1.8.9
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.
|
@@ -33,7 +33,7 @@ export const apiSecurityRules = [
|
|
|
33
33
|
severity: "high",
|
|
34
34
|
owasp: "API2:2023 Broken Authentication",
|
|
35
35
|
description: "Next.js Route Handler that performs data operations without any authentication check. API routes are publicly accessible by default.",
|
|
36
|
-
pattern: /export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|DELETE|PATCH)\s*\([^)]*\)\s*\{(?:(?!auth\s*\(|getServerSession|currentUser|getUser|requireAuth|verifyToken|checkAuth|clerkClient|getToken|session|protect)[\s\S]){10,}?(?:prisma|db|supabase|query|fetch|sql)\.\w+/g,
|
|
36
|
+
pattern: /export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|DELETE|PATCH)\s*\([^)]*\)\s*\{(?:(?!auth\s*\(|getServerSession|currentUser|getUser|requireAuth|requireAdmin|requireRole|isAuthenticated|verifyToken|checkAuth|clerkClient|getToken|session|protect|withAuth)[\s\S]){10,}?(?:prisma|db|supabase|query|fetch|sql)\.\w+/g,
|
|
37
37
|
languages: ["javascript", "typescript"],
|
|
38
38
|
fix: "Add authentication at the start of every Route Handler that reads or writes data.",
|
|
39
39
|
fixCode: 'import { auth } from "@clerk/nextjs/server";\n\nexport async function GET() {\n const { userId } = await auth();\n if (!userId) return new Response("Unauthorized", { status: 401 });\n // ... data access\n}',
|
|
@@ -76,6 +76,9 @@ export function analyzeCode(code, language, framework, filePath, configDir, rule
|
|
|
76
76
|
// Skip npm package rules (VG863/VG864/VG865): only apply to package.json files
|
|
77
77
|
if ((rule.id === "VG863" || rule.id === "VG864" || rule.id === "VG865") && filePath && !filePath.endsWith("package.json"))
|
|
78
78
|
continue;
|
|
79
|
+
// Skip destructive DDL rules (VG540-VG542) in migration directories
|
|
80
|
+
if (rule.id.startsWith("VG54") && filePath && /(?:migrations?|seeds?|fixtures)\//i.test(filePath))
|
|
81
|
+
continue;
|
|
79
82
|
// Skip server-only import rule (VG964) for files that are inherently server-only:
|
|
80
83
|
// Route Handlers (app/api/), middleware, instrumentation, next.config
|
|
81
84
|
if (rule.id === "VG964" && filePath && /(?:\/api\/|middleware\.|instrumentation\.|next\.config\.)/.test(filePath))
|
|
@@ -42,8 +42,10 @@ function detectLanguage(filePath) {
|
|
|
42
42
|
const ext = filePath.match(/\.[^.]+$/)?.[0]?.toLowerCase();
|
|
43
43
|
return ext ? extensionMap[ext] ?? null : null;
|
|
44
44
|
}
|
|
45
|
-
function calculateScore(critical, high, medium) {
|
|
46
|
-
|
|
45
|
+
function calculateScore(critical, high, medium, fileCount = 1) {
|
|
46
|
+
const weighted = critical * 10 + high * 3 + medium * 1;
|
|
47
|
+
const density = weighted / Math.max(fileCount, 1);
|
|
48
|
+
return Math.max(0, Math.min(100, Math.round(100 - density * 20)));
|
|
47
49
|
}
|
|
48
50
|
function scoreToGrade(score) {
|
|
49
51
|
if (score >= 90)
|
|
@@ -76,7 +78,7 @@ export function checkProject(files, format = "markdown", rules) {
|
|
|
76
78
|
const totalHigh = allFindings.filter((f) => f.rule.severity === "high").length;
|
|
77
79
|
const totalMedium = allFindings.filter((f) => f.rule.severity === "medium").length;
|
|
78
80
|
const totalIssues = totalCritical + totalHigh + totalMedium;
|
|
79
|
-
const score = calculateScore(totalCritical, totalHigh, totalMedium);
|
|
81
|
+
const score = calculateScore(totalCritical, totalHigh, totalMedium, scannedCount);
|
|
80
82
|
const grade = scoreToGrade(score);
|
|
81
83
|
if (format === "json") {
|
|
82
84
|
return formatFindingsJson(allFindings, { grade, score });
|
|
@@ -98,7 +98,13 @@ export function scanDirectory(path, recursive = true, exclude = [], format = "ma
|
|
|
98
98
|
const totalHigh = allFindings.filter(f => f.rule.severity === "high").length;
|
|
99
99
|
const totalMedium = allFindings.filter(f => f.rule.severity === "medium").length;
|
|
100
100
|
const totalIssues = totalCritical + totalHigh + totalMedium;
|
|
101
|
-
|
|
101
|
+
// Score based on weighted issue density (per file), not raw counts.
|
|
102
|
+
// This makes scoring fair for both small and large projects.
|
|
103
|
+
const filesScanned = scanResults.length || 1;
|
|
104
|
+
const weightedIssues = totalCritical * 10 + totalHigh * 3 + totalMedium * 1;
|
|
105
|
+
const density = weightedIssues / filesScanned;
|
|
106
|
+
// density 0 = 100, density >= 5 = 0
|
|
107
|
+
const score = Math.max(0, Math.min(100, Math.round(100 - density * 20)));
|
|
102
108
|
const grade = score >= 90 ? "A" : score >= 75 ? "B" : score >= 60 ? "C" : score >= 40 ? "D" : "F";
|
|
103
109
|
// Baseline comparison
|
|
104
110
|
let baselineDiff = null;
|
|
@@ -89,7 +89,9 @@ export function scanStaged(cwd = process.cwd(), format = "markdown", rules) {
|
|
|
89
89
|
const totalHigh = allFindings.filter(f => f.rule.severity === "high").length;
|
|
90
90
|
const totalMedium = allFindings.filter(f => f.rule.severity === "medium").length;
|
|
91
91
|
const totalIssues = totalCritical + totalHigh + totalMedium;
|
|
92
|
-
const
|
|
92
|
+
const weightedIssues = totalCritical * 10 + totalHigh * 3 + totalMedium * 1;
|
|
93
|
+
const density = weightedIssues / Math.max(scannedCount, 1);
|
|
94
|
+
const score = Math.max(0, Math.min(100, Math.round(100 - density * 20)));
|
|
93
95
|
const grade = score >= 90 ? "A" : score >= 75 ? "B" : score >= 60 ? "C" : score >= 40 ? "D" : "F";
|
|
94
96
|
if (format === "json") {
|
|
95
97
|
return formatFindingsJson(allFindings, { grade, score });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "guardvibe",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.9",
|
|
4
4
|
"description": "Security MCP for vibe coding. 277 rules, 22 tools for Next.js, Supabase, Clerk, Stripe, Prisma, tRPC, Hono, GraphQL, Convex, Turso, Uploadthing, AI SDK, and the full AI-generated stack.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|