@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/CHANGELOG.md +16 -0
- package/README.md +113 -8
- package/bin/misconfig.js +0 -0
- package/engine/catalog.js +94 -1
- package/engine/index.js +49 -58
- package/engine/templates.js +236 -0
- package/lib/findings.js +4 -1
- package/lib/formats.js +158 -0
- package/lib/html.js +4 -1
- package/lib/main.js +63 -14
- package/lib/package-update.js +1 -1
- package/lib/print.js +37 -11
- package/lib/rule-files.js +63 -0
- package/package.json +1 -1
- package/report/styles.css +6 -0
package/engine/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { maskSecrets, looksLikeSecret, looksLikeToken, isMasked, isPathLike, des
|
|
|
6
6
|
import { parseJSONC, parseTOML, parseYAML, parseCodexRules } from "./parse.js";
|
|
7
7
|
import { namedInstructions, NAMING_SETTINGS } from "./named.js";
|
|
8
8
|
import { RULES, CATEGORIES } from "./catalog.js";
|
|
9
|
+
import { TEMPLATES, holds, readers } from "./templates.js";
|
|
9
10
|
import { explainFile, agentLines, hiddenComments, hiddenTags, hiddenZeroWidth, fenceAt, inCodeSpan, CAN_IMPORT, scopeOf, HOOK_EVENTS, anthropicMarketplace, marketplaceSource } from "./explain.js";
|
|
10
11
|
import { ignoreRules, isIgnored, globMatch } from "./glob.js";
|
|
11
12
|
import { HOME_MARKERS, DOWNLOADS_LIKE, TOOL_ROOT, visibleName } from "./paths.js";
|
|
@@ -373,7 +374,9 @@ const SHELL_SERVER = /(?:^|[-_/@.])(?:shell|terminal|exec|executor|commands?|cmd
|
|
|
373
374
|
|
|
374
375
|
// --- Entry point -------------------------------------------------------------
|
|
375
376
|
|
|
376
|
-
|
|
377
|
+
// `rules` are a company's own, from readTemplate in templates.js. They can
|
|
378
|
+
// only add findings.
|
|
379
|
+
export function analyze(input, { rules = [] } = {}) {
|
|
377
380
|
const ctx = buildContext(input ?? {});
|
|
378
381
|
// A file that trips up a check is reported as unchecked. It can't stop
|
|
379
382
|
// the rest of the report.
|
|
@@ -386,6 +389,9 @@ export function analyze(input) {
|
|
|
386
389
|
};
|
|
387
390
|
for (const f of ctx.files) if (f.content) guard(f, () => collectMcpServers(ctx, f));
|
|
388
391
|
for (const f of ctx.files) if (f.content) guard(f, () => checkFile(ctx, f));
|
|
392
|
+
// After the built-in checks of every file, so a rule that trips on a file
|
|
393
|
+
// can't cost one of their findings.
|
|
394
|
+
if (rules.length) for (const f of ctx.files) if (f.content) guard(f, () => checkTemplates(ctx, f, rules));
|
|
389
395
|
for (const f of ctx.files) {
|
|
390
396
|
if (f.content && f.kind && (f.failed || (/\.(jsonc?|toml)$/i.test(f.path) && parsed(f) == null))) add(ctx, "WS-UNPARSED", { file: f });
|
|
391
397
|
}
|
|
@@ -394,16 +400,22 @@ export function analyze(input) {
|
|
|
394
400
|
// to different agents aren't all in front of any one of them.
|
|
395
401
|
// Agents that read the same file, such as Claude Code and Copilot with
|
|
396
402
|
// .mcp.json, are reported once.
|
|
403
|
+
// A project can define servers by the hundred thousand, so the lists are
|
|
404
|
+
// added to and compared in place, never copied or joined into one string.
|
|
397
405
|
const perAgent = new Map();
|
|
398
406
|
for (const s of ctx.mcpServers) {
|
|
399
407
|
if (s.disabled) continue;
|
|
400
|
-
for (const t of s.file.tools ?? [])
|
|
408
|
+
for (const t of s.file.tools ?? []) {
|
|
409
|
+
if (!perAgent.has(t)) perAgent.set(t, []);
|
|
410
|
+
perAgent.get(t).push(`${s.file.path}#${s.name}`);
|
|
411
|
+
}
|
|
401
412
|
}
|
|
402
|
-
const reported =
|
|
413
|
+
const reported = [];
|
|
403
414
|
for (const [tool, servers] of perAgent) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
reported.
|
|
415
|
+
if (servers.length <= 12) continue;
|
|
416
|
+
servers.sort();
|
|
417
|
+
if (reported.some((seen) => seen.length === servers.length && seen.every((name, i) => name === servers[i]))) continue;
|
|
418
|
+
reported.push(servers);
|
|
407
419
|
add(ctx, "MCP-MANY", { tool, vars: { tool, count: servers.length } });
|
|
408
420
|
}
|
|
409
421
|
checkWorkspace(ctx);
|
|
@@ -441,13 +453,11 @@ function checkFile(ctx, f) {
|
|
|
441
453
|
else if (/(^|\/)\.?amazonq\/cli-agents\//i.test(p)) checkAgentFile(ctx, f, "An Amazon Q hook");
|
|
442
454
|
else if (/(^|\/)\.grok\/hooks\//i.test(p)) checkJsonHooks(ctx, f, "A Grok hook");
|
|
443
455
|
else if (/(^|\/)\.cursor\/(cli-config|cli)\.json$/i.test(p)) checkCursorCli(ctx, f);
|
|
444
|
-
|
|
456
|
+
// Cursor's sandbox file and the settings of Zed, Cline and Amp: their rules are templates.
|
|
457
|
+
else if (readers(TEMPLATES, p).length) checkTemplates(ctx, f, TEMPLATES);
|
|
445
458
|
else if (/(^|\/)(\.vscode|(Code|Code - Insiders|VSCodium|Cursor|Windsurf)\/User)\/settings\.json$/i.test(p)) checkVSCode(ctx, f);
|
|
446
459
|
else if (/(^|\/)opencode\.jsonc?$/i.test(p)) checkOpenCode(ctx, f);
|
|
447
|
-
else if (/(^|\/)(\.zed|zed|Zed)\/settings\.json$/i.test(p)) checkZed(ctx, f);
|
|
448
|
-
else if (/(^|\/)\.cline\/data\/globalState\.json$/i.test(p)) checkCline(ctx, f);
|
|
449
460
|
else if (/(^|\/)\.grok\/config\.toml$/i.test(p)) checkGrok(ctx, f);
|
|
450
|
-
else if (/(^|\/)(\.amp|\.config\/amp)\/settings\.json$/i.test(p)) checkAmp(ctx, f);
|
|
451
461
|
else if (/(^|\/)goose\/config\.ya?ml$/i.test(p)) checkGoose(ctx, f);
|
|
452
462
|
else if (/(^|\/)\.continue\/(?:.+\/)?[^/]+\.(?:ya?ml|json)$/i.test(p)) checkContinue(ctx, f);
|
|
453
463
|
else if (f.kind === "Shell profile") checkShellProfile(ctx, f);
|
|
@@ -694,6 +704,18 @@ function evidenceLine(file, line) {
|
|
|
694
704
|
return line && file.lines ? clip(file.lines[line - 1] ?? "") : undefined;
|
|
695
705
|
}
|
|
696
706
|
|
|
707
|
+
// Rules written as data, from templates.js: for each one that reads this
|
|
708
|
+
// file and applies where the file is, a finding when its match holds.
|
|
709
|
+
function checkTemplates(ctx, f, templates) {
|
|
710
|
+
for (const t of readers(templates, f.path)) {
|
|
711
|
+
if (t.scope && (t.scope === "project") !== inProject(ctx, f)) continue;
|
|
712
|
+
const data = parsed(f);
|
|
713
|
+
if (data === null || typeof data !== "object" || !holds(t.match, data)) continue;
|
|
714
|
+
const line = t.line ? lineOf(f, t.line) : 0;
|
|
715
|
+
add(ctx, t.id, { file: f, line, evidence: evidenceLine(f, line), rule: t.rule });
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
697
719
|
function add(ctx, id, opts = {}) {
|
|
698
720
|
const { file, line = 0, vars = {} } = opts;
|
|
699
721
|
const key = [id, file?.path ?? null, line, ...["server", "key", "rule", "place", "ext", "pkg", "known", "name", "skill", "campaign", "path"].map((k) => vars[k] ?? "")].join("|");
|
|
@@ -702,12 +724,14 @@ function add(ctx, id, opts = {}) {
|
|
|
702
724
|
ctx.findings.push(makeFinding(id, opts));
|
|
703
725
|
}
|
|
704
726
|
|
|
705
|
-
|
|
706
|
-
|
|
727
|
+
// `own` is the wording of a company's own rule, which isn't in the catalog.
|
|
728
|
+
function makeFinding(id, { file, line = 0, evidence, vars = {}, tool, rule: own } = {}) {
|
|
729
|
+
const rule = own ?? RULES[id];
|
|
707
730
|
if (!rule) throw new Error(`Unknown rule ${id}`);
|
|
708
731
|
const filePath = file?.path ?? null;
|
|
709
732
|
const values = Object.fromEntries(Object.entries({ file: filePath ?? "", ...vars }).map(([k, v]) => [k, String(v ?? "")]));
|
|
710
|
-
|
|
733
|
+
// A company's rule can quote {file}. Other braces in it are its own words.
|
|
734
|
+
const fill = own ? (text) => text.replaceAll("{file}", () => values.file) : (text) => fillTemplate(text, values);
|
|
711
735
|
return {
|
|
712
736
|
id,
|
|
713
737
|
severity: rule.severity,
|
|
@@ -720,6 +744,8 @@ function makeFinding(id, { file, line = 0, evidence, vars = {}, tool } = {}) {
|
|
|
720
744
|
line: line || null,
|
|
721
745
|
evidence: evidence ? describeMasks(clip(evidence, 220)) : null,
|
|
722
746
|
vars: values,
|
|
747
|
+
// Set for a company's own rule: what it's called and where it's explained.
|
|
748
|
+
...(own ? { custom: { name: own.name, reference: own.reference } } : {}),
|
|
723
749
|
};
|
|
724
750
|
}
|
|
725
751
|
|
|
@@ -1090,7 +1116,7 @@ function checkShellProfile(ctx, f) {
|
|
|
1090
1116
|
}
|
|
1091
1117
|
}
|
|
1092
1118
|
|
|
1093
|
-
// --- Gemini, VS Code, OpenCode,
|
|
1119
|
+
// --- Gemini, VS Code, OpenCode, Aider ----------------------------------------
|
|
1094
1120
|
|
|
1095
1121
|
function checkGemini(ctx, f) {
|
|
1096
1122
|
const json = parsed(f);
|
|
@@ -1195,19 +1221,6 @@ function checkOpenCode(ctx, f) {
|
|
|
1195
1221
|
}
|
|
1196
1222
|
}
|
|
1197
1223
|
|
|
1198
|
-
function checkZed(ctx, f) {
|
|
1199
|
-
const json = parsed(f);
|
|
1200
|
-
if (!isObj(json)) return;
|
|
1201
|
-
if (json.agent?.always_allow_tool_actions === true || json.assistant?.always_allow_tool_actions === true || json.agent?.tool_permissions?.default === "allow") {
|
|
1202
|
-
const line = lineOf(f, /always_allow_tool_actions|"default"\s*:\s*"allow"/);
|
|
1203
|
-
add(ctx, "ZED-ALWAYS-ALLOW", { file: f, line, evidence: evidenceLine(f, line) });
|
|
1204
|
-
}
|
|
1205
|
-
if (json.session?.trust_all_worktrees === true) {
|
|
1206
|
-
const line = lineOf(f, /trust_all_worktrees/);
|
|
1207
|
-
add(ctx, "ZED-TRUST-ALL", { file: f, line, evidence: evidenceLine(f, line) });
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
1224
|
// --- Trusted folders, hooks and settings of other agents ---------------------
|
|
1212
1225
|
|
|
1213
1226
|
// Gemini CLI: { "/path": "TRUST_FOLDER" | "TRUST_PARENT" | "DO_NOT_TRUST" }.
|
|
@@ -1392,26 +1405,6 @@ function checkCursorCli(ctx, f) {
|
|
|
1392
1405
|
}
|
|
1393
1406
|
}
|
|
1394
1407
|
|
|
1395
|
-
function checkCursorSandbox(ctx, f) {
|
|
1396
|
-
if (parsed(f)?.type === "insecure_none") {
|
|
1397
|
-
const line = lineOf(f, /insecure_none/);
|
|
1398
|
-
add(ctx, "CU-NO-SANDBOX", { file: f, line, evidence: evidenceLine(f, line) });
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
// Cline keeps its approval settings in ~/.cline/data/globalState.json.
|
|
1403
|
-
function checkCline(ctx, f) {
|
|
1404
|
-
const json = parsed(f);
|
|
1405
|
-
if (!isObj(json)) return;
|
|
1406
|
-
if (json.yoloModeToggled === true) {
|
|
1407
|
-
const line = lineOf(f, /yoloModeToggled/);
|
|
1408
|
-
add(ctx, "CL-YOLO", { file: f, line, evidence: evidenceLine(f, line) });
|
|
1409
|
-
} else if (json.autoApprovalSettings?.enabled !== false && json.autoApprovalSettings?.actions?.executeAllCommands === true) {
|
|
1410
|
-
const line = lineOf(f, /executeAllCommands/);
|
|
1411
|
-
add(ctx, "CL-AUTO-COMMANDS", { file: f, line, evidence: evidenceLine(f, line) });
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
1408
|
function checkGrok(ctx, f) {
|
|
1416
1409
|
const toml = parsed(f);
|
|
1417
1410
|
for (const command of commandsIn(toml?.ui?.status_line?.command)) checkCommand(ctx, command, f, "Grok's status line command");
|
|
@@ -1422,13 +1415,6 @@ function checkGrok(ctx, f) {
|
|
|
1422
1415
|
}
|
|
1423
1416
|
}
|
|
1424
1417
|
|
|
1425
|
-
function checkAmp(ctx, f) {
|
|
1426
|
-
if (parsed(f)?.["amp.dangerouslyAllowAll"] === true) {
|
|
1427
|
-
const line = lineOf(f, /dangerouslyAllowAll/);
|
|
1428
|
-
add(ctx, "AMP-ALLOW-ALL", { file: f, line, evidence: evidenceLine(f, line) });
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
1418
|
// YAML, read line by line: GOOSE_MODE sits at the top level.
|
|
1433
1419
|
function checkGoose(ctx, f) {
|
|
1434
1420
|
const line = lineOf(f, /^GOOSE_MODE\s*:\s*["']?auto["']?\s*(#.*)?$/);
|
|
@@ -2673,15 +2659,19 @@ export function applyLookup(result, hits) {
|
|
|
2673
2659
|
const bySeverity = (a, b) =>
|
|
2674
2660
|
SEVERITIES.indexOf(a.severity) - SEVERITIES.indexOf(b.severity) || a.category.localeCompare(b.category) || (a.file ?? "").localeCompare(b.file ?? "");
|
|
2675
2661
|
|
|
2662
|
+
// The level of a finding's rule. A company's own rule isn't in the catalog,
|
|
2663
|
+
// so its finding says. Null for a finding that names no rule there is.
|
|
2664
|
+
const levelOf = (f) => (Object.hasOwn(RULES, f.id) ? RULES[f.id].severity : f.custom && Object.hasOwn(WEIGHT, f.severity) ? f.severity : null);
|
|
2665
|
+
|
|
2676
2666
|
// Score, grade and counts from a list of findings, for a check and again
|
|
2677
2667
|
// after a lookup.
|
|
2678
2668
|
function scoreFindings(findings, hasControlFiles) {
|
|
2679
2669
|
const counts = Object.fromEntries(SEVERITIES.map((s) => [s, findings.filter((f) => f.severity === s).length]));
|
|
2680
2670
|
// Repeats of the same rule count less, so one noisy pattern can't zero the score.
|
|
2681
2671
|
const byRule = new Map();
|
|
2682
|
-
for (const f of findings) byRule.set(f.id, (byRule.get(f.id) ?? 0) + 1);
|
|
2672
|
+
for (const f of findings) byRule.set(f.id, { severity: levelOf(f), n: (byRule.get(f.id)?.n ?? 0) + 1 });
|
|
2683
2673
|
let penalty = 0;
|
|
2684
|
-
for (const
|
|
2674
|
+
for (const { severity, n } of byRule.values()) penalty += WEIGHT[severity] * Math.min(2, 1 + 0.25 * (n - 1));
|
|
2685
2675
|
const score = Math.max(0, Math.min(100, Math.round(100 - penalty)));
|
|
2686
2676
|
let grade = GRADES.find(([, min]) => score >= min)?.[0] ?? "F";
|
|
2687
2677
|
if (counts.critical && "ABC".includes(grade)) grade = "D";
|
|
@@ -2694,8 +2684,9 @@ function scoreFindings(findings, hasControlFiles) {
|
|
|
2694
2684
|
export function pointsOff(findings) {
|
|
2695
2685
|
const byRule = new Map();
|
|
2696
2686
|
for (const f of findings) {
|
|
2697
|
-
|
|
2698
|
-
|
|
2687
|
+
const severity = levelOf(f);
|
|
2688
|
+
if (!severity) continue;
|
|
2689
|
+
const entry = byRule.get(f.id) ?? { id: f.id, severity, findings: [] };
|
|
2699
2690
|
entry.findings.push(f);
|
|
2700
2691
|
byRule.set(f.id, entry);
|
|
2701
2692
|
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Rules written as data. A template names the settings files it reads and
|
|
2
|
+
// what in them makes a finding, and one reader applies them all, so a rule
|
|
3
|
+
// like this needs no code of its own. The rules built in this way are at the
|
|
4
|
+
// end of the file, with their wording in catalog.js. --rules adds a company's
|
|
5
|
+
// own, which bring their wording with them.
|
|
6
|
+
//
|
|
7
|
+
// A template can only add a finding. It can't run anything, read a file or
|
|
8
|
+
// take a finding away. A company's rule holds no regular expression either:
|
|
9
|
+
// its files are paths and its tests compare text, so nothing in a rules file
|
|
10
|
+
// can be written to stall a check on a file from someone else.
|
|
11
|
+
|
|
12
|
+
import { CATEGORIES, LEVELS, RULES } from "./catalog.js";
|
|
13
|
+
|
|
14
|
+
// Capitals, digits and hyphens, as in CC-BYPASS.
|
|
15
|
+
const ID = /^[A-Z][A-Z0-9]*(?:-[A-Z0-9]+){0,6}$/;
|
|
16
|
+
const WORDING = ["name", "title", "severity", "category", "agent", "why", "fix", "reference"];
|
|
17
|
+
// Every key a rule can have, and every test a condition can make.
|
|
18
|
+
export const RULE_KEYS = ["id", ...WORDING, "files", "scope", "match", "line"];
|
|
19
|
+
export const RULE_TESTS = ["equals", "in", "contains", "startsWith", "endsWith", "exists"];
|
|
20
|
+
const MAX = { id: 40, name: 120, text: 600, files: 10, file: 300, stars: 4, line: 200, address: 300, path: 12, key: 200, depth: 6, conditions: 30, values: 50 };
|
|
21
|
+
|
|
22
|
+
const isObj = (x) => x !== null && typeof x === "object" && !Array.isArray(x);
|
|
23
|
+
const isValue = (x) => x === null || typeof x === "boolean" || (typeof x === "number" && Number.isFinite(x)) || (typeof x === "string" && x.length <= MAX.text);
|
|
24
|
+
const oneLine = (x, max) => typeof x === "string" && x.trim() !== "" && x.length <= max && !/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/.test(x);
|
|
25
|
+
|
|
26
|
+
// Where a rule's files are. A pattern is a path: **/ in front of it means in
|
|
27
|
+
// any folder, and * in the file's name stands for any run of characters.
|
|
28
|
+
// Nothing else in it is special, so trying one on a file takes about as long
|
|
29
|
+
// as the pattern and the file's name are, however long a path a project
|
|
30
|
+
// comes up with. Null for text that isn't such a pattern.
|
|
31
|
+
function filePattern(text) {
|
|
32
|
+
if (!oneLine(text, MAX.file)) return null;
|
|
33
|
+
const anywhere = text.startsWith("**/");
|
|
34
|
+
const rest = (anywhere ? text.slice(3) : text).toLowerCase();
|
|
35
|
+
const cut = rest.lastIndexOf("/") + 1;
|
|
36
|
+
const dir = rest.slice(0, cut);
|
|
37
|
+
const parts = rest.slice(cut).split("*");
|
|
38
|
+
if (cut === rest.length || /[*?[\]\\]/.test(dir) || parts.length - 1 > MAX.stars || parts.some((part, i) => /[?[\]\\]/.test(part) || (part === "" && i > 0 && i < parts.length - 1))) return null;
|
|
39
|
+
return { anywhere, dir, under: `/${dir}`, parts };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// True when a file's name fits a pattern's name, split where its *s were.
|
|
43
|
+
function named(parts, name) {
|
|
44
|
+
const first = parts[0];
|
|
45
|
+
const last = parts[parts.length - 1];
|
|
46
|
+
if (parts.length === 1) return name === first;
|
|
47
|
+
if (name.length < first.length + last.length || !name.startsWith(first) || !name.endsWith(last)) return false;
|
|
48
|
+
let at = first.length;
|
|
49
|
+
const end = name.length - last.length;
|
|
50
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
51
|
+
const found = name.indexOf(parts[i], at);
|
|
52
|
+
if (found < 0 || found + parts[i].length > end) return false;
|
|
53
|
+
at = found + parts[i].length;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// The templates that read the file at this path, whatever its case, as
|
|
59
|
+
// macOS and Windows open it.
|
|
60
|
+
export function readers(templates, path) {
|
|
61
|
+
const lower = path.toLowerCase();
|
|
62
|
+
const cut = lower.lastIndexOf("/") + 1;
|
|
63
|
+
const dir = lower.slice(0, cut);
|
|
64
|
+
const name = lower.slice(cut);
|
|
65
|
+
return templates.filter((t) => t.files.some((p) => (p.anywhere ? dir === p.dir || dir.endsWith(p.under) : dir === p.dir) && named(p.parts, name)));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// A template as the reader uses it, with every key checked, so a mistake is
|
|
69
|
+
// reported when the rules are loaded and not passed over during a check.
|
|
70
|
+
// Throws an Error that says what to change. The message quotes the rule's
|
|
71
|
+
// ID, or a key that's a plain word, and nothing else from the rule, so a
|
|
72
|
+
// rules file can't write to a log in words of its own.
|
|
73
|
+
//
|
|
74
|
+
// A built-in template takes its wording from the catalog, and can point at
|
|
75
|
+
// its line with a regular expression, `linePattern`. Any other brings its
|
|
76
|
+
// own wording and can't use a built-in rule's ID.
|
|
77
|
+
export function readTemplate(raw, { builtIn = false } = {}) {
|
|
78
|
+
const known = isObj(raw) && typeof raw.id === "string" && raw.id.length <= MAX.id && ID.test(raw.id);
|
|
79
|
+
const fail = (message) => {
|
|
80
|
+
throw new Error(`${known ? `${raw.id}: ` : ""}${message}`);
|
|
81
|
+
};
|
|
82
|
+
if (!isObj(raw)) fail("A rule is a set of keys, such as id, files and match.");
|
|
83
|
+
const allowed = builtIn ? ["id", "files", "scope", "match", "line", "linePattern"] : RULE_KEYS;
|
|
84
|
+
for (const key of Object.keys(raw)) {
|
|
85
|
+
if (allowed.includes(key)) continue;
|
|
86
|
+
if (builtIn && WORDING.includes(key)) fail(`A built-in rule's ${key} is in the catalog.`);
|
|
87
|
+
fail(`${/^[\w-]{1,30}$/.test(key) ? `“${key}”` : "One of its keys"} isn't a key a rule can have. The keys are ${allowed.join(", ")}.`);
|
|
88
|
+
}
|
|
89
|
+
if (!known) fail("id needs capitals, digits and hyphens, such as ACME-NO-YOLO.");
|
|
90
|
+
|
|
91
|
+
const files = Array.isArray(raw.files) && raw.files.length && raw.files.length <= MAX.files ? raw.files.map(filePattern) : [null];
|
|
92
|
+
if (files.includes(null)) fail(`files needs a list of 1 to ${MAX.files} paths, such as **/.claude/settings.json. **/ in front means in any folder, and * in the file's name, up to ${MAX.stars} times, means any run of characters.`);
|
|
93
|
+
if (raw.scope !== undefined && raw.scope !== "project" && raw.scope !== "computer") fail("scope is project, for files in the checked folder, or computer, for the settings outside it.");
|
|
94
|
+
|
|
95
|
+
let conditions = 0;
|
|
96
|
+
const condition = (node, depth) => {
|
|
97
|
+
if (depth > MAX.depth) fail(`match is nested more than ${MAX.depth} deep.`);
|
|
98
|
+
// A list on its own means all of them.
|
|
99
|
+
if (Array.isArray(node)) {
|
|
100
|
+
if (!node.length) fail("A list in match needs at least one condition.");
|
|
101
|
+
node = { all: node };
|
|
102
|
+
}
|
|
103
|
+
if (!isObj(node)) fail("Each part of match is a condition with a path, or all, any or not.");
|
|
104
|
+
const keys = Object.keys(node);
|
|
105
|
+
for (const group of ["all", "any"]) {
|
|
106
|
+
if (!Object.hasOwn(node, group)) continue;
|
|
107
|
+
if (keys.length !== 1 || !Array.isArray(node[group]) || !node[group].length) fail(`${group} needs a list of conditions and nothing beside it.`);
|
|
108
|
+
return { [group]: node[group].map((n) => condition(n, depth + 1)) };
|
|
109
|
+
}
|
|
110
|
+
if (Object.hasOwn(node, "not")) {
|
|
111
|
+
if (keys.length !== 1) fail("not needs one condition and nothing beside it.");
|
|
112
|
+
return { not: condition(node.not, depth + 1) };
|
|
113
|
+
}
|
|
114
|
+
if (++conditions > MAX.conditions) fail(`match has more than ${MAX.conditions} conditions.`);
|
|
115
|
+
// A path is keys joined by dots, or a list of keys for a key that has
|
|
116
|
+
// a dot in it. * stands for every key, or every item of a list.
|
|
117
|
+
const path = typeof node.path === "string" ? node.path.split(".") : node.path;
|
|
118
|
+
if (!Array.isArray(path) || !path.length || path.length > MAX.path || !path.every((key) => typeof key === "string" && key !== "" && key.length <= MAX.key)) {
|
|
119
|
+
fail("path needs keys joined by dots, such as permissions.defaultMode, or a list of keys.");
|
|
120
|
+
}
|
|
121
|
+
const tests = keys.filter((key) => key !== "path");
|
|
122
|
+
if (tests.length !== 1 || !RULE_TESTS.includes(tests[0])) fail(`A condition needs a path and one of ${RULE_TESTS.join(", ")}.`);
|
|
123
|
+
const [test] = tests;
|
|
124
|
+
const value = node[test];
|
|
125
|
+
if (test === "exists" && typeof value !== "boolean") fail("exists is true or false.");
|
|
126
|
+
if (test === "equals" && !isValue(value)) fail("equals needs text, a number, true, false or null.");
|
|
127
|
+
if (test === "in" && !(Array.isArray(value) && value.length && value.length <= MAX.values && value.every(isValue))) fail(`in needs a list of up to ${MAX.values} values. Each is text, a number, true, false or null.`);
|
|
128
|
+
if (["contains", "startsWith", "endsWith"].includes(test) && !(typeof value === "string" && value !== "" && value.length <= MAX.text)) fail(`${test} needs text of up to ${MAX.text} characters.`);
|
|
129
|
+
return { path, test, value };
|
|
130
|
+
};
|
|
131
|
+
if (raw.match === undefined) fail("match says what in the file makes a finding. It needs at least one condition.");
|
|
132
|
+
const match = condition(raw.match, 0);
|
|
133
|
+
|
|
134
|
+
// The line a finding points at is the first one that has this text.
|
|
135
|
+
// Without `line`, that's the last key of the first path.
|
|
136
|
+
const firstPath = (node) => node.path ?? firstPath((node.all ?? node.any ?? [node.not])[0]);
|
|
137
|
+
if (raw.line !== undefined && !oneLine(raw.line, MAX.line)) fail(`line needs text of up to ${MAX.line} characters that's on the line a finding should point at.`);
|
|
138
|
+
const line = raw.line ?? firstPath(match).filter((key) => key !== "*").pop() ?? null;
|
|
139
|
+
|
|
140
|
+
const template = { id: raw.id, files, scope: raw.scope ?? null, match, line, rule: null };
|
|
141
|
+
if (builtIn) {
|
|
142
|
+
if (!Object.hasOwn(RULES, raw.id)) fail("A built-in rule needs its wording in the catalog.");
|
|
143
|
+
return raw.linePattern === undefined ? template : { ...template, line: new RegExp(raw.linePattern) };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (Object.hasOwn(RULES, raw.id)) fail("That ID belongs to a built-in rule. Choose another, such as one that starts with your company's name.");
|
|
147
|
+
if (!oneLine(raw.name, MAX.name) || raw.name.includes("{file}")) fail(`name says what the rule finds, in one line of up to ${MAX.name} characters, without {file}.`);
|
|
148
|
+
if (raw.title !== undefined && !oneLine(raw.title, MAX.name)) fail(`title needs one line of up to ${MAX.name} characters.`);
|
|
149
|
+
for (const word of ["why", "fix"]) if (!oneLine(raw[word], MAX.text)) fail(`${word} needs one line of up to ${MAX.text} characters.`);
|
|
150
|
+
if (!Object.hasOwn(LEVELS, raw.severity)) fail(`severity is one of ${Object.keys(LEVELS).join(", ")}.`);
|
|
151
|
+
if (!Object.hasOwn(CATEGORIES, raw.category)) fail(`category is one of ${Object.keys(CATEGORIES).join(", ")}.`);
|
|
152
|
+
if (raw.agent !== undefined && !oneLine(raw.agent, 40)) fail("agent names the agent the setting belongs to, such as Claude Code, in up to 40 characters.");
|
|
153
|
+
let reference = null;
|
|
154
|
+
if (raw.reference !== undefined) {
|
|
155
|
+
try {
|
|
156
|
+
const url = new URL(oneLine(raw.reference, MAX.address) && !/\s/.test(raw.reference) ? raw.reference : "");
|
|
157
|
+
if (url.protocol !== "https:" || url.username || url.password) throw new Error();
|
|
158
|
+
reference = url.href;
|
|
159
|
+
} catch {
|
|
160
|
+
fail("reference needs an https address where the rule is explained.");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
...template,
|
|
165
|
+
rule: { severity: raw.severity, category: raw.category, ...(raw.agent ? { tool: raw.agent } : {}), title: raw.title ?? raw.name, name: raw.name, why: raw.why, fix: raw.fix, reference },
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Every value a path leads to in a parsed settings file, however many: a
|
|
170
|
+
// list padded with harmless items can't keep the last one from a rule. Only
|
|
171
|
+
// a file's own keys count, so a path can't lead to what every object carries.
|
|
172
|
+
function valuesAt(data, path) {
|
|
173
|
+
let found = [data];
|
|
174
|
+
for (const key of path) {
|
|
175
|
+
const next = [];
|
|
176
|
+
for (const value of found) {
|
|
177
|
+
if (key !== "*") {
|
|
178
|
+
if (isObj(value) && Object.hasOwn(value, key)) next.push(value[key]);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const items = Array.isArray(value) ? value : isObj(value) ? Object.values(value) : [];
|
|
182
|
+
for (const item of items) next.push(item);
|
|
183
|
+
}
|
|
184
|
+
found = next;
|
|
185
|
+
if (!found.length) break;
|
|
186
|
+
}
|
|
187
|
+
return found;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// A number and its spelling as text are the same value: settings written in
|
|
191
|
+
// YAML are read as text.
|
|
192
|
+
const same = (a, b) => a === b || (typeof a === "number" && typeof b === "string" && String(a) === b) || (typeof a === "string" && typeof b === "number" && a === String(b));
|
|
193
|
+
const spelled = (v) => (typeof v === "string" ? v : typeof v === "number" ? String(v) : null);
|
|
194
|
+
|
|
195
|
+
// True when a template's match holds for a parsed settings file. A condition
|
|
196
|
+
// holds when a value its path leads to passes its test. Text is compared
|
|
197
|
+
// whole, so padding around a value can't hide the rest of it.
|
|
198
|
+
export function holds(node, data) {
|
|
199
|
+
if (node.all) return node.all.every((n) => holds(n, data));
|
|
200
|
+
if (node.any) return node.any.some((n) => holds(n, data));
|
|
201
|
+
if (node.not) return !holds(node.not, data);
|
|
202
|
+
const found = valuesAt(data, node.path);
|
|
203
|
+
if (node.test === "exists") return found.length > 0 === node.value;
|
|
204
|
+
if (node.test === "equals") return found.some((v) => same(v, node.value));
|
|
205
|
+
if (node.test === "in") return found.some((v) => node.value.some((w) => same(v, w)));
|
|
206
|
+
if (node.test === "contains") return found.some((v) => spelled(v)?.includes(node.value) === true);
|
|
207
|
+
if (node.test === "startsWith") return found.some((v) => spelled(v)?.startsWith(node.value) === true);
|
|
208
|
+
return found.some((v) => spelled(v)?.endsWith(node.value) === true);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// --- Built-in rules ----------------------------------------------------------------
|
|
212
|
+
|
|
213
|
+
// Zed's own folder is named .zed in a project and zed or Zed on a computer.
|
|
214
|
+
const ZED = ["**/.zed/settings.json", "**/zed/settings.json"];
|
|
215
|
+
// Cline keeps its approval settings in ~/.cline/data/globalState.json.
|
|
216
|
+
const CLINE = ["**/.cline/data/globalState.json"];
|
|
217
|
+
|
|
218
|
+
export const TEMPLATES = [
|
|
219
|
+
{ id: "CU-NO-SANDBOX", files: ["**/.cursor/sandbox.json"], match: [{ path: "type", equals: "insecure_none" }], line: "insecure_none" },
|
|
220
|
+
{
|
|
221
|
+
id: "ZED-ALWAYS-ALLOW",
|
|
222
|
+
files: ZED,
|
|
223
|
+
match: { any: [{ path: "agent.always_allow_tool_actions", equals: true }, { path: "assistant.always_allow_tool_actions", equals: true }, { path: "agent.tool_permissions.default", equals: "allow" }] },
|
|
224
|
+
linePattern: 'always_allow_tool_actions|"default"\\s*:\\s*"allow"',
|
|
225
|
+
},
|
|
226
|
+
{ id: "ZED-TRUST-ALL", files: ZED, match: [{ path: "session.trust_all_worktrees", equals: true }] },
|
|
227
|
+
{ id: "CL-YOLO", files: CLINE, match: [{ path: "yoloModeToggled", equals: true }] },
|
|
228
|
+
// YOLO mode already approves everything, so this is for when it's off.
|
|
229
|
+
{
|
|
230
|
+
id: "CL-AUTO-COMMANDS",
|
|
231
|
+
files: CLINE,
|
|
232
|
+
match: [{ not: { path: "yoloModeToggled", equals: true } }, { not: { path: "autoApprovalSettings.enabled", equals: false } }, { path: "autoApprovalSettings.actions.executeAllCommands", equals: true }],
|
|
233
|
+
line: "executeAllCommands",
|
|
234
|
+
},
|
|
235
|
+
{ id: "AMP-ALLOW-ALL", files: ["**/.amp/settings.json", "**/.config/amp/settings.json"], match: [{ path: ["amp.dangerouslyAllowAll"], equals: true }], line: "dangerouslyAllowAll" },
|
|
236
|
+
].map((raw) => readTemplate(raw, { builtIn: true }));
|
package/lib/findings.js
CHANGED
|
@@ -31,7 +31,10 @@ function findingHtml(f, id = "", demo = false) {
|
|
|
31
31
|
const evidence = f.evidence
|
|
32
32
|
? `<pre class="evidence"><span class="evidence-where">${esc(f.file ? `${f.file}${f.line ? `, line ${f.line}` : ""}` : "Evidence")}</span>${esc(describeMasks(f.evidence))}</pre>`
|
|
33
33
|
: "";
|
|
34
|
-
|
|
34
|
+
// misconfig.ai/rules explains the built-in rules. One of your own links to
|
|
35
|
+
// its reference, or to nothing without one.
|
|
36
|
+
const link = !f.custom ? `https://misconfig.ai/rules#${f.id}` : typeof f.custom.reference === "string" && /^https:\/\//.test(f.custom.reference) ? f.custom.reference : "";
|
|
37
|
+
const rule = typeof f.id !== "string" || !RULE_ID.test(f.id) ? "" : link ? `<a class="f-rule" href="${esc(link)}" target="_blank" rel="noopener noreferrer">${f.id}</a>` : `<span class="f-rule">${f.id}</span>`;
|
|
35
38
|
const meta = [f.tool ? `<span>Affects ${esc(f.tool)}</span>` : "", rule].filter(Boolean).join("");
|
|
36
39
|
let review = "";
|
|
37
40
|
if (f.review) {
|
package/lib/formats.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// A finished check in the two formats other programs read: JSON Lines, one
|
|
2
|
+
// finding on each line, and SARIF 2.1.0, which GitHub code scanning and other
|
|
3
|
+
// viewers load. Nothing here reads a file or the network, so the same code
|
|
4
|
+
// can run wherever the engine does.
|
|
5
|
+
|
|
6
|
+
import { LEVELS, RULES } from "../engine/catalog.js";
|
|
7
|
+
|
|
8
|
+
const RULES_URL = "https://misconfig.ai/rules";
|
|
9
|
+
|
|
10
|
+
// JSON that's safe to print and to split into lines. A checked file can hold
|
|
11
|
+
// marks that reorder text on screen, and characters some programs treat as
|
|
12
|
+
// line breaks. A name in one can also spell a command that a CI system reads
|
|
13
|
+
// from its log, such as ##[error] or ##vso[task.setvariable]. JSON.stringify
|
|
14
|
+
// leaves all of these as they are, so they're written as \u escapes, which
|
|
15
|
+
// every JSON parser reads back unchanged.
|
|
16
|
+
const UNSAFE = /[\u007f-\u009f\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g;
|
|
17
|
+
export const stringify = (value, space) =>
|
|
18
|
+
JSON.stringify(value, null, space)
|
|
19
|
+
.replace(UNSAFE, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`)
|
|
20
|
+
.replace(/##(?=[a-z]*\[)/gi, "#\\u0023");
|
|
21
|
+
|
|
22
|
+
// --- JSON Lines ----------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
// One finding as a record. The keys are a contract: a 1.x release can add
|
|
25
|
+
// keys, and none is renamed or removed. Every key is always there, null when
|
|
26
|
+
// it doesn't apply. Each record names the check that made it, so lines from
|
|
27
|
+
// different runs and computers can share one file.
|
|
28
|
+
export function findingRecord(f, { version, ruleset, checkedAt }) {
|
|
29
|
+
return {
|
|
30
|
+
type: "finding",
|
|
31
|
+
rule: f.id,
|
|
32
|
+
severity: f.severity,
|
|
33
|
+
category: f.category,
|
|
34
|
+
agent: f.tool ?? null,
|
|
35
|
+
title: f.title,
|
|
36
|
+
why: f.why,
|
|
37
|
+
fix: f.fix,
|
|
38
|
+
file: f.file ?? null,
|
|
39
|
+
line: f.line ?? null,
|
|
40
|
+
evidence: f.evidence ?? null,
|
|
41
|
+
// For one of your own rules, its reference, or null without one.
|
|
42
|
+
ruleUrl: f.custom ? f.custom.reference : `${RULES_URL}#${f.id}`,
|
|
43
|
+
checkedAt: new Date(checkedAt).toISOString(),
|
|
44
|
+
ruleset,
|
|
45
|
+
cli: version,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// The findings, worst first, one JSON object on each line.
|
|
50
|
+
export function jsonLines(result, { version }) {
|
|
51
|
+
const run = { version, ruleset: result.version, checkedAt: result.checkedAt };
|
|
52
|
+
return result.findings.map((f) => `${stringify(findingRecord(f, run))}\n`).join("");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// --- SARIF -----------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
// Each level as SARIF and GitHub read it. SARIF has three levels. GitHub
|
|
58
|
+
// also reads a security severity from 0.1 to 10 and shows it as critical
|
|
59
|
+
// (over 9.0), high (7.0 to 8.9), medium (4.0 to 6.9) or low, so each level
|
|
60
|
+
// gets a number inside its band. Info findings are notes with no number.
|
|
61
|
+
const SARIF_LEVEL = { critical: "error", high: "error", medium: "warning", low: "note", info: "note" };
|
|
62
|
+
const SECURITY_SEVERITY = { critical: "9.5", high: "8.0", medium: "5.5", low: "2.5" };
|
|
63
|
+
|
|
64
|
+
// What each base in a file's address stands for. Neither is spelled out, so
|
|
65
|
+
// an address doesn't carry this computer's folder names.
|
|
66
|
+
const BASES = {
|
|
67
|
+
"%SRCROOT%": "The folder that was checked.",
|
|
68
|
+
HOME: "The home folder of the account that ran the check.",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// A rule as SARIF lists it. Its name says what it finds without one
|
|
72
|
+
// finding's values, and misconfig.ai/rules has the rest. One of your own
|
|
73
|
+
// rules isn't in the catalog, so its finding describes it, and its reference
|
|
74
|
+
// is where it's explained.
|
|
75
|
+
function ruleDescriptor(f) {
|
|
76
|
+
const rule = f.custom ? { name: f.custom.name, severity: f.severity, category: f.category } : RULES[f.id];
|
|
77
|
+
const name = rule.name ?? rule.title;
|
|
78
|
+
const url = f.custom ? f.custom.reference : `${RULES_URL}#${f.id}`;
|
|
79
|
+
const help = `What ${f.id} looks for, why it matters and how to fix it`;
|
|
80
|
+
return {
|
|
81
|
+
id: f.id,
|
|
82
|
+
shortDescription: { text: name },
|
|
83
|
+
fullDescription: { text: `${name}. ${LEVELS[rule.severity]}` },
|
|
84
|
+
...(url ? { help: { text: `${help}: ${url}`, ...(f.custom ? {} : { markdown: `[${help}](${url})` }) }, helpUri: url } : {}),
|
|
85
|
+
defaultConfiguration: { level: SARIF_LEVEL[rule.severity] },
|
|
86
|
+
properties: {
|
|
87
|
+
tags: ["security", rule.category],
|
|
88
|
+
...(SECURITY_SEVERITY[rule.severity] ? { "security-severity": SECURITY_SEVERITY[rule.severity] } : {}),
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// A file's address. A file in the checked folder is relative to it, which is
|
|
94
|
+
// how GitHub matches it to the repository. A file under the home folder is
|
|
95
|
+
// relative to HOME, so its address doesn't hold the account's name. Anything
|
|
96
|
+
// else, such as an administrator's settings, is a file: address.
|
|
97
|
+
function artifactLocation(file) {
|
|
98
|
+
// A name can hold half of a character pair, which can't be encoded.
|
|
99
|
+
const whole = (part) => part.replace(/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g, "\ufffd");
|
|
100
|
+
const encode = (p) => p.split("/").map((part) => encodeURIComponent(whole(part))).join("/");
|
|
101
|
+
if (file.startsWith("~/")) return { uri: encode(file.slice(2)), uriBaseId: "HOME" };
|
|
102
|
+
if (/^[A-Za-z]:\//.test(file)) return { uri: `file:///${file.slice(0, 2)}${encode(file.slice(2))}` };
|
|
103
|
+
if (file.startsWith("//")) return { uri: `file:${encode(file)}` };
|
|
104
|
+
if (file.startsWith("/")) return { uri: `file://${encode(file)}` };
|
|
105
|
+
return { uri: encode(file), uriBaseId: "%SRCROOT%" };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// A finding's own words: its title as a sentence, why it matters, and the
|
|
109
|
+
// fix. SARIF reads [text](address) in a message as a link, and names from a
|
|
110
|
+
// checked file are in these sentences, so the two marks are kept apart and a
|
|
111
|
+
// file can't put a link of its own in an alert.
|
|
112
|
+
function message(f) {
|
|
113
|
+
const title = /[.!?…]$/.test(f.title) ? f.title : `${f.title}.`;
|
|
114
|
+
return [title, f.why, `Fix: ${f.fix}`].join("\n").replace(/\]\(/g, "] (");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// GitHub refuses a file with more results than this, so a project crowded
|
|
118
|
+
// with findings can't keep the rest out of code scanning. The worst come
|
|
119
|
+
// first.
|
|
120
|
+
const MAX_RESULTS = 25000;
|
|
121
|
+
|
|
122
|
+
// The whole check as one SARIF run. Only the rules with findings are listed.
|
|
123
|
+
// A finding about a whole file points at its first line, which is where
|
|
124
|
+
// GitHub shows it. GitHub shows no finding that names no file.
|
|
125
|
+
export function sarif(result, { version }) {
|
|
126
|
+
const findings = result.findings.slice(0, MAX_RESULTS);
|
|
127
|
+
const ids = [...new Set(findings.map((f) => f.id))];
|
|
128
|
+
const results = findings.map((f) => ({
|
|
129
|
+
ruleId: f.id,
|
|
130
|
+
ruleIndex: ids.indexOf(f.id),
|
|
131
|
+
level: SARIF_LEVEL[f.severity],
|
|
132
|
+
message: { text: message(f) },
|
|
133
|
+
...(f.file ? { locations: [{ physicalLocation: { artifactLocation: artifactLocation(f.file), region: { startLine: f.line ?? 1 } } }] } : {}),
|
|
134
|
+
properties: { severity: f.severity, ...(f.tool ? { agent: f.tool } : {}) },
|
|
135
|
+
}));
|
|
136
|
+
const bases = [...new Set(results.map((r) => r.locations?.[0].physicalLocation.artifactLocation.uriBaseId).filter(Boolean))];
|
|
137
|
+
// A check that stopped early is marked as unfinished, so nothing that
|
|
138
|
+
// reads the file takes a finding it didn't reach for one that was fixed.
|
|
139
|
+
const stopped = result.stats.truncated;
|
|
140
|
+
const count = (n) => n.toLocaleString("en-US");
|
|
141
|
+
const notes = [];
|
|
142
|
+
if (stopped) notes.push({ level: "error", message: { text: `The check stopped after ${count(result.stats.entriesScanned)} files and folders, so agent files deeper in the folder may have been missed.` } });
|
|
143
|
+
const left = result.findings.length - MAX_RESULTS;
|
|
144
|
+
if (left > 0) notes.push({ level: "warning", message: { text: `This file has the ${count(MAX_RESULTS)} worst findings. ${count(left)} more ${left === 1 ? "was" : "were"} left out.` } });
|
|
145
|
+
return {
|
|
146
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
147
|
+
version: "2.1.0",
|
|
148
|
+
runs: [
|
|
149
|
+
{
|
|
150
|
+
tool: { driver: { name: "misconfig", semanticVersion: version, informationUri: "https://misconfig.ai", rules: ids.map((id) => ruleDescriptor(findings.find((f) => f.id === id))) } },
|
|
151
|
+
invocations: [{ executionSuccessful: !stopped, ...(notes.length ? { toolExecutionNotifications: notes } : {}) }],
|
|
152
|
+
...(bases.length ? { originalUriBaseIds: Object.fromEntries(bases.map((b) => [b, { description: { text: BASES[b] } }])) } : {}),
|
|
153
|
+
results,
|
|
154
|
+
properties: { ruleset: result.version },
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
};
|
|
158
|
+
}
|
package/lib/html.js
CHANGED
|
@@ -93,6 +93,9 @@ function body(r, { version, scanned }) {
|
|
|
93
93
|
].filter(Boolean);
|
|
94
94
|
const tilt = typeof r.score === "number" ? Math.round(14 * (1 - r.score / 100)) : 0;
|
|
95
95
|
const known = r.knownMalware ? ` Known malware as of ${new Date(r.knownMalware.asOf).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric", timeZone: "UTC" })}.` : "";
|
|
96
|
+
// The score counts findings from rules given with --rules, so the page says they were there.
|
|
97
|
+
const ownRules = Array.isArray(r.customRules) ? r.customRules.length : 0;
|
|
98
|
+
const own = ownRules ? ` ${plural(ownRules, "rule")} of your own ${ownRules === 1 ? "was" : "were"} checked too.` : "";
|
|
96
99
|
return `
|
|
97
100
|
<section class="result-head" aria-labelledby="report-headline">
|
|
98
101
|
<div class="grade-tile${r.grade === "–" ? " grade-none" : ""}" role="img" aria-label="${esc(typeof r.score === "number" ? `Grade ${r.grade}, score ${r.score} out of 100` : "No grade")}">
|
|
@@ -103,7 +106,7 @@ function body(r, { version, scanned }) {
|
|
|
103
106
|
${countsList(r.counts)}
|
|
104
107
|
<div class="result-meta">
|
|
105
108
|
${typeof r.score === "number" ? `<p>Score ${esc(r.score)} out of 100.</p>` : ""}
|
|
106
|
-
<p>Checked ${scanned.projectSkipped || !scanned.project ? esc(where) : `<code>${esc(where)}</code>`}${scanned.user && !scanned.demo ? " and the agent settings on this computer" : ""}.${esc(known)}</p>
|
|
109
|
+
<p>Checked ${scanned.projectSkipped || !scanned.project ? esc(where) : `<code>${esc(where)}</code>`}${scanned.user && !scanned.demo ? " and the agent settings on this computer" : ""}.${esc(known)}${esc(own)}</p>
|
|
107
110
|
<p>${esc(listText(checked))}.${r.tools.length ? ` Agents found: ${esc(listText(r.tools))}.` : ""}</p>
|
|
108
111
|
</div>
|
|
109
112
|
</div>
|