@misconfig/cli 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/main.js CHANGED
@@ -1,9 +1,13 @@
1
- import { readFile } from "node:fs/promises";
1
+ import { randomUUID } from "node:crypto";
2
+ import { readFile, rename, unlink, writeFile } from "node:fs/promises";
3
+ import path from "node:path";
2
4
  import { createInterface } from "node:readline/promises";
3
5
  import { analyze, applyLookup, useKnownMalware } from "../engine/index.js";
4
6
  import { KNOWN_AS_OF } from "../engine/known.js";
5
7
  import { discover } from "./discover.js";
6
- import { printReport, printOpenResult, printLookupPreview, printLookupResult, oneLine } from "./print.js";
8
+ import { printReport, printOpenResult, printSarifResult, printLookupPreview, printLookupResult, oneLine } from "./print.js";
9
+ import { jsonLines, sarif, stringify } from "./formats.js";
10
+ import { loadRules } from "./rule-files.js";
7
11
  import { writeReport, openInBrowser } from "./html.js";
8
12
  import { lookupQueries, osvLookup, installsOnly } from "./lookup.js";
9
13
  import { computerSnapshot } from "./computer-snapshot.js";
@@ -53,6 +57,12 @@ Options
53
57
  Same as setting MISCONFIG_OFFLINE=1.
54
58
  --yes Look up without asking, for scripts and CI
55
59
  --json Print the full result as JSON
60
+ --jsonl Print the findings as JSON Lines, one finding on each
61
+ line, for jq, grep and log collectors
62
+ --sarif FILE Also save the findings in FILE as SARIF 2.1.0, for
63
+ GitHub code scanning and other SARIF viewers
64
+ --rules FILE Also check with your own rules, from a JSON file.
65
+ Repeat it for more files.
56
66
  --project-only Skip the agent settings on this computer
57
67
  --fail-on <level> Exit with code 1 if anything at this level or worse is
58
68
  found: critical, high, medium or low. Useful in CI.
@@ -82,6 +92,17 @@ export async function main(argv) {
82
92
  else if (a === "--offline") opts.offline = true;
83
93
  else if (a === "--yes" || a === "-y") opts.yes = true;
84
94
  else if (a === "--json") opts.json = true;
95
+ else if (a === "--jsonl") opts.jsonl = true;
96
+ else if (a === "--sarif" || a.startsWith("--sarif=")) {
97
+ if (opts.sarif) throw new Error("Choose one file for --sarif.");
98
+ opts.sarif = a === "--sarif" ? argv[++i] : a.slice(8);
99
+ if (!opts.sarif || opts.sarif.startsWith("-")) throw new Error("--sarif needs a file to save the findings in, such as misconfig.sarif.");
100
+ }
101
+ else if (a === "--rules" || a.startsWith("--rules=")) {
102
+ const file = a === "--rules" ? argv[++i] : a.slice(8);
103
+ if (!file || file.startsWith("-")) throw new Error("--rules needs a file of your own rules, such as rules.json.");
104
+ (opts.rules ??= []).push(file);
105
+ }
85
106
  else if (a === "--explain") opts.explain = true;
86
107
  else if (a === "--project-only") opts.projectOnly = true;
87
108
  else if (a === "--no-history") opts.noHistory = true;
@@ -114,20 +135,21 @@ export async function main(argv) {
114
135
  else { opts.dir = a; opts.folderGiven = true; }
115
136
  }
116
137
 
138
+ if (opts.json && opts.jsonl) throw new Error("Choose --json or --jsonl. Each prints on its own.");
117
139
  if (opts.history || opts.claim || opts.checkUpdate) {
118
- if ([opts.history, opts.claim, opts.checkUpdate].filter(Boolean).length > 1 || opts.demo || opts.projectOnly || opts.noHistory || opts.review || opts.approve || opts.open || opts.lookup || opts.explain || opts.failOn || opts.yes || opts.folderGiven || opts.attribute) throw new Error("Use --history, --i-edited ID or --check-update as a separate command. Each supports --json.");
140
+ if ([opts.history, opts.claim, opts.checkUpdate].filter(Boolean).length > 1 || opts.demo || opts.projectOnly || opts.noHistory || opts.review || opts.approve || opts.open || opts.lookup || opts.explain || opts.failOn || opts.yes || opts.folderGiven || opts.attribute || opts.jsonl || opts.sarif || opts.rules) throw new Error("Use --history, --i-edited ID or --check-update as a separate command. Each supports --json.");
119
141
  if (opts.checkUpdate) {
120
142
  const update = await packageUpdate(await version(), { force: true, offline: opts.offline });
121
- console.log(opts.json ? JSON.stringify(update, null, 2) : updateMessage(update, true));
143
+ console.log(opts.json ? stringify(update, 2) : updateMessage(update, true));
122
144
  return ["unavailable", "offline"].includes(update.status) ? 2 : 0;
123
145
  }
124
146
  if (opts.claim) {
125
147
  const event = await updateReview((state) => claimEdit(state.history, opts.claim));
126
- console.log(opts.json ? JSON.stringify(event, null, 2) : oneLine(historyLine(event)));
148
+ console.log(opts.json ? stringify(event, 2) : oneLine(historyLine(event)));
127
149
  return 0;
128
150
  }
129
151
  const history = await readHistory();
130
- if (opts.json) console.log(JSON.stringify(history, null, 2));
152
+ if (opts.json) console.log(stringify(history, 2));
131
153
  else {
132
154
  const lines = ["Computer history (newest first)"];
133
155
  if (history.incomplete) lines.push(earlierBuildNote);
@@ -137,14 +159,16 @@ export async function main(argv) {
137
159
  }
138
160
  return 0;
139
161
  }
140
- if (opts.demo && (opts.attribute || opts.projectOnly || opts.noHistory || opts.approve || opts.lookup || opts.failOn || opts.yes || opts.folderGiven)) throw new Error("Use --demo to review the sample computer. It also supports --open, --explain and --json.");
162
+ if (opts.demo && (opts.attribute || opts.projectOnly || opts.noHistory || opts.approve || opts.lookup || opts.failOn || opts.yes || opts.folderGiven || opts.jsonl || opts.sarif || opts.rules)) throw new Error("Use --demo to review the sample computer. It also supports --open, --explain and --json.");
141
163
  if ((opts.attribute || opts.review || opts.approve) && (opts.noHistory || opts.projectOnly)) throw new Error("Computer review needs a scan with computer history enabled.");
142
- if (opts.review && (opts.approve || opts.json || !process.stdin.isTTY || !process.stdout.isTTY)) throw new Error("Use --review in a terminal, or run --approve ID to choose one item directly.");
164
+ if (opts.review && (opts.approve || opts.json || opts.jsonl || !process.stdin.isTTY || !process.stdout.isTTY)) throw new Error("Use --review in a terminal, or run --approve ID to choose one item directly.");
143
165
  if (opts.demo) return withDemo((demo) => runScan({ ...opts, offline: true }, demo));
144
166
  return runScan(opts);
145
167
  }
146
168
 
147
169
  async function runScan(opts, demo) {
170
+ // A mistake in a rules file stops the command before anything is checked.
171
+ const rules = opts.rules ? await loadRules(opts.rules) : [];
148
172
  const update = automaticUpdateCheck(opts) ? packageUpdate(await version()) : null;
149
173
  const known = opts.offline ? { asOf: `${KNOWN_AS_OF}T00:00:00Z`, from: "offline" } : await todaysList();
150
174
  // A concurrent local scan can cause the transaction to retry. Reuse an
@@ -158,7 +182,9 @@ async function runScan(opts, demo) {
158
182
  if (typeof original === "string" && original.length <= LIMITS.maxFileBytes && snapshot.verified.has(file)) currentFiles.set(file, original);
159
183
  } : snapshot?.collect;
160
184
  const input = await discover({ dir: opts.dir, includeUser: !opts.projectOnly, ...demo?.discovery, onComputerFile: collect });
161
- let result = { ...check(input), knownMalware: known };
185
+ let result = { ...check(input, rules), knownMalware: known };
186
+ // The rules of your own that the check ran with. Every report says how many.
187
+ if (rules.length) result.customRules = rules.map((rule) => rule.id);
162
188
  if (demo) { result.demo = true; input.scanned.demo = true; }
163
189
  let lookedUp = false;
164
190
  if (opts.lookup) {
@@ -213,7 +239,8 @@ async function runScan(opts, demo) {
213
239
  for (const item of [...review.pending, ...review.risks]) showApproval(review, result.findings, await decide(item.id, "Demo reviewer"));
214
240
  }
215
241
 
216
- if (opts.json) process.stdout.write(JSON.stringify(result, null, 2) + "\n");
242
+ if (opts.json) process.stdout.write(stringify(result, 2) + "\n");
243
+ else if (opts.jsonl) process.stdout.write(jsonLines(result, { version: await version() }));
217
244
  else printReport(result, { version: await version(), scanned: input.scanned, explain: opts.explain, open: opts.open, lookedUp, known });
218
245
  if (update) {
219
246
  const notice = updateMessage(await update);
@@ -221,6 +248,7 @@ async function runScan(opts, demo) {
221
248
  }
222
249
 
223
250
  if (opts.open) await openReport(opts, input, result);
251
+ if (opts.sarif) await saveSarif(opts, result);
224
252
 
225
253
  if (opts.failOn) {
226
254
  const worst = LEVELS.slice(0, LEVELS.indexOf(opts.failOn) + 1);
@@ -291,8 +319,8 @@ async function todaysList() {
291
319
  const doNotTrack = () => (/^(?:1|true)$/i.test(process.env.DO_NOT_TRACK ?? "") ? { dnt: "1" } : {});
292
320
 
293
321
  // Runs the checks, then points findings in reduced files back at real lines.
294
- function check(input) {
295
- const result = analyze(input);
322
+ function check(input, rules) {
323
+ const result = analyze(input, { rules });
296
324
  for (const f of result.findings) {
297
325
  const map = f.file && input.lineMaps?.[f.file];
298
326
  if (map && f.line) f.line = map[f.line - 1] ?? null;
@@ -302,7 +330,7 @@ function check(input) {
302
330
 
303
331
  // Asks OSV.dev about what's installed, after showing exactly what will be sent.
304
332
  async function lookup(opts, result) {
305
- const out = opts.json ? process.stderr : process.stdout;
333
+ const out = notes(opts);
306
334
  const base = serviceBase("MISCONFIG_OSV_URL", "https://api.osv.dev");
307
335
  const queries = lookupQueries(result);
308
336
  printLookupPreview(out, queries);
@@ -355,10 +383,14 @@ function serviceBase(name = "MISCONFIG_URL", fallback = "https://misconfig.ai")
355
383
  return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
356
384
  }
357
385
 
386
+ // With --json or --jsonl, stdout is for the program reading it, so what the
387
+ // command has to say to a person goes to stderr.
388
+ const notes = (opts) => (opts.json || opts.jsonl ? process.stderr : process.stdout);
389
+
358
390
  // The full report as a file on this computer, opened in the browser for
359
391
  // someone at a terminal. Nothing is uploaded.
360
392
  async function openReport(opts, input, result) {
361
- const out = opts.json ? process.stderr : process.stdout;
393
+ const out = notes(opts);
362
394
  // The list of packages is only for --lookup; the report doesn't show it.
363
395
  const report = { ...result };
364
396
  delete report.packages;
@@ -369,6 +401,23 @@ async function openReport(opts, input, result) {
369
401
  if (opening) openInBrowser(file);
370
402
  }
371
403
 
404
+ // --sarif: the findings as a file. It's written under another name and moved
405
+ // into place, so a link that a project from someone else left at that name
406
+ // is replaced, not followed into a file somewhere else.
407
+ async function saveSarif(opts, result) {
408
+ const file = path.resolve(opts.sarif);
409
+ const temp = `${file}.${randomUUID()}.tmp`;
410
+ try {
411
+ await writeFile(temp, stringify(sarif(result, { version: await version() }), 2) + "\n", { flag: "wx", mode: 0o600 });
412
+ await rename(temp, file);
413
+ } catch (err) {
414
+ await unlink(temp).catch(() => {});
415
+ const why = { ENOENT: "the folder it's in doesn't exist", ENOTDIR: "the folder it's in doesn't exist", EACCES: "this account can't write there", EPERM: "this account can't write there", EROFS: "this account can't write there", EISDIR: "a folder has that name" }[err?.code];
416
+ throw new Error(`The SARIF file wasn't saved at ${opts.sarif}: ${why ?? err?.message ?? err}.`);
417
+ }
418
+ printSarifResult(notes(opts), { file, stopped: result.stats.truncated });
419
+ }
420
+
372
421
  let cachedVersion = null;
373
422
  async function version() {
374
423
  cachedVersion ??= JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8")).version;
@@ -48,7 +48,7 @@ async function registryVersion(fetchImpl) {
48
48
  }
49
49
 
50
50
  export function automaticUpdateCheck(opts, env = process.env, terminal = process.stdout.isTTY && process.stdin.isTTY) {
51
- return Boolean(terminal && !opts.offline && !opts.demo && !opts.json && !opts.projectOnly && !opts.noHistory && !opts.noUpdate
51
+ return Boolean(terminal && !opts.offline && !opts.demo && !opts.json && !opts.jsonl && !opts.projectOnly && !opts.noHistory && !opts.noUpdate
52
52
  && !opts.failOn && !env.CI && !env.NO_UPDATE_NOTIFIER && env.MISCONFIG_NO_UPDATE_CHECK !== "1");
53
53
  }
54
54
 
package/lib/print.js CHANGED
@@ -54,7 +54,15 @@ const color = (name) => (s) => (on ? `\x1b[${code(name, "fg")}m${s}\x1b[39m` : S
54
54
  // Text from the files being checked can hold terminal control codes that
55
55
  // would rewrite the screen, or bidirectional marks that reorder it. They're
56
56
  // shown as the replacement character (U+FFFD) instead.
57
- const safe = (s) => String(s ?? "").replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, "\ufffd");
57
+ //
58
+ // A CI system also reads parts of its log as commands. GitHub Actions takes
59
+ // ##[name] anywhere in a line, Azure Pipelines takes ##vso[name], and
60
+ // TeamCity reads ##teamcity[name]. A name in a checked file could spell one,
61
+ // so the same character goes inside it and the line stays text.
62
+ const safe = (s) =>
63
+ String(s ?? "")
64
+ .replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, "\ufffd")
65
+ .replace(/#(?=#[a-z]*\[)/gi, "#\ufffd");
58
66
  // For text printed on one line, such as a title or a path: line breaks in it
59
67
  // would start a new line that looks like part of the report.
60
68
  export const oneLine = (s) => safe(s).replace(/[\t\n]/g, " ");
@@ -91,6 +99,12 @@ function fitPath(p, max) {
91
99
  }
92
100
 
93
101
  const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
102
+
103
+ // A report's lines as one piece of text. GitHub Actions reads a line that
104
+ // starts with ::name:: as a command, spaces before it or not, and a wrapped
105
+ // line can start with a word from a checked file. Such a line gets the
106
+ // replacement character between its colons.
107
+ const page = (lines) => lines.map((line) => line.replace(/^(\s*):(?=:)/, "$1:\ufffd")).join("\n") + "\n";
94
108
  const npx = process.platform === "win32" ? "npx.cmd" : "npx";
95
109
 
96
110
  // --- Report ------------------------------------------------------------------
@@ -106,7 +120,9 @@ export function printReport(result, { version, scanned, explain = false, open =
106
120
  const sent = lookedUp ? "Everything ran here. Only package names and versions went to OSV.dev, to look them up." : "Everything ran here; nothing was uploaded.";
107
121
  out.push(`${bold("misconfig")} ${dim(version)}`);
108
122
  const project = scanned.projectSkipped && !scanned.demo ? " To check a project, run it in the project's folder." : "";
109
- out.push(...wrap(`Checked ${where}${scanned.user && !scanned.demo ? " and the agent settings on this computer" : ""}. ${sent}${knownLine(known)}${project}`, 0).map(dim));
123
+ const ownRules = result.customRules?.length ?? 0;
124
+ const own = ownRules ? ` ${plural(ownRules, "rule")} of your own ${ownRules === 1 ? "was" : "were"} checked too.` : "";
125
+ out.push(...wrap(`Checked ${where}${scanned.user && !scanned.demo ? " and the agent settings on this computer" : ""}. ${sent}${knownLine(known)}${own}${project}`, 0).map(dim));
110
126
  out.push("");
111
127
  if (result.computerReview) {
112
128
  out.push(bold("Computer review"), ...reviewLines(result.computerReview, scanned.demo).map(oneLine), "");
@@ -179,7 +195,7 @@ export function printReport(result, { version, scanned, explain = false, open =
179
195
  if (!map.length && !findings.length) {
180
196
  out.push(...wrap("No files that control AI agents were found here. Run the check in the folder you open your agent in, usually the project root.", 0));
181
197
  if (result.stats.truncated) out.push("", ...stopped());
182
- process.stdout.write(out.join("\n") + "\n");
198
+ process.stdout.write(page(out));
183
199
  return;
184
200
  }
185
201
  // The verdict, last, where it's on screen when the check finishes.
@@ -187,18 +203,18 @@ export function printReport(result, { version, scanned, explain = false, open =
187
203
  if (result.stats.truncated) out.push(...stopped(), "");
188
204
  if (scanned.demo) {
189
205
  out.push("Run --demo again to start a fresh sample.");
190
- process.stdout.write(out.join("\n") + "\n");
206
+ process.stdout.write(page(out));
191
207
  return;
192
208
  }
193
209
  const next = [];
194
210
  if (!explain && map.some((f) => f.details?.length)) next.push(["Everything each file says", `${npx} @misconfig/cli --explain`]);
195
211
  if (!open) next.push(["Full report in your browser", `${npx} @misconfig/cli --open`]);
196
212
  if (!lookedUp && result.packages?.length) next.push(["Look up installs on OSV.dev", `${npx} @misconfig/cli --lookup`]);
197
- if (findings.length) next.push(["Every rule explained", "https://misconfig.ai/rules"]);
213
+ if (findings.some((f) => !f.custom)) next.push(["Every rule explained", "https://misconfig.ai/rules"]);
198
214
  next.push(["Full details as JSON", `${npx} @misconfig/cli --json`]);
199
215
  const pad = Math.max(...next.map(([label]) => label.length)) + 3;
200
216
  for (const [label, command] of next) out.push(`${dim(label.padEnd(pad))}${command}`);
201
- process.stdout.write(out.join("\n") + "\n");
217
+ process.stdout.write(page(out));
202
218
  }
203
219
 
204
220
  // Which list of known malware the check used.
@@ -242,7 +258,7 @@ export function printLookupPreview(out, queries) {
242
258
  const lines = ["", bold("Look up what's installed on OSV.dev")];
243
259
  if (!queries.length) {
244
260
  lines.push(...wrap("There's nothing to look up: no MCP packages, agent installs or editor extensions were found.", 2), "");
245
- out.write(lines.join("\n") + "\n");
261
+ out.write(page(lines));
246
262
  return;
247
263
  }
248
264
  lines.push(
@@ -256,7 +272,7 @@ export function printLookupPreview(out, queries) {
256
272
  const width = Math.max(...shown.map((q) => registryName(q.ecosystem).length));
257
273
  for (const q of shown) lines.push(oneLine(` ${registryName(q.ecosystem).padEnd(width)} ${q.name}${q.version ? ` ${q.version}` : ""}`) + (q.version ? "" : dim(" (any version)")));
258
274
  if (queries.length > shown.length) lines.push(dim(` and ${queries.length - shown.length} more`));
259
- out.write(lines.join("\n") + "\n");
275
+ out.write(page(lines));
260
276
  }
261
277
 
262
278
  export function printLookupResult(out, { asked, failed, found }) {
@@ -268,7 +284,17 @@ export function printLookupResult(out, { asked, failed, found }) {
268
284
  found ? `${plural(found, "finding")} added to the report.` : "Nothing new turned up.",
269
285
  failed ? `${plural(failed, "package")} couldn't be looked up; try again later.` : "",
270
286
  ];
271
- out.write(["", ...wrap(parts.filter(Boolean).join(" "), 2), ""].join("\n") + "\n");
287
+ out.write(page(["", ...wrap(parts.filter(Boolean).join(" "), 2), ""]));
288
+ }
289
+
290
+ // --- The findings as a file ----------------------------------------------------
291
+
292
+ // Where --sarif saved the findings.
293
+ export function printSarifResult(out, { file, stopped }) {
294
+ const note = stopped
295
+ ? "The check stopped early, and the file says so. Don't upload it to code scanning: findings it didn't reach would be marked as fixed."
296
+ : "Nothing was uploaded. The file names the files with findings and what was found in each, so read it before you share it.";
297
+ out.write(page(["", bold("Findings saved as SARIF"), ` ${oneLine(file)}`, "", ...wrap(note, 2).map(dim), ""]));
272
298
  }
273
299
 
274
300
  // --- The report in a browser ---------------------------------------------------
@@ -276,13 +302,13 @@ export function printLookupResult(out, { asked, failed, found }) {
276
302
  // Where --open saved the report.
277
303
  export function printOpenResult(out, { file, opening }) {
278
304
  out.write(
279
- [
305
+ page([
280
306
  "",
281
307
  bold("Full report saved on this computer"),
282
308
  ` ${file}`,
283
309
  "",
284
310
  ...wrap(`${opening ? "Opening it in your browser. " : ""}Nothing was uploaded. Anyone you send the file to can read everything in it, including the paths and settings on this computer.`, 2).map(dim),
285
311
  "",
286
- ].join("\n") + "\n",
312
+ ]),
287
313
  );
288
314
  }
@@ -0,0 +1,63 @@
1
+ // --rules: a company's own rules, from the files named on the command line.
2
+ // A file is JSON: one rule, a list of rules, or { "rules": [...] }, each in
3
+ // the form templates.js reads. Nothing looks for rules files by itself, so a
4
+ // checked project can't bring rules of its own.
5
+
6
+ import { open, stat } from "node:fs/promises";
7
+ import { readTemplate } from "../engine/templates.js";
8
+
9
+ const MAX_BYTES = 256 * 1024;
10
+ const MAX_RULES = 200;
11
+ const isObj = (x) => x !== null && typeof x === "object" && !Array.isArray(x);
12
+
13
+ async function readText(file) {
14
+ let handle;
15
+ try {
16
+ handle = await open(file, "r");
17
+ const info = await handle.stat();
18
+ if (info.isDirectory()) throw Object.assign(new Error(), { code: "EISDIR" });
19
+ // A pipe or a device has no size to check before it's read.
20
+ if (!info.isFile()) throw new Error("it isn't a file");
21
+ if (info.size > MAX_BYTES) throw new Error("it's larger than 256 KB");
22
+ return (await handle.readFile("utf8")).replace(/^\ufeff/, "");
23
+ } catch (err) {
24
+ let code = err?.code;
25
+ // Windows won't open a folder, and says so the way it does for a file this account can't read.
26
+ if ((code === "EPERM" || code === "EACCES") && (await stat(file).then((info) => info.isDirectory(), () => false))) code = "EISDIR";
27
+ const why = { ENOENT: "there's no file there", ENOTDIR: "there's no file there", EISDIR: "it's a folder", EACCES: "this account can't read it", EPERM: "this account can't read it" }[code] ?? (code ? `the system answered ${code}` : err.message);
28
+ throw new Error(`The rules file ${file} couldn't be read: ${why}.`);
29
+ } finally {
30
+ await handle?.close();
31
+ }
32
+ }
33
+
34
+ // The rules in these files, ready for a check. Throws an Error that names
35
+ // the file, the rule and what to change.
36
+ export async function loadRules(files) {
37
+ const rules = [];
38
+ const from = new Map();
39
+ for (const file of files) {
40
+ const text = await readText(file);
41
+ let data;
42
+ try {
43
+ data = JSON.parse(text);
44
+ } catch {
45
+ throw new Error(`The rules file ${file} isn't valid JSON.`);
46
+ }
47
+ const list = Array.isArray(data) ? data : isObj(data) && Array.isArray(data.rules) && Object.keys(data).length === 1 ? data.rules : isObj(data) && !Object.hasOwn(data, "rules") ? [data] : null;
48
+ if (!list?.length) throw new Error(`The rules file ${file} needs one rule, a list of rules, or a list of them under "rules" and nothing beside it.`);
49
+ for (const [i, raw] of list.entries()) {
50
+ let rule;
51
+ try {
52
+ rule = readTemplate(raw);
53
+ } catch (err) {
54
+ throw new Error(`${file}, rule ${i + 1}: ${err.message}`);
55
+ }
56
+ if (from.has(rule.id)) throw new Error(`${file}, rule ${i + 1}: ${rule.id} is already a rule in ${from.get(rule.id)}. Each rule needs its own ID.`);
57
+ from.set(rule.id, file);
58
+ rules.push(rule);
59
+ if (rules.length > MAX_RULES) throw new Error(`--rules takes up to ${MAX_RULES} rules.`);
60
+ }
61
+ }
62
+ return rules;
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@misconfig/cli",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Check AI agent settings for risks and known malware. Review changes since your last scan and keep a local history of approvals and accepted risks.",
5
5
  "keywords": [
6
6
  "claude-code",
package/report/styles.css CHANGED
@@ -1373,6 +1373,12 @@ p {
1373
1373
  color: var(--signal);
1374
1374
  text-decoration-color: currentColor;
1375
1375
  }
1376
+ /* One of your own rules with nowhere to link to. */
1377
+ span.f-rule,
1378
+ span.f-rule:hover {
1379
+ color: var(--text-3);
1380
+ text-decoration: none;
1381
+ }
1376
1382
 
1377
1383
  /* What to fix first: one line per rule, most points first. */
1378
1384
  .fix-first {