@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/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
|
*/
|
|
@@ -118,7 +120,7 @@ function referencesTainted(line, tainted) {
|
|
|
118
120
|
return null;
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
function
|
|
123
|
+
function analyzeTaintRegex(content, lines, relPath) {
|
|
122
124
|
const ext = path.extname(relPath || '').toLowerCase();
|
|
123
125
|
if (!TAINT_EXT.has(ext)) return [];
|
|
124
126
|
|
|
@@ -165,4 +167,28 @@ function analyzeTaint(content, lines, relPath) {
|
|
|
165
167
|
return findings;
|
|
166
168
|
}
|
|
167
169
|
|
|
168
|
-
|
|
170
|
+
// Primary entry point: tries AST-based taint first, falls back to regex.
|
|
171
|
+
// Accepts an optional pre-parsed tree to avoid re-parsing (one parse per file).
|
|
172
|
+
function analyzeTaint(content, lines, relPath, tree) {
|
|
173
|
+
const ext = path.extname(relPath || '').toLowerCase();
|
|
174
|
+
if (!TAINT_EXT.has(ext)) return [];
|
|
175
|
+
|
|
176
|
+
// Try AST-based analysis (scope-aware, sanitizer-aware, cross-function).
|
|
177
|
+
try {
|
|
178
|
+
const ast = require('./ast');
|
|
179
|
+
if (ast.isAvailable()) {
|
|
180
|
+
const t = tree || ast.parseSource(content, relPath);
|
|
181
|
+
if (t) {
|
|
182
|
+
const { analyzeTaintAst } = require('./taint-ast');
|
|
183
|
+
return analyzeTaintAst(content, lines, relPath, t);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} catch {
|
|
187
|
+
// fall through to regex
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Fallback: regex-based taint (no scopes, no AST).
|
|
191
|
+
return analyzeTaintRegex(content, lines, relPath);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
module.exports = { analyzeTaint, analyzeTaintRegex, SOURCE_RE, SINKS };
|