@misconfig/cli 1.3.0 → 1.3.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/engine/index.js CHANGED
@@ -1,17 +1,17 @@
1
- // The misconfig rule engine. The same code runs in the command line tool, in the
2
- // browser on misconfig.ai, and in the Worker that rebuilds shared reports.
1
+ // The misconfig rule engine. It runs in the command, on the user's computer.
2
+ // The Worker uses its rules version, scoring text and catalog for the rules
3
+ // page, and the site publishes it so anyone can read it.
3
4
 
4
5
  import { maskSecrets, looksLikeSecret, looksLikeToken, isMasked, isPathLike, describeMasks } from "./mask.js";
5
6
  import { parseJSONC, parseTOML, parseYAML, parseCodexRules } from "./parse.js";
6
7
  import { namedInstructions, NAMING_SETTINGS } from "./named.js";
7
8
  import { RULES, CATEGORIES } from "./catalog.js";
8
- import { explainFile, agentLines, hiddenComments, hiddenTags, hiddenZeroWidth, fenceAt, inCodeSpan, CAN_IMPORT, scopeOf, HOOK_EVENTS, SCOPES, anthropicMarketplace, marketplaceSource } from "./explain.js";
9
+ import { explainFile, agentLines, hiddenComments, hiddenTags, hiddenZeroWidth, fenceAt, inCodeSpan, CAN_IMPORT, scopeOf, HOOK_EVENTS, anthropicMarketplace, marketplaceSource } from "./explain.js";
9
10
  import { ignoreRules, isIgnored, globMatch } from "./glob.js";
10
- import { HOME_MARKERS, DOWNLOADS_LIKE, SKILL_PROGRAM, TOOL_ROOT, visibleName } from "./paths.js";
11
- import { findDangerFlag, trimWord, programName, COMMAND_BREAK, FLAG_NAMES, AGENT_NAMES } from "./flags.js";
11
+ import { HOME_MARKERS, DOWNLOADS_LIKE, TOOL_ROOT, visibleName } from "./paths.js";
12
+ import { findDangerFlag, trimWord, programName, COMMAND_BREAK } from "./flags.js";
12
13
  import {
13
14
  KNOWN_PACKAGES,
14
- KNOWN_EXTENSIONS,
15
15
  AGENT_EXTENSIONS,
16
16
  AGENT_PACKAGES,
17
17
  AGENT_ADVISORIES,
@@ -21,18 +21,16 @@ import {
21
21
  KNOWN_BAD_HOSTS,
22
22
  OFFICIAL_MCP_PACKAGES,
23
23
  OFFICIAL_PYPI_MCP,
24
+ OPEN_VSX_EDITORS,
25
+ addKnownMalware,
26
+ extensionListing,
24
27
  compareVersions,
25
28
  VERSION_RE,
26
29
  } from "./known.js";
27
30
 
28
31
  export { findDangerFlag };
29
32
 
30
- export const RULESET_VERSION = "2026.11.6";
31
- const RULESET_RE = /^\d{4}\.\d{1,2}\.\d{1,3}$/;
32
-
33
- // True when ruleset version a, such as "2026.11.4", is newer than b. A site
34
- // on an older ruleset doesn't know every check a newer command runs.
35
- export const rulesetIsNewer = (a, b) => typeof a === "string" && typeof b === "string" && RULESET_RE.test(a) && RULESET_RE.test(b) && compareVersions(a, b) > 0;
33
+ export const RULESET_VERSION = "2026.11.7";
36
34
 
37
35
  const WEIGHT = { critical: 30, high: 15, medium: 6, low: 2, info: 0 };
38
36
  const SEVERITIES = ["critical", "high", "medium", "low", "info"];
@@ -553,6 +551,10 @@ function buildContext(input) {
553
551
  traces: new Set((Array.isArray(input.traces) ? input.traces : []).filter((p) => typeof p === "string" && TRACE_PATHS.has(p))),
554
552
  packages: [],
555
553
  homeLike: topLevel.filter((n) => HOME_MARKERS.has(n)).length >= 3,
554
+ // The command was run in the home folder, so it checked the agent
555
+ // settings there, not a project. Where the agents themselves were
556
+ // started is in their own settings.
557
+ ranInHome: input.scanned?.projectSkipped === true,
556
558
  // Glob matching work allowed for the whole check.
557
559
  ignoreBudget: { left: 8_000_000 },
558
560
  findings: [],
@@ -733,9 +735,8 @@ function fillTemplate(text, values) {
733
735
 
734
736
  // Text from the user's files inside one of misconfig's own sentences: names,
735
737
  // paths, commands and quoted phrases. It's kept to one line, without double
736
- // quotes or direction marks, and cut to size, so a name in a hostile file, or
737
- // in a crafted private link, can't close misconfig's quotes or carry a
738
- // sentence of its own.
738
+ // quotes or direction marks, and cut to size, so a name in a hostile file
739
+ // can't close misconfig's quotes or carry a sentence of its own.
739
740
  const FROM_FILES = new Set(["cmd", "decoded", "phrase", "host", "ref", "path", "dir", "command", "rule", "files", "list", "key", "server", "pkg", "skill"]);
740
741
  const FILE_VALUE_MAX = { key: 80, server: 40, skill: 40, pkg: 80, host: 100, folder: 80 };
741
742
  function fileValue(value, k) {
@@ -750,36 +751,9 @@ function fileValue(value, k) {
750
751
  return text.length > max ? `${text.slice(0, max - 1)}…` : text;
751
752
  }
752
753
 
753
- // Parts of a finding that come from the user's own files: quoted text, paths,
754
- // commands and the names people choose for servers, packages, variables and
755
- // files. They never leave the computer. Shared reports show "[hidden]".
756
- const PRIVATE_VARS = new Set(["cmd", "decoded", "phrase", "host", "ref", "path", "dir", "command", "rule", "files", "list", "key", "server", "pkg", "lookup", "skill", "ext", "name", "summary", "worst"]);
757
-
758
- // "where" is a fixed phrase that can quote a name, as in The “deploy” script.
759
- const hideNames = (text) => String(text).replace(/“[^”]*”/g, "“[hidden]”");
760
-
761
- export function publicFinding(f) {
762
- const rule = RULES[f.id];
763
- const values = { ...(f.vars ?? {}) };
764
- for (const k of PRIVATE_VARS) values[k] = "[hidden]";
765
- if (typeof values.where === "string") values.where = hideNames(values.where);
766
- const fill = (text, fallback) => (rule ? fillTemplate(text, values) : fallback);
767
- return {
768
- id: f.id,
769
- severity: f.severity,
770
- category: f.category,
771
- tool: f.tool,
772
- title: fill(rule?.title ?? "", f.title),
773
- why: fill(rule?.why ?? "", f.why),
774
- fix: fill(rule?.fix ?? "", f.fix),
775
- file: f.file,
776
- line: f.line,
777
- };
778
- }
779
-
780
754
  // The worst finding in its own words, then how many more like it. Titles
781
755
  // start with names such as Codex or ~/.zshrc, so they're never lowercased.
782
- export function headlineFor(counts, top, hasControlFiles) {
756
+ function headlineFor(counts, top, hasControlFiles) {
783
757
  const minor = counts.medium + counts.low;
784
758
  if (!hasControlFiles && !top) return "No agent setup files found here.";
785
759
  const lead = (n, level) => (n > 1 ? `${top.title}, and ${n - 1} more ${level} issue${n === 2 ? "" : "s"}.` : `${top.title}.`);
@@ -848,8 +822,6 @@ const ENDPOINT_VARIABLES = new Set([
848
822
  "OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
849
823
  "HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY",
850
824
  ]);
851
- // Settings files' own names for a base address.
852
- const ENDPOINT_SETTINGS = new Set(["base_url", "openai-api-base", "baseURL", "apiBase"]);
853
825
  const CA_VARIABLES = new Set(["NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE", "REQUESTS_CA_BUNDLE", "CURL_CA_BUNDLE"]);
854
826
  // The services' own addresses, and cloud providers that host them.
855
827
  const OFFICIAL_ENDPOINT = /(?:^|\.)(?:anthropic\.com|claude\.ai|openai\.com|googleapis\.com|amazonaws\.com|azure\.com|azure\.net|windows\.net)$/i;
@@ -2013,17 +1985,25 @@ function launcherSpec(command, args, depth = 0) {
2013
1985
  return null;
2014
1986
  }
2015
1987
 
1988
+ // Package names as the registries allow them. The name goes into the fix a
1989
+ // report gives, such as "npm view NAME version", so anything else, such as
1990
+ // "x; curl ... | bash" in a hostile project's args, isn't treated as a package.
1991
+ const NPM_NAME = /^(?:@[a-z0-9][a-z0-9._~-]{0,100}\/)?[a-z0-9][a-z0-9._~-]{0,213}$/i;
1992
+ const PYTHON_NAME = /^[a-z0-9](?:[a-z0-9._-]{0,200}[a-z0-9])?$/i;
1993
+
2016
1994
  function judgeSpec(spec, python) {
2017
1995
  if (!spec) return null;
2018
1996
  // Local paths and URLs, such as ./server or git+https://..., aren't from a registry.
2019
1997
  if (/^(\.|\/|~|%|\$|[a-z][a-z0-9+.-]*:)/i.test(spec) || spec.includes("\\")) return null;
2020
1998
  if (python) {
2021
- const name = spec.split(/[=@<>~!\[]/)[0];
1999
+ const name = spec.split(/[=@<>~!\[]/)[0].trim();
2000
+ if (!PYTHON_NAME.test(name)) return null;
2022
2001
  const exact = spec.match(/(?:==|@)\s*(\d+(?:\.\d+){1,3})\s*$/);
2023
2002
  return { name, spec, pinned: /==\s*\d|@\s*\d/.test(spec), python: true, version: exact ? exact[1] : "" };
2024
2003
  }
2025
2004
  const at = spec.lastIndexOf("@");
2026
2005
  const name = at > 0 ? spec.slice(0, at) : spec;
2006
+ if (!NPM_NAME.test(name)) return null;
2027
2007
  const version = at > 0 ? spec.slice(at + 1) : "";
2028
2008
  const pinned = /^\d+\.\d+\.\d+([-+][\w.]+)?$/.test(version);
2029
2009
  return { name, spec, pinned, version: pinned ? version : "" };
@@ -2079,6 +2059,13 @@ export function isBroadPath(value) {
2079
2059
  );
2080
2060
  }
2081
2061
 
2062
+ // Folder names the checks write the usual way, such as Downloads.
2063
+ const FOLDER_NAMES = { downloads: "Downloads", download: "Downloads", desktop: "Desktop", temp: "Temp", tmp: "tmp" };
2064
+ const folderName = (name) => FOLDER_NAMES[String(name).toLowerCase()] ?? String(name);
2065
+
2066
+ // A folder agents read their settings from, such as .claude or .cursor/rules.
2067
+ const agentFolder = (p) => typeof p === "string" && TOOL_ROOT.test(p.split("/")[0]) && p.split("/").length <= 4;
2068
+
2082
2069
  // --- Workspace ---------------------------------------------------------------
2083
2070
 
2084
2071
  function checkWorkspace(ctx) {
@@ -2087,7 +2074,11 @@ function checkWorkspace(ctx) {
2087
2074
  const homeLike = ctx.homeLike;
2088
2075
  const downloadsLike = DOWNLOADS_LIKE.test(root);
2089
2076
 
2090
- if (homeLike) add(ctx, "WS-HOME", { vars: { markers: listNames(markers.filter((m) => m.startsWith(".") || m === "AppData").concat(markers).slice(0, 3)) } });
2077
+ // The command in a home folder with --project-only checks the folder
2078
+ // someone opens agents in. Run in the home folder as a
2079
+ // whole, the command only says where it ran, and the agents' own settings
2080
+ // say whether they were started there.
2081
+ if (homeLike && !ctx.ranInHome) add(ctx, "WS-HOME", { vars: { markers: listNames(markers.filter((m) => m.startsWith(".") || m === "AppData").concat(markers).slice(0, 3)) } });
2091
2082
  if (downloadsLike) add(ctx, "WS-DOWNLOADS", { vars: { root: folderName(root) } });
2092
2083
 
2093
2084
  if (downloadsLike) {
@@ -2282,9 +2273,19 @@ function extensionsFrom(list) {
2282
2273
  items: (Array.isArray(g.items) ? g.items : [])
2283
2274
  .slice(0, 3000)
2284
2275
  .filter((x) => isObj(x) && typeof x.id === "string" && EXT_ID.test(x.id))
2285
- .map((x) => ({ id: x.id.toLowerCase(), version: cleanVersion(x.version), source: x.source === "vsix" || x.source === "gallery" ? x.source : null })),
2276
+ .map((x) => ({
2277
+ id: x.id.toLowerCase(),
2278
+ // The ID with the capitals its publisher gave it, which OSV.dev
2279
+ // needs to find the extension. Only the same ID is accepted.
2280
+ published: typeof x.published === "string" && EXT_ID.test(x.published) && x.published.toLowerCase() === x.id.toLowerCase() ? x.published : null,
2281
+ version: cleanVersion(x.version),
2282
+ source: x.source === "vsix" || x.source === "gallery" ? x.source : null,
2283
+ })),
2286
2284
  }));
2287
2285
  }
2286
+ // Where each editor installs extensions from, as OSV.dev names it.
2287
+ const OPEN_VSX = "VSCode:https://open-vsx.org";
2288
+ const extensionRegistry = (editor) => (OPEN_VSX_EDITORS.includes(editor) ? OPEN_VSX : "VSCode");
2288
2289
 
2289
2290
  // The name known.js lists a package under: Python names are compared the way
2290
2291
  // PyPI compares them.
@@ -2293,7 +2294,6 @@ const knownPackage = (ecosystem, name) => {
2293
2294
  const key = `${ecosystem}:${knownName(ecosystem, name)}`;
2294
2295
  return Object.hasOwn(KNOWN_PACKAGES, key) ? KNOWN_PACKAGES[key] : null;
2295
2296
  };
2296
- const KNOWN_NAMES = new Set(Object.keys(KNOWN_PACKAGES).map((k) => k.slice(k.indexOf(":") + 1)));
2297
2297
  const affects = (entry, version) => entry.versions === "all" || Boolean(version && entry.versions.includes(version));
2298
2298
  // "Version 1.12.14 ... was" or "Versions 20.9.0, 20.10.0 and 21.5.0 ... were".
2299
2299
  function badVersions(entry) {
@@ -2419,10 +2419,10 @@ function checkExtensions(ctx) {
2419
2419
  const file = { path: group.dir, tools: group.editor === "Cursor" || group.editor === "Windsurf" ? [group.editor] : [] };
2420
2420
  const fromFiles = [];
2421
2421
  for (const x of group.items) {
2422
- ctx.packages.push({ ecosystem: "VSCode", name: x.id, version: x.version || null, where: `Installed as a ${group.editor} extension`, file: group.dir, via: "extension" });
2423
- const known = Object.hasOwn(KNOWN_EXTENSIONS, x.id) ? KNOWN_EXTENSIONS[x.id] : null;
2422
+ ctx.packages.push({ ecosystem: extensionRegistry(group.editor), name: x.published ?? x.id, version: x.version || null, where: `Installed as a ${group.editor} extension`, file: group.dir, via: "extension" });
2423
+ const known = extensionListing(x.id, group.editor);
2424
2424
  // A bad build one marketplace served doesn't apply to a copy installed from a file.
2425
- if (known && (!known.editors || (known.editors.includes(group.editor) && x.source !== "vsix")) && affects(known, x.version)) {
2425
+ if (known && (!known.editors || x.source !== "vsix") && affects(known, x.version)) {
2426
2426
  const advice = known.advice ?? EXT_ADVICE;
2427
2427
  add(ctx, "EXT-MALICIOUS", { file, vars: { editor: group.editor, ext: x.id, version: x.version || "", what: known.what, source: known.source, advice } });
2428
2428
  continue;
@@ -2551,8 +2551,8 @@ function checkSkillPrograms(ctx) {
2551
2551
  }
2552
2552
  for (const [dir, { skill, file, names }] of bySkill) {
2553
2553
  const files = names.slice(0, 3).join(", ") + (names.length > 3 ? ` and ${names.length - 3} more` : "");
2554
- // The finding points at the skill's SKILL.md when there is one, an agent
2555
- // file a share may name, rather than at the program.
2554
+ // The finding points at the skill's SKILL.md when there is one, rather
2555
+ // than at the program.
2556
2556
  // Without one, it points at the skill's folder, never at a program.
2557
2557
  const skillMd = ctx.files.find((x) => x.path.toLowerCase() === `${dir}/skill.md`.toLowerCase());
2558
2558
  const one = names.length === 1;
@@ -2590,9 +2590,6 @@ const LOOKUP_RULES = ["LOOKUP-VULN", "LOOKUP-VULN-MINOR", "LOOKUP-VULN-LOW"];
2590
2590
  const LOOKUP_NO_FIX = "No fixed version is listed yet. Update when one is out, and until then limit what it can reach";
2591
2591
  const LOOKUP_SOME_FIXED = " for the ones that are fixed. The rest have no fix listed yet, so limit what it can reach";
2592
2592
  const LOOKUP_UNKNOWN = "Update to the newest version. Some details didn't load from OSV.dev, so run --lookup again to see which version fixes each one";
2593
- // OSV.dev's summaries are shown as text, without links or anything that
2594
- // reads as a command.
2595
- const SAFE_SUMMARY = /^(?![\s\S]*(?::\/\/|www\.))[^|`$\n]{1,200}$/;
2596
2593
  function safeSummary(text) {
2597
2594
  return String(text ?? "")
2598
2595
  .replace(/[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, " ")
@@ -2604,7 +2601,10 @@ function safeSummary(text) {
2604
2601
  export function applyLookup(result, hits) {
2605
2602
  if (!isObj(result) || !Array.isArray(result.findings)) return result;
2606
2603
  const packages = Array.isArray(result.packages) ? result.packages.filter(isObj) : [];
2607
- const flagged = new Set(result.findings.filter((f) => MALWARE_RULES.has(f.id)).map((f) => `${f.vars?.known ?? f.vars?.ext}|${f.file}`));
2604
+ // Names as the bundled list's findings write them: extension IDs in
2605
+ // lowercase, Python names the way PyPI compares them.
2606
+ const loose = (name) => String(name).toLowerCase().replace(/[-_.]+/g, "-");
2607
+ const flagged = new Set(result.findings.filter((f) => MALWARE_RULES.has(f.id)).map((f) => `${loose(f.vars?.known ?? f.vars?.ext)}|${f.file}`));
2608
2608
  const counted = (name) => new Set((Object.hasOwn(AGENT_ADVISORIES, name) ? AGENT_ADVISORIES[name] : []).flatMap((a) => [a.id, a.cve]).filter(Boolean));
2609
2609
  const uses = new Map();
2610
2610
  for (const h of (Array.isArray(hits) ? hits : []).slice(0, 300)) {
@@ -2614,7 +2614,7 @@ export function applyLookup(result, hits) {
2614
2614
  if (pkg.ecosystem !== h.ecosystem || pkg.name !== h.name || (pkg.version ?? null) !== (h.version ?? null)) continue;
2615
2615
  // Without a version, only "this package is malware" applies.
2616
2616
  if (!malicious && !pkg.version) continue;
2617
- if (malicious && flagged.has(`${pkg.name}|${pkg.file}`)) continue;
2617
+ if (malicious && flagged.has(`${loose(pkg.name)}|${pkg.file}`)) continue;
2618
2618
  if (!malicious && pkg.via === "install" && counted(pkg.name).has(h.ref)) continue;
2619
2619
  const use = uses.get(pkg) ?? { malicious: null, vulns: new Map() };
2620
2620
  if (malicious) use.malicious ??= h;
@@ -2628,7 +2628,11 @@ export function applyLookup(result, hits) {
2628
2628
  const file = { path: typeof pkg.file === "string" ? pkg.file : null, tools: [] };
2629
2629
  const common = { name: pkg.name, version: pkg.version ?? "", where: pkg.where };
2630
2630
  if (use.malicious) {
2631
- extra.push(makeFinding("LOOKUP-MALICIOUS", { file, vars: { ...common, ref: use.malicious.ref } }));
2631
+ // Without a pinned version, a listing that names only some versions,
2632
+ // often of a real package whose account was taken over, says those
2633
+ // versions were malware, not the package.
2634
+ const some = !pkg.version && use.malicious.allVersions !== true;
2635
+ extra.push(makeFinding(some ? "LOOKUP-MALICIOUS-VERSION" : "LOOKUP-MALICIOUS", { file, vars: { ...common, ref: use.malicious.ref } }));
2632
2636
  continue;
2633
2637
  }
2634
2638
  const vulns = [...use.vulns.values()];
@@ -2669,9 +2673,9 @@ export function applyLookup(result, hits) {
2669
2673
  const bySeverity = (a, b) =>
2670
2674
  SEVERITIES.indexOf(a.severity) - SEVERITIES.indexOf(b.severity) || a.category.localeCompare(b.category) || (a.file ?? "").localeCompare(b.file ?? "");
2671
2675
 
2672
- // Score, grade and counts from a list of findings. Shared by the local check
2673
- // and by the Worker when it publishes a shared report.
2674
- export function scoreFindings(findings, hasControlFiles) {
2676
+ // Score, grade and counts from a list of findings, for a check and again
2677
+ // after a lookup.
2678
+ function scoreFindings(findings, hasControlFiles) {
2675
2679
  const counts = Object.fromEntries(SEVERITIES.map((s) => [s, findings.filter((f) => f.severity === s).length]));
2676
2680
  // Repeats of the same rule count less, so one noisy pattern can't zero the score.
2677
2681
  const byRule = new Map();
@@ -2685,6 +2689,21 @@ export function scoreFindings(findings, hasControlFiles) {
2685
2689
  return { counts, score: grade === "–" ? null : score, grade };
2686
2690
  }
2687
2691
 
2692
+ // What each rule's findings take off the score, most first: the order to fix
2693
+ // things in. The points are the same ones scoreFindings counts.
2694
+ export function pointsOff(findings) {
2695
+ const byRule = new Map();
2696
+ for (const f of findings) {
2697
+ if (!Object.hasOwn(RULES, f.id)) continue;
2698
+ const entry = byRule.get(f.id) ?? { id: f.id, severity: RULES[f.id].severity, findings: [] };
2699
+ entry.findings.push(f);
2700
+ byRule.set(f.id, entry);
2701
+ }
2702
+ const rules = [...byRule.values()].map((r) => ({ ...r, points: WEIGHT[r.severity] * Math.min(2, 1 + 0.25 * (r.findings.length - 1)) }));
2703
+ rules.sort((a, b) => b.points - a.points || SEVERITIES.indexOf(a.severity) - SEVERITIES.indexOf(b.severity));
2704
+ return { rules: rules.filter((r) => r.points > 0), total: rules.reduce((sum, r) => sum + r.points, 0) };
2705
+ }
2706
+
2688
2707
  function agentsIn(controlMap) {
2689
2708
  // Agents with files of their own. A file several agents read, such as
2690
2709
  // AGENTS.md or .mcp.json, doesn't show that each of them is in use.
@@ -2731,8 +2750,8 @@ function summarize(ctx) {
2731
2750
  findings,
2732
2751
  categories: CATEGORIES,
2733
2752
  tools: toolNames,
2734
- // What each file tells its agents, worked out here. A share keeps just
2735
- // the path; only an --open report, encrypted here, carries the rest.
2753
+ // What each file tells its agents, worked out here, for --explain and
2754
+ // the page --open saves.
2736
2755
  controlMap: controlFiles.map((f) => ({
2737
2756
  path: f.path,
2738
2757
  kind: f.kind,
@@ -2755,7 +2774,7 @@ function summarize(ctx) {
2755
2774
  agentInstalls: ctx.installs.filter((i) => Object.hasOwn(AGENT_PACKAGES, i.package)).length,
2756
2775
  extensions: ctx.extensions.reduce((n, g) => n + g.items.length, 0),
2757
2776
  },
2758
- // What's installed, for --explain and --lookup. Never part of a share.
2777
+ // What's installed, for --explain, --open and --lookup.
2759
2778
  installed: {
2760
2779
  agents: ctx.installs.filter((i) => Object.hasOwn(AGENT_PACKAGES, i.package)).map((i) => ({ tool: AGENT_PACKAGES[i.package].tool, version: i.version, via: i.via, path: i.path })),
2761
2780
  editors: ctx.extensions.map((g) => ({
@@ -2769,532 +2788,13 @@ function summarize(ctx) {
2769
2788
  };
2770
2789
  }
2771
2790
 
2772
- // --- Sharing -----------------------------------------------------------------
2773
- //
2774
- // What leaves the computer when someone chooses to share: rule IDs, the names
2775
- // of agent files inside the project, line numbers and values from the fixed
2776
- // lists below. Nothing quotes a file, names a local path, or carries a name
2777
- // the user chose. A value that isn't on the lists drops its finding, so a
2778
- // share link can't make a signed report say something no check would say.
2779
-
2780
- const FOLDER_NAMES = { downloads: "Downloads", download: "Downloads", desktop: "Desktop", temp: "Temp", tmp: "tmp" };
2781
- const folderName = (name) => FOLDER_NAMES[String(name).toLowerCase()] ?? String(name);
2782
- const PLACES = new Set(["your home folder", "the root of a drive", "a temp folder", ...Object.values(FOLDER_NAMES).map((n) => `your ${n} folder`)]);
2783
- const RISKS = new Set([RISK_HOME, RISK_DOWNLOADS, RISK_DRIVE]);
2784
- const AGENT_SETTINGS = ["allowedTools", "toolsSettings", "permissions"];
2785
- const SETTING_NAMES = new Set([...VS_CODE_AUTO_APPROVE, ...ALWAYS_ALLOW_KEYS, ...AGENT_SETTINGS]);
2786
- const DOCKER_FLAGS = /^(?:--privileged|--(?:pid|network|ipc|uts)=host|--cap-add=(?:ALL|SYS_ADMIN)|(?:-v|--mount) (?:\/|~|\/(?:etc|var|opt|usr|root)|\/var\/run\/docker\.sock|[A-Z]:\\))$/;
2787
- // The phrases each rule's {where} can be, with names already hidden.
2788
- const claudeHook = (v) => v === "A Claude Code hook" || (/^A Claude Code \w+ hook$/.test(v) && Object.hasOwn(HOOK_EVENTS, v.split(" ")[3]));
2789
- const ENV_WHERE = ["Claude Code's env setting", "Codex's shell_environment_policy", "Aider's set-env setting"];
2790
- const ENDPOINT_WHERE = [...ENV_WHERE, "An MCP server's env setting", "Codex's model_providers setting", "Aider's openai-api-base setting", "OpenCode's provider setting", "Continue's model settings"];
2791
- const COMMAND_SOURCES = [
2792
- "Codex's notify command",
2793
- "This hook script",
2794
- "A GitHub Copilot hook",
2795
- "A Cursor hook",
2796
- "Cursor's cloud agent setup",
2797
- "A Codex hook",
2798
- "Codex's model provider login command",
2799
- "Codex's MCP header command",
2800
- "A Gemini CLI hook",
2801
- "Gemini CLI's tool discovery command",
2802
- "Gemini CLI's tool call command",
2803
- "A Windsurf hook",
2804
- "A Kiro hook",
2805
- "An Amazon Q hook",
2806
- "A Grok hook",
2807
- "Grok's status line command",
2808
- "A task that runs when the folder opens",
2809
- "An MCP server's command",
2810
- ...Object.values(AIDER_COMMANDS),
2811
- ];
2812
- const runsCommands = (v) =>
2813
- claudeHook(v) ||
2814
- COMMAND_SOURCES.includes(v) ||
2815
- CLAUDE_COMMAND_KEYS.some((key) => v === `Claude Code's ${key} setting`);
2816
- const WHERE = {
2817
- "CX-YOLO": (v) => v === "" || v === " in profile “[hidden]”",
2818
- "CX-FULL-ACCESS": (v) => v === "" || v === " in profile “[hidden]”",
2819
- "CX-NEVER-ASK": (v) => v === "" || v === " in profile “[hidden]”",
2820
- "OC-BASH-ALLOW": (v) => v === "" || v === " for the “[hidden]” agent",
2821
- "FLAG-SCRIPT": (v) => runsCommands(v) || v === "The “[hidden]” script in package.json",
2822
- "HOOK-REMOTE-EXEC": runsCommands,
2823
- "HOOK-NETWORK": runsCommands,
2824
- "HOOK-DESTRUCTIVE": runsCommands,
2825
- "HOOK-OUTSIDE": runsCommands,
2826
- "HOOK-HTTP": claudeHook,
2827
- "ENV-CODE-LOAD": (v) => ENV_WHERE.includes(v),
2828
- "PROJECT-AUTORUN": runsCommands,
2829
- "AGENT-ENDPOINT": (v) => ENDPOINT_WHERE.includes(v),
2830
- "AGENT-ENDPOINT-USER": (v) => ENDPOINT_WHERE.includes(v),
2831
- "ENV-TLS-OFF": (v) => ENDPOINT_WHERE.includes(v),
2832
- "ENV-CA-PROJECT": (v) => ENDPOINT_WHERE.includes(v),
2833
- };
2834
-
2835
- const KNOWN_TOOLS = new Set([...AGENT_NAMES, ...CONTROL.flatMap(([, tools]) => (Array.isArray(tools) ? tools : [])), "Cursor", "Windsurf"]);
2836
-
2837
- // Numbers within what the checks can produce: files over 450,000 characters
2838
- // aren't read, so nothing larger can come out of one.
2839
- const between = (v, min, max) => Number(v.replace(/,/g, "")) >= min && Number(v.replace(/,/g, "")) <= max;
2840
- const PUBLIC_VARS = {
2841
- where: (v, id) => WHERE[id]?.(v) === true,
2842
- setting: (v) => SETTING_NAMES.has(v),
2843
- flag: (v) => FLAG_NAMES.has(v) || DOCKER_FLAGS.test(v),
2844
- count: (v) => (/^\d{1,5}$/.test(v) && between(v, 1, 99_999)) || /^(?:every tool|[1-9]\d{0,3} tools?)$/.test(v),
2845
- length: (v) => /^\d{1,3}(?:,\d{3})?$/.test(v) && between(v, 300, 450_000),
2846
- size: (v) => /^\d{1,3} KB$/.test(v) && between(v.slice(0, -3), 1, 450),
2847
- agent: (v) => AGENT_NAMES.has(v),
2848
- tool: (v) => KNOWN_TOOLS.has(v),
2849
- markers: (v) => v.split(/, | and /).every((m) => HOME_MARKERS.has(m)),
2850
- place: (v) => PLACES.has(v),
2851
- risk: (v) => RISKS.has(v),
2852
- root: (v) => Object.values(FOLDER_NAMES).includes(v),
2853
- mode: (v) => v === "always-approve" || v === "yolo",
2854
- what: (v) => KNOWN_PHRASES.what.has(v),
2855
- source: (v) => KNOWN_PHRASES.source.has(v),
2856
- campaign: (v) => KNOWN_PHRASES.campaign.has(v),
2857
- advice: (v) => KNOWN_PHRASES.advice.has(v),
2858
- official: (v) => OFFICIAL_MCP_PACKAGES.includes(v) || OFFICIAL_PYPI_MCP.includes(v) || OFFICIAL_SCOPES.includes(v),
2859
- origin: (v) => v === "a git repository" || v === "a web address",
2860
- version: (v) => VERSION_RE.test(v),
2861
- known: (v) => KNOWN_NAMES.has(v),
2862
- status: (v) => v === "a package listed as malicious" || v === "a version that was malware",
2863
- versions: (v) => /^Versions? [0-9][0-9A-Za-z., -]{0,400}$/.test(v),
2864
- were: (v) => v === "was" || v === "were",
2865
- one: (v) => v === "it" || v === "one of them",
2866
- programs: (v) => /^(?:a program|[1-9]\d{0,3} programs)$/.test(v),
2867
- them: (v) => v === "it" || v === "them",
2868
- commands: (v) => /^(?:a command|[1-9]\d{0,3} commands)$/.test(v),
2869
- remedy: (v) => /^(?:Remove \S{1,214} from the project|Move \S{1,214} to a version that wasn't malware) and update the lockfile$/.test(v),
2870
- variable: (v) => Object.hasOwn(CODE_LOADING_ENV, v) || /^GIT_CONFIG_KEY_\d{1,3}$/.test(v) || ENDPOINT_VARIABLES.has(v) || ENDPOINT_SETTINGS.has(v) || CA_VARIABLES.has(v) || v === "NODE_TLS_REJECT_UNAUTHORIZED",
2871
- };
2872
- // A fact as known.js words it now, or as an earlier release worded it.
2873
- const said = (entry, field, value) => entry?.[field] === value || (Array.isArray(entry?.was?.[field]) && entry.was[field].includes(value));
2874
- const phrases = (entries, field) => entries.flatMap((e) => [e[field], ...(Array.isArray(e.was?.[field]) ? e.was[field] : [])]).filter((v) => typeof v === "string");
2875
- // The fixed phrases known.js uses, which a shared report may repeat.
2876
- const KNOWN_PHRASES = {
2877
- what: new Set([...phrases(Object.values(KNOWN_PACKAGES), "what"), ...phrases(WORKFLOW_TRACES, "what"), ...phrases(SHELL_TRACES, "what")]),
2878
- source: new Set(phrases(Object.values(KNOWN_PACKAGES), "source")),
2879
- campaign: new Set([...phrases(WORKFLOW_TRACES, "campaign"), ...phrases(SHELL_TRACES, "campaign"), ...Object.values(KNOWN_BAD_HOSTS)]),
2880
- advice: new Set([...phrases(WORKFLOW_TRACES, "fix"), ...phrases(SHELL_TRACES, "fix")]),
2881
- };
2882
-
2883
- const templateVars = new Map(Object.entries(RULES).map(([id, r]) => [id, [...new Set([...`${r.title} ${r.why} ${r.fix}`.matchAll(/\{(\w+)\}/g)].map((m) => m[1]))]]));
2884
-
2885
- // A folder agents read their settings from, such as .claude or .cursor/rules.
2886
- const agentFolder = (p) => typeof p === "string" && TOOL_ROOT.test(p.split("/")[0]) && p.split("/").length <= 4;
2887
-
2888
- // A project path as the command and the browser check send it in a share.
2889
- // In each name, anything but letters, digits and ._@+- becomes _, and a long
2890
- // name keeps its start and its end, so a finding in "my rules.mdc" is still
2891
- // shared, as my_rules.mdc, and a name can't keep a finding out of a share.
2892
- const shareName = (part) => {
2893
- const plain = part.replace(/[^A-Za-z0-9._@+-]/g, "_");
2894
- return plain.length <= 80 ? plain : `${plain.slice(0, 60)}_${plain.slice(-19)}`;
2895
- };
2896
- const plainPath = (p) => (typeof p === "string" && !/^(\/|~|[A-Za-z]:)/.test(p) ? p.split("/").map(shareName).join("/") : p);
2897
-
2898
- // Whether a path can be shown on a shared page, which takes only plain names
2899
- // in project folders, as plainPath makes them, of files agents read under
2900
- // their usual names. Other names, such as a file a setting names as
2901
- // instructions, stay on the computer like any other file name.
2902
- function shareablePath(p) {
2903
- if (typeof p !== "string" || p.length > 1000) return null;
2904
- const clean = cleanPath(p);
2905
- if (!clean || /^(\/|~|[A-Za-z]:)/.test(clean)) return null;
2906
- const parts = clean.split("/");
2907
- if (parts.length > 12 || !parts.every((part) => /^[A-Za-z0-9._@+-]{1,80}$/.test(part))) return null;
2908
- if (/(^|\/)\.claude\/(projects|plugins)\//i.test(clean)) return null;
2909
- // Also the workflows worms add, and the project's copy of a package that
2910
- // was malware: both are names from known.js.
2911
- const workflow = WORKFLOW_TRACES.some((t) => t.name.test(clean));
2912
- const knownCopy = /^node_modules\/(?:\.pnpm\/[^/]+\/node_modules\/)?((?:@[^/]+\/)?[^/]+)$/.exec(clean)?.[1];
2913
- return controlFor(clean) || workflow || (knownCopy && knownPackage("npm", knownCopy)) || LOCKFILES.has(clean) || /^(?:[^/]+\/){0,3}\.gitignore$/i.test(clean) || clean === "package.json" || agentFolder(clean) ? clean : null;
2914
- }
2915
-
2916
- // Facts from known.js come as a set. A finding can't pair one package's name
2917
- // with another's description, name a version that wasn't malware, or credit
2918
- // an attack with another's files, so a share or a private link can't make
2919
- // misconfig accuse a package of something it never reported. Used for shares
2920
- // and private reports; values that are hidden in a share aren't checked here.
2921
- function knownFactsAgree(id, vars, file) {
2922
- const has = (k) => typeof vars[k] === "string" && vars[k] !== "" && vars[k] !== "[hidden]";
2923
- switch (id) {
2924
- case "PKG-MALICIOUS":
2925
- case "PKG-MALICIOUS-VERSION":
2926
- case "DEP-MALICIOUS":
2927
- case "DEP-LOCKFILE": {
2928
- const entry = knownPackage("npm", vars.known) ?? (id.startsWith("DEP-") ? null : knownPackage("PyPI", vars.known));
2929
- if (!entry || !said(entry, "source", vars.source)) return false;
2930
- if (id === "PKG-MALICIOUS") return said(entry, "what", vars.what);
2931
- if (id === "PKG-MALICIOUS-VERSION") {
2932
- if (!Array.isArray(entry.versions)) return false;
2933
- const want = badVersions(entry);
2934
- return want.versions === vars.versions && want.were === vars.were && want.one === vars.one;
2935
- }
2936
- const place = typeof file === "string" ? file : "";
2937
- return (
2938
- said(entry, "what", vars.what) &&
2939
- affects(entry, vars.version) &&
2940
- vars.status === (entry.versions === "all" ? "a package listed as malicious" : "a version that was malware") &&
2941
- (id === "DEP-LOCKFILE" ? LOCKFILES.has(place) && vars.remedy === lockRemedy(vars.known, entry) : place === `node_modules/${vars.known}` || place.endsWith(`/${vars.known}`))
2942
- );
2943
- }
2944
- case "EXT-MALICIOUS": {
2945
- const entry = Object.hasOwn(KNOWN_EXTENSIONS, vars.ext) ? KNOWN_EXTENSIONS[vars.ext] : null;
2946
- return Boolean(
2947
- entry &&
2948
- said(entry, "what", vars.what) &&
2949
- said(entry, "source", vars.source) &&
2950
- (entry.advice ? said(entry, "advice", vars.advice) : vars.advice === EXT_ADVICE) &&
2951
- (!entry.editors || entry.editors.includes(vars.editor)) &&
2952
- (!has("version") || affects(entry, vars.version)),
2953
- );
2954
- }
2955
- case "ATTACK-TRACE":
2956
- case "ATTACK-TRACE-WEAK": {
2957
- const t = TRACES.find((x) => said(x, "campaign", vars.campaign) && said(x, "what", vars.what) && said(x, "fix", vars.advice) && Boolean(x.strong) === (id === "ATTACK-TRACE"));
2958
- return Boolean(t && (!has("files") || vars.files.split(", ").every((p) => t.paths.includes(p))));
2959
- }
2960
- case "ATTACK-SHELL-LINE":
2961
- return SHELL_TRACES.some((x) => said(x, "campaign", vars.campaign) && said(x, "what", vars.what) && said(x, "fix", vars.advice));
2962
- case "ATTACK-WORKFLOW":
2963
- case "ATTACK-WORKFLOW-WEAK":
2964
- return WORKFLOW_TRACES.some((x) => x.name.test(file ?? "") && Boolean(x.strong) === (id === "ATTACK-WORKFLOW") && said(x, "campaign", vars.campaign) && said(x, "what", vars.what) && said(x, "fix", vars.advice));
2965
- case "TXT-KNOWN-C2":
2966
- return Object.values(KNOWN_BAD_HOSTS).includes(vars.campaign) && (!has("host") || KNOWN_BAD_HOSTS[vars.host.toLowerCase()] === vars.campaign);
2967
- case "SKILL-BINARY":
2968
- return (
2969
- (vars.programs === "a program") === (vars.them === "it") &&
2970
- (!has("files") || vars.files.replace(/ and \d+ more$/, "").split(", ").every((p) => SKILL_PROGRAM.test(p) || SKILL_PROGRAM.test(`${p}/`)))
2971
- );
2972
- case "AGENT-VULN":
2973
- case "AGENT-VULN-MINOR":
2974
- case "AGENT-VULN-LOW":
2975
- // Worked out again from the tool and version, for each platform.
2976
- return Object.entries(AGENT_PACKAGES).some(
2977
- ([pkg, meta]) =>
2978
- meta.tool === vars.tool &&
2979
- [...Object.values(meta.update), ...Object.values(GLOBAL_UPDATE).map((make) => make(pkg))].includes(vars.update) &&
2980
- [undefined, "mac", "windows", "linux"].some((platform) => {
2981
- const advice = agentAdvice(pkg, vars.version, platform);
2982
- return advice?.id === id && Object.entries(advice.vars).every(([k, v]) => (k === "worst" ? said(advice.worst, "title", vars.worst) : vars[k] === v));
2983
- }),
2984
- );
2985
- default:
2986
- return true;
2987
- }
2988
- }
2989
-
2990
- // The shareable form of one finding, or null when it can't be shared. The
2991
- // command and the browser use it to build the preview, and the Worker uses it
2992
- // again on what arrives, so the preview is exactly what a report will say.
2993
- function shareFinding(f) {
2994
- if (!isObj(f) || typeof f.id !== "string" || !Object.hasOwn(RULES, f.id)) return null;
2995
- const file = f.file == null ? null : shareablePath(f.file);
2996
- if (f.file != null && !file) return null;
2997
- const given = isObj(f.vars) ? f.vars : {};
2998
- const vars = {};
2999
- for (const k of templateVars.get(f.id)) {
3000
- if (k === "file" || PRIVATE_VARS.has(k)) continue;
3001
- const value = given[k];
3002
- if ((typeof value !== "string" && typeof value !== "number") || String(value).length > 200) return null;
3003
- const v = k === "where" ? hideNames(String(value)) : String(value);
3004
- if (!PUBLIC_VARS[k]?.(v, f.id)) return null;
3005
- vars[k] = v;
3006
- }
3007
- if (!knownFactsAgree(f.id, vars, file)) return null;
3008
- const out = { id: f.id, file, line: Number.isInteger(f.line) && f.line > 0 && f.line < 1e7 ? f.line : null, vars };
3009
- if (typeof f.tool === "string" && KNOWN_TOOLS.has(f.tool)) out.tool = f.tool;
3010
- return out;
3011
- }
3012
-
3013
- // Which agent a shared finding is about: the rule's own, else the one the
3014
- // check named, else the first agent that reads the file.
3015
- function sharedTool(f, rule) {
3016
- if (rule.tool) return rule.tool;
3017
- if (f.tool) return f.tool;
3018
- return (f.file && controlFor(f.file)?.tools[0]) ?? null;
3019
- }
3020
-
3021
- export function toShareable(result) {
3022
- return {
3023
- version: result.version,
3024
- findings: result.findings.map((f) => shareFinding(f.file == null ? f : { ...f, file: plainPath(f.file) })).filter(Boolean),
3025
- controlMap: result.controlMap.map((f) => plainPath(f.path)).filter((p) => shareablePath(p) && controlFor(p)),
3026
- stats: { filesChecked: result.stats.filesChecked, mcpServers: result.stats.mcpServers },
3027
- };
3028
- }
3029
-
3030
- // A shared report holds at most this many findings. The command and the
3031
- // browser check won't share a check with more, and the site refuses one.
3032
- export const SHARE_MAX_FINDINGS = 400;
3033
-
3034
- // How many findings in a shareable payload a report rebuilt here would leave
3035
- // out: ones from checks this copy doesn't know, or with values it won't show.
3036
- export function unshareable(payload) {
3037
- if (!isObj(payload) || !Array.isArray(payload.findings)) return 0;
3038
- return payload.findings.slice(0, SHARE_MAX_FINDINGS).filter((f) => !shareFinding(f)).length;
3039
- }
3040
-
3041
- // Rebuilds a public report from a shareable payload. Every title and sentence
3042
- // comes from the rule catalog.
3043
- export function publicReportFrom(payload) {
3044
- if (!isObj(payload) || !Array.isArray(payload.findings) || !Array.isArray(payload.controlMap)) return null;
3045
- const paths = [...new Set(payload.controlMap.slice(0, 300).map(shareablePath).filter((p) => p && controlFor(p)))];
3046
- const findings = payload.findings
3047
- .slice(0, SHARE_MAX_FINDINGS)
3048
- .map(shareFinding)
3049
- .filter(Boolean)
3050
- .map((f) => {
3051
- const rule = RULES[f.id];
3052
- return publicFinding({ id: f.id, severity: rule.severity, category: rule.category, tool: sharedTool(f, rule), file: f.file, line: f.line, vars: { ...f.vars, file: f.file ?? "" } });
3053
- })
3054
- .sort(bySeverity);
3055
- const controlMap = paths
3056
- .map((path) => ({ path, ...controlFor(path) }))
3057
- .map((f) => ({ ...f, findings: findings.filter((x) => x.file === f.path).length }));
3058
- const { counts, score, grade } = scoreFindings(findings, controlMap.length > 0);
3059
- const stats = isObj(payload.stats) ? payload.stats : {};
3060
- return {
3061
- version: typeof payload.version === "string" && RULESET_RE.test(payload.version) ? payload.version : "",
3062
- score,
3063
- grade,
3064
- headline: headlineFor(counts, findings[0], controlMap.length > 0),
3065
- counts,
3066
- tools: agentsIn(controlMap),
3067
- stats: { filesChecked: Math.min(toInt(stats.filesChecked), 100_000), mcpServers: Math.min(toInt(stats.mcpServers), 10_000) },
3068
- findings,
3069
- controlMap,
3070
- };
3071
- }
3072
-
3073
- // --- Private reports -----------------------------------------------------------
2791
+ // --- Today's list ------------------------------------------------------------------
3074
2792
  //
3075
- // The page at misconfig.ai/p/ shows a report the command encrypted. Anyone can
3076
- // make a link like that with any content in it, so nothing in it is trusted.
3077
- // Findings are rebuilt from the rule catalog by ID, so every title, severity
3078
- // and fix is the catalog's own; the grade and headline are worked out again;
3079
- // and text from the files (names, summaries, what each file says) is kept as
3080
- // plain text, cut to size. Whatever doesn't fit is dropped and counted.
3081
-
3082
- const PRIVATE_LIMITS = { findings: 1000, files: 1000, lines: 20_000, value: 400, text: 400, line: 1000, evidence: 600 };
3083
- const KNOWN_KINDS = new Set([...CONTROL.map(([, , kind]) => kind), "Loose file", "Plugin hooks", "Plugin MCP servers"]);
3084
- const LOOSE_TOOL = "Any agent started there";
3085
- const plainText = (v, max) => (typeof v === "string" ? v : typeof v === "number" && Number.isFinite(v) ? String(v) : "").slice(0, max);
3086
-
3087
- // Words a report says in misconfig's own voice: commands to run, advice, what
3088
- // known malware does and where that's reported. A private link can't put
3089
- // other words there, so a crafted link can't tell its reader to run something
3090
- // misconfig never suggested. A finding with anything else is dropped, as in a
3091
- // share link. Names from the user's own files stay as text.
3092
- const UPDATE_COMMANDS = new Set([
3093
- ...Object.values(AGENT_PACKAGES).flatMap((m) => Object.values(m.update)),
3094
- ...Object.keys(AGENT_PACKAGES).flatMap((p) => Object.values(GLOBAL_UPDATE).map((make) => make(p))),
3095
- ]);
3096
- const OWN_WORDS = {
3097
- what: new Set([...KNOWN_PHRASES.what, ...phrases(Object.values(KNOWN_EXTENSIONS), "what"), ...phrases(TRACES, "what")]),
3098
- source: new Set([...KNOWN_PHRASES.source, ...phrases(Object.values(KNOWN_EXTENSIONS), "source")]),
3099
- campaign: new Set([...KNOWN_PHRASES.campaign, ...phrases(TRACES, "campaign")]),
3100
- advice: new Set([
3101
- ...KNOWN_PHRASES.advice,
3102
- ...phrases(TRACES, "fix"),
3103
- ...phrases(Object.values(KNOWN_EXTENSIONS), "advice"),
3104
- EXT_ADVICE,
3105
- LOOKUP_NO_FIX,
3106
- LOOKUP_UNKNOWN,
3107
- ]),
3108
- worst: new Set(phrases(Object.values(AGENT_ADVISORIES).flat(), "title")),
3109
- };
3110
- const LOOKUP_ADVICE = /^Update to (\S{1,80}) or later(.*)$/s;
3111
- const PRIVATE_OWN = {
3112
- what: (v) => OWN_WORDS.what.has(v),
3113
- source: (v) => OWN_WORDS.source.has(v),
3114
- campaign: (v) => OWN_WORDS.campaign.has(v),
3115
- worst: (v) => OWN_WORDS.worst.has(v),
3116
- advice: (v) => {
3117
- const m = LOOKUP_ADVICE.exec(v);
3118
- return OWN_WORDS.advice.has(v) || Boolean(m && VERSION_RE.test(m[1]) && (m[2] === "" || m[2] === LOOKUP_SOME_FIXED));
3119
- },
3120
- update: (v) => UPDATE_COMMANDS.has(v),
3121
- lookup: (v, values) => /^@?[A-Za-z0-9._/-]{1,214}$/.test(values.pkg ?? "") && (v === `npm view ${values.pkg} version` || v === `pip index versions ${values.pkg}`),
3122
- tool: (v) => KNOWN_TOOLS.has(v),
3123
- version: (v) => VERSION_RE.test(v),
3124
- fixed: (v) => VERSION_RE.test(v),
3125
- // Names that are package names or extension IDs in a real report.
3126
- name: (v) => PACKAGE_NAME.test(v),
3127
- known: (v) => KNOWN_NAMES.has(v),
3128
- ext: (v) => EXT_ID.test(v),
3129
- editor: (v) => EDITORS.has(v),
3130
- official: (v) => PUBLIC_VARS.official(v) || Object.values(AGENT_EXTENSIONS).includes(v),
3131
- officialId: (v) => Object.hasOwn(AGENT_EXTENSIONS, v),
3132
- origin: (v) => PUBLIC_VARS.origin(v),
3133
- fixes: (v) => /^(?:a security fix|[1-9]\d{0,2} security fixes)$/.test(v),
3134
- vulns: (v) => /^(?:a published vulnerability|[1-9]\d{0,2} published vulnerabilities)$/.test(v),
3135
- marketplaces: (v) => /^(?:a marketplace|[1-9]\d{0,2} marketplaces)$/.test(v),
3136
- lead: (v) => v === "The issue" || v === "The most serious",
3137
- every: (v) => v === "the fix" || v === "every fix",
3138
- fromFiles: (v) => /^(?:an extension installed from a file|[1-9]\d{0,3} extensions installed from files)$/.test(v),
3139
- summary: (v) => SAFE_SUMMARY.test(v),
3140
- status: (v) => PUBLIC_VARS.status(v),
3141
- versions: (v) => PUBLIC_VARS.versions(v),
3142
- were: (v) => PUBLIC_VARS.were(v),
3143
- one: (v) => PUBLIC_VARS.one(v),
3144
- programs: (v) => PUBLIC_VARS.programs(v),
3145
- them: (v) => PUBLIC_VARS.them(v),
3146
- };
3147
- // The rules whose `ref` and `where` come from a lookup or an advisory, not
3148
- // from the user's files.
3149
- const LOOKUP_IDS = new Set(["LOOKUP-MALICIOUS", "LOOKUP-VULN", "LOOKUP-VULN-MINOR", "LOOKUP-VULN-LOW"]);
3150
- const LOOKUP_WHERE = new RegExp(
3151
- `^(?:Used by MCP server “[^\\n]{1,300}” in [^\\n]{1,300}|Installed as an? (?:${[...EDITORS].join("|")}) extension|This is your (?:${[...new Set(Object.values(AGENT_PACKAGES).map((m) => m.tool))].join("|")}) install)$`,
3152
- );
3153
- const PACKAGE_NAME = /^@?[A-Za-z0-9._~-]{1,214}(?:\/[A-Za-z0-9._~-]{1,214})?$/;
3154
-
3155
- // A path in a private report: cleaned, its control characters made
3156
- // visible, and no longer than a real path needs to be shown.
3157
- const privatePath = (p) => {
3158
- const clean = typeof p === "string" ? cleanPath(p) : null;
3159
- return clean && clean.length <= 1000 ? visibleName(clean) : null;
3160
- };
3161
-
3162
- function privateFinding(f) {
3163
- if (!isObj(f) || typeof f.id !== "string" || !Object.hasOwn(RULES, f.id)) return null;
3164
- const rule = RULES[f.id];
3165
- const file = privatePath(f.file);
3166
- const given = isObj(f.vars) ? f.vars : {};
3167
- const values = { file: file ?? "" };
3168
- for (const k of templateVars.get(f.id)) {
3169
- if (k !== "file" && Object.hasOwn(given, k)) values[k] = plainText(given[k], PRIVATE_LIMITS.value);
3170
- }
3171
- for (const [k, own] of Object.entries(PRIVATE_OWN)) {
3172
- if (Object.hasOwn(values, k) && values[k] !== "" && !own(values[k], values)) return null;
3173
- }
3174
- // Values a share link checks against fixed lists are checked the same way,
3175
- // since they're the same in a private report. Package names are checked
3176
- // as names, whether or not the command to look one up came with them.
3177
- for (const [k, v] of Object.entries(values)) {
3178
- if (k === "file" || v === "" || PRIVATE_VARS.has(k) || Object.hasOwn(PRIVATE_OWN, k) || !PUBLIC_VARS[k]) continue;
3179
- // A lookup's "where" is checked below; it's never in a share.
3180
- if (k === "where" && !WHERE[f.id]) continue;
3181
- if (!PUBLIC_VARS[k](k === "where" ? hideNames(v) : v, f.id)) return null;
3182
- }
3183
- if (values.pkg && !/^@?[A-Za-z0-9._/-]{1,214}$/.test(values.pkg)) return null;
3184
- if (LOOKUP_IDS.has(f.id)) {
3185
- const where = values.where ?? "";
3186
- if (!LOOKUP_REF.test(values.ref ?? "") || !LOOKUP_WHERE.test(where)) return null;
3187
- if (where.startsWith("Used by MCP server “") && (!file || !where.endsWith(`” in ${file}`) || where.slice(0, -` in ${file}`.length).includes("” in "))) return null;
3188
- }
3189
- if (!knownFactsAgree(f.id, values, file)) return null;
3190
- const tool = typeof f.tool === "string" && KNOWN_TOOLS.has(f.tool) ? f.tool : (rule.tool ?? (file ? controlFor(file)?.tools[0] : null) ?? null);
3191
- return {
3192
- id: f.id,
3193
- severity: rule.severity,
3194
- category: rule.category,
3195
- tool,
3196
- title: fillTemplate(rule.title, values),
3197
- why: fillTemplate(rule.why, values),
3198
- fix: fillTemplate(rule.fix, values),
3199
- file,
3200
- line: Number.isInteger(f.line) && f.line > 0 && f.line < 1e7 ? f.line : null,
3201
- evidence: plainText(f.evidence, PRIVATE_LIMITS.evidence) || null,
3202
- };
3203
- }
3204
-
3205
- function privateFile(f, budget) {
3206
- if (!isObj(f) || typeof f.path !== "string") return null;
3207
- const path = privatePath(f.path);
3208
- if (!path) return null;
3209
- const control = controlFor(path);
3210
- const tools = control?.tools ?? arr(f.tools).filter((t) => KNOWN_TOOLS.has(t) || t === LOOSE_TOOL).slice(0, 20);
3211
- const lines = arr(f.details);
3212
- const kept = lines.slice(0, Math.max(0, Math.min(lines.length, budget.left)));
3213
- budget.left -= kept.length;
3214
- const kind = control?.kind ?? (KNOWN_KINDS.has(f.kind) ? f.kind : "Agent file");
3215
- return {
3216
- path,
3217
- kind,
3218
- tools,
3219
- // Plugin code is listed by name and never read.
3220
- ...(f.listed === true && kind === "Plugin code" ? { listed: true } : {}),
3221
- scope: Object.hasOwn(SCOPES, f.scope) ? f.scope : scopeOf({ path, loose: tools.length === 1 && tools[0] === LOOSE_TOOL }),
3222
- summary: plainText(f.summary, PRIVATE_LIMITS.text),
3223
- details: kept.map((d) => d.slice(0, PRIVATE_LIMITS.line)),
3224
- // Lines left out to keep the page a size a browser can draw.
3225
- moreDetails: lines.length - kept.length,
3226
- };
3227
- }
3228
-
3229
- // A private report as the page draws it, or null when the decrypted data
3230
- // isn't one.
3231
- export function privateReportFrom(data) {
3232
- if (!isObj(data) || data.v !== 1 || !isObj(data.result)) return null;
3233
- const r = data.result;
3234
- const givenFindings = Array.isArray(r.findings) ? r.findings : [];
3235
- const givenFiles = Array.isArray(r.controlMap) ? r.controlMap : [];
3236
- const findings = givenFindings.slice(0, PRIVATE_LIMITS.findings).map(privateFinding).filter(Boolean).sort(bySeverity);
3237
- const budget = { left: PRIVATE_LIMITS.lines };
3238
- const seen = new Set();
3239
- const controlMap = givenFiles
3240
- .slice(0, PRIVATE_LIMITS.files)
3241
- .map((f) => privateFile(f, budget))
3242
- .filter((f) => f && !seen.has(f.path) && seen.add(f.path))
3243
- .map((f) => ({ ...f, findings: findings.filter((x) => x.file === f.path).length }));
3244
- const { counts, score, grade } = scoreFindings(findings, controlMap.length > 0);
3245
- const scanned = isObj(data.scanned) ? data.scanned : {};
3246
- const stats = isObj(r.stats) ? r.stats : {};
3247
- return {
3248
- createdAt: Number.isFinite(data.createdAt) && data.createdAt > 0 ? data.createdAt : null,
3249
- version: typeof data.version === "string" && /^\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(data.version) ? data.version : "",
3250
- scanned: {
3251
- // The folder the check ran in, as the command writes it: ~/..., /...
3252
- // or a drive letter. Anything else isn't shown.
3253
- project: /^(?:~\/|\/|[A-Za-z]:\/)/.test(plainText(scanned.project, 300)) ? fileValue(plainText(scanned.project, 300), "folder") : "",
3254
- projectSkipped: scanned.projectSkipped === true,
3255
- user: scanned.user === true,
3256
- },
3257
- // What was left out, so the page can say so rather than drop it quietly.
3258
- dropped: { findings: givenFindings.length - findings.length, files: givenFiles.length - controlMap.length },
3259
- result: {
3260
- score,
3261
- grade,
3262
- headline: headlineFor(counts, findings[0], controlMap.length > 0),
3263
- counts,
3264
- tools: agentsIn(controlMap),
3265
- stats: {
3266
- filesChecked: Math.min(toInt(stats.filesChecked), 100_000),
3267
- mcpServers: Math.min(toInt(stats.mcpServers), 10_000),
3268
- agentInstalls: Math.min(toInt(stats.agentInstalls), 200),
3269
- extensions: Math.min(toInt(stats.extensions), 30_000),
3270
- },
3271
- findings,
3272
- controlMap,
3273
- installed: privateInstalled(r.installed),
3274
- },
3275
- };
3276
- }
3277
-
3278
- // What's installed, rebuilt from the fixed lists: agents and editors
3279
- // misconfig knows, extension IDs from its list of agent extensions,
3280
- // versions that look like versions and cleaned paths. Anything else is
3281
- // left out.
3282
- const AGENT_TOOLS = new Set(Object.values(AGENT_PACKAGES).map((m) => m.tool));
3283
- function privateInstalled(given) {
3284
- const g = isObj(given) ? given : {};
3285
- const list = (x, max) => (Array.isArray(x) ? x.slice(0, max).filter(isObj) : []);
3286
- const agents = list(g.agents, 50)
3287
- .filter((a) => AGENT_TOOLS.has(a.tool) && cleanVersion(a.version) && INSTALL_VIA.has(a.via) && privatePath(a.path))
3288
- .map((a) => ({ tool: a.tool, version: cleanVersion(a.version), via: a.via, path: privatePath(a.path) }));
3289
- const editors = list(g.editors, 12)
3290
- .filter((e) => EDITORS.has(e.editor) && privatePath(e.dir))
3291
- .map((e) => ({
3292
- editor: e.editor,
3293
- dir: privatePath(e.dir),
3294
- count: Math.min(toInt(e.count), 3000),
3295
- agents: list(e.agents, 30)
3296
- .filter((x) => typeof x.id === "string" && Object.hasOwn(AGENT_EXTENSIONS, x.id))
3297
- .map((x) => ({ name: AGENT_EXTENSIONS[x.id], id: x.id, version: cleanVersion(x.version) })),
3298
- }));
3299
- return { agents, editors };
2793
+ // Adds the malware misconfig.ai lists since this release (addKnownMalware in
2794
+ // known.js). Call it before a check; calling it again with a newer list
2795
+ // replaces what the last one added. Returns when the list was made and how
2796
+ // many entries it holds, or null when it isn't a list.
2797
+ export function useKnownMalware(feed) {
2798
+ const added = addKnownMalware(feed);
2799
+ return added ? { updated: added.updated, packages: added.packages.length, extensions: added.extensions.length } : null;
3300
2800
  }