@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.
Files changed (52) hide show
  1. package/README.md +600 -0
  2. package/bin/cli.js +1640 -0
  3. package/ci/vibeguard.yml +41 -0
  4. package/ci-templates/Jenkinsfile +26 -0
  5. package/ci-templates/azure-pipelines.yml +29 -0
  6. package/ci-templates/circleci.yml +24 -0
  7. package/ci-templates/gitlab.yml +19 -0
  8. package/hooks/pre-commit +31 -0
  9. package/package.json +94 -0
  10. package/src/ai-guard.js +205 -0
  11. package/src/ast.js +319 -0
  12. package/src/audit-trail.js +154 -0
  13. package/src/autofix.js +524 -0
  14. package/src/badge.js +42 -0
  15. package/src/behavior.js +205 -0
  16. package/src/compliance.js +151 -0
  17. package/src/crosstaint.js +324 -0
  18. package/src/cve-intel.js +136 -0
  19. package/src/dashboard.js +279 -0
  20. package/src/deps.js +159 -0
  21. package/src/doctor.js +111 -0
  22. package/src/engine.js +234 -0
  23. package/src/external.js +160 -0
  24. package/src/firewall.js +517 -0
  25. package/src/history.js +87 -0
  26. package/src/hook.js +151 -0
  27. package/src/install.js +248 -0
  28. package/src/interceptor.js +476 -0
  29. package/src/mcp-server.js +1804 -0
  30. package/src/net-audit.js +208 -0
  31. package/src/pii.js +212 -0
  32. package/src/plugin.js +80 -0
  33. package/src/policy-gen.js +288 -0
  34. package/src/pre-deploy.js +282 -0
  35. package/src/presets.js +113 -0
  36. package/src/privacy-audit.js +273 -0
  37. package/src/repl.js +150 -0
  38. package/src/report.js +312 -0
  39. package/src/rules-pack.js +2753 -0
  40. package/src/rules.js +1446 -0
  41. package/src/sandbox.js +139 -0
  42. package/src/scanner.js +651 -0
  43. package/src/secure-prompt.js +140 -0
  44. package/src/slopsquat.js +144 -0
  45. package/src/supply-firewall.js +243 -0
  46. package/src/suppress.js +89 -0
  47. package/src/taint.js +168 -0
  48. package/src/trace.js +220 -0
  49. package/src/urlscan.js +142 -0
  50. package/src/vault.js +145 -0
  51. package/src/verify.js +98 -0
  52. package/src/verifykeys.js +87 -0
package/src/verify.js ADDED
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * The fix -> verify loop.
5
+ *
6
+ * `scan` can drop a baseline file. `verify` re-scans and reports, per baseline
7
+ * finding, whether it is RESOLVED or STILL PRESENT, plus any NEW issues.
8
+ *
9
+ * Matching is intentionally forgiving on line numbers: after an edit, lines
10
+ * shift. We key primarily on (ruleId + file + snippet), then fall back to
11
+ * (ruleId + file).
12
+ */
13
+
14
+ const fs = require('fs');
15
+ const path = require('path');
16
+ const { scan } = require('./scanner');
17
+
18
+ const BASELINE_NAME = '.vibeguard-baseline.json';
19
+
20
+ function baselinePath(root) {
21
+ return path.join(path.resolve(root), BASELINE_NAME);
22
+ }
23
+
24
+ function writeBaseline(root, result) {
25
+ const data = {
26
+ generatedAt: result.generatedAt,
27
+ grade: result.grade,
28
+ counts: result.counts,
29
+ findings: result.findings,
30
+ };
31
+ fs.writeFileSync(baselinePath(root), JSON.stringify(data, null, 2));
32
+ return baselinePath(root);
33
+ }
34
+
35
+ function readBaseline(root) {
36
+ try {
37
+ return JSON.parse(fs.readFileSync(baselinePath(root), 'utf8'));
38
+ } catch {
39
+ return null;
40
+ }
41
+ }
42
+
43
+ // Stable identity for a finding across edits.
44
+ function fingerprint(f) {
45
+ return `${f.ruleId}::${f.file}::${(f.snippet || '').trim()}`;
46
+ }
47
+ function looseKey(f) {
48
+ return `${f.ruleId}::${f.file}`;
49
+ }
50
+
51
+ /**
52
+ * Re-scan and diff against baseline (if present).
53
+ * If no baseline exists, we treat the *current* scan as the reference and just
54
+ * report current state (still useful in CI right after a fix).
55
+ */
56
+ function verify(root, opts = {}) {
57
+ const baseline = readBaseline(root);
58
+ const current = scan(root, opts);
59
+
60
+ const currentFP = new Set(current.findings.map(fingerprint));
61
+ const currentLoose = new Set(current.findings.map(looseKey));
62
+
63
+ if (!baseline) {
64
+ return {
65
+ hasBaseline: false,
66
+ current,
67
+ resolved: [],
68
+ remaining: current.findings,
69
+ introduced: [],
70
+ };
71
+ }
72
+
73
+ const resolved = [];
74
+ const remaining = [];
75
+ for (const f of baseline.findings) {
76
+ const stillExact = currentFP.has(fingerprint(f));
77
+ const stillLoose = currentLoose.has(looseKey(f));
78
+ if (stillExact || stillLoose) remaining.push(f);
79
+ else resolved.push(f);
80
+ }
81
+
82
+ // New issues introduced since baseline (e.g. a bad "fix").
83
+ const baseLoose = new Set(baseline.findings.map(looseKey));
84
+ const baseFP = new Set(baseline.findings.map(fingerprint));
85
+ const introduced = current.findings.filter(
86
+ (f) => !baseFP.has(fingerprint(f)) && !baseLoose.has(looseKey(f))
87
+ );
88
+
89
+ return { hasBaseline: true, baseline, current, resolved, remaining, introduced };
90
+ }
91
+
92
+ module.exports = {
93
+ verify,
94
+ writeBaseline,
95
+ readBaseline,
96
+ baselinePath,
97
+ BASELINE_NAME,
98
+ };
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * Opt-in live-key verification (`--verify-keys`).
5
+ *
6
+ * For a few providers, confirm whether a found key is ACTIVE by making a cheap,
7
+ * read-only API call. This turns "looks like a secret" into "confirmed live
8
+ * secret" — the difference between a warning and an emergency.
9
+ *
10
+ * SECURITY / PRIVACY: this sends the key to the provider that already owns it
11
+ * (nowhere else). It is OFF by default and only runs on explicit --verify-keys.
12
+ * Findings store a redacted snippet, so we re-read the file to get the raw value.
13
+ */
14
+
15
+ const fs = require('fs');
16
+ const path = require('path');
17
+
18
+ // ruleId -> { extract regex, verify(key) -> Promise<'live'|'inactive'|'unknown'> }
19
+ const PROVIDERS = {
20
+ 'secret.openai-key': {
21
+ extract: /\bsk-(?!ant-)(?:proj-)?[A-Za-z0-9_\-]{20,}\b/,
22
+ async verify(key) {
23
+ return probe('https://api.openai.com/v1/models', { authorization: `Bearer ${key}` });
24
+ },
25
+ },
26
+ 'secret.stripe-live-key': {
27
+ extract: /\b(?:sk|rk)_live_[A-Za-z0-9]{16,}\b/,
28
+ async verify(key) {
29
+ return probe('https://api.stripe.com/v1/balance', { authorization: `Bearer ${key}` });
30
+ },
31
+ },
32
+ };
33
+
34
+ async function probe(url, headers) {
35
+ const controller = new AbortController();
36
+ const t = setTimeout(() => controller.abort(), 8000);
37
+ try {
38
+ const res = await fetch(url, { headers, signal: controller.signal });
39
+ clearTimeout(t);
40
+ if (res.status === 200) return 'live';
41
+ if (res.status === 401 || res.status === 403) return 'inactive';
42
+ return 'unknown';
43
+ } catch {
44
+ clearTimeout(t);
45
+ return 'unknown';
46
+ }
47
+ }
48
+
49
+ function extractRaw(root, finding, re) {
50
+ try {
51
+ const lines = fs.readFileSync(path.join(root, finding.file), 'utf8').split(/\r?\n/);
52
+ const line = lines[finding.line - 1] || '';
53
+ const m = re.exec(line);
54
+ return m ? m[0] : null;
55
+ } catch {
56
+ return null;
57
+ }
58
+ }
59
+
60
+ // Annotate findings in place with a `verified` field. Returns the count of live keys.
61
+ async function verifyKeys(root, findings) {
62
+ let liveCount = 0;
63
+ const tasks = [];
64
+ for (const f of findings) {
65
+ const provider = PROVIDERS[f.ruleId];
66
+ if (!provider) continue;
67
+ const raw = extractRaw(root, f, provider.extract);
68
+ if (!raw) {
69
+ f.verified = 'unknown';
70
+ continue;
71
+ }
72
+ tasks.push(
73
+ provider.verify(raw).then((status) => {
74
+ f.verified = status;
75
+ if (status === 'live') {
76
+ liveCount++;
77
+ f.message = 'CONFIRMED LIVE — ' + f.message;
78
+ f.severity = 'critical';
79
+ }
80
+ })
81
+ );
82
+ }
83
+ await Promise.all(tasks);
84
+ return liveCount;
85
+ }
86
+
87
+ module.exports = { verifyKeys, PROVIDERS };