xovris 0.2.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/bin/xovris.mjs +0 -0
- package/dist/{apicmd-3jWpFhG3.js → apicmd-BHGPPVbb.js} +8 -1
- package/dist/cli.js +5447 -2150
- package/dist/{code-DKbqSLWT.js → code-Cv9xmjOW.js} +1 -1
- package/dist/{collector-join-CkBmhc2w.js → collector-join-B_k2_7BR.js} +1 -1
- package/dist/{deploy-guard-BdzcbJTF.js → deploy-guard-D06kPPwV.js} +1 -1
- package/dist/{findings-CcqH4Q2I.js → findings-wu3dKZAq.js} +2 -2
- package/dist/{finishing-CZ013_fT.js → finishing-DQEath5m.js} +1 -1
- package/dist/{gated-write-B8Aln6GU.js → gated-write-C1W3tG1Z.js} +1 -1
- package/dist/{hunt-Ce77c8DT.js → hunt-CKCYvtG9.js} +2 -2
- package/dist/{languages-9JrWtbQN.js → languages-f62XcE8m.js} +1 -1
- package/dist/limit-zU8xPAtN.js +74 -0
- package/dist/mapping-6HQuqcRm.js +48 -0
- package/dist/{merge-B-lFy27Y.js → merge-DYdlN4fU.js} +3 -3
- package/dist/{review-ui-DGEc-h8N.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-B7Knrrs4.js → sourcemaps-DFeg7Yue.js} +85 -16
- package/dist/spend-CvJZo_T1.js +118 -0
- package/dist/{src-CZstFB4j.js → src-F88zycxp.js} +5695 -543
- package/dist/symbols-DAUTKzoB.js +97 -0
- package/dist/tls-chain-DiOt1wwo.js +169 -0
- package/dist/{trace-1RWrsTAT.js → trace-BlK_FFnw.js} +1 -1
- package/package.json +18 -16
- package/dist/tls-chain-B3-Xk3Gg.js +0 -101
|
@@ -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 };
|
|
@@ -1,19 +1,42 @@
|
|
|
1
|
-
import "./src-
|
|
2
|
-
import { i as gatedWrite } from "./gated-write-
|
|
3
|
-
import { join, sep } from "node:path";
|
|
1
|
+
import "./src-F88zycxp.js";
|
|
2
|
+
import { i as gatedWrite } from "./gated-write-C1W3tG1Z.js";
|
|
3
|
+
import { basename, dirname, join, sep } from "node:path";
|
|
4
4
|
import { readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
|
|
7
7
|
//#region src/sourcemaps.ts
|
|
8
8
|
const MAX_FILES = 5e3;
|
|
9
9
|
const MARK = /\/\/# debugId=([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/;
|
|
10
|
-
const register = (id) => `;!function(){try{var g="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},s=(new g.Error).stack;s&&(g._xovrisDebugIds=g._xovrisDebugIds||{},g._xovrisDebugIds[s]="${id}")}catch(e){}}();`;
|
|
10
|
+
const register = (id) => `;!function(){try{var g="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},s=(new g.Error).stack;s&&(g._xovrisDebugIds=g._xovrisDebugIds||{},g._xovrisDebugIds[s]="${id}",g._sentryDebugIds=g._sentryDebugIds||{},g._sentryDebugIds[s]="${id}")}catch(e){}}();`;
|
|
11
11
|
/** A UUID drawn from the SHA-256 of the map's own bytes: building the same code twice marks it the same. */
|
|
12
12
|
function debugIdFor(map) {
|
|
13
13
|
const h = createHash("sha256").update(map).digest("hex");
|
|
14
14
|
return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-${"89ab"[parseInt(h[16], 16) % 4]}${h.slice(17, 20)}-${h.slice(20, 32)}`;
|
|
15
15
|
}
|
|
16
16
|
const OUTSIDE = "a link that does not stay inside the build folder: only files inside the folder given are read, marked and sent";
|
|
17
|
+
const HERMES = "compiled Hermes bytecode, which is never written into, and neither its map nor a packager map in the build names a debug ID - so no crash from this build can be matched to it. A Metro step that writes the debug ID into the bundle before Hermes compiles it gives it one (the metro.config.js wrapper of the React Native SDK the app sends with), and the next build is read as its own code";
|
|
18
|
+
const BUILT = /\.(js|mjs|cjs|bundle|jsbundle)$/;
|
|
19
|
+
const HBC = Buffer.from([
|
|
20
|
+
198,
|
|
21
|
+
31,
|
|
22
|
+
188,
|
|
23
|
+
3,
|
|
24
|
+
193,
|
|
25
|
+
3,
|
|
26
|
+
25,
|
|
27
|
+
31
|
|
28
|
+
]);
|
|
29
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
30
|
+
/** The debug ID a bundler already wrote into the map (debugId, or debug_id), when it has one. */
|
|
31
|
+
function ownId(map) {
|
|
32
|
+
try {
|
|
33
|
+
const m = JSON.parse(map);
|
|
34
|
+
const id = String(m.debugId ?? m.debug_id ?? "").toLowerCase();
|
|
35
|
+
return UUID.test(id) ? id : null;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
17
40
|
/** The real place of a path when it lies inside the build folder; null when a link takes it out or leads nowhere. */
|
|
18
41
|
function inside(root, p) {
|
|
19
42
|
try {
|
|
@@ -29,7 +52,7 @@ async function writeInside(root, file, text) {
|
|
|
29
52
|
await gatedWrite(root, file, text, "the built file");
|
|
30
53
|
return true;
|
|
31
54
|
}
|
|
32
|
-
function builtFiles(root, dir, out, left, seen) {
|
|
55
|
+
function builtFiles(root, dir, out, left, seen, lone = [], packager = /* @__PURE__ */ new Map()) {
|
|
33
56
|
for (const name of readdirSync(dir)) {
|
|
34
57
|
if (out.length >= MAX_FILES || name === "node_modules" || name.startsWith(".git")) continue;
|
|
35
58
|
const p = join(dir, name);
|
|
@@ -40,26 +63,75 @@ function builtFiles(root, dir, out, left, seen) {
|
|
|
40
63
|
}
|
|
41
64
|
if (seen.has(real)) continue;
|
|
42
65
|
seen.add(real);
|
|
43
|
-
if (statSync(real).isDirectory()) builtFiles(root, p, out, left, seen);
|
|
44
|
-
else if (
|
|
66
|
+
if (statSync(real).isDirectory()) builtFiles(root, p, out, left, seen, lone, packager);
|
|
67
|
+
else if (name.endsWith(".packager.map")) {
|
|
68
|
+
const key = `${basename(dir)}/${name.slice(0, -13)}`;
|
|
69
|
+
packager.set(key, packager.has(key) ? null : p);
|
|
70
|
+
} else if (BUILT.test(name) && statSync(`${p}.map`, { throwIfNoEntry: false })?.isFile()) (inside(root, `${p}.map`) ? out : left).push(p);
|
|
71
|
+
else if (name.endsWith(".map") && BUILT.test(name.slice(0, -4)) && !statSync(p.slice(0, -4), { throwIfNoEntry: false })?.isFile()) lone.push(p);
|
|
45
72
|
}
|
|
46
73
|
}
|
|
47
74
|
async function mark(dir) {
|
|
48
75
|
const root = realpathSync(dir);
|
|
49
76
|
const found = [];
|
|
50
|
-
const
|
|
51
|
-
|
|
77
|
+
const outside = [];
|
|
78
|
+
const lone = [];
|
|
79
|
+
const packager = /* @__PURE__ */ new Map();
|
|
80
|
+
builtFiles(root, dir, found, outside, new Set([root]), lone, packager);
|
|
81
|
+
const idFor = async (mapFile, map) => {
|
|
82
|
+
const own = ownId(map);
|
|
83
|
+
if (own) return own;
|
|
84
|
+
const from = packager.get(`${basename(dirname(mapFile))}/${basename(mapFile).slice(0, -4)}`);
|
|
85
|
+
const id = from ? ownId(readFileSync(from, "utf8")) : null;
|
|
86
|
+
if (id) try {
|
|
87
|
+
await writeInside(root, mapFile, JSON.stringify({
|
|
88
|
+
...JSON.parse(map),
|
|
89
|
+
debugId: id,
|
|
90
|
+
debug_id: id
|
|
91
|
+
}));
|
|
92
|
+
} catch {}
|
|
93
|
+
return id;
|
|
94
|
+
};
|
|
95
|
+
const left = outside.map((file) => ({
|
|
96
|
+
file,
|
|
97
|
+
why: OUTSIDE
|
|
98
|
+
}));
|
|
52
99
|
const files = [];
|
|
100
|
+
for (const mapFile of lone) {
|
|
101
|
+
const id = await idFor(mapFile, readFileSync(mapFile, "utf8"));
|
|
102
|
+
if (id) files.push({
|
|
103
|
+
file: mapFile.slice(0, -4),
|
|
104
|
+
mapFile,
|
|
105
|
+
debugId: id
|
|
106
|
+
});
|
|
107
|
+
}
|
|
53
108
|
for (const file of found) {
|
|
54
109
|
const mapFile = `${file}.map`;
|
|
55
110
|
const map = readFileSync(mapFile, "utf8");
|
|
56
|
-
const
|
|
111
|
+
const bytes = readFileSync(file);
|
|
112
|
+
if (bytes.subarray(0, HBC.length).equals(HBC)) {
|
|
113
|
+
const id = await idFor(mapFile, map);
|
|
114
|
+
if (id) files.push({
|
|
115
|
+
file,
|
|
116
|
+
mapFile,
|
|
117
|
+
debugId: id
|
|
118
|
+
});
|
|
119
|
+
else left.push({
|
|
120
|
+
file,
|
|
121
|
+
why: HERMES
|
|
122
|
+
});
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const js = bytes.toString("utf8");
|
|
57
126
|
const had = MARK.exec(js)?.[1];
|
|
58
|
-
const debugId = had ?? debugIdFor(map);
|
|
127
|
+
const debugId = had ?? ownId(map) ?? debugIdFor(map);
|
|
59
128
|
if (!had) {
|
|
60
129
|
const at = js.lastIndexOf("//# sourceMappingURL=");
|
|
61
130
|
if (!await writeInside(root, file, `${at >= 0 ? js.slice(0, at) : js.endsWith("\n") ? js : `${js}\n`}${register(debugId)}\n//# debugId=${debugId}\n${at >= 0 ? js.slice(at) : ""}`)) {
|
|
62
|
-
left.push(
|
|
131
|
+
left.push({
|
|
132
|
+
file,
|
|
133
|
+
why: OUTSIDE
|
|
134
|
+
});
|
|
63
135
|
continue;
|
|
64
136
|
}
|
|
65
137
|
try {
|
|
@@ -84,10 +156,7 @@ async function mark(dir) {
|
|
|
84
156
|
/** Marks the build, then sends each map. Without the token or the project nothing is sent, and the result says so as a diagnosis. */
|
|
85
157
|
async function uploadSourceMaps(o) {
|
|
86
158
|
const { files, left } = await mark(o.dir);
|
|
87
|
-
const outside = left
|
|
88
|
-
file,
|
|
89
|
-
why: OUTSIDE
|
|
90
|
-
}));
|
|
159
|
+
const outside = left;
|
|
91
160
|
if (!o.token || !o.project) {
|
|
92
161
|
const lacks = !o.token ? "the source-map upload token (XOVRIS_BUILD_TOKEN)" : "its project id (XOVRIS_PROJECT)";
|
|
93
162
|
return {
|