vigilsutra 0.2.2 → 0.4.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 +26 -0
- package/README.md +34 -28
- package/advisories/db.json.gz +0 -0
- package/agents/agents-registry.json +14 -2
- package/agents/agentshield/SKILL.md +12 -0
- package/agents/apishield/SKILL.md +12 -0
- package/agents/codeguard/SKILL.md +1 -1
- package/agents/compliancemap/SKILL.md +12 -0
- package/agents/datashield/SKILL.md +12 -0
- package/agents/identityguard/SKILL.md +12 -0
- package/agents/mobileshield/SKILL.md +12 -0
- package/agents/pipelineguard/SKILL.md +12 -0
- package/agents/remedy/SKILL.md +12 -0
- package/agents/riskrank/SKILL.md +12 -0
- package/agents/secretwatch/SKILL.md +1 -1
- package/agents/supplywatch/SKILL.md +12 -0
- package/agents/threatmap/SKILL.md +12 -0
- package/agents/webshield/SKILL.md +12 -0
- package/dist/adapters.js +35 -19
- package/dist/advisories.js +83 -0
- package/dist/cli.js +101 -30
- package/dist/components.js +116 -0
- package/dist/engine.js +99 -13
- package/dist/fix.js +85 -0
- package/dist/git-index.js +17 -6
- package/dist/git-objects.js +558 -0
- package/dist/policy.js +21 -2
- package/dist/redact.js +7 -1
- package/dist/rules/code.js +23 -6
- package/dist/rules/index.js +3 -2
- package/dist/rules/secrets.js +72 -0
- package/dist/rules/supply.js +103 -0
- package/dist/rules/util.js +29 -16
- package/dist/scope.js +3 -4
- package/dist/taint.js +83 -0
- package/docs/agent-contract.md +1 -1
- package/docs/assurance/benchmark.md +2 -0
- package/docs/assurance/coverage-raw.txt +151 -111
- package/docs/assurance/coverage.md +26 -18
- package/docs/assurance/fuzzing.md +1 -1
- package/docs/assurance/internal-review.md +3 -1
- package/docs/ci-cd.md +13 -4
- package/docs/compatibility.md +4 -4
- package/docs/index.html +75 -0
- package/docs/quickstart.md +5 -3
- package/docs/rules.md +92 -2
- package/docs/security-model.md +1 -1
- package/llms.txt +2 -2
- package/package.json +3 -2
- package/policies/safe-default.yaml +3 -0
- package/templates/pre-commit +7 -0
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,10 @@ import { audit, exceeds, VERSION } from "./engine.js";
|
|
|
5
5
|
import { loadPolicy } from "./policy.js";
|
|
6
6
|
import { render, FORMATS } from "./reporters/index.js";
|
|
7
7
|
import { ALL_RULES, findRule, RULES_VERSION } from "./rules/index.js";
|
|
8
|
-
import { ADAPTERS, PACKAGE_ROOT,
|
|
8
|
+
import { ADAPTERS, PACKAGE_ROOT, installAdapter, planAdapter, uninstallAdapter } from "./adapters.js";
|
|
9
|
+
import { locateGit } from "./git-objects.js";
|
|
10
|
+
import { cycloneDx, readComponents } from "./components.js";
|
|
11
|
+
import { applyFixes, planFixes } from "./fix.js";
|
|
9
12
|
import { SEVERITY_ORDER } from "./types.js";
|
|
10
13
|
const HELP = `VigilSutra AI ${VERSION} - offline, read-only security & privacy auditor. Created by Vatsal Shah.
|
|
11
14
|
|
|
@@ -19,25 +22,35 @@ Commands:
|
|
|
19
22
|
--baseline <file> Suppress findings whose fingerprints are in this baseline
|
|
20
23
|
--policy <file> Use this policy file instead of the project's .vigilsutra.yml
|
|
21
24
|
--no-policy Ignore the project's .vigilsutra.yml (use when auditing code you do not own)
|
|
22
|
-
--report
|
|
25
|
+
--report Write report.md and report.html (also results.json and results.sarif) to ./vigilsutra-report/. This is the default.
|
|
23
26
|
--report-dir <dir> Same, into <dir>
|
|
24
|
-
--no-report Do not write
|
|
27
|
+
--no-report Do not write those files
|
|
28
|
+
--no-history Do not read git objects for secrets that were removed from the worktree
|
|
29
|
+
--since <rev> Scan only worktree files that differ from this git revision (skips history)
|
|
30
|
+
--staged Scan the git index (what a commit would record) instead of the worktree
|
|
31
|
+
--no-advisories Do not match the shipped advisory snapshot
|
|
32
|
+
--advisories <file> Match this advisory snapshot instead of the shipped one
|
|
25
33
|
--no-color Plain output (also honours NO_COLOR)
|
|
26
|
-
report [path]
|
|
34
|
+
report [path] Same scan as audit. Always writes report.md and report.html (plus JSON and SARIF)
|
|
35
|
+
sbom [path] Write a CycloneDX 1.6 JSON SBOM of pinned npm, PyPI and Go components
|
|
36
|
+
--out <file> Write the SBOM to a file instead of stdout
|
|
37
|
+
fix [path] Show deterministic safe edits (dry-run). Secrets are never rewritten
|
|
38
|
+
--apply Write those edits
|
|
27
39
|
baseline [path] --out <file> Record current findings as an accepted baseline
|
|
28
40
|
verify [path] --previous <results.json> Re-scan and compare with an earlier JSON result
|
|
29
41
|
rules list List implemented rules
|
|
30
42
|
explain <RULE-ID> Show rule details, fix and false-positive notes
|
|
31
43
|
doctor Environment and offline-readiness check
|
|
32
44
|
init [path] Create .vigilsutra.yml if absent (never overwrites)
|
|
45
|
+
--hook Also install templates/pre-commit as .git/hooks/pre-commit if that hook is absent
|
|
33
46
|
adapters list Show adapter status
|
|
34
|
-
adapters install claude [--project <dir>] [--dry-run] [--force]
|
|
35
|
-
adapters uninstall claude [--project <dir>]
|
|
47
|
+
adapters install <claude|cursor|codex|gemini|copilot> [--project <dir>] [--dry-run] [--force]
|
|
48
|
+
adapters uninstall <claude|cursor|codex|gemini|copilot> [--project <dir>]
|
|
36
49
|
--help, --version
|
|
37
50
|
|
|
38
51
|
Exit codes: 0 ok | 1 findings at/above --fail-on | 2 usage or runtime error
|
|
39
52
|
`;
|
|
40
|
-
const VALUE_FLAGS = new Set(["format", "out", "fail-on", "baseline", "previous", "project", "policy", "report-dir"]);
|
|
53
|
+
const VALUE_FLAGS = new Set(["format", "out", "fail-on", "baseline", "previous", "project", "policy", "report-dir", "since", "advisories"]);
|
|
41
54
|
function parse(argv) {
|
|
42
55
|
const pos = [];
|
|
43
56
|
const flags = new Map();
|
|
@@ -63,6 +76,19 @@ function policyOpts(flags) {
|
|
|
63
76
|
const p = flags.get("policy");
|
|
64
77
|
return { policyFile: typeof p === "string" ? resolve(p) : undefined, ignoreProjectPolicy: flags.has("no-policy") };
|
|
65
78
|
}
|
|
79
|
+
function auditOpts(root, flags) {
|
|
80
|
+
const since = flags.get("since");
|
|
81
|
+
const advisories = flags.get("advisories");
|
|
82
|
+
return {
|
|
83
|
+
root,
|
|
84
|
+
history: !flags.has("no-history"),
|
|
85
|
+
since: typeof since === "string" ? since : undefined,
|
|
86
|
+
staged: flags.has("staged"),
|
|
87
|
+
advisories: !flags.has("no-advisories"),
|
|
88
|
+
advisoriesFile: typeof advisories === "string" ? resolve(advisories) : undefined,
|
|
89
|
+
...policyOpts(flags)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
66
92
|
function fail(msg) {
|
|
67
93
|
process.stderr.write(`vigilsutra: ${msg}\n`);
|
|
68
94
|
process.exit(2);
|
|
@@ -116,7 +142,10 @@ function main() {
|
|
|
116
142
|
fail(`unknown format "${format}"`);
|
|
117
143
|
const baselineFile = flags.get("baseline");
|
|
118
144
|
const pol = policyOpts(flags);
|
|
119
|
-
const result = audit({
|
|
145
|
+
const result = audit({
|
|
146
|
+
...auditOpts(root, flags),
|
|
147
|
+
baselineFile: typeof baselineFile === "string" ? resolve(baselineFile) : undefined
|
|
148
|
+
});
|
|
120
149
|
const failOn = sev(flags.get("fail-on")) ?? loadPolicy(root, { explicitFile: pol.policyFile, ignoreProjectPolicy: pol.ignoreProjectPolicy }).failOn;
|
|
121
150
|
const out = flags.get("out");
|
|
122
151
|
if (typeof out === "string") {
|
|
@@ -125,19 +154,12 @@ function main() {
|
|
|
125
154
|
}
|
|
126
155
|
else
|
|
127
156
|
process.stdout.write(render(result, format, color));
|
|
128
|
-
//
|
|
129
|
-
const explicitOutput = flags.has("format") || typeof out === "string";
|
|
157
|
+
// Readable reports are files, not only a terminal scrollback. Stdout stays the chosen format.
|
|
130
158
|
const dirFlag = flags.get("report-dir");
|
|
131
|
-
|
|
132
|
-
if (wantReport) {
|
|
159
|
+
if (!flags.has("no-report")) {
|
|
133
160
|
const dir = resolve(typeof dirFlag === "string" ? dirFlag : "vigilsutra-report");
|
|
134
161
|
writeReportFolder(dir, result);
|
|
135
|
-
process.
|
|
136
|
-
Reports written to ${dir}
|
|
137
|
-
report.html open this in a browser
|
|
138
|
-
report.md Markdown version
|
|
139
|
-
results.json, results.sarif for tools and CI
|
|
140
|
-
`);
|
|
162
|
+
process.stderr.write(`Reports written to ${dir}\n report.html open this in a browser\n report.md Markdown version\n results.json, results.sarif for tools and CI\n`);
|
|
141
163
|
}
|
|
142
164
|
if (failOn && exceeds(result, failOn))
|
|
143
165
|
process.exit(1);
|
|
@@ -148,7 +170,7 @@ Reports written to ${dir}
|
|
|
148
170
|
const out = flags.get("out");
|
|
149
171
|
if (typeof out !== "string")
|
|
150
172
|
fail("baseline needs --out <file>");
|
|
151
|
-
const result = audit(
|
|
173
|
+
const result = audit(auditOpts(root, flags));
|
|
152
174
|
writeOut(out, JSON.stringify({ tool: "vigilsutra", version: VERSION, createdAt: result.generatedAt, fingerprints: result.findings.map((f) => f.fingerprint).sort() }, null, 2) + "\n");
|
|
153
175
|
process.stdout.write(`Baseline of ${result.findings.length} finding(s) written to ${out}\n`);
|
|
154
176
|
return;
|
|
@@ -167,7 +189,7 @@ Reports written to ${dir}
|
|
|
167
189
|
}
|
|
168
190
|
if (!Array.isArray(prev.findings))
|
|
169
191
|
fail("previous file is not a VigilSutra JSON result");
|
|
170
|
-
const now = audit(
|
|
192
|
+
const now = audit(auditOpts(root, flags));
|
|
171
193
|
const before = new Map(prev.findings.map((f) => [f.fingerprint, f]));
|
|
172
194
|
const after = new Map(now.findings.map((f) => [f.fingerprint, f]));
|
|
173
195
|
const resolved = [...before.values()].filter((f) => !after.has(f.fingerprint));
|
|
@@ -185,6 +207,36 @@ Reports written to ${dir}
|
|
|
185
207
|
process.exit(1);
|
|
186
208
|
return;
|
|
187
209
|
}
|
|
210
|
+
case "sbom": {
|
|
211
|
+
const root = checkRoot(pos[0] ?? ".");
|
|
212
|
+
const text = cycloneDx(readComponents(root), VERSION);
|
|
213
|
+
const out = flags.get("out");
|
|
214
|
+
if (typeof out === "string") {
|
|
215
|
+
writeOut(out, text);
|
|
216
|
+
process.stderr.write(`SBOM written to ${out}\n`);
|
|
217
|
+
}
|
|
218
|
+
else
|
|
219
|
+
process.stdout.write(text);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
case "fix": {
|
|
223
|
+
const root = checkRoot(pos[0] ?? ".");
|
|
224
|
+
const result = audit({ ...auditOpts(root, flags), history: false });
|
|
225
|
+
const edits = planFixes(result.findings, root);
|
|
226
|
+
if (!edits.length) {
|
|
227
|
+
process.stdout.write("No safe edits. Secrets, users, and commit SHAs are never invented.\n");
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
for (const e of edits)
|
|
231
|
+
process.stdout.write(`${e.path}:${e.line} ${e.ruleId}\n- ${e.before}\n+ ${e.after}\n`);
|
|
232
|
+
if (flags.has("apply")) {
|
|
233
|
+
const n = applyFixes(edits, root);
|
|
234
|
+
process.stdout.write(`Applied ${n} edit(s).\n`);
|
|
235
|
+
}
|
|
236
|
+
else
|
|
237
|
+
process.stdout.write("Dry run. Pass --apply to write these edits.\n");
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
188
240
|
case "rules": {
|
|
189
241
|
if (pos[0] !== "list")
|
|
190
242
|
fail("usage: vigilsutra rules list");
|
|
@@ -236,15 +288,32 @@ Reports written to ${dir}
|
|
|
236
288
|
try {
|
|
237
289
|
// "wx" creates the file only if it does not exist, atomically (no check-then-write race).
|
|
238
290
|
writeFileSync(file, tpl, { flag: "wx" });
|
|
291
|
+
process.stdout.write(`Created ${file}\n`);
|
|
239
292
|
}
|
|
240
293
|
catch (e) {
|
|
241
|
-
if (e.code === "EEXIST")
|
|
294
|
+
if (e.code === "EEXIST")
|
|
242
295
|
process.stdout.write(".vigilsutra.yml already exists; not modified.\n");
|
|
243
|
-
|
|
296
|
+
else
|
|
297
|
+
throw e;
|
|
298
|
+
}
|
|
299
|
+
if (flags.has("hook")) {
|
|
300
|
+
const located = locateGit(root);
|
|
301
|
+
if (!located)
|
|
302
|
+
fail("--hook needs a git directory for this project");
|
|
303
|
+
const dest = join(located.gitDir, "hooks", "pre-commit");
|
|
304
|
+
const hook = readFileSync(join(PACKAGE_ROOT, "templates", "pre-commit"), "utf8");
|
|
305
|
+
try {
|
|
306
|
+
mkdirSync(join(located.gitDir, "hooks"), { recursive: true });
|
|
307
|
+
writeFileSync(dest, hook, { flag: "wx", mode: 0o755 });
|
|
308
|
+
process.stdout.write(`Created ${dest}\n`);
|
|
309
|
+
}
|
|
310
|
+
catch (e) {
|
|
311
|
+
if (e.code === "EEXIST")
|
|
312
|
+
process.stdout.write("pre-commit hook already exists; not modified.\n");
|
|
313
|
+
else
|
|
314
|
+
throw e;
|
|
244
315
|
}
|
|
245
|
-
throw e;
|
|
246
316
|
}
|
|
247
|
-
process.stdout.write(`Created ${file}\n`);
|
|
248
317
|
return;
|
|
249
318
|
}
|
|
250
319
|
case "adapters": {
|
|
@@ -254,26 +323,28 @@ Reports written to ${dir}
|
|
|
254
323
|
process.stdout.write(`${a.name.padEnd(12)} ${a.status.padEnd(10)} ${a.detail}\n`);
|
|
255
324
|
return;
|
|
256
325
|
}
|
|
257
|
-
|
|
326
|
+
const names = new Set(["claude", "cursor", "codex", "gemini", "copilot"]);
|
|
327
|
+
if ((sub === "install" || sub === "uninstall") && names.has(pos[1] ?? "")) {
|
|
328
|
+
const adapter = pos[1];
|
|
258
329
|
const proj = checkRoot(typeof flags.get("project") === "string" ? flags.get("project") : ".");
|
|
259
330
|
if (sub === "uninstall") {
|
|
260
|
-
const removed =
|
|
331
|
+
const removed = uninstallAdapter(proj, adapter);
|
|
261
332
|
process.stdout.write(removed.length ? `Removed:\n${removed.map((r) => " " + r).join("\n")}\n` : "Nothing installed by VigilSutra found.\n");
|
|
262
333
|
return;
|
|
263
334
|
}
|
|
264
335
|
const force = flags.has("force");
|
|
265
336
|
if (flags.has("dry-run")) {
|
|
266
|
-
for (const p of
|
|
337
|
+
for (const p of planAdapter(proj, adapter, force))
|
|
267
338
|
process.stdout.write(`${p.action.padEnd(12)} ${p.to}\n`);
|
|
268
339
|
process.stdout.write("Dry run: no files written.\n");
|
|
269
340
|
return;
|
|
270
341
|
}
|
|
271
|
-
for (const p of
|
|
342
|
+
for (const p of installAdapter(proj, adapter, force))
|
|
272
343
|
process.stdout.write(`${p.action.padEnd(12)} ${p.to}\n`);
|
|
273
|
-
process.stdout.write("Existing files are never overwritten without --force.\n");
|
|
344
|
+
process.stdout.write("Existing files are never overwritten without --force. In-IDE behaviour is not automated-tested.\n");
|
|
274
345
|
return;
|
|
275
346
|
}
|
|
276
|
-
fail("usage: vigilsutra adapters list | install claude | uninstall claude");
|
|
347
|
+
fail("usage: vigilsutra adapters list | install <claude|cursor|codex|gemini|copilot> | uninstall <claude|cursor|codex|gemini|copilot>");
|
|
277
348
|
}
|
|
278
349
|
default:
|
|
279
350
|
fail(`unknown command "${cmd}". Run: vigilsutra --help`);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
const MAX = 20 * 1024 * 1024;
|
|
5
|
+
function readText(root, rel) {
|
|
6
|
+
const abs = join(root, rel);
|
|
7
|
+
try {
|
|
8
|
+
if (!existsSync(abs))
|
|
9
|
+
return null;
|
|
10
|
+
const buf = readFileSync(abs);
|
|
11
|
+
if (buf.length > MAX || buf.subarray(0, 8192).includes(0))
|
|
12
|
+
return null;
|
|
13
|
+
return buf.toString("utf8");
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Resolved components from lockfiles and pinned manifests. Ranges are skipped. Lockfiles are read even when the scan ignores them. */
|
|
20
|
+
export function readComponents(root) {
|
|
21
|
+
const out = [];
|
|
22
|
+
const seen = new Set();
|
|
23
|
+
const add = (c) => {
|
|
24
|
+
if (!c.version || !/^\d/.test(c.version.replace(/^v/, "")))
|
|
25
|
+
return;
|
|
26
|
+
const key = `${c.ecosystem}\0${c.name.toLowerCase()}\0${c.version}`;
|
|
27
|
+
if (seen.has(key))
|
|
28
|
+
return;
|
|
29
|
+
seen.add(key);
|
|
30
|
+
out.push(c);
|
|
31
|
+
};
|
|
32
|
+
const lock = readText(root, "package-lock.json");
|
|
33
|
+
if (lock) {
|
|
34
|
+
try {
|
|
35
|
+
const json = JSON.parse(lock);
|
|
36
|
+
for (const [path, meta] of Object.entries(json.packages ?? {})) {
|
|
37
|
+
if (!path || !meta.version)
|
|
38
|
+
continue;
|
|
39
|
+
const name = meta.name ?? path.split("node_modules/").pop();
|
|
40
|
+
if (!name || name === path)
|
|
41
|
+
continue;
|
|
42
|
+
add({ ecosystem: "npm", name, version: meta.version, path: "package-lock.json" });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
/* not a lockfile */
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const req = readText(root, "requirements.txt");
|
|
50
|
+
if (req) {
|
|
51
|
+
for (const line of req.split(/\n/)) {
|
|
52
|
+
const m = /^\s*([A-Za-z0-9_.-]+)\s*==\s*([0-9][^\\\s]*)/.exec(line);
|
|
53
|
+
if (m)
|
|
54
|
+
add({ ecosystem: "pypi", name: m[1], version: m[2], path: "requirements.txt" });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const yarn = readText(root, "yarn.lock");
|
|
58
|
+
if (yarn) {
|
|
59
|
+
let name = "";
|
|
60
|
+
for (const line of yarn.split(/\n/)) {
|
|
61
|
+
if (!line.startsWith(" ") && !line.startsWith("\t")) {
|
|
62
|
+
const head = /^"?(@?[^@"\s]+)@/.exec(line);
|
|
63
|
+
if (head)
|
|
64
|
+
name = head[1];
|
|
65
|
+
}
|
|
66
|
+
const ver = /^ {2}version "(\d[^"]*)"/.exec(line);
|
|
67
|
+
if (ver && name)
|
|
68
|
+
add({ ecosystem: "npm", name, version: ver[1], path: "yarn.lock" });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const pnpm = readText(root, "pnpm-lock.yaml");
|
|
72
|
+
if (pnpm) {
|
|
73
|
+
for (const line of pnpm.split(/\n/)) {
|
|
74
|
+
const m = /^\s{2}\/?(@?[^@\s'"]+)@(\d[^:(/'"]*)/.exec(line);
|
|
75
|
+
if (m)
|
|
76
|
+
add({ ecosystem: "npm", name: m[1], version: m[2], path: "pnpm-lock.yaml" });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const gomod = readText(root, "go.mod");
|
|
80
|
+
if (gomod) {
|
|
81
|
+
for (const line of gomod.split(/\n/)) {
|
|
82
|
+
const m = /(?:^|\s)([A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)+)\s+v([0-9][^\s]*)/.exec(line);
|
|
83
|
+
if (m)
|
|
84
|
+
add({ ecosystem: "golang", name: m[1], version: m[2], path: "go.mod" });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
export function cycloneDx(components, version) {
|
|
90
|
+
const bom = {
|
|
91
|
+
bomFormat: "CycloneDX",
|
|
92
|
+
specVersion: "1.6",
|
|
93
|
+
serialNumber: `urn:uuid:${randomUUID()}`,
|
|
94
|
+
version: 1,
|
|
95
|
+
metadata: {
|
|
96
|
+
timestamp: new Date().toISOString(),
|
|
97
|
+
tools: { components: [{ type: "application", name: "vigilsutra", version }] },
|
|
98
|
+
component: { type: "application", name: "scanned-project" }
|
|
99
|
+
},
|
|
100
|
+
components: components.map((c) => ({
|
|
101
|
+
type: "library",
|
|
102
|
+
name: c.name,
|
|
103
|
+
version: c.version,
|
|
104
|
+
purl: purl(c),
|
|
105
|
+
properties: [{ name: "vigilsutra:manifest", value: c.path }]
|
|
106
|
+
}))
|
|
107
|
+
};
|
|
108
|
+
return JSON.stringify(bom, null, 2) + "\n";
|
|
109
|
+
}
|
|
110
|
+
function purl(c) {
|
|
111
|
+
if (c.ecosystem === "npm")
|
|
112
|
+
return `pkg:npm/${c.name.replace("/", "%2F")}@${c.version}`;
|
|
113
|
+
if (c.ecosystem === "pypi")
|
|
114
|
+
return `pkg:pypi/${c.name.toLowerCase()}@${c.version}`;
|
|
115
|
+
return `pkg:golang/${c.name}@v${c.version}`;
|
|
116
|
+
}
|
package/dist/engine.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
-
import { basename, join } from "node:path";
|
|
3
|
+
import { basename, extname, join } from "node:path";
|
|
4
4
|
import { ALL_RULES, CWE_NOTE, RULES_VERSION, findRule } from "./rules/index.js";
|
|
5
5
|
import { isTestPath } from "./rules/util.js";
|
|
6
6
|
import { inventory } from "./scope.js";
|
|
7
|
+
import { blobHash, revisionTree, scanHistory, stagedBlobs } from "./git-objects.js";
|
|
8
|
+
import { readComponents } from "./components.js";
|
|
9
|
+
import { matchAdvisories, openAdvisoryDb } from "./advisories.js";
|
|
10
|
+
import { propagateTaint } from "./taint.js";
|
|
7
11
|
import { DEFAULT_POLICY, loadPolicy } from "./policy.js";
|
|
8
12
|
import { redactSpan, scrubTokens, tidy } from "./redact.js";
|
|
9
13
|
import { SEVERITY_ORDER } from "./types.js";
|
|
10
|
-
export const VERSION = "0.
|
|
14
|
+
export const VERSION = "0.4.0";
|
|
11
15
|
/** Per rule, per file. Keeps one noisy file from producing an unbounded report. */
|
|
12
16
|
export const MAX_PER_RULE_PER_FILE = 200;
|
|
13
17
|
function sha(s) {
|
|
@@ -101,13 +105,54 @@ export function loadBaseline(file) {
|
|
|
101
105
|
export function audit(opts) {
|
|
102
106
|
const root = realpathSync(opts.root);
|
|
103
107
|
const policy = opts.policy ?? loadPolicy(root, { explicitFile: opts.policyFile, ignoreProjectPolicy: opts.ignoreProjectPolicy });
|
|
104
|
-
const
|
|
108
|
+
const deadline = Date.now() + policy.timeLimitMs;
|
|
109
|
+
const inv = inventory(root, policy, deadline);
|
|
110
|
+
const extraNotes = [];
|
|
111
|
+
let historyRan = false;
|
|
112
|
+
let files = inv.files;
|
|
113
|
+
if (opts.staged && opts.since)
|
|
114
|
+
throw new Error("use either --staged or --since, not both");
|
|
115
|
+
if (opts.staged) {
|
|
116
|
+
const staged = stagedBlobs(root);
|
|
117
|
+
if (!staged)
|
|
118
|
+
throw new Error("--staged needs a readable git index in this project");
|
|
119
|
+
files = staged.map((s) => ({ path: s.path, name: basename(s.path).toLowerCase(), ext: extname(s.path).toLowerCase(), text: s.text, lines: s.text.split(/\r\n|\n|\r/) }));
|
|
120
|
+
extraNotes.push("Staged scan reads blobs in the git index. The worktree and older history were not scanned.");
|
|
121
|
+
}
|
|
122
|
+
else if (opts.since) {
|
|
123
|
+
const rev = revisionTree(root, opts.since);
|
|
124
|
+
if (!rev.blobs)
|
|
125
|
+
throw new Error(rev.note);
|
|
126
|
+
files = files.filter((f) => rev.blobs.get(f.path) !== blobHash(f.text, rev.algo));
|
|
127
|
+
extraNotes.push(`Diff scan kept worktree files that differ from ${opts.since}. Git history was not scanned. Run without --since to read history.`);
|
|
128
|
+
}
|
|
129
|
+
else if (opts.history !== false) {
|
|
130
|
+
const current = new Map(files.map((f) => [f.path, f.text]));
|
|
131
|
+
const hist = scanHistory(root, policy.ignore, current, deadline);
|
|
132
|
+
files = files.concat(hist.files);
|
|
133
|
+
extraNotes.push(...hist.notes);
|
|
134
|
+
historyRan = hist.commitsSeen > 0 || hist.notes.some((n) => n.startsWith("Git history read"));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
extraNotes.push("Git history was not scanned (--no-history).");
|
|
138
|
+
}
|
|
139
|
+
propagateTaint(files);
|
|
140
|
+
const opened = opts.advisories === false
|
|
141
|
+
? { db: null, note: "Advisory matching was skipped (--no-advisories)." }
|
|
142
|
+
: openAdvisoryDb(opts.advisoriesFile);
|
|
143
|
+
extraNotes.push(opened.note);
|
|
105
144
|
let capped = 0;
|
|
106
145
|
const disabled = new Set(policy.disableRules.map((r) => r.toUpperCase()));
|
|
107
146
|
const rules = ALL_RULES.filter((r) => !disabled.has(r.id));
|
|
108
147
|
const baseline = opts.baselineFile ? loadBaseline(opts.baselineFile) : new Set();
|
|
109
148
|
let findings = [];
|
|
110
|
-
for (const file of
|
|
149
|
+
for (const file of files) {
|
|
150
|
+
if (Date.now() > deadline) {
|
|
151
|
+
inv.stats.truncated = true;
|
|
152
|
+
inv.stats.truncatedReason = inv.stats.truncatedReason ?? "time limit reached";
|
|
153
|
+
extraNotes.push("The time limit was reached while applying rules. Results are incomplete.");
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
111
156
|
const raw = [];
|
|
112
157
|
// Every secret span found on a line is redacted from every finding that quotes that line.
|
|
113
158
|
const lineSpans = new Map();
|
|
@@ -150,6 +195,21 @@ export function audit(opts) {
|
|
|
150
195
|
}
|
|
151
196
|
}
|
|
152
197
|
}
|
|
198
|
+
const advRule = findRule("VS-SUPPLY-004");
|
|
199
|
+
if (advRule && opened.db && !disabled.has(advRule.id)) {
|
|
200
|
+
const matches = matchAdvisories(readComponents(root), opened.db);
|
|
201
|
+
const shown = matches.slice(0, 500);
|
|
202
|
+
if (matches.length > shown.length)
|
|
203
|
+
extraNotes.push(`${matches.length - shown.length} advisory match(es) were not listed (cap 500).`);
|
|
204
|
+
for (const m of shown) {
|
|
205
|
+
findings.push(toFinding(advRule, { path: m.component.path }, {
|
|
206
|
+
line: 1,
|
|
207
|
+
excerpt: `${m.component.name}@${m.component.version} ${m.advisory.id}`,
|
|
208
|
+
severity: m.advisory.severity,
|
|
209
|
+
note: `Recorded range starts at ${m.advisory.introduced}${m.advisory.fixed ? ` and is fixed in ${m.advisory.fixed}` : m.advisory.lastAffected ? ` through ${m.advisory.lastAffected}` : " and has no recorded fix"}.`
|
|
210
|
+
}, 0));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
153
213
|
const proc = findRule("VS-PROC-001");
|
|
154
214
|
if (proc && !disabled.has(proc.id) && !inv.stats.truncated) {
|
|
155
215
|
const found = ["security.md", ".github/security.md", "docs/security.md"].some((p) => [...inv.allPaths].some((x) => x.toLowerCase() === p));
|
|
@@ -161,12 +221,23 @@ export function audit(opts) {
|
|
|
161
221
|
}
|
|
162
222
|
}
|
|
163
223
|
let suppressed = 0;
|
|
224
|
+
let waiversApplied = 0;
|
|
225
|
+
let waiversExpired = 0;
|
|
226
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
164
227
|
findings = findings.filter((f) => {
|
|
165
228
|
if (baseline.has(f.fingerprint)) {
|
|
166
229
|
suppressed++;
|
|
167
230
|
return false;
|
|
168
231
|
}
|
|
169
|
-
|
|
232
|
+
const waiver = policy.waivers.find((w) => w.ruleId === f.ruleId && w.path === f.path);
|
|
233
|
+
if (!waiver)
|
|
234
|
+
return true;
|
|
235
|
+
if (waiver.until < today) {
|
|
236
|
+
waiversExpired++;
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
waiversApplied++;
|
|
240
|
+
return false;
|
|
170
241
|
});
|
|
171
242
|
findings.sort((a, b) => {
|
|
172
243
|
const s = SEVERITY_ORDER.indexOf(b.severity) - SEVERITY_ORDER.indexOf(a.severity);
|
|
@@ -185,20 +256,28 @@ export function audit(opts) {
|
|
|
185
256
|
byStatus[f.status] = (byStatus[f.status] ?? 0) + 1;
|
|
186
257
|
}
|
|
187
258
|
const limitations = [
|
|
188
|
-
"Pattern-based static review of text files
|
|
259
|
+
"Pattern-based static review of text files. A request-like assignment is tracked by identifier through relative imports in this project. Object fields, dynamic import(), and values returned from functions are not tracked.",
|
|
189
260
|
"Source-pattern matches are reported as 'potential' unless the evidence itself is conclusive (for example a token format or an explicit unsafe setting).",
|
|
190
261
|
"A match on a secret format shows the format, not that the credential is live. No credential was tested.",
|
|
191
|
-
|
|
262
|
+
opened.db
|
|
263
|
+
? "Advisory matches use the database shipped with this version. It is a snapshot of recorded ranges, not a live feed, and it does not prove a vulnerable function is reachable."
|
|
264
|
+
: "No advisory database was loaded, so known vulnerabilities were not matched.",
|
|
192
265
|
"Untracked .env files are not read when a git index is present. .env.example, .env.sample and .env.template are never treated as secret files.",
|
|
193
|
-
"
|
|
266
|
+
"Lines longer than 2,000 characters are scanned in overlapping windows. The excerpt is the window that matched.",
|
|
267
|
+
"When a filesystem reports inode 0, a swapped file is refused only when size or mtime also changes.",
|
|
268
|
+
"Git history is read until the time limit. A blob larger than 1 MiB is skipped. SHA-1 and SHA-256 object ids are both read.",
|
|
269
|
+
"Absence of findings is not evidence of security.",
|
|
270
|
+
...extraNotes
|
|
194
271
|
];
|
|
195
272
|
if (inv.stats.truncated)
|
|
196
273
|
limitations.push(`Scan was truncated: ${inv.stats.truncatedReason}. Results are incomplete.`);
|
|
197
274
|
const limitsOverridden = policy.maxFileSize !== DEFAULT_POLICY.maxFileSize || policy.maxFiles !== DEFAULT_POLICY.maxFiles || policy.timeLimitMs !== DEFAULT_POLICY.timeLimitMs;
|
|
198
|
-
const narrowed = (policy.userIgnores ?? 0) > 0 || policy.disableRules.length > 0 || limitsOverridden;
|
|
275
|
+
const narrowed = (policy.userIgnores ?? 0) > 0 || policy.disableRules.length > 0 || policy.waivers.length > 0 || limitsOverridden;
|
|
199
276
|
if (narrowed) {
|
|
200
|
-
limitations.push(`Scan scope was changed by ${policy.source}: ${policy.userIgnores ?? 0} extra ignore pattern(s), ${policy.disableRules.length} disabled rule(s)${limitsOverridden ? ", custom limits" : ""}. If you did not write this policy (for example when auditing someone else's repository), re-run with --no-policy.`);
|
|
277
|
+
limitations.push(`Scan scope was changed by ${policy.source}: ${policy.userIgnores ?? 0} extra ignore pattern(s), ${policy.disableRules.length} disabled rule(s), ${policy.waivers.length} waiver(s)${limitsOverridden ? ", custom limits" : ""}. If you did not write this policy (for example when auditing someone else's repository), re-run with --no-policy.`);
|
|
201
278
|
}
|
|
279
|
+
if (waiversExpired)
|
|
280
|
+
limitations.push(`${waiversExpired} finding(s) matched a waiver whose until date has passed. Those findings stay in the report.`);
|
|
202
281
|
if (capped > 0)
|
|
203
282
|
limitations.push(`${capped} additional finding(s) were not listed because a rule exceeded ${MAX_PER_RULE_PER_FILE} matches in one file.`);
|
|
204
283
|
inv.stats.policy = { source: policy.source ?? "built-in defaults", userIgnorePatterns: policy.userIgnores ?? 0, disabledRules: [...policy.disableRules], limitsOverridden };
|
|
@@ -211,9 +290,16 @@ export function audit(opts) {
|
|
|
211
290
|
mode: "local",
|
|
212
291
|
project: { name: basename(root), detected: detectProject(inv.files) },
|
|
213
292
|
scope: inv.stats,
|
|
214
|
-
summary: { total: findings.length, bySeverity, byStatus, baselineSuppressed: suppressed },
|
|
215
|
-
categoriesAssessed: ["secrets", "cicd", "containers", "iac", "code", "ai-agents", "privacy", "process"],
|
|
216
|
-
notAssessed: [
|
|
293
|
+
summary: { total: findings.length, bySeverity, byStatus, baselineSuppressed: suppressed, waiversApplied, waiversExpired },
|
|
294
|
+
categoriesAssessed: ["secrets", "cicd", "containers", "iac", "code", "ai-agents", "privacy", "process", "supply"],
|
|
295
|
+
notAssessed: [
|
|
296
|
+
...(historyRan ? [] : ["git history"]),
|
|
297
|
+
...(opened.db ? [] : ["vulnerability advisories"]),
|
|
298
|
+
"authentication and authorization design",
|
|
299
|
+
"runtime and cloud state",
|
|
300
|
+
"mobile applications",
|
|
301
|
+
"object-field, dynamic-import, and call-return taint"
|
|
302
|
+
],
|
|
217
303
|
limitations,
|
|
218
304
|
findings
|
|
219
305
|
};
|
package/dist/fix.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
/** Deterministic text replacements. A secret is never rewritten. A value that cannot be known (a user name, a commit SHA) is not invented. */
|
|
4
|
+
const REPLACEMENTS = {
|
|
5
|
+
"VS-K8S-001": [{ from: /privileged:\s*true\b/, to: "privileged: false" }],
|
|
6
|
+
"VS-K8S-002": [{ from: /host(?:Network|PID|IPC):\s*true\b/, to: "$&" }],
|
|
7
|
+
"VS-K8S-003": [
|
|
8
|
+
{ from: /allowPrivilegeEscalation:\s*true\b/, to: "allowPrivilegeEscalation: false" },
|
|
9
|
+
{ from: /runAsNonRoot:\s*false\b/, to: "runAsNonRoot: true" }
|
|
10
|
+
],
|
|
11
|
+
"VS-IAC-002": [
|
|
12
|
+
{ from: /public-read-write/, to: "private" },
|
|
13
|
+
{ from: /public-read/, to: "private" }
|
|
14
|
+
],
|
|
15
|
+
"VS-CODE-005": [
|
|
16
|
+
{ from: /rejectUnauthorized\s*:\s*false/, to: "rejectUnauthorized: true" },
|
|
17
|
+
{ from: /NODE_TLS_REJECT_UNAUTHORIZED\s*=\s*["']?0["']?/, to: "NODE_TLS_REJECT_UNAUTHORIZED=1" },
|
|
18
|
+
{ from: /\bverify\s*=\s*False\b/, to: "verify=True" }
|
|
19
|
+
],
|
|
20
|
+
"VS-CODE-006": [
|
|
21
|
+
{ from: /createHash\(\s*["']md5["']\s*\)/i, to: 'createHash("sha256")' },
|
|
22
|
+
{ from: /createHash\(\s*["']sha1["']\s*\)/i, to: 'createHash("sha256")' },
|
|
23
|
+
{ from: /hashlib\.md5\s*\(/i, to: "hashlib.sha256(" },
|
|
24
|
+
{ from: /hashlib\.sha1\s*\(/i, to: "hashlib.sha256(" }
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
export function planFixes(findings, root) {
|
|
28
|
+
const out = [];
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
for (const f of findings) {
|
|
31
|
+
if (!REPLACEMENTS[f.ruleId] || f.path === "." || f.path.startsWith("git-history/") || f.path.includes(".."))
|
|
32
|
+
continue;
|
|
33
|
+
const key = `${f.path}:${f.startLine}:${f.ruleId}`;
|
|
34
|
+
if (seen.has(key))
|
|
35
|
+
continue;
|
|
36
|
+
seen.add(key);
|
|
37
|
+
let text;
|
|
38
|
+
try {
|
|
39
|
+
text = readFileSync(join(root, f.path), "utf8");
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const lines = text.split(/\r?\n/);
|
|
45
|
+
const line = lines[f.startLine - 1];
|
|
46
|
+
if (line === undefined)
|
|
47
|
+
continue;
|
|
48
|
+
const after = rewrite(f.ruleId, line);
|
|
49
|
+
if (!after || after === line)
|
|
50
|
+
continue;
|
|
51
|
+
out.push({ path: f.path, line: f.startLine, ruleId: f.ruleId, before: line, after });
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
function rewrite(ruleId, line) {
|
|
56
|
+
if (ruleId === "VS-K8S-002")
|
|
57
|
+
return line.replace(/host(Network|PID|IPC):\s*true\b/, "host$1: false");
|
|
58
|
+
let after = line;
|
|
59
|
+
for (const r of REPLACEMENTS[ruleId] ?? [])
|
|
60
|
+
after = after.replace(r.from, r.to);
|
|
61
|
+
return after;
|
|
62
|
+
}
|
|
63
|
+
export function applyFixes(edits, root) {
|
|
64
|
+
const byPath = new Map();
|
|
65
|
+
for (const e of edits)
|
|
66
|
+
byPath.set(e.path, [...(byPath.get(e.path) ?? []), e]);
|
|
67
|
+
let written = 0;
|
|
68
|
+
for (const [path, list] of byPath) {
|
|
69
|
+
const abs = join(root, path);
|
|
70
|
+
const text = readFileSync(abs, "utf8");
|
|
71
|
+
const nl = text.includes("\r\n") ? "\r\n" : "\n";
|
|
72
|
+
const lines = text.split(/\r?\n/);
|
|
73
|
+
let changed = false;
|
|
74
|
+
for (const e of list) {
|
|
75
|
+
if (lines[e.line - 1] !== e.before)
|
|
76
|
+
continue;
|
|
77
|
+
lines[e.line - 1] = e.after;
|
|
78
|
+
changed = true;
|
|
79
|
+
written++;
|
|
80
|
+
}
|
|
81
|
+
if (changed)
|
|
82
|
+
writeFileSync(abs, lines.join(nl));
|
|
83
|
+
}
|
|
84
|
+
return written;
|
|
85
|
+
}
|