guardvibe 2.0.3 → 2.1.1
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/build/cli.js +91 -52
- package/build/data/rules/core.js +28 -4
- package/package.json +1 -1
package/build/cli.js
CHANGED
|
@@ -50,9 +50,8 @@ function setupPlatform(name) {
|
|
|
50
50
|
}
|
|
51
51
|
if (existing.mcpServers["guardvibe"]) {
|
|
52
52
|
console.log(` [OK] GuardVibe already configured in ${platform.description}`);
|
|
53
|
-
// Still ensure
|
|
54
|
-
|
|
55
|
-
setupClaudeHooksAndGuide();
|
|
53
|
+
// Still ensure security guidance and .gitignore are set up
|
|
54
|
+
setupSecurityGuide(name);
|
|
56
55
|
return true;
|
|
57
56
|
}
|
|
58
57
|
existing.mcpServers["guardvibe"] = GUARDVIBE_MCP_CONFIG;
|
|
@@ -66,77 +65,117 @@ function setupPlatform(name) {
|
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
67
|
console.log(` [OK] Added MCP server to ${platform.description}`);
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
setupClaudeHooksAndGuide();
|
|
72
|
-
}
|
|
68
|
+
// Set up platform-specific security guidance + universal security rules
|
|
69
|
+
setupSecurityGuide(name);
|
|
73
70
|
return true;
|
|
74
71
|
}
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
// ── Universal security rules (shared across all AI platforms) ────────
|
|
73
|
+
const SECURITY_RULES = `## Security Rules (enforced by GuardVibe MCP)
|
|
74
|
+
|
|
75
|
+
### Mandatory checks
|
|
76
|
+
- AFTER writing any API route, Server Action, or database query: use the guardvibe scan_file MCP tool on the file
|
|
77
|
+
- BEFORE committing: use the guardvibe scan_staged MCP tool
|
|
78
|
+
- When GuardVibe reports HIGH or CRITICAL: fix immediately before moving on
|
|
79
|
+
- BEFORE creating a PR: use scan_changed_files to review all changes
|
|
80
|
+
|
|
81
|
+
### Writing secure code
|
|
82
|
+
- Every API route handler MUST have auth check before DB access
|
|
83
|
+
- Every POST endpoint MUST have input validation (zod/joi schema)
|
|
84
|
+
- Never pass user input to innerHTML, eval, exec, or raw SQL
|
|
85
|
+
- Never pass user-controlled URLs to fetch() without allowlist validation
|
|
86
|
+
- Always use select: in Prisma/Drizzle queries from Server Actions (never return full objects to client)
|
|
87
|
+
- Always validate redirect URLs against trusted domain allowlist
|
|
88
|
+
- Set security headers (CSP, HSTS, X-Frame-Options, X-Content-Type-Options)
|
|
89
|
+
- Verify webhook signatures before processing events
|
|
90
|
+
- Use parameterized queries, never string concatenation/template literals for SQL
|
|
91
|
+
|
|
92
|
+
### When in doubt
|
|
93
|
+
- Use the guardvibe explain_remediation MCP tool with the rule ID for detailed fix guidance
|
|
94
|
+
- Use the guardvibe check_code MCP tool to verify a code snippet is secure before applying
|
|
95
|
+
`;
|
|
96
|
+
function setupSecurityGuide(platformName) {
|
|
97
|
+
// 1. Platform-specific guidance file
|
|
98
|
+
if (platformName === "claude")
|
|
99
|
+
setupClaudeGuide();
|
|
100
|
+
else if (platformName === "cursor")
|
|
101
|
+
setupCursorGuide();
|
|
102
|
+
else if (platformName === "gemini")
|
|
103
|
+
setupGeminiGuide();
|
|
104
|
+
// 2. Platform-specific .gitignore entries
|
|
105
|
+
const gitignoreEntries = {
|
|
106
|
+
claude: [".claude.json", ".claude/", "CLAUDE.md"],
|
|
107
|
+
cursor: [".cursor/", ".cursorrules"],
|
|
108
|
+
gemini: ["GEMINI.md"],
|
|
109
|
+
};
|
|
110
|
+
const entries = gitignoreEntries[platformName] || [];
|
|
111
|
+
if (entries.length > 0)
|
|
112
|
+
addToGitignore(entries);
|
|
113
|
+
}
|
|
114
|
+
function setupClaudeGuide() {
|
|
115
|
+
// Claude Code hooks
|
|
77
116
|
const claudeSettingsDir = join(process.cwd(), ".claude");
|
|
78
|
-
if (!existsSync(claudeSettingsDir))
|
|
117
|
+
if (!existsSync(claudeSettingsDir))
|
|
79
118
|
mkdirSync(claudeSettingsDir, { recursive: true });
|
|
80
|
-
}
|
|
81
119
|
const claudeSettingsPath = join(claudeSettingsDir, "settings.json");
|
|
82
120
|
const existingSettings = readJsonFile(claudeSettingsPath) || {};
|
|
83
|
-
if (!existingSettings.hooks)
|
|
121
|
+
if (!existingSettings.hooks)
|
|
84
122
|
existingSettings.hooks = {};
|
|
85
|
-
}
|
|
86
|
-
// Real security hook: scan edited files automatically after every Edit/Write
|
|
87
|
-
// Claude Code passes tool_input as JSON on stdin — extract file_path with jq
|
|
88
123
|
if (!existingSettings.hooks.PostToolUse) {
|
|
89
124
|
existingSettings.hooks.PostToolUse = [
|
|
90
125
|
{
|
|
91
126
|
matcher: "Edit|Write",
|
|
92
|
-
hooks: [
|
|
93
|
-
{
|
|
127
|
+
hooks: [{
|
|
94
128
|
type: "command",
|
|
95
129
|
command: "jq -r '.tool_input.file_path' | xargs npx -y guardvibe check --format markdown 2>/dev/null || true"
|
|
96
|
-
}
|
|
97
|
-
]
|
|
130
|
+
}]
|
|
98
131
|
}
|
|
99
132
|
];
|
|
100
133
|
}
|
|
101
134
|
writeJsonFile(claudeSettingsPath, existingSettings);
|
|
102
135
|
console.log(` [OK] Claude Code hooks configured (.claude/settings.json)`);
|
|
103
|
-
//
|
|
136
|
+
// CLAUDE.md
|
|
104
137
|
const claudeMdPath = join(process.cwd(), "CLAUDE.md");
|
|
105
|
-
const guardvibeBlock = `
|
|
106
|
-
## Security Rules (enforced by GuardVibe MCP)
|
|
107
|
-
|
|
108
|
-
### Mandatory checks
|
|
109
|
-
- BEFORE writing any API route, Server Action, or database query: call \`scan_file\` on the file after editing
|
|
110
|
-
- BEFORE committing: call \`scan_staged\` to catch issues in staged files
|
|
111
|
-
- When GuardVibe reports HIGH or CRITICAL: fix immediately before moving on
|
|
112
|
-
|
|
113
|
-
### Writing secure code
|
|
114
|
-
- Every API route handler MUST have auth check before DB access
|
|
115
|
-
- Every POST endpoint MUST have input validation (zod/joi schema)
|
|
116
|
-
- Never pass user input to \`innerHTML\`, \`eval\`, \`exec\`, or raw SQL
|
|
117
|
-
- Never pass user-controlled URLs to \`fetch()\` without allowlist validation
|
|
118
|
-
- Always use \`select:\` in Prisma queries from Server Actions (never return full objects)
|
|
119
|
-
- Always validate redirect URLs against trusted domain allowlist
|
|
120
|
-
- Set security headers in next.config.ts (CSP, HSTS, X-Frame-Options)
|
|
121
|
-
|
|
122
|
-
### When in doubt
|
|
123
|
-
- Use \`explain_remediation\` with the rule ID for detailed fix guidance
|
|
124
|
-
- Use \`scan_changed_files\` with base branch before creating PR
|
|
125
|
-
- Use \`check_code\` to verify a code snippet is secure before applying
|
|
126
|
-
`;
|
|
127
138
|
if (existsSync(claudeMdPath)) {
|
|
128
139
|
const content = readFileSync(claudeMdPath, "utf-8");
|
|
129
140
|
if (!content.includes("GuardVibe")) {
|
|
130
|
-
writeFileSync(claudeMdPath, content +
|
|
131
|
-
console.log(` [OK] GuardVibe
|
|
141
|
+
writeFileSync(claudeMdPath, content + "\n" + SECURITY_RULES, "utf-8");
|
|
142
|
+
console.log(` [OK] GuardVibe rules added to CLAUDE.md`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
writeFileSync(claudeMdPath, `# Project Guidelines\n\n${SECURITY_RULES}`, "utf-8");
|
|
147
|
+
console.log(` [OK] Created CLAUDE.md with security rules`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function setupCursorGuide() {
|
|
151
|
+
// .cursorrules — Cursor reads this file for AI instructions
|
|
152
|
+
const cursorrules = join(process.cwd(), ".cursorrules");
|
|
153
|
+
if (existsSync(cursorrules)) {
|
|
154
|
+
const content = readFileSync(cursorrules, "utf-8");
|
|
155
|
+
if (!content.includes("GuardVibe")) {
|
|
156
|
+
writeFileSync(cursorrules, content + "\n" + SECURITY_RULES, "utf-8");
|
|
157
|
+
console.log(` [OK] GuardVibe rules added to .cursorrules`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
writeFileSync(cursorrules, SECURITY_RULES, "utf-8");
|
|
162
|
+
console.log(` [OK] Created .cursorrules with security rules`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function setupGeminiGuide() {
|
|
166
|
+
// GEMINI.md — Gemini CLI reads this for project context
|
|
167
|
+
const geminiMd = join(process.cwd(), "GEMINI.md");
|
|
168
|
+
if (existsSync(geminiMd)) {
|
|
169
|
+
const content = readFileSync(geminiMd, "utf-8");
|
|
170
|
+
if (!content.includes("GuardVibe")) {
|
|
171
|
+
writeFileSync(geminiMd, content + "\n" + SECURITY_RULES, "utf-8");
|
|
172
|
+
console.log(` [OK] GuardVibe rules added to GEMINI.md`);
|
|
132
173
|
}
|
|
133
174
|
}
|
|
134
175
|
else {
|
|
135
|
-
writeFileSync(
|
|
136
|
-
console.log(` [OK] Created
|
|
176
|
+
writeFileSync(geminiMd, `# Project Guidelines\n\n${SECURITY_RULES}`, "utf-8");
|
|
177
|
+
console.log(` [OK] Created GEMINI.md with security rules`);
|
|
137
178
|
}
|
|
138
|
-
// Add generated files to .gitignore so they don't get committed
|
|
139
|
-
addToGitignore([".claude.json", ".claude/", "CLAUDE.md"]);
|
|
140
179
|
}
|
|
141
180
|
function addToGitignore(entries) {
|
|
142
181
|
const gitignorePath = join(process.cwd(), ".gitignore");
|
|
@@ -148,7 +187,7 @@ function addToGitignore(entries) {
|
|
|
148
187
|
const missing = entries.filter(e => !content.split("\n").some(line => line.trim() === e));
|
|
149
188
|
if (missing.length === 0)
|
|
150
189
|
return;
|
|
151
|
-
const block = `\n# GuardVibe
|
|
190
|
+
const block = `\n# GuardVibe (auto-added by guardvibe init)\n${missing.join("\n")}\n`;
|
|
152
191
|
writeFileSync(gitignorePath, content.trimEnd() + block, "utf-8");
|
|
153
192
|
console.log(` [OK] Added ${missing.join(", ")} to .gitignore`);
|
|
154
193
|
}
|
|
@@ -553,9 +592,9 @@ function printUsage() {
|
|
|
553
592
|
--help, -h Show this help message
|
|
554
593
|
|
|
555
594
|
MCP Platforms:
|
|
556
|
-
claude Claude Code (.claude.json
|
|
557
|
-
|
|
558
|
-
|
|
595
|
+
claude Claude Code (.claude.json + CLAUDE.md + hooks)
|
|
596
|
+
cursor Cursor (.cursor/mcp.json + .cursorrules)
|
|
597
|
+
gemini Gemini CLI (~/.gemini/settings.json + GEMINI.md)
|
|
559
598
|
all All platforms at once
|
|
560
599
|
|
|
561
600
|
Supported File Types:
|
package/build/data/rules/core.js
CHANGED
|
@@ -387,7 +387,7 @@ export const coreRules = [
|
|
|
387
387
|
compliance: ["SOC2:CC7.1"],
|
|
388
388
|
},
|
|
389
389
|
{
|
|
390
|
-
id: "
|
|
390
|
+
id: "VG120",
|
|
391
391
|
name: "SSRF via User-Controlled URL",
|
|
392
392
|
severity: "high",
|
|
393
393
|
owasp: "A10:2025 Server-Side Request Forgery",
|
|
@@ -399,7 +399,7 @@ export const coreRules = [
|
|
|
399
399
|
compliance: ["SOC2:CC7.1", "PCI-DSS:Req6.5.1"],
|
|
400
400
|
},
|
|
401
401
|
{
|
|
402
|
-
id: "
|
|
402
|
+
id: "VG121",
|
|
403
403
|
name: "XSS via insertAdjacentHTML",
|
|
404
404
|
severity: "high",
|
|
405
405
|
owasp: "A02:2025 Injection",
|
|
@@ -411,7 +411,7 @@ export const coreRules = [
|
|
|
411
411
|
compliance: ["SOC2:CC7.1", "PCI-DSS:Req6.5.7"],
|
|
412
412
|
},
|
|
413
413
|
{
|
|
414
|
-
id: "
|
|
414
|
+
id: "VG122",
|
|
415
415
|
name: "XSS/SSRF via XMLHttpRequest",
|
|
416
416
|
severity: "high",
|
|
417
417
|
owasp: "A02:2025 Injection",
|
|
@@ -423,7 +423,7 @@ export const coreRules = [
|
|
|
423
423
|
compliance: ["SOC2:CC7.1"],
|
|
424
424
|
},
|
|
425
425
|
{
|
|
426
|
-
id: "
|
|
426
|
+
id: "VG123",
|
|
427
427
|
name: "SQL Injection via Template Literal",
|
|
428
428
|
severity: "critical",
|
|
429
429
|
owasp: "A02:2025 Injection",
|
|
@@ -434,4 +434,28 @@ export const coreRules = [
|
|
|
434
434
|
fixCode: '// BAD: template literal SQL\ndb.query(`SELECT * FROM users WHERE id = \'${userId}\'`);\n\n// GOOD: parameterized query\ndb.query("SELECT * FROM users WHERE id = $1", [userId]);\n\n// ALSO SAFE: tagged template literal (Prisma/Drizzle)\nimport { sql } from "drizzle-orm";\ndb.execute(sql`SELECT * FROM users WHERE id = ${userId}`);',
|
|
435
435
|
compliance: ["SOC2:CC7.1", "PCI-DSS:Req6.5.1"],
|
|
436
436
|
},
|
|
437
|
+
{
|
|
438
|
+
id: "VG124",
|
|
439
|
+
name: "Insecure Random for Security Token",
|
|
440
|
+
severity: "high",
|
|
441
|
+
owasp: "A02:2025 Cryptographic Failures",
|
|
442
|
+
description: "Math.random() is used to generate tokens, IDs, codes, or nonces. Math.random() is not cryptographically secure — its output is predictable, allowing attackers to guess reset tokens, session IDs, verification codes, or API keys.",
|
|
443
|
+
pattern: /(?:(?:token|secret|key|code|nonce|session|reset|verify|otp|password|auth|invite|magic|csrf)\w*\s*=[\s\S]{0,30}?Math\.random|Math\.random\s*\(\s*\)[\s\S]{0,50}?(?:token|secret|key|code|nonce|session|reset|verify|otp|password|auth|invite|magic|csrf))/gi,
|
|
444
|
+
languages: ["javascript", "typescript"],
|
|
445
|
+
fix: "Use crypto.randomUUID() or crypto.randomBytes() for security-sensitive random values.",
|
|
446
|
+
fixCode: '// BAD: predictable\nconst token = Math.random().toString(36);\n\n// GOOD: cryptographically secure\nimport { randomUUID, randomBytes } from "crypto";\nconst token = randomUUID();\nconst resetCode = randomBytes(32).toString("hex");\n// Or in browser:\nconst token = crypto.randomUUID();',
|
|
447
|
+
compliance: ["SOC2:CC6.1", "PCI-DSS:Req6.5.3"],
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
id: "VG125",
|
|
451
|
+
name: "Session Not Regenerated After Authentication",
|
|
452
|
+
severity: "high",
|
|
453
|
+
owasp: "A07:2025 Identification and Authentication Failures",
|
|
454
|
+
description: "User session is not regenerated after login/authentication. This enables session fixation attacks — an attacker can set a known session ID before the user logs in, then hijack their authenticated session.",
|
|
455
|
+
pattern: /(?:login|signIn|authenticate|logIn)\s*(?:=\s*async|\([\s\S]*?\)\s*(?:=>|{))[\s\S]{0,500}?(?:req\.session\.\w+\s*=)(?:(?!regenerate|destroy|create|rotate)[\s\S]){0,300}?(?:res\.|return|next\()/gi,
|
|
456
|
+
languages: ["javascript", "typescript"],
|
|
457
|
+
fix: "Regenerate the session after successful authentication. In Express: req.session.regenerate(). In Next.js: use a new session token.",
|
|
458
|
+
fixCode: '// Express: regenerate session after login\napp.post("/login", async (req, res) => {\n const user = await authenticate(req.body);\n if (!user) return res.status(401).json({ error: "Invalid credentials" });\n req.session.regenerate((err) => {\n req.session.userId = user.id;\n res.json({ ok: true });\n });\n});',
|
|
459
|
+
compliance: ["SOC2:CC6.6", "PCI-DSS:Req6.5.10"],
|
|
460
|
+
},
|
|
437
461
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "guardvibe",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Security MCP for vibe coding. 277 rules, 24 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": {
|