@yagyeshvyas/vibeguard 0.1.0 → 1.0.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/CHANGELOG.md +63 -0
- package/README.md +302 -31
- package/bin/cli.js +318 -4
- package/package.json +14 -11
- package/src/ast.js +4 -0
- package/src/auto.js +422 -0
- package/src/crosstaint.js +154 -9
- package/src/daemon-run.js +12 -0
- package/src/daemon.js +342 -0
- package/src/guard.js +80 -0
- package/src/mcp-server.js +0 -5
- package/src/rules-pack.js +112 -12
- package/src/rules.js +11 -6
- package/src/scanner.js +36 -2
- package/src/shell-guard.js +276 -0
- package/src/shell-hook.ps1 +135 -0
- package/src/shell-hook.sh +90 -0
- package/src/suppress.js +78 -8
- package/src/taint-ast.js +852 -0
- package/src/taint.js +38 -12
package/bin/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ const {
|
|
|
23
23
|
} = require('../src/report');
|
|
24
24
|
|
|
25
25
|
// Flags that take a value (support both --flag=value and --flag value).
|
|
26
|
-
const VALUE_FLAGS = new Set(['fail-on', 'scope', 'focus', 'model', 'since', 'base', 'o', 'output', 'file', 'types']);
|
|
26
|
+
const VALUE_FLAGS = new Set(['fail-on', 'scope', 'focus', 'model', 'since', 'base', 'o', 'output', 'file', 'types', 'min-confidence']);
|
|
27
27
|
|
|
28
28
|
function parseArgs(argv) {
|
|
29
29
|
const args = { _: [], flags: {} };
|
|
@@ -114,6 +114,13 @@ Usage:
|
|
|
114
114
|
vibeguard preset --list List all available presets.
|
|
115
115
|
vibeguard redact "<text>" Redact personal data (email/SSN/card/phone/…) from text.
|
|
116
116
|
vibeguard detect-pii "<text>" List personal data found in text (no redaction).
|
|
117
|
+
vibeguard guard "<cmd>" Check a single command for danger (pre-exec scan).
|
|
118
|
+
vibeguard install-shell-hook Install pre-exec hook into bash/zsh/PowerShell profile.
|
|
119
|
+
vibeguard uninstall-shell-hook Remove the VibeGuard shell hook.
|
|
120
|
+
vibeguard auto [dir] One command: install shell hook + start daemon + scan.
|
|
121
|
+
vibeguard auto-start [dir] Start background daemon (auto-scans on file change).
|
|
122
|
+
vibeguard auto-stop [dir] Stop the background daemon.
|
|
123
|
+
vibeguard auto-status [dir] Check if daemon is running and show stats.
|
|
117
124
|
|
|
118
125
|
Options:
|
|
119
126
|
--json Output machine-readable JSON.
|
|
@@ -129,6 +136,8 @@ Options:
|
|
|
129
136
|
--fail-on <level> (scan) Exit non-zero only at/above this severity (critical..low/none).
|
|
130
137
|
--precommit Exit non-zero only on CRITICAL findings (hook mode).
|
|
131
138
|
--no-summary Suppress the trailing summary line.
|
|
139
|
+
--min-confidence <level> Show only findings at or above confidence (low|medium|high).
|
|
140
|
+
--show-suppressed Include inline-suppressed findings in output (annotated).
|
|
132
141
|
--patch Output findings as a unified diff (git-apply format).
|
|
133
142
|
-o, --output <file> (html) Output file path for HTML report.
|
|
134
143
|
-h, --help Show this help.
|
|
@@ -167,6 +176,28 @@ function cmdScan(dir, flags) {
|
|
|
167
176
|
deps: flags.deps !== false && !flags['no-deps'],
|
|
168
177
|
deep: !!flags.deep,
|
|
169
178
|
});
|
|
179
|
+
|
|
180
|
+
// --min-confidence: filter out findings below the threshold.
|
|
181
|
+
const CONFIDENCE_ORDER = { low: 0, medium: 1, high: 2 };
|
|
182
|
+
if (flags['min-confidence']) {
|
|
183
|
+
const threshold = CONFIDENCE_ORDER[String(flags['min-confidence']).toLowerCase()];
|
|
184
|
+
if (threshold !== undefined) {
|
|
185
|
+
result.findings = result.findings.filter((f) => {
|
|
186
|
+
const fc = CONFIDENCE_ORDER[f.confidence] || 0;
|
|
187
|
+
return fc >= threshold;
|
|
188
|
+
});
|
|
189
|
+
const { computeGrade } = require('../src/scanner');
|
|
190
|
+
const g = computeGrade(result.findings);
|
|
191
|
+
result.grade = g.grade;
|
|
192
|
+
result.counts = g.counts;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// --show-suppressed: re-add suppressed findings (annotated) to the output.
|
|
197
|
+
if (flags['show-suppressed'] && result.suppressedFindings) {
|
|
198
|
+
result.findings = result.findings.concat(result.suppressedFindings);
|
|
199
|
+
}
|
|
200
|
+
|
|
170
201
|
// --new-only: report only findings not present in the saved baseline.
|
|
171
202
|
if (flags['new-only']) {
|
|
172
203
|
const { readBaseline } = require('../src/verify');
|
|
@@ -622,14 +653,14 @@ async function main() {
|
|
|
622
653
|
const cmd = args._[0] || 'scan';
|
|
623
654
|
const dir = args._[1] || '.';
|
|
624
655
|
|
|
625
|
-
const noDirCmds = new Set(['url', 'rules', 'explain', 'secure-prompt', 'redact', 'detect-pii', 'firewall', 'exfil-check', 'dep-firewall', 'sandbox', 'output-guard', 'vault', 'audit-trail', 'why']);
|
|
656
|
+
const noDirCmds = new Set(['url', 'rules', 'explain', 'secure-prompt', 'redact', 'detect-pii', 'firewall', 'exfil-check', 'dep-firewall', 'sandbox', 'output-guard', 'vault', 'audit-trail', 'why', 'guard', 'install-shell-hook', 'uninstall-shell-hook', 'auto-start', 'auto-stop', 'auto-status', 'auto']);
|
|
626
657
|
if (!noDirCmds.has(cmd) && !fs.existsSync(dir)) {
|
|
627
658
|
process.stderr.write(`error: directory not found: ${dir}\n`);
|
|
628
659
|
process.exit(2);
|
|
629
660
|
}
|
|
630
661
|
|
|
631
662
|
// MCP server mode: hand off to the server (it runs until stdin closes).
|
|
632
|
-
// This is what `npx -y
|
|
663
|
+
// This is what `npx -y vibeguard mcp` starts inside Claude Code / Cursor / etc.
|
|
633
664
|
if (cmd === 'mcp') {
|
|
634
665
|
require('../src/mcp-server.js');
|
|
635
666
|
return; // do NOT process.exit — the server owns the process lifetime
|
|
@@ -739,6 +770,13 @@ async function main() {
|
|
|
739
770
|
else if (cmd === 'pre-deploy') code = cmdPreDeploy(dir, flags);
|
|
740
771
|
else if (cmd === 'redact') code = cmdRedact(args, flags);
|
|
741
772
|
else if (cmd === 'detect-pii') code = cmdDetectPII(args, flags);
|
|
773
|
+
else if (cmd === 'guard') code = cmdGuard(args, flags);
|
|
774
|
+
else if (cmd === 'install-shell-hook') code = cmdInstallShellHook(flags);
|
|
775
|
+
else if (cmd === 'uninstall-shell-hook') code = cmdUninstallShellHook(flags);
|
|
776
|
+
else if (cmd === 'auto') code = cmdAutoUnified(dir, args, flags);
|
|
777
|
+
else if (cmd === 'auto-start') code = cmdAutoStart(dir, flags);
|
|
778
|
+
else if (cmd === 'auto-stop') code = cmdAutoStop(dir, flags);
|
|
779
|
+
else if (cmd === 'auto-status') code = cmdAutoStatus(dir, flags);
|
|
742
780
|
else {
|
|
743
781
|
process.stderr.write(`unknown command: ${cmd}\n`);
|
|
744
782
|
printHelp();
|
|
@@ -972,7 +1010,7 @@ Before writing code, verify against these rules:
|
|
|
972
1010
|
- Never pass user input to exec() or spawn() without sanitization
|
|
973
1011
|
- For AI agents: add maxSteps, sandbox file access, allowlist commands
|
|
974
1012
|
- For AI prompts: never put user input in the system prompt
|
|
975
|
-
- Run: npx
|
|
1013
|
+
- Run: npx vibeguard scan . before committing
|
|
976
1014
|
|
|
977
1015
|
Tracked by: vibeguard scan --precommit (blocks on CRITICAL)
|
|
978
1016
|
`;
|
|
@@ -1634,6 +1672,282 @@ function cmdPRComment(dir, flags) {
|
|
|
1634
1672
|
return result.findings.length > 0 ? 1 : 0;
|
|
1635
1673
|
}
|
|
1636
1674
|
|
|
1675
|
+
function cmdGuard(args, flags) {
|
|
1676
|
+
const { checkCommand } = require('../src/shell-guard');
|
|
1677
|
+
const cmd = args._.slice(1).join(' ');
|
|
1678
|
+
if (!cmd) {
|
|
1679
|
+
process.stderr.write('Usage: vibeguard guard "<command>"\n');
|
|
1680
|
+
process.stderr.write('Checks a command for danger before execution.\n');
|
|
1681
|
+
process.stderr.write('Exit 0 = safe, exit 1 = blocked, exit 2 = error.\n');
|
|
1682
|
+
return 2;
|
|
1683
|
+
}
|
|
1684
|
+
const result = checkCommand(cmd);
|
|
1685
|
+
if (flags.json) {
|
|
1686
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
1687
|
+
} else if (result.blocked) {
|
|
1688
|
+
process.stdout.write(`\n ${C.red}[VibeGuard] BLOCKED:${C.reset} ${C.bold}${result.command}${C.reset}\n`);
|
|
1689
|
+
process.stdout.write(` ${C.red}Reason:${C.reset} ${result.reason}\n`);
|
|
1690
|
+
process.stdout.write(` ${C.red}Severity:${C.reset} ${result.severity}\n`);
|
|
1691
|
+
if (result.violations.length > 1) {
|
|
1692
|
+
process.stdout.write(` ${C.red}All violations:${C.reset}\n`);
|
|
1693
|
+
for (const v of result.violations) {
|
|
1694
|
+
process.stdout.write(` - [${v.severity}] ${v.type}: ${v.reason}\n`);
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
process.stdout.write(`\n ${C.dim}Override: VG_OVERRIDE=1 <command>${C.reset}\n\n`);
|
|
1698
|
+
} else {
|
|
1699
|
+
process.stdout.write(`${C.green}[VibeGuard] Safe:${C.reset} ${cmd.slice(0, 100)}\n`);
|
|
1700
|
+
}
|
|
1701
|
+
return result.blocked ? 1 : 0;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
function cmdInstallShellHook(flags) {
|
|
1705
|
+
const fs = require('fs');
|
|
1706
|
+
const os = require('os');
|
|
1707
|
+
const path = require('path');
|
|
1708
|
+
const srcDir = path.resolve(__dirname, '..', 'src');
|
|
1709
|
+
const home = os.homedir();
|
|
1710
|
+
const results = [];
|
|
1711
|
+
|
|
1712
|
+
// Detect shells and install
|
|
1713
|
+
// 1. bash
|
|
1714
|
+
const bashProfile = path.join(home, '.bashrc');
|
|
1715
|
+
const bashMarker = '# >>> VibeGuard shell hook >>>';
|
|
1716
|
+
const bashEndMarker = '# <<< VibeGuard shell hook <<<';
|
|
1717
|
+
const bashHook = [
|
|
1718
|
+
bashMarker,
|
|
1719
|
+
`source "${path.join(srcDir, 'shell-hook.sh')}"`,
|
|
1720
|
+
bashEndMarker,
|
|
1721
|
+
].join('\n');
|
|
1722
|
+
|
|
1723
|
+
try {
|
|
1724
|
+
let content = fs.existsSync(bashProfile) ? fs.readFileSync(bashProfile, 'utf8') : '';
|
|
1725
|
+
// Remove old hook
|
|
1726
|
+
content = content.replace(new RegExp(`${bashMarker}[\\s\\S]*?${bashEndMarker}\\n?`, 'g'), '');
|
|
1727
|
+
content = content.trimEnd() + '\n' + bashHook + '\n';
|
|
1728
|
+
fs.writeFileSync(bashProfile, content);
|
|
1729
|
+
results.push(`bash: installed in ${bashProfile}`);
|
|
1730
|
+
} catch (e) {
|
|
1731
|
+
results.push(`bash: failed (${e.message})`);
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
// 2. zsh
|
|
1735
|
+
const zshProfile = path.join(home, '.zshrc');
|
|
1736
|
+
try {
|
|
1737
|
+
let content = fs.existsSync(zshProfile) ? fs.readFileSync(zshProfile, 'utf8') : '';
|
|
1738
|
+
content = content.replace(new RegExp(`${bashMarker}[\\s\\S]*?${bashEndMarker}\\n?`, 'g'), '');
|
|
1739
|
+
content = content.trimEnd() + '\n' + bashHook + '\n';
|
|
1740
|
+
fs.writeFileSync(zshProfile, content);
|
|
1741
|
+
results.push(`zsh: installed in ${zshProfile}`);
|
|
1742
|
+
} catch (e) {
|
|
1743
|
+
results.push(`zsh: failed (${e.message})`);
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
// 3. PowerShell (Windows)
|
|
1747
|
+
if (process.platform === 'win32') {
|
|
1748
|
+
try {
|
|
1749
|
+
const psProfileDir = path.join(home, 'Documents', 'WindowsPowerShell');
|
|
1750
|
+
if (!fs.existsSync(psProfileDir)) fs.mkdirSync(psProfileDir, { recursive: true });
|
|
1751
|
+
const psProfile = path.join(psProfileDir, 'Microsoft.PowerShell_profile.ps1');
|
|
1752
|
+
const psMarker = '### >>> VibeGuard shell hook >>>';
|
|
1753
|
+
const psEndMarker = '### <<< VibeGuard shell hook <<<';
|
|
1754
|
+
let content = fs.existsSync(psProfile) ? fs.readFileSync(psProfile, 'utf8') : '';
|
|
1755
|
+
content = content.replace(new RegExp(`${psMarker}[\\s\\S]*?${psEndMarker}\\n?`, 'g'), '');
|
|
1756
|
+
const psHook = [
|
|
1757
|
+
psMarker,
|
|
1758
|
+
`$VG_SCRIPT_DIR = "${srcDir.replace(/\\/g, '\\\\')}"`,
|
|
1759
|
+
`. "${path.join(srcDir, 'shell-hook.ps1').replace(/\\/g, '\\\\')}"`,
|
|
1760
|
+
psEndMarker,
|
|
1761
|
+
].join('\n');
|
|
1762
|
+
content = content.trimEnd() + '\n' + psHook + '\n';
|
|
1763
|
+
fs.writeFileSync(psProfile, content);
|
|
1764
|
+
results.push(`powershell: installed in ${psProfile}`);
|
|
1765
|
+
} catch (e) {
|
|
1766
|
+
results.push(`powershell: failed (${e.message})`);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
// 4. Node.js guard info
|
|
1771
|
+
results.push(`node: use --require vibeguard/guard to protect any Node.js process`);
|
|
1772
|
+
|
|
1773
|
+
process.stdout.write(`\n${C.green}[VibeGuard] Shell hook installed:${C.reset}\n\n`);
|
|
1774
|
+
for (const r of results) {
|
|
1775
|
+
process.stdout.write(` ${C.bold}${r}${C.reset}\n`);
|
|
1776
|
+
}
|
|
1777
|
+
process.stdout.write(`\n${C.dim}Restart your shell for changes to take effect.${C.reset}\n`);
|
|
1778
|
+
process.stdout.write(`${C.dim}Override: set VG_OVERRIDE=1 to bypass for a single command.${C.reset}\n`);
|
|
1779
|
+
process.stdout.write(`${C.dim}Uninstall: vibeguard uninstall-shell-hook${C.reset}\n\n`);
|
|
1780
|
+
return 0;
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
function cmdUninstallShellHook(flags) {
|
|
1784
|
+
const fs = require('fs');
|
|
1785
|
+
const os = require('os');
|
|
1786
|
+
const path = require('path');
|
|
1787
|
+
const home = os.homedir();
|
|
1788
|
+
const results = [];
|
|
1789
|
+
const bashMarker = '# >>> VibeGuard shell hook >>>';
|
|
1790
|
+
const bashEndMarker = '# <<< VibeGuard shell hook <<<';
|
|
1791
|
+
const psMarker = '### >>> VibeGuard shell hook >>>';
|
|
1792
|
+
const psEndMarker = '### <<< VibeGuard shell hook <<<';
|
|
1793
|
+
|
|
1794
|
+
for (const profile of ['.bashrc', '.zshrc']) {
|
|
1795
|
+
const p = path.join(home, profile);
|
|
1796
|
+
try {
|
|
1797
|
+
if (fs.existsSync(p)) {
|
|
1798
|
+
let content = fs.readFileSync(p, 'utf8');
|
|
1799
|
+
content = content.replace(new RegExp(`${bashMarker}[\\s\\S]*?${bashEndMarker}\\n?`, 'g'), '');
|
|
1800
|
+
fs.writeFileSync(p, content);
|
|
1801
|
+
results.push(`${profile}: removed`);
|
|
1802
|
+
}
|
|
1803
|
+
} catch (e) {
|
|
1804
|
+
results.push(`${profile}: failed (${e.message})`);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
if (process.platform === 'win32') {
|
|
1809
|
+
try {
|
|
1810
|
+
const psProfile = path.join(home, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
1811
|
+
if (fs.existsSync(psProfile)) {
|
|
1812
|
+
let content = fs.readFileSync(psProfile, 'utf8');
|
|
1813
|
+
content = content.replace(new RegExp(`${psMarker}[\\s\\S]*?${psEndMarker}\\n?`, 'g'), '');
|
|
1814
|
+
fs.writeFileSync(psProfile, content);
|
|
1815
|
+
results.push('powershell: removed');
|
|
1816
|
+
}
|
|
1817
|
+
} catch (e) {
|
|
1818
|
+
results.push(`powershell: failed (${e.message})`);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
process.stdout.write(`\n${C.green}[VibeGuard] Shell hook removed:${C.reset}\n\n`);
|
|
1823
|
+
for (const r of results) {
|
|
1824
|
+
process.stdout.write(` ${C.bold}${r}${C.reset}\n`);
|
|
1825
|
+
}
|
|
1826
|
+
process.stdout.write(`\n${C.dim}Restart your shell for changes to take effect.${C.reset}\n\n`);
|
|
1827
|
+
return 0;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
// ─── unified auto: delegates to src/auto.js ────────────────────────────────
|
|
1831
|
+
|
|
1832
|
+
function cmdAutoUnified(dir, args, flags) {
|
|
1833
|
+
const auto = require('../src/auto');
|
|
1834
|
+
const rootDir = path.resolve(dir || '.');
|
|
1835
|
+
|
|
1836
|
+
// auto --stop
|
|
1837
|
+
if (flags.stop || (args._ && args._[1] === '--stop')) {
|
|
1838
|
+
const r = auto.autoStop(rootDir);
|
|
1839
|
+
if (!r.ok) {
|
|
1840
|
+
process.stdout.write(`${C.yellow}[VibeGuard] ${r.reason}${C.reset}\n`);
|
|
1841
|
+
return 0;
|
|
1842
|
+
}
|
|
1843
|
+
process.stdout.write(`${C.green}[VibeGuard] Auto protection stopped.${C.reset}\n\n`);
|
|
1844
|
+
for (const s of r.reversed) {
|
|
1845
|
+
process.stdout.write(` ${C.green}OK${C.reset} ${s}\n`);
|
|
1846
|
+
}
|
|
1847
|
+
process.stdout.write(`\n${C.dim}All hooks removed. Repo restored.${C.reset}\n`);
|
|
1848
|
+
return 0;
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
// auto --status
|
|
1852
|
+
if (flags.status || (args._ && args._[1] === '--status')) {
|
|
1853
|
+
const s = auto.autoStatus(rootDir);
|
|
1854
|
+
if (flags.json) {
|
|
1855
|
+
process.stdout.write(JSON.stringify(s, null, 2) + '\n');
|
|
1856
|
+
return 0;
|
|
1857
|
+
}
|
|
1858
|
+
if (!s.running) {
|
|
1859
|
+
process.stdout.write(`${C.dim}[VibeGuard] Not active${C.reset}\n`);
|
|
1860
|
+
process.stdout.write(`${C.dim}Run 'vibeguard auto' to start.${C.reset}\n`);
|
|
1861
|
+
return 0;
|
|
1862
|
+
}
|
|
1863
|
+
process.stdout.write(`${C.green}[VibeGuard] Active${C.reset}\n\n`);
|
|
1864
|
+
process.stdout.write(` ${C.bold}PID:${C.reset} ${s.pid}\n`);
|
|
1865
|
+
process.stdout.write(` ${C.bold}Daemon PID:${C.reset} ${s.daemonPid || 'n/a'} ${s.daemonAlive ? C.green + '(alive)' + C.reset : C.red + '(dead)' + C.reset}\n`);
|
|
1866
|
+
process.stdout.write(` ${C.bold}Started:${C.reset} ${s.startedAt}\n`);
|
|
1867
|
+
process.stdout.write(` ${C.bold}Uptime:${C.reset} ${Math.round(s.uptimeMs / 1000)}s\n`);
|
|
1868
|
+
process.stdout.write(` ${C.bold}Last scan:${C.reset} ${s.lastScan || 'n/a'}\n`);
|
|
1869
|
+
process.stdout.write(` ${C.bold}Findings:${C.reset} ${s.findingsSinceStart}\n\n`);
|
|
1870
|
+
process.stdout.write(` ${C.bold}Features:${C.reset}\n`);
|
|
1871
|
+
for (const [k, v] of Object.entries(s.features || {})) {
|
|
1872
|
+
process.stdout.write(` ${v ? C.green + 'ON' + C.reset : C.dim + 'OFF' + C.reset} ${k}\n`);
|
|
1873
|
+
}
|
|
1874
|
+
process.stdout.write(`\n ${C.dim}Stop: vibeguard auto --stop${C.reset}\n`);
|
|
1875
|
+
return 0;
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
// auto --ci (non-interactive pipeline mode)
|
|
1879
|
+
if (flags.ci) {
|
|
1880
|
+
const r = auto.autoCI(rootDir, { ci: true, strict: flags.strict, deep: flags.deep });
|
|
1881
|
+
if (r.ci) {
|
|
1882
|
+
for (const step of r.steps) {
|
|
1883
|
+
if (step.step === 'scan') {
|
|
1884
|
+
process.stdout.write(`Grade: ${step.grade} Critical: ${step.counts.critical || 0} High: ${step.counts.high || 0}\n`);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
return r.exitCode || 0;
|
|
1888
|
+
}
|
|
1889
|
+
process.stderr.write(`${C.red}[VibeGuard] CI mode failed${C.reset}\n`);
|
|
1890
|
+
return 2;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
// auto (full start)
|
|
1894
|
+
const opts = {
|
|
1895
|
+
fix: !!flags.fix,
|
|
1896
|
+
strict: !!flags.strict,
|
|
1897
|
+
noShell: !!flags['no-shell'],
|
|
1898
|
+
deep: !!flags.deep,
|
|
1899
|
+
verbose: !!flags.verbose,
|
|
1900
|
+
};
|
|
1901
|
+
|
|
1902
|
+
process.stdout.write(`\n${C.bold}${C.cyan}[VibeGuard] Activating full protection...${C.reset}\n\n`);
|
|
1903
|
+
|
|
1904
|
+
const r = auto.autoStart(rootDir, opts);
|
|
1905
|
+
if (!r.ok) {
|
|
1906
|
+
process.stderr.write(`${C.red}[VibeGuard] ${r.reason}${C.reset}\n`);
|
|
1907
|
+
return 2;
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
if (r.alreadyRunning) {
|
|
1911
|
+
process.stdout.write(`${C.yellow}[VibeGuard] Already active. Use 'vibeguard auto --status' for details.${C.reset}\n`);
|
|
1912
|
+
return 0;
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
// Print steps
|
|
1916
|
+
for (const step of r.steps) {
|
|
1917
|
+
const icon = step.error ? C.red + 'X' : C.green + 'OK';
|
|
1918
|
+
const name = step.step.padEnd(20);
|
|
1919
|
+
if (step.error) {
|
|
1920
|
+
process.stdout.write(` ${icon} ${name} ${C.red}${step.error}${C.reset}\n`);
|
|
1921
|
+
} else if (step.step === 'scan') {
|
|
1922
|
+
process.stdout.write(` ${icon} ${name} ${C.bold}Grade: ${step.grade}${C.reset} Critical: ${step.counts.critical || 0} High: ${step.counts.high || 0}${C.reset}\n`);
|
|
1923
|
+
} else {
|
|
1924
|
+
process.stdout.write(` ${icon} ${name} ${C.dim}done${C.reset}\n`);
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
process.stdout.write(`\n${C.green}${C.bold}[VibeGuard] Fully active:${C.reset}\n\n`);
|
|
1929
|
+
process.stdout.write(` ${C.green}1.${C.reset} Daemon — auto-scans every file change\n`);
|
|
1930
|
+
process.stdout.write(` ${C.green}2.${C.reset} Pre-commit hook — blocks commits on critical\n`);
|
|
1931
|
+
process.stdout.write(` ${C.green}3.${C.reset} Post-edit hook — scans AI agent edits\n`);
|
|
1932
|
+
process.stdout.write(` ${C.green}4.${C.reset} Shell guard — blocks dangerous commands${C.reset}\n\n`);
|
|
1933
|
+
process.stdout.write(` ${C.dim}Status: vibeguard auto --status${C.reset}\n`);
|
|
1934
|
+
process.stdout.write(` ${C.dim}Stop: vibeguard auto --stop${C.reset}\n`);
|
|
1935
|
+
process.stdout.write(` ${C.dim}Override: VG_OVERRIDE=1 <command>${C.reset}\n\n`);
|
|
1936
|
+
|
|
1937
|
+
return 0;
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
// Keep old auto-* commands as aliases to unified auto
|
|
1941
|
+
function cmdAutoStart(dir, flags) {
|
|
1942
|
+
return cmdAutoUnified(dir, {}, flags);
|
|
1943
|
+
}
|
|
1944
|
+
function cmdAutoStop(dir, flags) {
|
|
1945
|
+
return cmdAutoUnified(dir, { _: ['', '--stop'] }, { stop: true, ...flags });
|
|
1946
|
+
}
|
|
1947
|
+
function cmdAutoStatus(dir, flags) {
|
|
1948
|
+
return cmdAutoUnified(dir, { _: ['', '--status'] }, { status: true, ...flags });
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1637
1951
|
main().catch((err) => {
|
|
1638
1952
|
process.stderr.write(`vibeguard error: ${err && err.message ? err.message : err}\n`);
|
|
1639
1953
|
process.exit(2);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yagyeshvyas/vibeguard",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Offline security scanner for AI-generated code. 693 rules, 75 MCP tools, AST taint analysis, shell guard. Zero telemetry, zero dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"author": "Yagyesh Vyas <https://www.linkedin.com/in/yagyeshvyas/>",
|
|
@@ -23,44 +23,47 @@
|
|
|
23
23
|
"hooks",
|
|
24
24
|
"ci",
|
|
25
25
|
"ci-templates",
|
|
26
|
-
"README.md"
|
|
26
|
+
"README.md",
|
|
27
|
+
"CHANGELOG.md"
|
|
27
28
|
],
|
|
28
29
|
"scripts": {
|
|
29
30
|
"test": "node test/run.js",
|
|
30
31
|
"scan": "node bin/cli.js scan",
|
|
31
32
|
"lint": "eslint src/ bin/ --ignore-pattern node_modules",
|
|
32
33
|
"coverage": "c8 node test/run.js",
|
|
33
|
-
"
|
|
34
|
+
"counts": "node scripts/counts.js",
|
|
35
|
+
"benchmark": "node test/benchmark/run.js",
|
|
36
|
+
"postinstall": "node scripts/postinstall.js",
|
|
37
|
+
"prepublishOnly": "node test/run.js && npm run lint"
|
|
34
38
|
},
|
|
35
39
|
"keywords": [
|
|
36
40
|
"security",
|
|
37
|
-
"sast",
|
|
38
41
|
"scanner",
|
|
42
|
+
"sast",
|
|
43
|
+
"vibe-coding",
|
|
44
|
+
"ai-code",
|
|
45
|
+
"mcp",
|
|
39
46
|
"secrets",
|
|
47
|
+
"prompt-injection",
|
|
48
|
+
"static-analysis",
|
|
40
49
|
"sarif",
|
|
41
|
-
"mcp",
|
|
42
50
|
"claude",
|
|
43
51
|
"cursor",
|
|
44
52
|
"windsurf",
|
|
45
53
|
"codex",
|
|
46
|
-
"vibe-coding",
|
|
47
54
|
"vibecoding",
|
|
48
55
|
"ai-security",
|
|
49
|
-
"prompt-injection",
|
|
50
56
|
"jailbreak",
|
|
51
57
|
"privacy",
|
|
52
58
|
"pii",
|
|
53
59
|
"firewall",
|
|
54
60
|
"sandbox",
|
|
55
|
-
"zero-trust",
|
|
56
61
|
"supply-chain",
|
|
57
62
|
"compliance",
|
|
58
63
|
"gdpr",
|
|
59
64
|
"soc2",
|
|
60
|
-
"hipaa",
|
|
61
65
|
"pre-commit",
|
|
62
66
|
"linter",
|
|
63
|
-
"static-analysis",
|
|
64
67
|
"vulnerability",
|
|
65
68
|
"xss",
|
|
66
69
|
"sql-injection",
|
package/src/ast.js
CHANGED
|
@@ -180,6 +180,10 @@ function analyzeAst(content, relPath, preparsed) {
|
|
|
180
180
|
if (QUERY_METHODS.has(prop) && isReqDerived(a0)) {
|
|
181
181
|
push(node, { ruleId: 'ast.nosql-injection', severity: 'high', title: 'NoSQL query from request (AST-confirmed)', message: `${prop}() uses the request as a query object — operator injection ({"$gt":""}).`, fix: 'Build the query from validated scalar fields only.', snippet: `${prop}(req.*)` });
|
|
182
182
|
}
|
|
183
|
+
// Model.find({ name: req.body.name }) — request data nested in query object
|
|
184
|
+
if (QUERY_METHODS.has(prop) && a0 && a0.type === 'ObjectExpression' && a0.properties.some(p => p.value && isReqDerived(p.value))) {
|
|
185
|
+
push(node, { ruleId: 'ast.nosql-injection', severity: 'high', title: 'NoSQL query with request data (AST-confirmed)', message: `${prop}() builds a query from request fields — operator injection if attacker sends {"$gt":""}.`, fix: 'Validate each field type before building the query; reject objects with $ operators.', snippet: `${prop}({...req.*})` });
|
|
186
|
+
}
|
|
183
187
|
// any call whose object arg contains $where
|
|
184
188
|
if (args.some(objectHasWhere)) {
|
|
185
189
|
push(node, { ruleId: 'ast.nosql-injection', severity: 'high', title: 'NoSQL $where operator (AST-confirmed)', message: 'A query uses the $where operator, which executes JavaScript on the DB server — injection risk.', fix: 'Avoid $where; use structured query operators on validated fields.', snippet: '$where' });
|