vigilsutra 0.2.3 → 0.4.1
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 +28 -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 +96 -18
- 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 +76 -0
- package/docs/quickstart.md +3 -2
- package/docs/rules.md +92 -2
- package/docs/security-model.md +1 -1
- package/llms.txt +2 -2
- package/package.json +7 -3
- package/policies/safe-default.yaml +3 -0
- package/templates/pre-commit +7 -0
package/dist/cli.js
CHANGED
|
@@ -5,9 +5,12 @@ 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
|
-
const HELP = `VigilSutra AI ${VERSION} - offline, read-only security & privacy auditor. Created by Vatsal Shah.
|
|
13
|
+
const HELP = `VigilSutra AI ${VERSION} - offline, read-only security & privacy auditor. Created by Vatsal Shah (https://shahvatsal.com).
|
|
11
14
|
|
|
12
15
|
Usage: vigilsutra <command> [options]
|
|
13
16
|
|
|
@@ -22,22 +25,32 @@ Commands:
|
|
|
22
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
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
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") {
|
|
@@ -141,7 +170,7 @@ function main() {
|
|
|
141
170
|
const out = flags.get("out");
|
|
142
171
|
if (typeof out !== "string")
|
|
143
172
|
fail("baseline needs --out <file>");
|
|
144
|
-
const result = audit(
|
|
173
|
+
const result = audit(auditOpts(root, flags));
|
|
145
174
|
writeOut(out, JSON.stringify({ tool: "vigilsutra", version: VERSION, createdAt: result.generatedAt, fingerprints: result.findings.map((f) => f.fingerprint).sort() }, null, 2) + "\n");
|
|
146
175
|
process.stdout.write(`Baseline of ${result.findings.length} finding(s) written to ${out}\n`);
|
|
147
176
|
return;
|
|
@@ -160,7 +189,7 @@ function main() {
|
|
|
160
189
|
}
|
|
161
190
|
if (!Array.isArray(prev.findings))
|
|
162
191
|
fail("previous file is not a VigilSutra JSON result");
|
|
163
|
-
const now = audit(
|
|
192
|
+
const now = audit(auditOpts(root, flags));
|
|
164
193
|
const before = new Map(prev.findings.map((f) => [f.fingerprint, f]));
|
|
165
194
|
const after = new Map(now.findings.map((f) => [f.fingerprint, f]));
|
|
166
195
|
const resolved = [...before.values()].filter((f) => !after.has(f.fingerprint));
|
|
@@ -178,6 +207,36 @@ function main() {
|
|
|
178
207
|
process.exit(1);
|
|
179
208
|
return;
|
|
180
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
|
+
}
|
|
181
240
|
case "rules": {
|
|
182
241
|
if (pos[0] !== "list")
|
|
183
242
|
fail("usage: vigilsutra rules list");
|
|
@@ -229,15 +288,32 @@ function main() {
|
|
|
229
288
|
try {
|
|
230
289
|
// "wx" creates the file only if it does not exist, atomically (no check-then-write race).
|
|
231
290
|
writeFileSync(file, tpl, { flag: "wx" });
|
|
291
|
+
process.stdout.write(`Created ${file}\n`);
|
|
232
292
|
}
|
|
233
293
|
catch (e) {
|
|
234
|
-
if (e.code === "EEXIST")
|
|
294
|
+
if (e.code === "EEXIST")
|
|
235
295
|
process.stdout.write(".vigilsutra.yml already exists; not modified.\n");
|
|
236
|
-
|
|
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;
|
|
237
315
|
}
|
|
238
|
-
throw e;
|
|
239
316
|
}
|
|
240
|
-
process.stdout.write(`Created ${file}\n`);
|
|
241
317
|
return;
|
|
242
318
|
}
|
|
243
319
|
case "adapters": {
|
|
@@ -247,26 +323,28 @@ function main() {
|
|
|
247
323
|
process.stdout.write(`${a.name.padEnd(12)} ${a.status.padEnd(10)} ${a.detail}\n`);
|
|
248
324
|
return;
|
|
249
325
|
}
|
|
250
|
-
|
|
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];
|
|
251
329
|
const proj = checkRoot(typeof flags.get("project") === "string" ? flags.get("project") : ".");
|
|
252
330
|
if (sub === "uninstall") {
|
|
253
|
-
const removed =
|
|
331
|
+
const removed = uninstallAdapter(proj, adapter);
|
|
254
332
|
process.stdout.write(removed.length ? `Removed:\n${removed.map((r) => " " + r).join("\n")}\n` : "Nothing installed by VigilSutra found.\n");
|
|
255
333
|
return;
|
|
256
334
|
}
|
|
257
335
|
const force = flags.has("force");
|
|
258
336
|
if (flags.has("dry-run")) {
|
|
259
|
-
for (const p of
|
|
337
|
+
for (const p of planAdapter(proj, adapter, force))
|
|
260
338
|
process.stdout.write(`${p.action.padEnd(12)} ${p.to}\n`);
|
|
261
339
|
process.stdout.write("Dry run: no files written.\n");
|
|
262
340
|
return;
|
|
263
341
|
}
|
|
264
|
-
for (const p of
|
|
342
|
+
for (const p of installAdapter(proj, adapter, force))
|
|
265
343
|
process.stdout.write(`${p.action.padEnd(12)} ${p.to}\n`);
|
|
266
|
-
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");
|
|
267
345
|
return;
|
|
268
346
|
}
|
|
269
|
-
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>");
|
|
270
348
|
}
|
|
271
349
|
default:
|
|
272
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.1";
|
|
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
|
+
}
|
package/dist/git-index.js
CHANGED
|
@@ -148,9 +148,7 @@ function readRegular(abs, expected) {
|
|
|
148
148
|
}
|
|
149
149
|
try {
|
|
150
150
|
const now = fstatSync(fd);
|
|
151
|
-
if (!
|
|
152
|
-
return null;
|
|
153
|
-
if (expected.ino !== 0 && (now.ino !== expected.ino || now.dev !== expected.dev))
|
|
151
|
+
if (!sameIdentity(expected, now))
|
|
154
152
|
return null;
|
|
155
153
|
const buf = Buffer.alloc(now.size);
|
|
156
154
|
let off = 0;
|
|
@@ -172,8 +170,21 @@ function readRegular(abs, expected) {
|
|
|
172
170
|
}
|
|
173
171
|
}
|
|
174
172
|
const FILE_MODES = new Set([0o100644, 0o100755, 0o100664, 0o120000, 0o160000]);
|
|
173
|
+
/** Same file after open: inode when the filesystem has one, otherwise size and mtime. */
|
|
174
|
+
export function sameIdentity(expected, now) {
|
|
175
|
+
if (!now.isFile() || now.size !== expected.size)
|
|
176
|
+
return false;
|
|
177
|
+
if (expected.ino !== 0 || now.ino !== 0)
|
|
178
|
+
return now.ino === expected.ino && now.dev === expected.dev;
|
|
179
|
+
return now.mtimeMs === expected.mtimeMs;
|
|
180
|
+
}
|
|
175
181
|
/** Parse a git index (versions 2, 3, and 4; SHA-1 or SHA-256). Returns null if the bytes are not a valid index. */
|
|
176
182
|
export function parseGitIndex(buf) {
|
|
183
|
+
const entries = parseGitIndexEntries(buf);
|
|
184
|
+
return entries ? new Set(entries.map((e) => e.path)) : null;
|
|
185
|
+
}
|
|
186
|
+
/** Index paths plus the staged blob id. Returns null if the bytes are not a valid index. */
|
|
187
|
+
export function parseGitIndexEntries(buf) {
|
|
177
188
|
return parseWithHash(buf, 20) ?? parseWithHash(buf, 32);
|
|
178
189
|
}
|
|
179
190
|
function parseWithHash(buf, hashLen) {
|
|
@@ -192,7 +203,7 @@ function parseWithHash(buf, hashLen) {
|
|
|
192
203
|
const sum = createHash(algo).update(buf.subarray(0, end)).digest();
|
|
193
204
|
if (!sum.equals(buf.subarray(end)))
|
|
194
205
|
return null;
|
|
195
|
-
const
|
|
206
|
+
const entries = [];
|
|
196
207
|
let pos = 12;
|
|
197
208
|
let prev = "";
|
|
198
209
|
const flagAt = 40 + hashLen;
|
|
@@ -245,7 +256,7 @@ function parseWithHash(buf, hashLen) {
|
|
|
245
256
|
}
|
|
246
257
|
if (!name || name.includes("\\") || name.startsWith("/") || name.split("/").includes(".."))
|
|
247
258
|
return null;
|
|
248
|
-
|
|
259
|
+
entries.push({ path: name, sha: buf.subarray(pos + 40, pos + 40 + hashLen).toString("hex") });
|
|
249
260
|
if (next <= pos || next > end)
|
|
250
261
|
return null;
|
|
251
262
|
pos = next;
|
|
@@ -262,7 +273,7 @@ function parseWithHash(buf, hashLen) {
|
|
|
262
273
|
}
|
|
263
274
|
if (pos !== end)
|
|
264
275
|
return null;
|
|
265
|
-
return
|
|
276
|
+
return entries;
|
|
266
277
|
}
|
|
267
278
|
/** Git's offset varint: continuation bytes are biased by +1. See git's decode_varint. */
|
|
268
279
|
function decodeVarint(buf, pos, end) {
|