@yagyeshvyas/vibeguard 0.1.0 → 1.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/CHANGELOG.md +126 -0
- package/LICENSE +21 -0
- package/README.md +499 -599
- package/bin/cli.js +2083 -1640
- package/ci/vibeguard.yml +42 -41
- package/package.json +14 -11
- package/src/ast.js +4 -0
- package/src/auto.js +427 -0
- package/src/crosstaint.js +154 -9
- package/src/daemon-run.js +12 -0
- package/src/daemon.js +342 -0
- package/src/engine.js +294 -234
- package/src/guard.js +80 -0
- package/src/mcp-server.js +1814 -1804
- package/src/report.js +325 -312
- package/src/rules-pack.js +121 -14
- package/src/rules.js +1506 -1446
- package/src/scanner.js +805 -651
- package/src/shell-guard.js +292 -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 +1004 -0
- package/src/taint.js +52 -13
package/src/taint.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
|
-
*
|
|
4
|
+
* Intra-file taint analysis — AST-based when acorn is available, regex fallback.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The primary path is the scope-aware AST analysis in taint-ast.js, which
|
|
7
|
+
* handles variable declarations, assignments, template literals, binary
|
|
8
|
+
* string concat, function parameters, object property reads/writes, block/
|
|
9
|
+
* function scope with shadowing, reassignment clearing, and sanitizer
|
|
10
|
+
* recognition. Sinks are matched on CallExpression nodes, not text.
|
|
9
11
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
12
|
+
* When acorn is unavailable or a file doesn't parse, this module falls back
|
|
13
|
+
* to the original regex-based taint pass (below) so behavior never regresses
|
|
14
|
+
* on unparseable files.
|
|
13
15
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
16
|
+
* Public export analyzeTaint(content, lines, relPath) is unchanged; an
|
|
17
|
+
* optional tree argument is accepted to reuse a preparsed AST (one parse
|
|
18
|
+
* per file, threaded through scanFileContent).
|
|
17
19
|
*
|
|
18
20
|
* Scope: JS/TS-family files. Best-effort, not a substitute for a real taint tool.
|
|
19
21
|
*/
|
|
@@ -112,13 +114,15 @@ function newlyTainted(line, tainted) {
|
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
function referencesTainted(line, tainted) {
|
|
117
|
+
// Strip string literals so we don't match variable names inside SQL strings.
|
|
118
|
+
const stripped = line.replace(/(["'`])(?:[^\\]|\\.)*?\1/g, '""');
|
|
115
119
|
for (const t of tainted) {
|
|
116
|
-
if (new RegExp(`\\b${t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(
|
|
120
|
+
if (new RegExp(`\\b${t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(stripped)) return t;
|
|
117
121
|
}
|
|
118
122
|
return null;
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
function
|
|
125
|
+
function analyzeTaintRegex(content, lines, relPath) {
|
|
122
126
|
const ext = path.extname(relPath || '').toLowerCase();
|
|
123
127
|
if (!TAINT_EXT.has(ext)) return [];
|
|
124
128
|
|
|
@@ -138,6 +142,17 @@ function analyzeTaint(content, lines, relPath) {
|
|
|
138
142
|
// Skip the inline source case — the regex rules already report it; taint
|
|
139
143
|
// exists to catch the *multi-step* case where the source is elsewhere.
|
|
140
144
|
if (SOURCE_RE.test(line)) continue;
|
|
145
|
+
// Skip parameterized queries: if the tainted var is inside an array
|
|
146
|
+
// literal (second arg), it's a bound parameter, not SQL injection.
|
|
147
|
+
// Heuristic: if the line has "query(" or "execute(" or "raw(" and the
|
|
148
|
+
// tainted var appears after a comma followed by [, skip it.
|
|
149
|
+
if (sink.ruleId === 'taint.sql-injection' && /,\s*\[/.test(line)) {
|
|
150
|
+
// Check if the tainted var is ONLY in the array, not in the SQL string.
|
|
151
|
+
const beforeArray = line.split(/,\s*\[/)[0];
|
|
152
|
+
const afterArray = ',' + line.split(/,\s*\[/).slice(1).join(',[');
|
|
153
|
+
const viaSql = referencesTainted(beforeArray, tainted);
|
|
154
|
+
if (!viaSql) continue; // tainted var only in params array — safe
|
|
155
|
+
}
|
|
141
156
|
const via = referencesTainted(line, tainted);
|
|
142
157
|
if (via) {
|
|
143
158
|
findings.push({
|
|
@@ -165,4 +180,28 @@ function analyzeTaint(content, lines, relPath) {
|
|
|
165
180
|
return findings;
|
|
166
181
|
}
|
|
167
182
|
|
|
168
|
-
|
|
183
|
+
// Primary entry point: tries AST-based taint first, falls back to regex.
|
|
184
|
+
// Accepts an optional pre-parsed tree to avoid re-parsing (one parse per file).
|
|
185
|
+
function analyzeTaint(content, lines, relPath, tree) {
|
|
186
|
+
const ext = path.extname(relPath || '').toLowerCase();
|
|
187
|
+
if (!TAINT_EXT.has(ext)) return [];
|
|
188
|
+
|
|
189
|
+
// Try AST-based analysis (scope-aware, sanitizer-aware, cross-function).
|
|
190
|
+
try {
|
|
191
|
+
const ast = require('./ast');
|
|
192
|
+
if (ast.isAvailable()) {
|
|
193
|
+
const t = tree || ast.parseSource(content, relPath);
|
|
194
|
+
if (t) {
|
|
195
|
+
const { analyzeTaintAst } = require('./taint-ast');
|
|
196
|
+
return analyzeTaintAst(content, lines, relPath, t);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} catch {
|
|
200
|
+
// fall through to regex
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Fallback: regex-based taint (no scopes, no AST).
|
|
204
|
+
return analyzeTaintRegex(content, lines, relPath);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
module.exports = { analyzeTaint, analyzeTaintRegex, SOURCE_RE, SINKS };
|