@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,288 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* VibeGuard Privacy Policy Generator.
|
|
5
|
+
*
|
|
6
|
+
* Analyzes the codebase and auto-generates a privacy policy based on:
|
|
7
|
+
* - What PII is collected (forms, inputs, API params)
|
|
8
|
+
* - Where data is stored (DB, cookies, localStorage)
|
|
9
|
+
* - What third-party services are used (analytics, AI, error tracking)
|
|
10
|
+
* - What consent mechanisms exist
|
|
11
|
+
* - What data retention policies exist
|
|
12
|
+
*
|
|
13
|
+
* Generates a markdown privacy policy ready for legal review.
|
|
14
|
+
*
|
|
15
|
+
* 100% local. Zero network. Zero dependencies.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const { auditPrivacy } = require('./privacy-audit');
|
|
19
|
+
const { auditNetwork } = require('./net-audit');
|
|
20
|
+
|
|
21
|
+
function generatePrivacyPolicy(dir, files) {
|
|
22
|
+
const inv = auditPrivacy(dir, files);
|
|
23
|
+
const net = auditNetwork(dir, files);
|
|
24
|
+
|
|
25
|
+
const pii = inv.summary.piiFieldsDetected || [];
|
|
26
|
+
const storage = inv.storage || [];
|
|
27
|
+
const transmission = inv.transmission || [];
|
|
28
|
+
const hasConsent = inv.summary.consentMechanisms > 0;
|
|
29
|
+
const hasEncryption = inv.summary.encryptionPoints > 0;
|
|
30
|
+
const hasRetention = inv.summary.retentionPolicies > 0;
|
|
31
|
+
|
|
32
|
+
// Identify third-party services
|
|
33
|
+
const thirdParty = new Set();
|
|
34
|
+
for (const t of transmission) {
|
|
35
|
+
if (t.type === 'Google Analytics') thirdParty.add('Google Analytics');
|
|
36
|
+
if (t.type === 'Mixpanel') thirdParty.add('Mixpanel');
|
|
37
|
+
if (t.type === 'Segment') thirdParty.add('Segment');
|
|
38
|
+
if (t.type === 'PostHog') thirdParty.add('PostHog');
|
|
39
|
+
if (t.type === 'Amplitude') thirdParty.add('Amplitude');
|
|
40
|
+
if (t.type === 'Sentry') thirdParty.add('Sentry');
|
|
41
|
+
if (t.type === 'Social tracking') thirdParty.add('Social Media Tracking (Facebook/Meta)');
|
|
42
|
+
if (t.type === 'AI API') thirdParty.add('AI/LLM Provider (OpenAI/Anthropic/Google)');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Identify storage types
|
|
46
|
+
const storageTypes = new Set();
|
|
47
|
+
for (const s of storage) {
|
|
48
|
+
storageTypes.add(s.type);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
52
|
+
|
|
53
|
+
let md = `# Privacy Policy\n\n`;
|
|
54
|
+
md += `**Last updated: ${date}**\n\n`;
|
|
55
|
+
md += `> This privacy policy was auto-generated by VibeGuard based on code analysis. It must be reviewed by a legal professional before publication.\n\n`;
|
|
56
|
+
|
|
57
|
+
// Introduction
|
|
58
|
+
md += `## 1. Introduction\n\n`;
|
|
59
|
+
md += `This privacy policy describes how we collect, use, store, and protect your personal information when you use our application.\n\n`;
|
|
60
|
+
|
|
61
|
+
// Information we collect
|
|
62
|
+
md += `## 2. Information We Collect\n\n`;
|
|
63
|
+
if (pii.length > 0) {
|
|
64
|
+
md += `### Personal Information\n\n`;
|
|
65
|
+
md += `We collect the following types of personal information:\n\n`;
|
|
66
|
+
for (const field of pii) {
|
|
67
|
+
md += `- ${field.replace(/_/g, ' ')}\n`;
|
|
68
|
+
}
|
|
69
|
+
md += `\n`;
|
|
70
|
+
} else {
|
|
71
|
+
md += `Based on our code analysis, we do not appear to collect personal information directly. If this is incorrect, please update this policy.\n\n`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
md += `### Automatically Collected Information\n\n`;
|
|
75
|
+
md += `When you use our application, we may automatically collect:\n\n`;
|
|
76
|
+
md += `- IP address (if logged)\n`;
|
|
77
|
+
md += `- Browser type and version\n`;
|
|
78
|
+
md += `- Device information\n`;
|
|
79
|
+
md += `- Usage data and interactions\n`;
|
|
80
|
+
if (thirdParty.size > 0) {
|
|
81
|
+
md += `- Analytics data (see Section 4)\n`;
|
|
82
|
+
}
|
|
83
|
+
md += `\n`;
|
|
84
|
+
|
|
85
|
+
// How we use information
|
|
86
|
+
md += `## 3. How We Use Your Information\n\n`;
|
|
87
|
+
md += `We use the information we collect to:\n\n`;
|
|
88
|
+
md += `- Provide and maintain our service\n`;
|
|
89
|
+
md += `- Respond to your requests and inquiries\n`;
|
|
90
|
+
md += `- Improve our application and user experience\n`;
|
|
91
|
+
if (thirdParty.has('AI/LLM Provider (OpenAI/Anthropic/Google)')) {
|
|
92
|
+
md += `- Process your inputs through AI/LLM services to generate responses\n`;
|
|
93
|
+
}
|
|
94
|
+
if (thirdParty.has('Google Analytics') || thirdParty.has('Mixpanel') || thirdParty.has('Segment') || thirdParty.has('PostHog') || thirdParty.has('Amplitude')) {
|
|
95
|
+
md += `- Analyze usage patterns and trends\n`;
|
|
96
|
+
}
|
|
97
|
+
md += `- Detect and prevent fraud or abuse\n`;
|
|
98
|
+
md += `- Comply with legal obligations\n`;
|
|
99
|
+
md += `\n`;
|
|
100
|
+
|
|
101
|
+
// Third-party services
|
|
102
|
+
md += `## 4. Third-Party Services\n\n`;
|
|
103
|
+
if (thirdParty.size > 0) {
|
|
104
|
+
md += `We use the following third-party services that may process your data:\n\n`;
|
|
105
|
+
for (const tp of [...thirdParty].sort()) {
|
|
106
|
+
md += `- **${tp}**: Used for ${tp.includes('Analytics') ? 'usage analytics' : tp.includes('Sentry') ? 'error monitoring' : tp.includes('AI') ? 'AI processing' : 'tracking'}. Their privacy policies apply to data they process.\n`;
|
|
107
|
+
}
|
|
108
|
+
md += `\n`;
|
|
109
|
+
if (!hasConsent) {
|
|
110
|
+
md += `> **WARNING (VibeGuard)**: No consent mechanism was detected in the code. Under GDPR/CCPA, you must obtain user consent before enabling third-party tracking.\n\n`;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
md += `Based on our code analysis, we do not use third-party tracking or analytics services.\n\n`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Data storage
|
|
117
|
+
md += `## 5. Data Storage and Security\n\n`;
|
|
118
|
+
if (storageTypes.size > 0) {
|
|
119
|
+
md += `### Where We Store Data\n\n`;
|
|
120
|
+
for (const st of storageTypes) {
|
|
121
|
+
md += `- ${st}\n`;
|
|
122
|
+
}
|
|
123
|
+
md += `\n`;
|
|
124
|
+
}
|
|
125
|
+
if (hasEncryption) {
|
|
126
|
+
md += `### Encryption\n\nWe use encryption to protect your personal information both in transit (HTTPS/TLS) and at rest.\n\n`;
|
|
127
|
+
} else {
|
|
128
|
+
md += `### Encryption\n\n> **WARNING (VibeGuard)**: No encryption was detected in the codebase. We recommend implementing encryption for personal data at rest and in transit.\n\n`;
|
|
129
|
+
}
|
|
130
|
+
md += `### Data Retention\n\n`;
|
|
131
|
+
if (hasRetention) {
|
|
132
|
+
md += `We retain personal data only as long as necessary for the purposes described in this policy or as required by law.\n\n`;
|
|
133
|
+
} else {
|
|
134
|
+
md += `> **WARNING (VibeGuard)**: No data retention policy was detected in the code. Under GDPR, you must define and implement data retention periods.\n\n`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Your rights
|
|
138
|
+
md += `## 6. Your Privacy Rights\n\n`;
|
|
139
|
+
md += `Depending on your location, you may have the following rights:\n\n`;
|
|
140
|
+
md += `- **Right to access**: Request a copy of your personal data\n`;
|
|
141
|
+
md += `- **Right to rectification**: Request correction of inaccurate data\n`;
|
|
142
|
+
md += `- **Right to erasure**: Request deletion of your personal data ("right to be forgotten")\n`;
|
|
143
|
+
md += `- **Right to restrict processing**: Request restriction of data processing\n`;
|
|
144
|
+
md += `- **Right to data portability**: Request transfer of your data to another service\n`;
|
|
145
|
+
md += `- **Right to object**: Object to processing of your data\n`;
|
|
146
|
+
md += `- **Right to withdraw consent**: Withdraw consent at any time (if processing is based on consent)\n\n`;
|
|
147
|
+
md += `To exercise these rights, contact us using the information in Section 8.\n\n`;
|
|
148
|
+
|
|
149
|
+
// AI-specific disclosure
|
|
150
|
+
if (thirdParty.has('AI/LLM Provider (OpenAI/Anthropic/Google)')) {
|
|
151
|
+
md += `## 7. AI Data Processing\n\n`;
|
|
152
|
+
md += `Our application uses AI/LLM services (such as OpenAI, Anthropic, or Google) to process user inputs. When you interact with our AI features:\n\n`;
|
|
153
|
+
md += `- Your input text is sent to the AI provider for processing\n`;
|
|
154
|
+
md += `- The AI provider processes your input on their servers\n`;
|
|
155
|
+
md += `- We do not control the AI provider's retention of your input\n`;
|
|
156
|
+
md += `- We recommend not sharing sensitive personal information (SSN, credit cards, health information) through AI features\n\n`;
|
|
157
|
+
if (!inv.encryption.some(e => /redact|anonym|mask|scrub/i.test(e))) {
|
|
158
|
+
md += `> **WARNING (VibeGuard)**: No PII redaction was detected before sending data to AI providers. We strongly recommend implementing PII redaction before AI API calls.\n\n`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Contact
|
|
163
|
+
md += `## 8. Contact Us\n\n`;
|
|
164
|
+
md += `If you have questions about this privacy policy or want to exercise your privacy rights, contact:\n\n`;
|
|
165
|
+
md += `- Email: [your-privacy-email@yourdomain.com]\n`;
|
|
166
|
+
md += `- Address: [your business address]\n\n`;
|
|
167
|
+
|
|
168
|
+
// Compliance notes
|
|
169
|
+
md += `## 9. Compliance Notes\n\n`;
|
|
170
|
+
md += `- **GDPR**: This policy is designed to comply with the EU General Data Protection Regulation.\n`;
|
|
171
|
+
md += `- **CCPA**: This policy is designed to comply with the California Consumer Privacy Act.\n`;
|
|
172
|
+
md += `- **COPPA**: If your application is directed at children under 13, additional compliance is required.\n\n`;
|
|
173
|
+
|
|
174
|
+
// VibeGuard warnings
|
|
175
|
+
const warnings = [];
|
|
176
|
+
if (!hasConsent) warnings.push('No consent mechanism detected in code');
|
|
177
|
+
if (!hasEncryption) warnings.push('No encryption detected in codebase');
|
|
178
|
+
if (!hasRetention) warnings.push('No data retention policy detected in code');
|
|
179
|
+
if (thirdParty.has('AI/LLM Provider (OpenAI/Anthropic/Google)')) warnings.push('Data sent to AI providers — verify PII redaction');
|
|
180
|
+
|
|
181
|
+
if (warnings.length > 0) {
|
|
182
|
+
md += `## 10. VibeGuard Audit Warnings\n\n`;
|
|
183
|
+
md += `The following warnings were identified by VibeGuard's automated code analysis:\n\n`;
|
|
184
|
+
for (const w of warnings) {
|
|
185
|
+
md += `- ${w}\n`;
|
|
186
|
+
}
|
|
187
|
+
md += `\nThese warnings must be addressed before publishing this privacy policy.\n\n`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
md += `---\n\n`;
|
|
191
|
+
md += `*This privacy policy was auto-generated by VibeGuard on ${date}. It must be reviewed by a qualified legal professional before publication.*\n`;
|
|
192
|
+
|
|
193
|
+
return md;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function generateCSP(dir, files) {
|
|
197
|
+
const fs = require('fs');
|
|
198
|
+
const path = require('path');
|
|
199
|
+
|
|
200
|
+
const sources = {
|
|
201
|
+
'default-src': ["'self'"],
|
|
202
|
+
'script-src': ["'self'"],
|
|
203
|
+
'style-src': ["'self'"],
|
|
204
|
+
'img-src': ["'self'", 'data:', 'https:'],
|
|
205
|
+
'font-src': ["'self'", 'https://fonts.gstatic.com'],
|
|
206
|
+
'connect-src': ["'self'"],
|
|
207
|
+
'frame-src': ["'none'"],
|
|
208
|
+
'object-src': ["'none'"],
|
|
209
|
+
'base-uri': ["'self'"],
|
|
210
|
+
'form-action': ["'self'"],
|
|
211
|
+
'upgrade-insecure-requests': [],
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const externalDomains = new Set();
|
|
215
|
+
|
|
216
|
+
for (const file of files) {
|
|
217
|
+
let content;
|
|
218
|
+
try { content = fs.readFileSync(file, 'utf8'); } catch { continue; }
|
|
219
|
+
|
|
220
|
+
// Find external script/style sources
|
|
221
|
+
let m;
|
|
222
|
+
const scriptRe = /<script\s+src\s*=\s*['"]https?:\/\/([^'"/]+)/gi;
|
|
223
|
+
while ((m = scriptRe.exec(content)) !== null) {
|
|
224
|
+
externalDomains.add(m[1]);
|
|
225
|
+
sources['script-src'].push(`https://${m[1]}`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const styleRe = /<link\s+[^>]*href\s*=\s*['"]https?:\/\/([^'"/]+)/gi;
|
|
229
|
+
while ((m = styleRe.exec(content)) !== null) {
|
|
230
|
+
sources['style-src'].push(`https://${m[1]}`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const imgRe = /src\s*=\s*['"]https?:\/\/([^'"/]+)/gi;
|
|
234
|
+
while ((m = imgRe.exec(content)) !== null) {
|
|
235
|
+
if (!m[1].includes('localhost') && !m[1].includes('127.0.0.1')) {
|
|
236
|
+
sources['img-src'].push(`https://${m[1]}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Find API endpoints
|
|
241
|
+
const apiRe = /fetch\s*\(\s*['"]https?:\/\/([^'"/]+)/gi;
|
|
242
|
+
while ((m = apiRe.exec(content)) !== null) {
|
|
243
|
+
if (m[1] !== 'localhost' && m[1] !== '127.0.0.1') {
|
|
244
|
+
sources['connect-src'].push(`https://${m[1]}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Check for inline scripts (dangerous)
|
|
249
|
+
if (/<script[^>]*>[^<]+/i.test(content) && !/<script[^>]*src\s*=/i.test(content)) {
|
|
250
|
+
sources['script-src'].push("'unsafe-inline'");
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Check for inline styles
|
|
254
|
+
if (/<style[^>]*>/i.test(content)) {
|
|
255
|
+
sources['style-src'].push("'unsafe-inline'");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Remove duplicates
|
|
260
|
+
for (const key of Object.keys(sources)) {
|
|
261
|
+
sources[key] = [...new Set(sources[key])];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Build CSP string
|
|
265
|
+
const parts = [];
|
|
266
|
+
for (const [key, vals] of Object.entries(sources)) {
|
|
267
|
+
if (vals.length === 0 && key === 'upgrade-insecure-requests') {
|
|
268
|
+
parts.push(key);
|
|
269
|
+
} else if (vals.length > 0) {
|
|
270
|
+
parts.push(`${key} ${vals.join(' ')}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const csp = parts.join('; ');
|
|
275
|
+
const helmet = `// Express/Helmet:\napp.use(helmet.contentSecurityPolicy({\n directives: ${JSON.stringify(sources, null, 2).replace(/"/g, "'").replace(/'/g, '"').replace(/\n/g, '\n ')}\n}));`;
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
csp,
|
|
279
|
+
helmet,
|
|
280
|
+
sources,
|
|
281
|
+
warnings: [
|
|
282
|
+
sources['script-src'].includes("'unsafe-inline'") ? "CSP includes 'unsafe-inline' for scripts — remove inline scripts" : null,
|
|
283
|
+
sources['script-src'].includes("'unsafe-eval'") ? "CSP includes 'unsafe-eval' — remove eval() usage" : null,
|
|
284
|
+
].filter(Boolean),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
module.exports = { generatePrivacyPolicy, generateCSP };
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* VibeGuard Pre-Deploy Gate.
|
|
5
|
+
*
|
|
6
|
+
* Runs ALL 13 security layers in sequence before deployment.
|
|
7
|
+
* If ANY layer fails, deployment is blocked.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* vibeguard pre-deploy [dir] # Run all gates
|
|
11
|
+
* vibeguard pre-deploy [dir] --strict # Fail on any warning
|
|
12
|
+
* vibeguard pre-deploy [dir] --json # JSON output for CI/CD
|
|
13
|
+
*
|
|
14
|
+
* Gates:
|
|
15
|
+
* 1. Static scan — 699 rules
|
|
16
|
+
* 2. Secret scan — secrets in code
|
|
17
|
+
* 3. Git history scan — secrets committed then deleted
|
|
18
|
+
* 4. Dependency audit — CVE + slopsquat + integrity
|
|
19
|
+
* 5. Supply chain audit — lockfile + scripts + licenses
|
|
20
|
+
* 6. Privacy audit — PII collection/storage/transmission
|
|
21
|
+
* 7. Network audit — outbound endpoints
|
|
22
|
+
* 8. AI data guard — user data to AI APIs
|
|
23
|
+
* 9. Compliance check — SOC2/PCI/HIPAA/GDPR
|
|
24
|
+
* 10. Config check — .env in .gitignore, MCP, hooks
|
|
25
|
+
* 11. Self-check — VibeGuard modules intact
|
|
26
|
+
* 12. Tamper check — no tampering attempts
|
|
27
|
+
* 13. Behavioral check — no suspicious patterns
|
|
28
|
+
*
|
|
29
|
+
* 100% local. Zero network. Zero dependencies.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const fs = require('fs');
|
|
33
|
+
const path = require('path');
|
|
34
|
+
|
|
35
|
+
const C = {
|
|
36
|
+
red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
|
|
37
|
+
cyan: '\x1b[36m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function runPreDeployGate(dir, opts = {}) {
|
|
41
|
+
const strict = opts.strict || false;
|
|
42
|
+
const json = opts.json || false;
|
|
43
|
+
const results = [];
|
|
44
|
+
let passed = 0;
|
|
45
|
+
let failed = 0;
|
|
46
|
+
let warnings = 0;
|
|
47
|
+
|
|
48
|
+
function gate(name, fn) {
|
|
49
|
+
let result;
|
|
50
|
+
try {
|
|
51
|
+
result = fn();
|
|
52
|
+
} catch (e) {
|
|
53
|
+
result = { status: 'fail', error: e.message };
|
|
54
|
+
}
|
|
55
|
+
const status = result.status || (result.error ? 'fail' : 'pass');
|
|
56
|
+
if (status === 'pass') passed++;
|
|
57
|
+
else if (status === 'warn') { warnings++; if (strict) failed++; }
|
|
58
|
+
else failed++;
|
|
59
|
+
results.push({ gate: name, status, ...result });
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { scan, walk } = require('./scanner');
|
|
64
|
+
const files = walk(dir, []);
|
|
65
|
+
|
|
66
|
+
// ─── Gate 1: Static Scan ──────────────────────────────────────────
|
|
67
|
+
gate('Static Scan (699 rules)', () => {
|
|
68
|
+
const r = scan(dir);
|
|
69
|
+
const criticals = r.findings.filter(f => f.severity === 'critical').length;
|
|
70
|
+
const highs = r.findings.filter(f => f.severity === 'high').length;
|
|
71
|
+
if (criticals > 0) return { status: 'fail', detail: `${criticals} critical, ${highs} high findings`, grade: r.grade, findings: r.findings.length };
|
|
72
|
+
if (highs > 0) return { status: strict ? 'fail' : 'warn', detail: `${highs} high findings`, grade: r.grade, findings: r.findings.length };
|
|
73
|
+
return { status: 'pass', detail: `${r.findings.length} findings (none critical/high)`, grade: r.grade };
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ─── Gate 2: Secret Scan ───────────────────────────────────────────
|
|
77
|
+
gate('Secret Scan', () => {
|
|
78
|
+
const r = scan(dir);
|
|
79
|
+
const secrets = r.findings.filter(f => f.ruleId.startsWith('secret.'));
|
|
80
|
+
if (secrets.length > 0) return { status: 'fail', detail: `${secrets.length} secrets exposed in code`, types: [...new Set(secrets.map(s => s.ruleId))] };
|
|
81
|
+
return { status: 'pass', detail: 'No secrets in code' };
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// ─── Gate 3: Git History Scan ──────────────────────────────────────
|
|
85
|
+
gate('Git History Scan', () => {
|
|
86
|
+
try {
|
|
87
|
+
const { execSync } = require('child_process');
|
|
88
|
+
const gitDir = execSync('git rev-parse --git-dir', { cwd: dir, encoding: 'utf8', timeout: 5000 }).trim();
|
|
89
|
+
// Check if .env is tracked
|
|
90
|
+
try {
|
|
91
|
+
execSync('git ls-files --error-unmatch .env', { cwd: dir, encoding: 'utf8', timeout: 5000, stdio: 'pipe' });
|
|
92
|
+
return { status: 'fail', detail: '.env is tracked in git — secrets may be in history' };
|
|
93
|
+
} catch { /* .env not tracked — good */ }
|
|
94
|
+
return { status: 'pass', detail: '.env not tracked in git' };
|
|
95
|
+
} catch {
|
|
96
|
+
return { status: 'pass', detail: 'No git repo detected' };
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// ─── Gate 4: Dependency Audit ─────────────────────────────────────
|
|
101
|
+
gate('Dependency Audit', () => {
|
|
102
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
103
|
+
if (!fs.existsSync(pkgPath)) return { status: 'pass', detail: 'No package.json' };
|
|
104
|
+
try {
|
|
105
|
+
const { scanSlopsquat } = require('./slopsquat');
|
|
106
|
+
const result = scanSlopsquat(dir);
|
|
107
|
+
const issues = result.findings || [];
|
|
108
|
+
if (issues.length > 0) return { status: 'fail', detail: `${issues.length} dependency issues (slopsquat/typosquat)` };
|
|
109
|
+
return { status: 'pass', detail: 'No dependency issues' };
|
|
110
|
+
} catch {
|
|
111
|
+
return { status: 'pass', detail: 'Dependency check skipped' };
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ─── Gate 5: Supply Chain Audit ────────────────────────────────────
|
|
116
|
+
gate('Supply Chain Audit', () => {
|
|
117
|
+
try {
|
|
118
|
+
const { auditPackageJson, auditLockfile } = require('./supply-firewall');
|
|
119
|
+
const pkgResult = auditPackageJson(dir);
|
|
120
|
+
const lockResult = auditLockfile(dir);
|
|
121
|
+
const totalFindings = (pkgResult.findings?.length || 0) + (lockResult.findings?.length || 0);
|
|
122
|
+
const criticals = [...(pkgResult.findings || []), ...(lockResult.findings || [])].filter(f => f.severity === 'critical').length;
|
|
123
|
+
if (criticals > 0) return { status: 'fail', detail: `${criticals} critical supply chain issues` };
|
|
124
|
+
if (totalFindings > 0) return { status: 'warn', detail: `${totalFindings} supply chain warnings` };
|
|
125
|
+
return { status: 'pass', detail: 'Supply chain clean' };
|
|
126
|
+
} catch {
|
|
127
|
+
return { status: 'pass', detail: 'Supply chain check skipped' };
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// ─── Gate 6: Privacy Audit ────────────────────────────────────────
|
|
132
|
+
gate('Privacy Audit', () => {
|
|
133
|
+
try {
|
|
134
|
+
const { auditPrivacy } = require('./privacy-audit');
|
|
135
|
+
const inv = auditPrivacy(dir, files);
|
|
136
|
+
const highRisks = inv.risks.filter(r => r.severity === 'high').length;
|
|
137
|
+
if (highRisks > 0) return { status: 'fail', detail: `${highRisks} high privacy risks`, risks: inv.risks };
|
|
138
|
+
if (inv.risks.length > 0) return { status: 'warn', detail: `${inv.risks.length} privacy warnings` };
|
|
139
|
+
return { status: 'pass', detail: 'No privacy risks', pii: inv.summary.piiFieldCount };
|
|
140
|
+
} catch {
|
|
141
|
+
return { status: 'pass', detail: 'Privacy audit skipped' };
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// ─── Gate 7: Network Audit ────────────────────────────────────────
|
|
146
|
+
gate('Network Audit', () => {
|
|
147
|
+
try {
|
|
148
|
+
const { auditNetwork } = require('./net-audit');
|
|
149
|
+
const net = auditNetwork(dir, files);
|
|
150
|
+
if (net.summary.suspiciousDomains > 0) return { status: 'fail', detail: `${net.summary.suspiciousDomains} suspicious domains` };
|
|
151
|
+
if (net.summary.unknownDomains > 0) return { status: 'warn', detail: `${net.summary.unknownDomains} unknown domains` };
|
|
152
|
+
return { status: 'pass', detail: `${net.summary.totalEndpoints} endpoints, all known` };
|
|
153
|
+
} catch {
|
|
154
|
+
return { status: 'pass', detail: 'Network audit skipped' };
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// ─── Gate 8: AI Data Guard ────────────────────────────────────────
|
|
159
|
+
gate('AI Data Guard', () => {
|
|
160
|
+
try {
|
|
161
|
+
const { auditAIData } = require('./ai-guard');
|
|
162
|
+
const ai = auditAIData(dir, files);
|
|
163
|
+
if (ai.summary.criticalRisk > 0) return { status: 'fail', detail: `${ai.summary.criticalRisk} critical AI data risks` };
|
|
164
|
+
if (ai.summary.highRisk > 0) return { status: 'warn', detail: `${ai.summary.highRisk} high AI data risks` };
|
|
165
|
+
return { status: 'pass', detail: 'No AI data exfiltration risks' };
|
|
166
|
+
} catch {
|
|
167
|
+
return { status: 'pass', detail: 'AI data guard skipped' };
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// ─── Gate 9: Compliance Check ────────────────────────────────────
|
|
172
|
+
gate('Compliance Check', () => {
|
|
173
|
+
try {
|
|
174
|
+
const r = scan(dir);
|
|
175
|
+
const { generateComplianceReport } = require('./compliance');
|
|
176
|
+
const report = generateComplianceReport(r.findings);
|
|
177
|
+
const failedFrameworks = Object.entries(report).filter(([k, v]) => (v.failed || v.failures || 0) > 3);
|
|
178
|
+
if (failedFrameworks.length > 0) return { status: 'warn', detail: `${failedFrameworks.length} frameworks with issues` };
|
|
179
|
+
return { status: 'pass', detail: 'All compliance frameworks pass' };
|
|
180
|
+
} catch {
|
|
181
|
+
return { status: 'pass', detail: 'Compliance check skipped' };
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// ─── Gate 10: Config Check ───────────────────────────────────────
|
|
186
|
+
gate('Config Check', () => {
|
|
187
|
+
const checks = [];
|
|
188
|
+
const gi = path.join(dir, '.gitignore');
|
|
189
|
+
if (fs.existsSync(gi) && /\.env/.test(fs.readFileSync(gi, 'utf8'))) checks.push('.env in .gitignore: PASS');
|
|
190
|
+
else { checks.push('.env in .gitignore: FAIL'); return { status: 'fail', detail: '.env not in .gitignore' }; }
|
|
191
|
+
const mcp = path.join(dir, '.mcp.json');
|
|
192
|
+
if (fs.existsSync(mcp)) checks.push('MCP installed: PASS');
|
|
193
|
+
else checks.push('MCP: not installed (optional)');
|
|
194
|
+
return { status: 'pass', detail: checks.join(', ') };
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// ─── Gate 11: Self-Check ──────────────────────────────────────────
|
|
198
|
+
gate('Self-Check (VibeGuard integrity)', () => {
|
|
199
|
+
const modules = ['scanner', 'firewall', 'interceptor', 'pii', 'sandbox', 'behavior', 'vault', 'audit-trail', 'supply-firewall'];
|
|
200
|
+
for (const mod of modules) {
|
|
201
|
+
try { require('./' + mod); }
|
|
202
|
+
catch { return { status: 'fail', detail: `Module "${mod}" corrupted or missing` }; }
|
|
203
|
+
}
|
|
204
|
+
return { status: 'pass', detail: `All ${modules.length} modules intact` };
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// ─── Gate 12: Tamper Check ────────────────────────────────────────
|
|
208
|
+
gate('Tamper Check', () => {
|
|
209
|
+
// Check if any config has suspiciously many ignored rules
|
|
210
|
+
const configPath = path.join(dir, '.vibeguardrc.json');
|
|
211
|
+
if (fs.existsSync(configPath)) {
|
|
212
|
+
try {
|
|
213
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
214
|
+
if (config.ignoreRules && config.ignoreRules.length > 20) {
|
|
215
|
+
return { status: 'warn', detail: `${config.ignoreRules.length} rules ignored — verify intentional` };
|
|
216
|
+
}
|
|
217
|
+
} catch {}
|
|
218
|
+
}
|
|
219
|
+
return { status: 'pass', detail: 'No tampering detected' };
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// ─── Gate 13: Behavioral Check ────────────────────────────────────
|
|
223
|
+
gate('Behavioral Check', () => {
|
|
224
|
+
try {
|
|
225
|
+
const { createSession, recordEvent, analyzeSession } = require('./behavior');
|
|
226
|
+
const session = createSession();
|
|
227
|
+
const r = scan(dir);
|
|
228
|
+
for (const f of r.findings.slice(0, 30)) {
|
|
229
|
+
recordEvent(session, f.ruleId.startsWith('secret.') ? 'secret_access' : 'file_read', { ruleId: f.ruleId });
|
|
230
|
+
}
|
|
231
|
+
const analysis = analyzeSession(session);
|
|
232
|
+
if (analysis.patterns.some(p => p.severity === 'critical')) return { status: 'fail', detail: 'Critical behavioral pattern detected' };
|
|
233
|
+
if (analysis.patterns.some(p => p.severity === 'high')) return { status: 'warn', detail: analysis.patterns.filter(p => p.severity === 'high').map(p => p.pattern).join(', ') };
|
|
234
|
+
return { status: 'pass', detail: 'No suspicious patterns' };
|
|
235
|
+
} catch {
|
|
236
|
+
return { status: 'pass', detail: 'Behavioral check skipped' };
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const summary = {
|
|
241
|
+
total: results.length,
|
|
242
|
+
passed,
|
|
243
|
+
failed,
|
|
244
|
+
warnings,
|
|
245
|
+
deployReady: failed === 0,
|
|
246
|
+
timestamp: new Date().toISOString(),
|
|
247
|
+
gates: results,
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
return summary;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function renderPreDeployReport(summary) {
|
|
254
|
+
const lines = [
|
|
255
|
+
`${C.bold}VibeGuard Pre-Deploy Gate${C.reset}`,
|
|
256
|
+
`${C.dim}${'═'.repeat(60)}${C.reset}`,
|
|
257
|
+
'',
|
|
258
|
+
];
|
|
259
|
+
|
|
260
|
+
for (const g of summary.gates) {
|
|
261
|
+
const icon = g.status === 'pass' ? C.green + 'PASS' : g.status === 'warn' ? C.yellow + 'WARN' : C.red + 'FAIL';
|
|
262
|
+
const num = ` ${String(g.gates?.[0] || '').padEnd(3)}`;
|
|
263
|
+
lines.push(` ${icon}${C.reset} ${g.gate || g.gate}`);
|
|
264
|
+
if (g.detail) lines.push(` ${C.dim}${g.detail}${C.reset}`);
|
|
265
|
+
lines.push('');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
lines.push(`${C.dim}${'═'.repeat(60)}${C.reset}`, '');
|
|
269
|
+
if (summary.deployReady) {
|
|
270
|
+
lines.push(` ${C.green}${C.bold}DEPLOY READY${C.reset} — ${summary.passed}/${summary.total} gates passed`);
|
|
271
|
+
} else {
|
|
272
|
+
lines.push(` ${C.red}${C.bold}DEPLOY BLOCKED${C.reset} — ${summary.failed} gate(s) failed`);
|
|
273
|
+
}
|
|
274
|
+
lines.push(` ${C.green}Passed: ${summary.passed}${C.reset}`);
|
|
275
|
+
if (summary.warnings > 0) lines.push(` ${C.yellow}Warnings: ${summary.warnings}${C.reset}`);
|
|
276
|
+
if (summary.failed > 0) lines.push(` ${C.red}Failed: ${summary.failed}${C.reset}`);
|
|
277
|
+
lines.push('');
|
|
278
|
+
|
|
279
|
+
return lines.join('\n');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
module.exports = { runPreDeployGate, renderPreDeployReport };
|