xovris 0.1.0 → 0.2.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/dist/{apicmd-3jWpFhG3.js → apicmd-BHGPPVbb.js} +8 -1
- package/dist/cli.js +4753 -1067
- package/dist/{code-DsDiCUXb.js → code-Cv9xmjOW.js} +12 -6
- package/dist/{collector-join-CwjwINuL.js → collector-join-B_k2_7BR.js} +1 -1
- package/dist/{deploy-guard-BdzcbJTF.js → deploy-guard-D06kPPwV.js} +1 -1
- package/dist/{findings-BHh24V38.js → findings-wu3dKZAq.js} +2 -2
- package/dist/{finishing-Dsc2jn0-.js → finishing-DQEath5m.js} +1 -1
- package/dist/{gated-write-DRftDST4.js → gated-write-C1W3tG1Z.js} +1 -1
- package/dist/{hunt-BmQxPIL8.js → hunt-CKCYvtG9.js} +2 -2
- package/dist/{languages-DhPS_td-.js → languages-f62XcE8m.js} +1 -1
- package/dist/limit-zU8xPAtN.js +74 -0
- package/dist/mapping-6HQuqcRm.js +48 -0
- package/dist/{merge-BK7G5i5Q.js → merge-DYdlN4fU.js} +3 -3
- package/dist/{review-ui-DsFuGF7B.js → review-ui-D-aMGRo2.js} +1 -1
- package/dist/sbom-AGsBNlj-.js +134 -0
- package/dist/secrets-scan-BcPn_pPi.js +175 -0
- package/dist/{sourcemaps-tbnp_n01.js → sourcemaps-DFeg7Yue.js} +85 -16
- package/dist/spend-CvJZo_T1.js +118 -0
- package/dist/{src-DPO9_Gtz.js → src-F88zycxp.js} +7495 -605
- package/dist/symbols-DAUTKzoB.js +97 -0
- package/dist/tls-chain-DiOt1wwo.js +169 -0
- package/dist/{trace-DoQjPlBv.js → trace-BlK_FFnw.js} +1 -1
- package/package.json +7 -5
- package/dist/tls-chain-B3-Xk3Gg.js +0 -101
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as tokenFor, u as Api } from "./apicmd-
|
|
1
|
+
import { i as tokenFor, u as Api } from "./apicmd-BHGPPVbb.js";
|
|
2
2
|
|
|
3
3
|
//#region src/code.ts
|
|
4
4
|
const plain = (s, max = 400) => String(s ?? "").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, max);
|
|
@@ -22,11 +22,17 @@ async function codeCommand(a, sys, io) {
|
|
|
22
22
|
job: await r.json().catch(() => ({})) ?? {}
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
let started;
|
|
26
|
+
try {
|
|
27
|
+
started = await call("POST", "/code/tasks", {
|
|
28
|
+
words,
|
|
29
|
+
...a.repository ? { repository: a.repository } : {},
|
|
30
|
+
via: "cli"
|
|
31
|
+
});
|
|
32
|
+
} catch (e) {
|
|
33
|
+
io.err(`Xovris did not answer at ${plain(a.api, 200)} (${plain(e?.cause?.message ?? e?.message ?? e, 160)}). Nothing was started; check the address or your network and run it again.\n`);
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
30
36
|
if (started.status !== 202 || !started.job.id) {
|
|
31
37
|
io.err(`${plain(started.job.title ?? `Xovris did not take the job (${started.status})`)}. ${plain(started.job.detail ?? "")}\n${plain(started.job.next ?? "Try again in a moment.")}\n`);
|
|
32
38
|
return started.status === 400 ? 2 : 1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as gatedService } from "./gated-write-
|
|
1
|
+
import { r as gatedService } from "./gated-write-C1W3tG1Z.js";
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { isAbsolute, resolve } from "node:path";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as tokenFor, u as Api } from "./apicmd-
|
|
1
|
+
import { c as FACET_AXES, l as checkFacetQuery, lt as SEVERITIES, o as EFFORTS, s as EFFORT_UNMEASURED } from "./src-F88zycxp.js";
|
|
2
|
+
import { i as tokenFor, u as Api } from "./apicmd-BHGPPVbb.js";
|
|
3
3
|
|
|
4
4
|
//#region src/findings.ts
|
|
5
5
|
/** The order a person reads each closed axis in; an open axis (kind, file) reads busiest first. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as jobRunner, I as writeProven, L as contentDigest, d as generateTests, f as proveResolution, p as touchesFor, u as applyTouches } from "./src-F88zycxp.js";
|
|
2
2
|
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
3
3
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
4
4
|
import { execFileSync } from "node:child_process";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as writeProven, L as contentDigest, P as filesOf, R as valueCopy, z as applyGuarded } from "./src-F88zycxp.js";
|
|
2
2
|
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as HUNT_CLASSES, t as huntRepository } from "./src-
|
|
2
|
-
import { o as stripAnsi, s as styleFor } from "./review-ui-
|
|
1
|
+
import { n as HUNT_CLASSES, t as huntRepository } from "./src-F88zycxp.js";
|
|
2
|
+
import { o as stripAnsi, s as styleFor } from "./review-ui-D-aMGRo2.js";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { existsSync, statSync } from "node:fs";
|
|
5
5
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { i as tokenFor, u as Api } from "./apicmd-BHGPPVbb.js";
|
|
2
|
+
|
|
3
|
+
//#region src/limit.ts
|
|
4
|
+
/** What `xovris limit ...` asks for, or why it cannot be sent - the server's own range is checked there, never guessed here. */
|
|
5
|
+
function limitRequest(a) {
|
|
6
|
+
if (a.action === "show") return {
|
|
7
|
+
method: "GET",
|
|
8
|
+
body: null
|
|
9
|
+
};
|
|
10
|
+
if (a.action === "remove") return {
|
|
11
|
+
method: "PATCH",
|
|
12
|
+
body: { monthlyLimit: null }
|
|
13
|
+
};
|
|
14
|
+
const n = a.value === null ? NaN : Number(a.value);
|
|
15
|
+
if (!Number.isInteger(n) || n < 0) return { problem: "Say the limit as a whole number of fixed issues a month: xovris limit set 20 (or xovris limit remove for none)." };
|
|
16
|
+
return {
|
|
17
|
+
method: "PATCH",
|
|
18
|
+
body: { monthlyLimit: n }
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** The limit as a person reads it: the month's use, the next point they are told at, and what never stops. */
|
|
22
|
+
function limitLines(v) {
|
|
23
|
+
const month = v.period.slice(0, 7);
|
|
24
|
+
const cap = v.monthlyLimit === null ? `no limit of your own - your plan includes ${v.included} this month` : `the limit you set${v.included !== v.monthlyLimit ? ` (your plan includes ${v.included})` : ""}`;
|
|
25
|
+
const of = v.monthlyLimit ?? v.included;
|
|
26
|
+
return [
|
|
27
|
+
`${month}: ${v.used} of ${of} AI-fixed issues used - ${cap}. ${v.remaining} left.`,
|
|
28
|
+
v.nextAlert ? `Next told at ${v.nextAlert.at}% (${v.nextAlert.atUsed} fixed issues), on every channel that works.` : "Every point this month has been told.",
|
|
29
|
+
`At the limit: ${v.alwaysOn}`,
|
|
30
|
+
...v.setBy && v.setAt ? [`Set by ${v.setBy} on ${v.setAt.slice(0, 10)}.`] : []
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
async function limitCommand(a, o, sys, secrets, io) {
|
|
34
|
+
const req = limitRequest(a);
|
|
35
|
+
if ("problem" in req) {
|
|
36
|
+
io.err(`${req.problem}\n`);
|
|
37
|
+
return 2;
|
|
38
|
+
}
|
|
39
|
+
const token = await tokenFor(o.api);
|
|
40
|
+
if (!token) {
|
|
41
|
+
io.err("Not signed in. Run xovris login, or set XOVRIS_TOKEN to a key from Settings, Developers.\n");
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
secrets.add(token);
|
|
45
|
+
const api = new Api(o.api, sys);
|
|
46
|
+
api.token = token;
|
|
47
|
+
let res;
|
|
48
|
+
try {
|
|
49
|
+
res = await api.raw(req.method, "/settings/ai-limit", req.body ?? void 0, req.method === "PATCH" ? { "idempotency-key": crypto.randomUUID() } : {});
|
|
50
|
+
} catch {
|
|
51
|
+
io.err(`${o.api} gave this computer no answer - run xovris limit again once its connection is back, or name another address with --api.\n`);
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
const text = await res.text();
|
|
55
|
+
let body = null;
|
|
56
|
+
try {
|
|
57
|
+
body = text ? JSON.parse(text) : null;
|
|
58
|
+
} catch {}
|
|
59
|
+
if (res.status < 200 || res.status >= 300) {
|
|
60
|
+
const e = body?.error;
|
|
61
|
+
io.err(`${secrets.redact(e ? `${e.message ?? ""} ${e.nextStep ?? ""}`.trim() : text || `HTTP ${res.status}`)}\n`);
|
|
62
|
+
if (res.status === 403) io.err("Only an owner or a billing member changes the limit; this key is not one. Its permissions are on Settings, Developers.\n");
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
if (a.json) {
|
|
66
|
+
io.out(`${secrets.redact(JSON.stringify(body, null, 2))}\n`);
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
io.out(`${limitLines(body).join("\n")}\n`);
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { limitCommand, limitLines, limitRequest };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { gzipSync } from "node:zlib";
|
|
3
|
+
|
|
4
|
+
//#region src/mapping.ts
|
|
5
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6
|
+
/** Sends one mapping file; without the token or the project nothing is sent, and the line says what Xovris needs. */
|
|
7
|
+
async function uploadMapping(o) {
|
|
8
|
+
if (o.uuid && !UUID.test(o.uuid)) return {
|
|
9
|
+
sent: false,
|
|
10
|
+
uuid: null,
|
|
11
|
+
said: `"${o.uuid}" is not a mapping UUID: it is the 36-character ID your build wrote into the app (io.sentry.ProguardUuids). Leave --uuid out and Xovris files it under the one its content names.`
|
|
12
|
+
};
|
|
13
|
+
if (!o.token || !o.project) return {
|
|
14
|
+
sent: false,
|
|
15
|
+
uuid: null,
|
|
16
|
+
said: `This build ran without ${!o.token ? "the upload token (XOVRIS_BUILD_TOKEN)" : "its project id (XOVRIS_PROJECT)"}, so the mapping was not sent and crashes from this build stay obfuscated. Xovris sets both for you: run npx xovris in the project and it writes them into your build settings with your approval. Do it yourself instead: set XOVRIS_BUILD_TOKEN and XOVRIS_PROJECT where the build runs.`
|
|
17
|
+
};
|
|
18
|
+
const body = gzipSync(readFileSync(o.file));
|
|
19
|
+
const name = o.file.replace(/\\/g, "/").split("/").pop() ?? "mapping.txt";
|
|
20
|
+
const url = `${o.api.replace(/\/$/, "")}/v1/projects/${encodeURIComponent(o.project)}/debug-files/proguard?fileName=${encodeURIComponent(name)}${o.uuid ? `&uuid=${o.uuid.toLowerCase()}` : ""}`;
|
|
21
|
+
const res = await (o.fetch ?? fetch)(url, {
|
|
22
|
+
method: "PUT",
|
|
23
|
+
headers: {
|
|
24
|
+
authorization: `Bearer ${o.token}`,
|
|
25
|
+
"content-type": "application/octet-stream"
|
|
26
|
+
},
|
|
27
|
+
body
|
|
28
|
+
}).catch((e) => ({
|
|
29
|
+
ok: false,
|
|
30
|
+
status: 0,
|
|
31
|
+
json: async () => ({ error: { message: e instanceof Error ? e.message : "the request never got an answer" } })
|
|
32
|
+
}));
|
|
33
|
+
const j = await res.json().catch(() => null);
|
|
34
|
+
if (!res.ok) return {
|
|
35
|
+
sent: false,
|
|
36
|
+
uuid: null,
|
|
37
|
+
said: `The mapping was not kept (${res.status || "no answer"}: ${j?.error?.message ?? "refused"})${j?.error?.nextStep ? ` ${j.error.nextStep}` : ""}`
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
sent: true,
|
|
41
|
+
uuid: j?.uuid ?? null,
|
|
42
|
+
replaced: j?.replaced === true,
|
|
43
|
+
said: `Mapping ${name} ${j?.replaced ? "replaced" : "kept"} under ${j?.uuid}: crashes from this build read as your own code.`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { uploadMapping };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./gated-write-
|
|
3
|
-
import { i as splitCommandLine } from "./collector-join-
|
|
1
|
+
import { a as runMergeQueue, i as queueOrder, nt as dirReader, r as gitQueueRepo, rt as workOut } from "./src-F88zycxp.js";
|
|
2
|
+
import "./gated-write-C1W3tG1Z.js";
|
|
3
|
+
import { i as splitCommandLine } from "./collector-join-B_k2_7BR.js";
|
|
4
4
|
|
|
5
5
|
//#region src/merge.ts
|
|
6
6
|
async function mergeCommand(o, sys, out) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lt as SEVERITIES, ut as SEVERITY_LABEL } from "./src-F88zycxp.js";
|
|
2
2
|
|
|
3
3
|
//#region src/review-ui.ts
|
|
4
4
|
/** Colour only for a person at a terminal that asked for none of the plain modes (no-color.org; CI is never a terminal). */
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { H as osvAdvisories, U as dependenciesIn, V as npmDependencies, _ as spdxOf, b as withLicences, g as sbomOf, h as lockOfBom, m as HOSTING_FILES, ot as readingsOf, v as spdxTagValue, y as lockfilesIn } from "./src-F88zycxp.js";
|
|
2
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
3
|
+
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
//#region src/sbom.ts
|
|
6
|
+
function hostingFiles(dir, depth = 3) {
|
|
7
|
+
const out = [];
|
|
8
|
+
const walk = (d, left) => {
|
|
9
|
+
let names = [];
|
|
10
|
+
try {
|
|
11
|
+
names = readdirSync(d);
|
|
12
|
+
} catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
for (const n of names) {
|
|
16
|
+
if (n === "node_modules" || n.startsWith(".")) continue;
|
|
17
|
+
const p = join(d, n);
|
|
18
|
+
let dirLike = false;
|
|
19
|
+
try {
|
|
20
|
+
dirLike = statSync(p).isDirectory();
|
|
21
|
+
} catch {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (dirLike) {
|
|
25
|
+
if (left > 0) walk(p, left - 1);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (HOSTING_FILES.test(n)) try {
|
|
29
|
+
out.push({
|
|
30
|
+
path: relative(dir, p).replace(/\\/g, "/"),
|
|
31
|
+
text: readFileSync(p, "utf8").slice(0, 1e6)
|
|
32
|
+
});
|
|
33
|
+
} catch {}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
walk(dir, depth);
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
async function sbomCommand(o, say = (s) => {
|
|
40
|
+
process.stderr.write(s);
|
|
41
|
+
}, write = (s) => {
|
|
42
|
+
process.stdout.write(s);
|
|
43
|
+
}) {
|
|
44
|
+
if (!existsSync(o.cwd)) {
|
|
45
|
+
let up = resolve(o.cwd);
|
|
46
|
+
while (!existsSync(up) && dirname(up) !== up) up = dirname(up);
|
|
47
|
+
if (!existsSync(up)) {
|
|
48
|
+
say(`There is no folder at ${o.cwd} or above it on this machine; Xovris has nothing to read there. Do it yourself instead: pass --cwd <folder>.\n`);
|
|
49
|
+
return 2;
|
|
50
|
+
}
|
|
51
|
+
say(`There is no folder at ${o.cwd}; Xovris reads the nearest folder above it, ${up}. Do it yourself instead: pass --cwd <folder>.\n`);
|
|
52
|
+
o = {
|
|
53
|
+
...o,
|
|
54
|
+
cwd: up
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const format = (o.format ?? "cyclonedx").toLowerCase();
|
|
58
|
+
if (format !== "cyclonedx" && format !== "spdx-json" && format !== "spdx") {
|
|
59
|
+
say(`--format ${o.format} is not one Xovris writes, so it writes CycloneDX 1.6 (cyclonedx, the default); it also writes SPDX 2.3 as JSON (spdx-json) or tag-value (spdx). Do it yourself instead: pass --format spdx-json.\n`);
|
|
60
|
+
o = {
|
|
61
|
+
...o,
|
|
62
|
+
format: "cyclonedx"
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
let given = null;
|
|
66
|
+
if (o.from) {
|
|
67
|
+
let doc = null, why = "";
|
|
68
|
+
try {
|
|
69
|
+
doc = JSON.parse(readFileSync(existsSync(o.from) ? o.from : join(o.cwd, o.from), "utf8"));
|
|
70
|
+
} catch (e) {
|
|
71
|
+
why = e instanceof Error ? e.message : String(e);
|
|
72
|
+
}
|
|
73
|
+
given = doc === null ? null : lockOfBom(o.from, doc);
|
|
74
|
+
if (!given) say(`The bill at ${o.from} was not read as CycloneDX or SPDX JSON${why ? ` (${why})` : ""}, so Xovris reads the folder's own lockfiles and manifests instead.\n`);
|
|
75
|
+
}
|
|
76
|
+
const read = given ? {
|
|
77
|
+
deps: [],
|
|
78
|
+
read: [],
|
|
79
|
+
notRead: []
|
|
80
|
+
} : dependenciesIn(o.cwd, (dir) => npmDependencies(dir).map((x) => ({
|
|
81
|
+
...x,
|
|
82
|
+
manifest: "package.json",
|
|
83
|
+
root: ""
|
|
84
|
+
})));
|
|
85
|
+
let hosts = [];
|
|
86
|
+
if (o.live) {
|
|
87
|
+
let doc = null, why = "";
|
|
88
|
+
try {
|
|
89
|
+
doc = /^https?:\/\//.test(o.live) ? await (await fetch(o.live, { signal: AbortSignal.timeout(15e3) })).json() : JSON.parse(readFileSync(existsSync(o.live) ? o.live : join(o.cwd, o.live), "utf8"));
|
|
90
|
+
} catch (e) {
|
|
91
|
+
why = e instanceof Error ? e.message : String(e);
|
|
92
|
+
}
|
|
93
|
+
const r = doc === null ? { refused: why } : readingsOf(doc, o.live);
|
|
94
|
+
if ("refused" in r) say(`The live readings at ${o.live} were not read (${r.refused}), so Xovris writes the bill without them - each advisory in a build is marked in triage - and reads them again on the next run. They are the JSON xovris review --live reads, with hosts: [{ host, https, paths: [{ path, status }] }].\n`);
|
|
95
|
+
else hosts = r.hosts ?? [];
|
|
96
|
+
}
|
|
97
|
+
const locked = given ? [given] : withLicences(o.cwd, lockfilesIn(o.cwd));
|
|
98
|
+
const seen = /* @__PURE__ */ new Set(), pkgs = [];
|
|
99
|
+
for (const p of [...read.deps.filter((d) => d.current).map((d) => ({
|
|
100
|
+
ecosystem: d.ecosystem,
|
|
101
|
+
name: d.name,
|
|
102
|
+
version: d.current
|
|
103
|
+
})), ...locked.flatMap((g) => g.packages.map((x) => ({
|
|
104
|
+
ecosystem: x.ecosystem,
|
|
105
|
+
name: x.name,
|
|
106
|
+
version: x.version
|
|
107
|
+
})))]) {
|
|
108
|
+
const k = `${p.ecosystem}\u0000${p.name}\u0000${p.version}`;
|
|
109
|
+
if (!seen.has(k)) {
|
|
110
|
+
seen.add(k);
|
|
111
|
+
pkgs.push(p);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const got = pkgs.length ? await (o.advisories ?? osvAdvisories())(pkgs) : [];
|
|
115
|
+
if (!Array.isArray(got)) say(`The advisories were not read (${got.why}); the bill of materials lists every dependency, and Xovris reads the advisories again on the next run.\n`);
|
|
116
|
+
const bom = sbomOf(read.deps, Array.isArray(got) ? got : [], {
|
|
117
|
+
name: basename(o.cwd),
|
|
118
|
+
files: hostingFiles(o.cwd),
|
|
119
|
+
hosts,
|
|
120
|
+
locked,
|
|
121
|
+
...o.now ? { at: o.now } : {}
|
|
122
|
+
});
|
|
123
|
+
const as = o.format?.toLowerCase();
|
|
124
|
+
const text = as === "spdx" ? spdxTagValue(spdxOf(bom)) : `${JSON.stringify(as === "spdx-json" ? spdxOf(bom) : bom, null, 2)}\n`;
|
|
125
|
+
if (o.out) writeFileSync(o.out, text);
|
|
126
|
+
else write(text);
|
|
127
|
+
const served = bom.vulnerabilities.filter((v) => v.analysis.state === "exploitable");
|
|
128
|
+
const ids = new Set(bom.vulnerabilities.map((v) => v.id));
|
|
129
|
+
say(`${bom.components.length} packages (${bom.components.filter((c) => c.scope === "excluded").length} only in development, ${bom.components.filter((c) => c.licenses).length} with their licence) from ${given ? `the bill at ${o.from}` : `${locked.length} lockfiles and ${read.read.length} manifests`}; ${ids.size} advisories for versions in use - ${served.length} in a build served now, ${bom.vulnerabilities.filter((v) => v.analysis.state === "not_affected").length} in no build, ${bom.vulnerabilities.filter((v) => v.analysis.state === "in_triage").length} in a build no checked host serves.${o.out ? ` Written to ${o.out}.` : ""}\n`);
|
|
130
|
+
return served.length ? 1 : 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
export { sbomCommand };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { $ as secretFindings, Q as findSecrets, ct as parseDiff } from "./src-F88zycxp.js";
|
|
2
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
//#region src/secrets-scan.ts
|
|
7
|
+
const HOOK_MARK = "# xovris secrets hook";
|
|
8
|
+
const BEFORE = "pre-commit.before-xovris";
|
|
9
|
+
const git = (cwd, args) => execFileSync("git", args, {
|
|
10
|
+
cwd,
|
|
11
|
+
encoding: "utf8",
|
|
12
|
+
maxBuffer: 512 * 1024 * 1024,
|
|
13
|
+
stdio: [
|
|
14
|
+
"ignore",
|
|
15
|
+
"pipe",
|
|
16
|
+
"pipe"
|
|
17
|
+
]
|
|
18
|
+
});
|
|
19
|
+
/** The staged lines' secrets: the same check the pull request door holds a change on. */
|
|
20
|
+
function staged(top) {
|
|
21
|
+
const files = parseDiff(git(top, [
|
|
22
|
+
"diff",
|
|
23
|
+
"--cached",
|
|
24
|
+
"--no-color",
|
|
25
|
+
"--no-ext-diff",
|
|
26
|
+
"--unified=0",
|
|
27
|
+
"--diff-filter=ACMR"
|
|
28
|
+
]));
|
|
29
|
+
return {
|
|
30
|
+
hits: secretFindings(files).map((f) => ({
|
|
31
|
+
file: f.file,
|
|
32
|
+
line: f.line ?? 0,
|
|
33
|
+
what: f.title,
|
|
34
|
+
masked: f.evidence
|
|
35
|
+
})),
|
|
36
|
+
files: files.length
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Every key ever written on any branch or tag: each commit's added lines read with the same rules, a value named once - the newest
|
|
40
|
+
* commit that carries it - so a key taken out of the files but still in the history is found (the history clean then removes it). */
|
|
41
|
+
function history(top) {
|
|
42
|
+
const log = git(top, [
|
|
43
|
+
"log",
|
|
44
|
+
"--all",
|
|
45
|
+
"-p",
|
|
46
|
+
"--no-color",
|
|
47
|
+
"--no-ext-diff",
|
|
48
|
+
"--unified=0",
|
|
49
|
+
"--diff-filter=ACMR",
|
|
50
|
+
"--format=%x00commit %H %h",
|
|
51
|
+
"--abbrev=12"
|
|
52
|
+
]);
|
|
53
|
+
const hits = [];
|
|
54
|
+
const seen = /* @__PURE__ */ new Set();
|
|
55
|
+
let commits = 0;
|
|
56
|
+
for (const chunk of log.split("\0commit ")) {
|
|
57
|
+
const head = /^([0-9a-f]{40}) ([0-9a-f]+)/.exec(chunk);
|
|
58
|
+
if (!head) continue;
|
|
59
|
+
commits++;
|
|
60
|
+
for (const f of secretFindings(parseDiff(chunk.substring(head[0].length)))) {
|
|
61
|
+
const fp = /sha256:[0-9a-f]+/.exec(f.evidence)?.[0] ?? f.evidence;
|
|
62
|
+
if (seen.has(fp)) continue;
|
|
63
|
+
seen.add(fp);
|
|
64
|
+
hits.push({
|
|
65
|
+
file: `${head[2]} ${f.file}`,
|
|
66
|
+
line: f.line ?? 0,
|
|
67
|
+
what: f.title,
|
|
68
|
+
masked: f.evidence
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
hits,
|
|
74
|
+
files: commits
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** The named files' secrets, each read whole; a file outside the repository or not there is said, never read. */
|
|
78
|
+
function named(cwd, top, paths, io) {
|
|
79
|
+
const hits = [];
|
|
80
|
+
let files = 0, unread = 0;
|
|
81
|
+
for (const p of paths) {
|
|
82
|
+
const abs = isAbsolute(p) ? p : resolve(cwd, p);
|
|
83
|
+
const rel = relative(top, abs);
|
|
84
|
+
if (rel.startsWith("..") || isAbsolute(rel)) {
|
|
85
|
+
io.err(`${p} is outside this repository, so Xovris does not read it.`);
|
|
86
|
+
unread++;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (!existsSync(abs) || !statSync(abs).isFile()) {
|
|
90
|
+
io.err(`${p} is not a file here, so it was not read.`);
|
|
91
|
+
unread++;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
files++;
|
|
95
|
+
for (const s of findSecrets(readFileSync(abs, "utf8"), rel)) hits.push({
|
|
96
|
+
file: rel.replace(/\\/g, "/"),
|
|
97
|
+
line: s.line,
|
|
98
|
+
what: `A ${s.provider} key`,
|
|
99
|
+
masked: `${s.masked} (${s.rule}, ${s.fingerprint})`
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
hits,
|
|
104
|
+
files,
|
|
105
|
+
unread
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** The repository's own pre-commit hook runs this read first; a hook that was there is kept and runs before it, as it did. */
|
|
109
|
+
function installHook(top, cwd, self, io) {
|
|
110
|
+
const dir = resolve(cwd, git(cwd, [
|
|
111
|
+
"rev-parse",
|
|
112
|
+
"--git-path",
|
|
113
|
+
"hooks"
|
|
114
|
+
]).trim());
|
|
115
|
+
mkdirSync(dir, { recursive: true });
|
|
116
|
+
const hook = join(dir, "pre-commit");
|
|
117
|
+
if (existsSync(hook) && readFileSync(hook, "utf8").includes(HOOK_MARK)) {
|
|
118
|
+
io.out(`The secrets hook is already in place at ${relative(top, hook).replace(/\\/g, "/")} - every commit here is read first.`);
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
const kept = existsSync(hook);
|
|
122
|
+
if (kept) renameSync(hook, join(dir, BEFORE));
|
|
123
|
+
const q = (s) => `'${s.replace(/\\/g, "/").replace(/'/g, `'\\''`)}'`;
|
|
124
|
+
writeFileSync(hook, [
|
|
125
|
+
"#!/bin/sh",
|
|
126
|
+
`${HOOK_MARK} - a commit that writes a secret is held (npx xovris secrets --install-hook put it here)`,
|
|
127
|
+
`here="$(dirname "$0")"`,
|
|
128
|
+
`if [ -x "$here/${BEFORE}" ]; then "$here/${BEFORE}" "$@" || exit $?; fi`,
|
|
129
|
+
`exec ${self.map(q).join(" ")} secrets`,
|
|
130
|
+
""
|
|
131
|
+
].join("\n"), "utf8");
|
|
132
|
+
chmodSync(hook, 493);
|
|
133
|
+
if (kept) chmodSync(join(dir, BEFORE), 493);
|
|
134
|
+
io.out(`The secrets hook is in place at ${relative(top, hook).replace(/\\/g, "/")}: every commit here is read for secrets first, and one that writes a secret is held.${kept ? ` The hook that was there runs first, as before (${BEFORE}).` : ""}`);
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
async function secretsCommand(o, io) {
|
|
138
|
+
if (!existsSync(o.cwd)) {
|
|
139
|
+
io.err(`${o.cwd} is not a folder on this computer, so nothing was read.`);
|
|
140
|
+
return 2;
|
|
141
|
+
}
|
|
142
|
+
let top;
|
|
143
|
+
try {
|
|
144
|
+
top = git(o.cwd, ["rev-parse", "--show-toplevel"]).trim();
|
|
145
|
+
} catch {
|
|
146
|
+
io.err("This folder is not inside a git repository, so there is nothing staged to read; files named after the command are read instead (npx xovris secrets <file>).");
|
|
147
|
+
return 2;
|
|
148
|
+
}
|
|
149
|
+
const entry = process.argv[1] ?? "";
|
|
150
|
+
const self = o.self ?? (!entry || /[\\/]_npx[\\/]/.test(entry) ? [
|
|
151
|
+
"npx",
|
|
152
|
+
"--yes",
|
|
153
|
+
"xovris"
|
|
154
|
+
] : [process.execPath, entry]);
|
|
155
|
+
if (o.installHook) return installHook(top, o.cwd, self, io);
|
|
156
|
+
const r = o.paths.length ? named(o.cwd, top, o.paths, io) : {
|
|
157
|
+
...o.history ? history(top) : staged(top),
|
|
158
|
+
unread: 0
|
|
159
|
+
};
|
|
160
|
+
if (o.json) io.out(JSON.stringify({
|
|
161
|
+
found: r.hits,
|
|
162
|
+
files: r.files,
|
|
163
|
+
unread: r.unread
|
|
164
|
+
}));
|
|
165
|
+
else {
|
|
166
|
+
for (const h of r.hits) io.out(`${h.file}:${h.line} ${h.what} - ${h.masked}`);
|
|
167
|
+
const where = o.paths.length ? `the ${r.files} file${r.files === 1 ? "" : "s"} named` : o.history ? `this repository's history (${r.files} commit${r.files === 1 ? "" : "s"} on every branch and tag)` : `the ${r.files} staged file${r.files === 1 ? "" : "s"}`;
|
|
168
|
+
io.out(r.hits.length ? `${r.hits.length} secret${r.hits.length === 1 ? "" : "s"} in ${where}${o.history ? " - each is still readable in every clone, even where the files no longer hold it" : " - the commit is held"}. Read each from the environment or a secret store instead; if one is live, Xovris replaces it everywhere it is used and revokes it. A line marked xovris:allow-secret is passed.` : `No secret in ${where}.`);
|
|
169
|
+
}
|
|
170
|
+
if (r.hits.length) return 1;
|
|
171
|
+
return r.unread && !r.files ? 2 : 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
export { HOOK_MARK, secretsCommand };
|