@misconfig/cli 1.3.0 → 1.3.2

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/known.js CHANGED
@@ -9,10 +9,177 @@
9
9
  // release, keep the old wording in the entry's `was` (for example
10
10
  // was: { what: ["..."] }), so reports made by earlier versions still open.
11
11
 
12
+ // The day the OSV.dev listings below were taken. misconfig.ai publishes the
13
+ // ones listed since (see addKnownMalware).
14
+ export const KNOWN_AS_OF = "2026-11-02";
15
+
16
+ // MCP packages OSV.dev lists as malware (IDs starting MAL-), as of
17
+ // KNOWN_AS_OF, with the versions each listing names, or "all". A package with a
18
+ // few versions listed is often a real one whose publishing account was taken
19
+ // over, so only those versions count against it.
20
+ const OSV_MALWARE = [
21
+ ["npm", "@ifasn/md-doc-mcp", "MAL-2026-18486", "1.0.3 1.0.4 1.0.5"],
22
+ ["npm", "@ifasn/mmd-doc-mcp", "MAL-2026-18488", "1.0.0 1.0.2"],
23
+ ["npm", "@ifasn/mmdd-doc-mcp", "MAL-2026-18489", "1.0.1 1.0.3 1.0.4 1.0.4-2 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9-2 2.0.1 2.0.4"],
24
+ ["npm", "@ifasn/mdd-doc-mcp", "MAL-2026-18487", "1.0.7 1.0.8 2.0.6"],
25
+ ["npm", "mcp-consultasdeveiculos-client", "MAL-2026-15869", "0.0.2 0.1.0 0.1.1"],
26
+ ["npm", "feishu-docx-mcp", "MAL-2026-16032", "all"],
27
+ ["npm", "@yongot/canary-mcp-isolation", "MAL-2026-16061", "1.0.0 1.0.1 1.0.2"],
28
+ ["npm", "@yongot/canary-mcp-test", "MAL-2026-16062", "1.0.0 2.0.0 3.0.0 4.0.0"],
29
+ ["npm", "mcp-real-chrome", "MAL-2026-14414", "all"],
30
+ ["npm", "homekit-mcp", "MAL-2026-14297", "1.0.0"],
31
+ ["npm", "code-assist-mcp", "MAL-2026-14233", "1.0.0"],
32
+ ["npm", "@httttt/mcp-demo", "MAL-2026-14315", "all"],
33
+ ["npm", "chrome-enterprise-premium-mcp", "MAL-2026-14230", "1.0.0"],
34
+ ["npm", "mcp-dev-toolkit", "MAL-2026-14295", "1.5.0"],
35
+ ["npm", "broadcast-graphics-mcp", "MAL-2026-14228", "1.0.0"],
36
+ ["npm", "fa-mcp-sdk", "MAL-2026-12789", "0.12.72"],
37
+ ["npm", "devplatform-react-mcp", "MAL-2026-13502", "35.5.6"],
38
+ ["npm", "agenthub-multiagent-mcp", "MAL-2026-13399", "1.57.0"],
39
+ ["npm", "xrblocks-mcp", "MAL-2026-13988", "6.3.1"],
40
+ ["npm", "mcp-util-helpers", "MAL-2026-13880", "1.0.0"],
41
+ ["npm", "@kolbo/mcp", "MAL-2026-13938", "1.57.1"],
42
+ ["npm", "mcp-audit-sync-internal", "MAL-2026-12401", "99.9.9"],
43
+ ["npm", "@or-sdk/mcp-tools", "MAL-2026-11713", "0.5.2 0.5.3 0.5.4"],
44
+ ["npm", "@servicetitan/anvil2-mcp", "MAL-2026-11829", "0.0.9 0.0.10 0.0.11 0.0.12 0.0.13 0.0.14 0.0.15"],
45
+ ["npm", "hit-mcp", "MAL-2026-11466", "1.0.0"],
46
+ ["npm", "@copilot-mcp/apex", "MAL-2026-12314", "1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.16 1.0.17 1.0.21 1.0.22"],
47
+ ["npm", "code-analyzer-mcp", "MAL-2026-12354", "1.0.0"],
48
+ ["npm", "iwomm-mcp", "MAL-2026-11469", "1.0.0"],
49
+ ["npm", "sap-mcp-facilitator", "MAL-2026-11482", "1.0.0"],
50
+ ["npm", "mcp-server-boilerplate", "MAL-2026-11472", "1.0.0"],
51
+ ["npm", "gtm-mcp-auth", "MAL-2026-11464", "1.0.0"],
52
+ ["npm", "refbase-mcp", "MAL-2026-11477", "1.0.0"],
53
+ ["npm", "chaos-mcp", "MAL-2026-11458", "1.0.0"],
54
+ ["npm", "maximumsats-mcp", "MAL-2026-11471", "1.0.0"],
55
+ ["npm", "kip-mcp-http", "MAL-2026-11470", "1.0.0"],
56
+ ["npm", "pm-claude-skills-mcp", "MAL-2026-11475", "1.0.0"],
57
+ ["npm", "smart-npv-mcp", "MAL-2026-11486", "1.0.0"],
58
+ ["npm", "routerbase-mcp", "MAL-2026-11480", "1.0.0"],
59
+ ["npm", "sap-mcp-config", "MAL-2026-11481", "1.0.0"],
60
+ ["npm", "@vite-mcp/vite-type", "MAL-2026-10525", "all"],
61
+ ["npm", "proxy-seller-mcp", "MAL-2026-10541", "0.1.7"],
62
+ ["npm", "sensorium-mcp", "MAL-2026-10747", "3.0.95"],
63
+ ["npm", "mcp-notes-server-poc-praetorian", "MAL-2026-10210", "all"],
64
+ ["npm", "sidecar-mcp", "MAL-2026-10161", "all"],
65
+ ["npm", "polymarket-mcp-v2", "MAL-2026-10481", "all"],
66
+ ["npm", "mcp-ci-runner-poc", "MAL-2026-7318", "1.0.0"],
67
+ ["npm", "cue-mcp", "MAL-2026-6294", "9999.99.99"],
68
+ ["npm", "zomato-mcp", "MAL-2026-6270", "1.0.0"],
69
+ ["npm", "@mastra/mcp-docs-server", "MAL-2026-5956", "1.1.47"],
70
+ ["npm", "@mastra/mcp-registry-registry", "MAL-2026-6027", "1.0.2"],
71
+ ["npm", "@mastra/mcp", "MAL-2026-5955", "1.10.1"],
72
+ ["npm", "mcp-server-pg", "MAL-2026-6922", "all"],
73
+ ["npm", "sp-api-dev-assistant-mcp-server", "MAL-2026-5853", "all"],
74
+ ["npm", "claude-token-tracker-mcp", "MAL-2026-10693", "all"],
75
+ ["npm", "mcp-server-git", "MAL-2026-5478", "all"],
76
+ ["npm", "mcp-server-fetch", "MAL-2026-5476", "all"],
77
+ ["npm", "mcp-server-postgres", "MAL-2026-5481", "all"],
78
+ ["npm", "mcp-server-redis", "MAL-2026-5482", "all"],
79
+ ["npm", "mcp-server-sequential-thinking", "MAL-2026-5484", "all"],
80
+ ["npm", "mcp-server-figma", "MAL-2026-5477", "all"],
81
+ ["npm", "mcp-server-notion", "MAL-2026-5480", "all"],
82
+ ["npm", "mcp-server-sentry", "MAL-2026-5483", "all"],
83
+ ["npm", "mcp-server-supabase", "MAL-2026-5485", "all"],
84
+ ["npm", "screenpipe-mcp-http", "MAL-2026-5402", "9999.99.99"],
85
+ ["npm", "create-docs-mcp", "MAL-2026-5397", "9999.99.99"],
86
+ ["npm", "t-invest-mcp-server", "MAL-2026-5403", "9999.99.99"],
87
+ ["npm", "autotel-mcp", "MAL-2026-5223", "0.1.14 2.0.1 3.0.1 4.0.1 5.0.1 6.0.1 7.0.1 8.0.1 9.0.1 10.0.1 11.0.1 13.0.1 14.0.1 15.0.2 16.0.1 17.0.2 18.0.1 19.0.1 20.0.1 21.1.1 22.0.1 23.0.1 24.0.1 25.0.1 26.0.2 27.0.1 28.0.3 29.0.1"],
88
+ ["npm", "autotel-mcp-instrumentation", "MAL-2026-5224", "29.0.2 30.0.5 31.0.1 32.0.1 33.0.2 34.0.1"],
89
+ ["npm", "executable-stories-mcp", "MAL-2026-5255", "0.3.3"],
90
+ ["npm", "brave-search-mcp-server", "MAL-2026-5182", "1.0.0"],
91
+ ["npm", "@redhat-cloud-services/hcc-feo-mcp", "MAL-2026-5129", "0.3.1 0.3.2 0.3.4"],
92
+ ["npm", "@redhat-cloud-services/hcc-kessel-mcp", "MAL-2026-5139", "0.3.1 0.3.2 0.3.4"],
93
+ ["npm", "@redhat-cloud-services/hcc-pf-mcp", "MAL-2026-5140", "0.6.1 0.6.2 0.6.4"],
94
+ ["npm", "@cloudplatform-single-spa/ml-ai-agents-mcp-server", "MAL-2026-4938", "all"],
95
+ ["npm", "explorhub-mcp-server", "MAL-2026-4312", "all"],
96
+ ["npm", "mcp-dashboards-shared", "MAL-2026-4296", "all"],
97
+ ["npm", "@djessicatony/folk-mcp-canary", "MAL-2026-4382", "0.0.1"],
98
+ ["npm", "bitrix24-tasks-mcp-server", "MAL-2026-4498", "1.1.0 1.2.0 1.4.0 1.5.0 1.5.1"],
99
+ ["npm", "bricks-builder-mcp", "MAL-2026-4500", "3.6.1 3.10.0 3.11.2 3.12.3"],
100
+ ["npm", "@antv/mcp-server-antv", "MAL-2026-4068", "0.2.8 0.3.8"],
101
+ ["npm", "@antv/mcp-server-chart", "MAL-2026-4069", "0.10.10 0.11.10"],
102
+ ["npm", "mcp-echarts", "MAL-2026-4146", "0.8.1 0.9.1"],
103
+ ["npm", "mcp-mermaid", "MAL-2026-4147", "0.5.1 0.6.1"],
104
+ ["npm", "nextmove-mcp", "MAL-2026-3589", "0.1.3 0.1.4 0.1.5 0.1.6 0.1.7"],
105
+ ["npm", "cmux-agent-mcp", "MAL-2026-3588", "0.1.3 0.1.4 0.1.5 0.1.6 0.1.7 0.1.8"],
106
+ ["npm", "@squawk/mcp", "MAL-2026-3448", "0.9.1 0.9.2 0.9.3 0.9.4 0.9.5"],
107
+ ["npm", "pi-exa-mcp", "MAL-2026-3280", "all"],
108
+ ["npm", "claudcode-mcp", "MAL-2026-2974", "all"],
109
+ ["npm", "mcp-server-todo", "MAL-2026-2328", "all"],
110
+ ["npm", "@iflow-mcp/watercrawl-watercrawl-mcp", "MAL-2026-1930", "1.3.0 1.3.1 1.3.2 1.3.3 1.3.4"],
111
+ ["npm", "@upstashed/context7-mcp", "MAL-2026-1642", "1.0.2"],
112
+ ["npm", "excluder-mcp", "MAL-2025-192746", "all"],
113
+ ["npm", "excluder-mcp-package", "MAL-2025-192747", "all"],
114
+ ["npm", "vscode-azure-mcp-server", "MAL-2025-192601", "all"],
115
+ ["npm", "solana-dev-mcp", "MAL-2025-191527", "all"],
116
+ ["npm", "mcp-polymarket", "MAL-2025-191465", "all"],
117
+ ["npm", "@browserbasehq/mcp-server-browserbase", "MAL-2025-191196", "2.4.2"],
118
+ ["npm", "@browserbasehq/mcp", "MAL-2025-191195", "all"],
119
+ ["npm", "@seezo/sdr-mcp-server", "MAL-2025-191053", "0.0.5"],
120
+ ["npm", "@relyt/mcp-server-relytone", "MAL-2025-191052", "all"],
121
+ ["npm", "@relyt/claude-context-mcp", "MAL-2025-191051", "all"],
122
+ ["npm", "ids-enterprise-mcp-server", "MAL-2025-191107", "0.0.2"],
123
+ ["npm", "web-scraper-mcp", "MAL-2025-190943", "1.1.4"],
124
+ ["npm", "@mcp-use/cli", "MAL-2025-190867", "2.2.6 2.2.7"],
125
+ ["npm", "@mcp-use/inspector", "MAL-2025-190868", "0.6.2 0.6.3"],
126
+ ["npm", "@mcp-use/mcp-use", "MAL-2025-190869", "1.0.1 1.0.2"],
127
+ ["npm", "@postman/mcp-ui-client", "MAL-2025-190902", "5.5.1 5.5.2 5.5.3"],
128
+ ["npm", "@postman/postman-mcp-cli", "MAL-2025-190908", "1.0.3 1.0.4 1.0.5"],
129
+ ["npm", "@postman/postman-mcp-server", "MAL-2025-190909", "2.4.10 2.4.11 2.4.12"],
130
+ ["npm", "@zapier/mcp-integration", "MAL-2025-190918", "3.0.1 3.0.2 3.0.3"],
131
+ ["npm", "create-mcp-use-app", "MAL-2025-190922", "0.5.3 0.5.4"],
132
+ ["npm", "mcp-use", "MAL-2025-190923", "1.4.2 1.4.3"],
133
+ ["npm", "lite-serper-mcp-server", "MAL-2025-190848", "all"],
134
+ ["npm", "rce-poc-test-honor-mcp", "MAL-2025-49383", "all"],
135
+ ["npm", "revenuecat-mcp-extension", "MAL-2025-49378", "all"],
136
+ ["npm", "demo-mercadopago-mcp-server", "MAL-2025-48558", "99.0.0 99.0.1 99.0.2 99.0.3 99.0.4 99.0.5"],
137
+ ["npm", "shiprocket-mcp", "MAL-2025-48761", "all"],
138
+ ["npm", "mcp-server-fixthis", "MAL-2025-47929", "all"],
139
+ ["npm", "mcp-knowledge-graph", "MAL-2025-47327", "1.2.1"],
140
+ ["npm", "mcp-knowledge-base", "MAL-2025-47326", "all"],
141
+ ["npm", "mcp-lumin", "MAL-2025-47076", "all"],
142
+ ["npm", "mcp-chat-client", "MAL-2025-47098", "all"],
143
+ ["npm", "mcp-server-everything", "MAL-2025-46986", "all"],
144
+ ["npm", "wealthsimple-mcp-server", "MAL-2025-42116", "all"],
145
+ ["npm", "auth0-mcp-server", "MAL-2025-15093", "all"],
146
+ ["npm", "mcp-menu", "MAL-2025-26053", "all"],
147
+ ["npm", "mcp-opencage-server", "MAL-2025-26054", "all"],
148
+ ["npm", "@jaswanthlanka/mcp-proxy", "MAL-2025-6139", "all"],
149
+ ["npm", "glean-mcp-server", "MAL-2025-5813", "all"],
150
+ ["npm", "rush-mcp-example-plugin", "MAL-2025-5286", "all"],
151
+ ["npm", "yaml-mcp-wrapper", "MAL-2025-4635", "all"],
152
+ ["PyPI", "marketing-mcp", "MAL-2026-16250", "0.1.0"],
153
+ ["PyPI", "mcp-search-server", "MAL-2026-11198", "1.0.0 2.0.0 2.0.1"],
154
+ ["PyPI", "openai-mcp", "MAL-2026-5320", "2.41.1 2.41.2"],
155
+ ["PyPI", "tiktoken-mcp", "MAL-2026-5326", "0.13.1 0.13.2"],
156
+ ["PyPI", "instructor-mcp", "MAL-2026-5317", "1.15.2 1.15.3"],
157
+ ["PyPI", "langchain-core-mcp", "MAL-2026-5318", "1.4.2 1.4.3"],
158
+ ["PyPI", "ray-mcp-server", "MAL-2026-5325", "0.2.1"],
159
+ ["PyPI", "docontrol-mcp", "MAL-2026-4811", "999.0.0"],
160
+ ["PyPI", "vulndify-mcp-server", "MAL-2026-4774", "0.3.0"],
161
+ ["PyPI", "ant-mcp-proxy-for-test", "MAL-2026-2669", "0.10.0"],
162
+ ["PyPI", "latinum-wallet-mcp", "MAL-2026-2315", "0.0.32 0.0.33 0.0.34 0.0.35 0.0.36"],
163
+ ["PyPI", "mcp-transport-proto", "MAL-2026-1990", "9.9.9"],
164
+ ["PyPI", "mcp-pdftool-plus", "MAL-2026-603", "0.1.3 0.1.4 0.1.5"],
165
+ ["PyPI", "mcp-weather-full", "MAL-2025-191789", "0.8.0 0.8.1 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.8.8 0.8.9 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 1.0.0 1.0.1"],
166
+ ["PyPI", "mcp-runcmd-server", "MAL-2025-191788", "1.0 2.0"],
167
+ ["PyPI", "mcp-runcommand-server2", "MAL-2025-191648", "1.0.6"],
168
+ ["PyPI", "mcp-runcommand-server", "MAL-2025-191647", "1.0.5 1.0.7 1.0.8 1.0.9 1.0.10 1.0.11 1.0.12 1.0.13"],
169
+ ["PyPI", "groq-mcp", "MAL-2025-6007", "0.0.1 9.9.9"],
170
+ ["PyPI", "story-mcp-hub", "MAL-2025-3471", "9999.0.0"],
171
+ ["PyPI", "mcp-xyz", "MAL-2025-4223", "0.1.0"],
172
+ ];
173
+
12
174
  // Packages, by "ecosystem:name". `versions` is "all" when every version is
13
175
  // unsafe (including a copy that looks harmless), or the versions that were
14
176
  // malware.
177
+ const listedPackage = (ref, versions, kind) =>
178
+ versions === "all"
179
+ ? { versions: "all", what: `${kind} listed as malware`, source: `OSV ${ref}` }
180
+ : { versions: versions.split(" "), what: `${kind} with versions listed as malware`, source: `OSV ${ref}` };
15
181
  export const KNOWN_PACKAGES = {
182
+ ...Object.fromEntries(OSV_MALWARE.map(([ecosystem, name, ref, versions]) => [`${ecosystem}:${name}`, listedPackage(ref, versions, versions === "all" ? "an MCP server" : "an MCP package")])),
16
183
  "npm:postmark-mcp": {
17
184
  versions: "all",
18
185
  what: "a copy of Postmark's MCP server published by someone else. From version 1.0.16 it secretly copied every email it sent to the publisher",
@@ -67,7 +234,43 @@ const GLASSWORM = {
67
234
  what: "one of the extensions in the GlassWorm campaign, which installs remote-access malware",
68
235
  source: "The Hacker News, December 2025",
69
236
  };
237
+ // Editors that install from Open VSX, and those that use Microsoft's
238
+ // marketplace. The same extension ID can belong to different publishers on
239
+ // each, so a listing for one doesn't apply to the other.
240
+ export const OPEN_VSX_EDITORS = ["VSCodium", "Cursor", "Windsurf", "Kiro"];
241
+ const MICROSOFT_EDITORS = ["VS Code", "VS Code Insiders"];
242
+ // Extensions OSV.dev lists as malware, as of November 2, 2026: ID, the
243
+ // marketplace it names, the listing, and the versions it names or "all".
244
+ const OSV_EXTENSIONS = [
245
+ ["azurecdninfo.edrtester", "microsoft", "MAL-2026-16010", "1.0.4"],
246
+ ["nrwl.angular-console", "both", "MAL-2026-5161", "18.95.0"],
247
+ ["checkmarx.ast-results", "open-vsx", "MAL-2026-2231", "2.35.0 2.36.0 2.37.0 2.38.0 2.39.0 2.40.0 2.42.0 2.43.0 2.44.0 2.45.0 2.46.0 2.47.0 2.48.0 2.49.0 2.49.1772191521 2.49.1772192163 2.50.0 2.51.0 2.52.0 2.53.0 2.56.0"],
248
+ ["checkmarx.cx-dev-assist", "open-vsx", "MAL-2026-2232", "1.1.0 1.2.0 1.3.0 1.3.1772191535 1.3.1772192178 1.4.0 1.5.0 1.6.0 1.7.0 1.10.0"],
249
+ ["aquasecurityofficial.trivy-vulnerability-scanner", "open-vsx", "MAL-2026-2230", "1.8.12 1.8.13"],
250
+ ["effetmer.darkgpt", "microsoft", "MAL-2025-192568", "all"],
251
+ ["cline-ai-main.cline-ai-agent", "microsoft", "MAL-2025-191157", "all"],
252
+ ["codeinklingon.git-worktree-menu", "open-vsx", "MAL-2025-191158", "all"],
253
+ ["codejoy.codejoy-vscode-extension", "open-vsx", "MAL-2025-191159", "all"],
254
+ ["ellacrity.recoil", "open-vsx", "MAL-2025-191160", "all"],
255
+ ["ginfuru.better-nunjucks", "open-vsx", "MAL-2025-191161", "all"],
256
+ ["grrrck.positron-plus-1-e", "open-vsx", "MAL-2025-191162", "all"],
257
+ ["jeronimoekerdt.color-picker-universal", "open-vsx", "MAL-2025-191163", "all"],
258
+ ["jscearcy.rust-doc-viewer", "open-vsx", "MAL-2025-191164", "all"],
259
+ ["kleinesfilmroellchen.serenity-dsl-syntaxhighlight", "open-vsx", "MAL-2025-191165", "all"],
260
+ ["l-igh-t.vscode-theme-seti-folder", "open-vsx", "MAL-2025-191166", "all"],
261
+ ["sirilmp.dark-theme-sm", "open-vsx", "MAL-2025-191167", "all"],
262
+ ["sissel.shopify-liquid", "open-vsx", "MAL-2025-191168", "all"],
263
+ ["srcery-colors.srcery-colors", "open-vsx", "MAL-2025-191169", "all"],
264
+ ["tretinv3.forts-api-extention", "open-vsx", "MAL-2025-191170", "all"],
265
+ ];
266
+ const listedExtension = (marketplace, ref, versions) => ({
267
+ versions: versions === "all" ? "all" : versions.split(" "),
268
+ ...(marketplace === "both" ? {} : { editors: marketplace === "open-vsx" ? OPEN_VSX_EDITORS : MICROSOFT_EDITORS }),
269
+ what: versions === "all" ? "an extension listed as malware" : "a release listed as malware",
270
+ source: `OSV ${ref}`,
271
+ });
70
272
  export const KNOWN_EXTENSIONS = {
273
+ ...Object.fromEntries(OSV_EXTENSIONS.map(([id, marketplace, ref, versions]) => [id, listedExtension(marketplace, ref, versions)])),
71
274
  "anthropic.claude-code": {
72
275
  versions: ["2.1.312", "2.1.313"],
73
276
  editors: ["Cursor"],
@@ -102,6 +305,65 @@ export const KNOWN_EXTENSIONS = {
102
305
  ),
103
306
  };
104
307
 
308
+ // Malware OSV.dev has listed since KNOWN_AS_OF, as misconfig.ai publishes it
309
+ // at /api/known: {v: 1, updated, packages: [["npm:name", ref, versions]],
310
+ // extensions: [[id, marketplace, ref, versions]]}, where versions is "all" or
311
+ // the versions listed, separated by spaces, and an extension listed on both
312
+ // marketplaces comes once for each. It comes over the network, so every value
313
+ // must match the shape the lists above use, and anything else is dropped.
314
+ // Entries in the lists above are never changed. What an earlier list added is
315
+ // replaced, so a listing that's changed or withdrawn is changed or gone here
316
+ // too. Returns the keys it holds and when the list was made, or null if it
317
+ // isn't a list.
318
+ const LISTED_REF = /^MAL-\d{4}-\d{1,7}$/;
319
+ const LISTED_NAME = {
320
+ npm: /^(?:@[a-z0-9~][a-z0-9._~-]{0,100}\/)?[a-z0-9~][a-z0-9._~-]{0,213}$/,
321
+ PyPI: /^[a-z0-9](?:[a-z0-9-]{0,98}[a-z0-9])?$/,
322
+ };
323
+ const LISTED_EXTENSION = /^[a-z0-9][a-z0-9-]{0,99}\.[a-z0-9][a-z0-9._-]{0,99}$/;
324
+ export const MAX_LISTED_VERSIONS = 2000;
325
+ const listedVersions = (v) => typeof v === "string" && (v === "all" || (v.length <= 40_000 && v.split(" ").length <= MAX_LISTED_VERSIONS && v.split(" ").every((x) => VERSION_RE.test(x))));
326
+ const FROM_LIST = { packages: new Set(), extensions: new Set() };
327
+ export function addKnownMalware(feed) {
328
+ const isObj = (x) => x !== null && typeof x === "object" && !Array.isArray(x);
329
+ if (!isObj(feed) || feed.v !== 1 || typeof feed.updated !== "string" || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/.test(feed.updated) || Number.isNaN(Date.parse(feed.updated))) return null;
330
+ const ours = (list, key) => !Object.hasOwn(list === "packages" ? KNOWN_PACKAGES : KNOWN_EXTENSIONS, key) || FROM_LIST[list].has(key);
331
+ const packages = new Map();
332
+ for (const p of Array.isArray(feed.packages) ? feed.packages.slice(0, 20_000) : []) {
333
+ if (!Array.isArray(p) || p.length !== 3) continue;
334
+ const [key, ref, versions] = p;
335
+ const m = typeof key === "string" ? /^(npm|PyPI):(.+)$/.exec(key) : null;
336
+ if (!m || !LISTED_NAME[m[1]].test(m[2]) || typeof ref !== "string" || !LISTED_REF.test(ref) || !listedVersions(versions) || !ours("packages", key) || packages.has(key)) continue;
337
+ packages.set(key, listedPackage(ref, versions, "a package"));
338
+ }
339
+ const extensions = new Map();
340
+ for (const x of Array.isArray(feed.extensions) ? feed.extensions.slice(0, 5000) : []) {
341
+ if (!Array.isArray(x) || x.length !== 4) continue;
342
+ const [id, marketplace, ref, versions] = x;
343
+ if (typeof id !== "string" || !LISTED_EXTENSION.test(id) || !["microsoft", "open-vsx", "both"].includes(marketplace) || typeof ref !== "string" || !LISTED_REF.test(ref) || !listedVersions(versions) || !ours("extensions", id)) continue;
344
+ const entry = listedExtension(marketplace, ref, versions);
345
+ const had = extensions.get(id);
346
+ // A listing for each marketplace: the second is kept beside the first,
347
+ // for the editors that install from there.
348
+ if (!had) extensions.set(id, entry);
349
+ else if (!had.alt && had.editors && entry.editors && had.editors !== entry.editors) had.alt = entry;
350
+ }
351
+ for (const [list, now, into] of [["packages", packages, KNOWN_PACKAGES], ["extensions", extensions, KNOWN_EXTENSIONS]]) {
352
+ for (const key of FROM_LIST[list]) if (!now.has(key)) delete into[key];
353
+ for (const [key, entry] of now) into[key] = entry;
354
+ FROM_LIST[list] = new Set(now.keys());
355
+ }
356
+ return { updated: feed.updated, packages: [...packages.keys()], extensions: [...extensions.keys()] };
357
+ }
358
+
359
+ // The listing of an extension that applies to an editor: listings for one
360
+ // marketplace apply only to the editors that install from it.
361
+ export function extensionListing(id, editor) {
362
+ const entry = Object.hasOwn(KNOWN_EXTENSIONS, id) ? KNOWN_EXTENSIONS[id] : null;
363
+ for (const e of entry ? [entry, entry.alt] : []) if (e && (!e.editors || e.editors.includes(editor))) return e;
364
+ return null;
365
+ }
366
+
105
367
  // The official extensions of AI coding agents. Another publisher's extension
106
368
  // with the same name, or a near copy of the name and publisher, is flagged.
107
369
  export const AGENT_EXTENSIONS = {
@@ -321,4 +583,5 @@ export function compareVersions(a, b) {
321
583
  return 0;
322
584
  }
323
585
 
324
- export const VERSION_RE = /^v?\d{1,6}(?:\.\d{1,6}){1,3}(?:[-+][0-9A-Za-z.-]{1,40})?$/;
586
+ // Up to ten digits a part, for builds numbered by date, such as 2.49.1772191521.
587
+ export const VERSION_RE = /^v?\d{1,10}(?:\.\d{1,10}){1,3}(?:[-+][0-9A-Za-z.-]{1,40})?$/;
@@ -6,8 +6,6 @@
6
6
  // ~/.config on Linux. A path ending in "/" is a folder of agent files, and
7
7
  // "*" stands for any one folder or file name.
8
8
 
9
- export const OSES = { mac: "macOS", windows: "Windows", linux: "Linux" };
10
-
11
9
  export const LOCATIONS = [
12
10
  {
13
11
  agent: "Claude Code",
package/engine/named.js CHANGED
@@ -2,8 +2,7 @@
2
2
  // names: Gemini CLI's context file names, Codex's fallback names for
3
3
  // AGENTS.md, OpenCode's instructions list and Aider's read list. A project
4
4
  // can use them to keep its instructions in a file the usual names don't
5
- // cover, so the browser check, the command and the checks all read them as
6
- // instructions. Shared by all three.
5
+ // cover, so the command and the checks both read them as instructions.
7
6
 
8
7
  import { parseJSONC, parseTOML, parseYAML } from "./parse.js";
9
8
  import { globMatch } from "./glob.js";
package/engine/paths.js CHANGED
@@ -1,5 +1,5 @@
1
- // Which files steer AI agents. Shared by the browser walker, the command
2
- // line tool and the rule engine, so all three agree on what gets read.
1
+ // Which files steer AI agents. Shared by the command, which finds and reads
2
+ // them, and the rule engine, so both agree on what gets read.
3
3
 
4
4
  export const SKIP_DIRS = new Set([
5
5
  "node_modules", ".git", ".hg", ".svn", "dist", "build", "out", ".next", ".nuxt", ".svelte-kit",
@@ -76,10 +76,9 @@ export const SENSITIVE = [
76
76
 
77
77
  export const DOWNLOADS_LIKE = /^(downloads?|desktop|temp|tmp)$/i;
78
78
 
79
- // Dropping a tool folder itself (for example ~/.claude) keeps its name in
80
- // the paths, so ".claude/settings.json" is still recognized.
79
+ // The folders agents keep their settings in at the top of a project, such
80
+ // as .claude. A check reads these first.
81
81
  export const TOOL_ROOT = /^\.(claude|codex|gemini|cursor|grok|opencode|windsurf|roo|kiro|amazonq|continue|zed|junie|github|vscode)$/i;
82
- export const withToolRoot = (root, relPath) => (root && TOOL_ROOT.test(root) ? `${root}/${relPath}` : relPath);
83
82
 
84
83
  // A name at the top of a project that would read as a place on the computer,
85
84
  // such as a folder named "~" or "C:". The checks tell files on the computer
package/lib/discover.js CHANGED
@@ -16,7 +16,7 @@ import { TRACES, AGENT_PACKAGES, KNOWN_PACKAGES, VERSION_RE } from "../engine/kn
16
16
  export const PLATFORM = process.platform === "win32" ? "windows" : process.platform === "darwin" ? "mac" : "linux";
17
17
  const LOOSE_NAMES = /\.(md|mdc|txt)$/i;
18
18
 
19
- // `limits` is for tests; the command always uses the same limits as the browser check.
19
+ // `limits` is for tests; the command always uses LIMITS from the engine.
20
20
  export async function discover({ dir = process.cwd(), includeUser = true, home = homeDir(), env = process.env, limits = LIMITS } = {}) {
21
21
  const projectDir = path.resolve(dir);
22
22
  const info = await fs.stat(projectDir).catch(() => null);
@@ -43,7 +43,7 @@ export async function discover({ dir = process.cwd(), includeUser = true, home =
43
43
  masked += m.count;
44
44
  files.push({ path: enginePath, size, content: m.text, ...extra });
45
45
  };
46
- // `budget` limits what's read in all from the project, as in the browser check.
46
+ // `budget` limits what's read in all from the project.
47
47
  const addFile = async (abs, enginePath, kind, maxBytes = LIMITS.maxFileBytes, extra = {}, budget = null) => {
48
48
  const stat = await fs.stat(abs).catch(() => null);
49
49
  if (!stat?.isFile()) return;
@@ -172,9 +172,9 @@ export async function discover({ dir = process.cwd(), includeUser = true, home =
172
172
  }
173
173
  }
174
174
  candidates.push(...pickNamed(namedInstructions(naming), others, (o) => o.rel));
175
- // Read in order of importance, up to the same limits as the browser
176
- // check: agent files, then the .gitignore and package.json files some
177
- // checks use, then files listed by name, then loose text files.
175
+ // Read in order of importance, up to LIMITS: agent files, then the
176
+ // .gitignore and package.json files some checks use, then files listed
177
+ // by name, then loose text files.
178
178
  const helper = (p) => /(^|\/)(\.gitignore|package\.json)$/i.test(p);
179
179
  const order = (c) => (c.kind === "content" ? (helper(c.rel) ? 1 : 0) : c.kind === "sensitive" || c.kind === "listed" ? 2 : 3);
180
180
  candidates.sort((a, b) => order(a) - order(b) || a.rel.split("/").length - b.rel.split("/").length || (a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0));
@@ -331,18 +331,32 @@ async function packageVersion(file) {
331
331
  }
332
332
  }
333
333
 
334
+ // The npm packages known.js lists, including any added from today's list.
335
+ const npmKnown = () => Object.keys(KNOWN_PACKAGES).filter((k) => k.startsWith("npm:")).map((k) => k.slice(4));
336
+
337
+ // The package names in a node_modules folder, scoped ones included.
338
+ async function installedNames(dir) {
339
+ const names = new Set();
340
+ for (const entry of (await readdir(dir)).slice(0, 20_000)) {
341
+ if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
342
+ if (!entry.name.startsWith("@")) names.add(entry.name);
343
+ else for (const inner of (await readdir(path.join(dir, entry.name))).slice(0, 5000)) names.add(`${entry.name}/${inner.name}`);
344
+ }
345
+ return names;
346
+ }
347
+
334
348
  // Versions of packages that were malware, in the project's node_modules.
335
- const NPM_KNOWN = Object.keys(KNOWN_PACKAGES).filter((k) => k.startsWith("npm:")).map((k) => k.slice(4));
336
349
  async function projectPackages(projectDir) {
337
350
  const out = [];
338
- for (const name of NPM_KNOWN) {
351
+ const here = await installedNames(path.join(projectDir, "node_modules"));
352
+ for (const name of npmKnown().filter((n) => here.has(n))) {
339
353
  const found = await packageVersion(path.join(projectDir, "node_modules", ...name.split("/"), "package.json"));
340
354
  if (found?.name === name) out.push({ package: name, version: found.version, via: "project", path: `node_modules/${name}` });
341
355
  }
342
356
  // pnpm keeps every package, including ones other packages pulled in, in
343
357
  // node_modules/.pnpm, in folders named name@version (@scope+name@version).
344
358
  // The names say enough; nothing in them is read.
345
- const known = new Set(NPM_KNOWN);
359
+ const known = new Set(npmKnown());
346
360
  for (const entry of (await readdir(path.join(projectDir, "node_modules", ".pnpm"))).slice(0, 30_000)) {
347
361
  const m = entry.isDirectory() ? entry.name.match(/^((?:@[^+@/]+\+)?[^+@/]+)@([^_/]+)/) : null;
348
362
  const name = m ? m[1].replace("+", "/") : null;
@@ -363,14 +377,16 @@ async function projectPackages(projectDir) {
363
377
  const LOCKFILES = ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lock"];
364
378
  const MAX_LOCKFILE_BYTES = 64 * 1024 * 1024;
365
379
  const SEMVER = String.raw`\d{1,6}\.\d{1,6}\.\d{1,6}(?:-[0-9A-Za-z.-]{1,40})?`;
366
- const LOCKED_URL = new RegExp(String.raw`/((?:@[a-z0-9][a-z0-9._~-]{0,100}/)?[a-z0-9][a-z0-9._~-]{0,213})/-/[a-z0-9][a-z0-9._~-]{0,213}-(${SEMVER})\.tgz`, "g");
380
+ // Any package name; the ones that count are picked out after, so the patterns
381
+ // stay as fast with thousands of known names as with a few.
382
+ const NAME = String.raw`(?:@[a-z0-9][a-z0-9._~-]{0,100}/)?[a-z0-9][a-z0-9._~-]{0,213}`;
383
+ const LOCKED_URL = new RegExp(String.raw`/(${NAME})/-/[a-z0-9][a-z0-9._~-]{0,213}-(${SEMVER})\.tgz`, "g");
384
+ const LOCKED_KEY = new RegExp(String.raw`(?:^|["'/\s])(${NAME})@(?:npm:)?(${SEMVER})(?=["'\s:(_,]|$)`, "gm");
385
+ // npm's own entries, nested or not, and lockfile version 1's "nx": { "version" }.
386
+ const LOCKED_ENTRY = new RegExp(String.raw`"(?:node_modules/(?:[^"\n]{0,400}?/node_modules/)?)?(${NAME})":\s{0,20}\{[^{}]{0,2000}?"version":\s{0,20}"(${SEMVER})"`, "g");
387
+ const LOCKED_PNPM = new RegExp(String.raw`^\s{0,8}['"]?/(${NAME})/(${SEMVER})(?=[:_('"]|$)`, "gm");
367
388
  async function lockedPackages(projectDir) {
368
- const known = new Set(NPM_KNOWN);
369
- const names = NPM_KNOWN.map((n) => n.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")).join("|");
370
- const keyed = new RegExp(String.raw`(?:^|["'/\s])(${names})@(?:npm:)?(${SEMVER})(?=["'\s:(_,]|$)`, "gm");
371
- // npm's own entries, nested or not, and lockfile version 1's "nx": { "version" }.
372
- const entry = new RegExp(String.raw`"(?:node_modules/(?:[^"\n]{0,400}?/node_modules/)?)?(${names})":\s{0,20}\{[^{}]{0,2000}?"version":\s{0,20}"(${SEMVER})"`, "g");
373
- const pnpmOld = new RegExp(String.raw`^\s{0,8}['"]?/(${names})/(${SEMVER})(?=[:_('"]|$)`, "gm");
389
+ const known = new Set(npmKnown());
374
390
  const out = [];
375
391
  for (const file of LOCKFILES) {
376
392
  const abs = path.join(projectDir, file);
@@ -378,11 +394,11 @@ async function lockedPackages(projectDir) {
378
394
  if (!stat?.isFile() || stat.size > MAX_LOCKFILE_BYTES) continue;
379
395
  const text = await fs.readFile(abs, "utf8").catch(() => "");
380
396
  const seen = new Set();
381
- for (const re of [LOCKED_URL, keyed, entry, pnpmOld]) {
397
+ for (const re of [LOCKED_URL, LOCKED_KEY, LOCKED_ENTRY, LOCKED_PNPM]) {
382
398
  for (const m of text.matchAll(re)) {
383
399
  const key = `${m[1]}@${m[2]}`;
384
400
  // An npm alias ("node_modules/nx": { "name": "other" }) is some other package.
385
- if (re === entry && m[0].includes('"name":')) continue;
401
+ if (re === LOCKED_ENTRY && m[0].includes('"name":')) continue;
386
402
  if (!known.has(m[1]) || seen.has(key) || seen.size >= 200) continue;
387
403
  seen.add(key);
388
404
  out.push({ file, package: m[1], version: m[2] });
@@ -434,15 +450,19 @@ async function agentInstalls({ home, env, tilde }) {
434
450
  seen.add(key);
435
451
  out.push({ package: pkg, version, via, path: tilde(abs), platform: PLATFORM });
436
452
  };
437
- const npmPackages = [...Object.keys(AGENT_PACKAGES).filter((p) => p !== "Claude Desktop"), ...NPM_KNOWN];
453
+ const npmPackages = [...Object.keys(AGENT_PACKAGES).filter((p) => p !== "Claude Desktop"), ...npmKnown()];
438
454
  for (const dir of await globalPackageDirs({ home, env })) {
439
- for (const name of npmPackages) {
455
+ // Only the names installed there are looked at, so a long list of known
456
+ // packages costs one folder listing, not a look for each name.
457
+ const here = await installedNames(dir);
458
+ for (const name of npmPackages.filter((n) => here.has(n))) {
440
459
  const found = await packageVersion(path.join(dir, ...name.split("/"), "package.json"));
441
460
  if (found?.name === name) push(name, found.version, /pnpm/i.test(dir) ? "pnpm" : /[\\/]\.bun[\\/]/.test(dir) ? "bun" : "npm", path.join(dir, ...name.split("/")));
442
461
  }
443
462
  }
444
463
  const voltaRoot = PLATFORM === "windows" && env.LOCALAPPDATA ? path.join(env.LOCALAPPDATA, "Volta") : path.join(home, ".volta");
445
- for (const name of npmPackages) {
464
+ const volta = await installedNames(path.join(voltaRoot, "tools", "image", "packages"));
465
+ for (const name of npmPackages.filter((n) => volta.has(n))) {
446
466
  const image = path.join(voltaRoot, "tools", "image", "packages", ...name.split("/"));
447
467
  // Volta keeps the package under lib/node_modules, or node_modules on Windows.
448
468
  for (const lib of [["lib", "node_modules"], ["node_modules"]]) {
@@ -519,19 +539,39 @@ async function editorExtensions({ home, env, tilde }) {
519
539
  for (const e of Array.isArray(json) ? json.slice(0, 3000) : []) {
520
540
  const id = typeof e?.identifier?.id === "string" ? e.identifier.id.toLowerCase() : null;
521
541
  const version = typeof e?.version === "string" ? e.version : "";
522
- if (id) items.set(`${id}@${version}`, { id, version, source: typeof e?.metadata?.source === "string" ? e.metadata.source : null });
542
+ const folder = typeof e?.relativeLocation === "string" && /^[^/\\]{1,250}$/.test(e.relativeLocation) && e.relativeLocation !== ".." ? e.relativeLocation : null;
543
+ if (id) items.set(`${id}@${version}`, { id, version, source: typeof e?.metadata?.source === "string" ? e.metadata.source : null, folder });
523
544
  }
524
545
  }
525
546
  // Folders on disk too, including old versions not cleaned up yet.
526
547
  for (const entry of entries.slice(0, 3000)) {
527
548
  const m = entry.isDirectory() ? entry.name.match(EXTENSION_FOLDER) : null;
528
- if (m && !items.has(`${m[1].toLowerCase()}@${m[2]}`)) items.set(`${m[1].toLowerCase()}@${m[2]}`, { id: m[1].toLowerCase(), version: m[2], source: null });
549
+ if (m && !items.has(`${m[1].toLowerCase()}@${m[2]}`)) items.set(`${m[1].toLowerCase()}@${m[2]}`, { id: m[1].toLowerCase(), version: m[2], source: null, folder: entry.name });
529
550
  }
530
- if (items.size) out.push({ editor, dir: tilde(dir), items: [...items.values()] });
551
+ const found = [...items.values()];
552
+ for (let i = 0; i < found.length; i += 16) await Promise.all(found.slice(i, i + 16).map(async (x) => (x.published = await publishedId(dir, x))));
553
+ if (found.length) out.push({ editor, dir: tilde(dir), items: found.map(({ folder, ...x }) => x) });
531
554
  }
532
555
  return out;
533
556
  }
534
557
 
558
+ // An extension's ID with the capitals its publisher gave it, from the
559
+ // publisher and name fields of its package.json, or null. OSV.dev needs it
560
+ // to find the extension; nothing else in the file is kept.
561
+ async function publishedId(dir, item) {
562
+ if (!item.folder) return null;
563
+ const file = path.join(dir, item.folder, "package.json");
564
+ const stat = await fs.stat(file).catch(() => null);
565
+ if (!stat?.isFile() || stat.size > 4 * 1024 * 1024) return null;
566
+ try {
567
+ const json = JSON.parse((await readText(file)) ?? "");
568
+ const id = typeof json?.publisher === "string" && typeof json?.name === "string" ? `${json.publisher}.${json.name}` : "";
569
+ return id.toLowerCase() === item.id ? id : null;
570
+ } catch {
571
+ return null;
572
+ }
573
+ }
574
+
535
575
  // Files attacks leave, checked by name only. Their contents are never read.
536
576
  async function traceFiles({ home, env }) {
537
577
  const found = [];
@@ -0,0 +1,109 @@
1
+ // How findings are drawn in the report --open writes. It makes HTML text
2
+ // only, with no page or DOM.
3
+ //
4
+ // A short list of what to fix first comes before the findings, with what each
5
+ // rule takes off the score. Critical and high findings open with why they
6
+ // matter and the fix showing; the rest open on a click. Each names its rule,
7
+ // which misconfig.ai/rules explains, and the levels are explained beside the
8
+ // list. Everything that comes from the files is escaped as text.
9
+
10
+ import { LEVELS } from "../engine/catalog.js";
11
+ import { SCORING, pointsOff } from "../engine/index.js";
12
+ import { describeMasks } from "../engine/mask.js";
13
+
14
+ export const LABEL = { critical: "Critical", high: "High", medium: "Medium", low: "Low", info: "Info" };
15
+ const SEVERITIES = Object.keys(LABEL);
16
+
17
+ // Text is escaped, and control codes and marks that reorder text, which a
18
+ // checked file can hold, are shown as the replacement character, as in the
19
+ // terminal.
20
+ const esc = (value) =>
21
+ String(value ?? "")
22
+ .replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, "\ufffd")
23
+ .replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
24
+ // Rule IDs are capitals, digits and hyphens, such as CC-BYPASS.
25
+ const RULE_ID = /^[A-Z][A-Z0-9]*(?:-[A-Z0-9]+){0,6}$/;
26
+ const OPEN = new Set(["critical", "high"]);
27
+
28
+ function findingHtml(f, id = "") {
29
+ const sev = Object.hasOwn(LABEL, f.severity) ? f.severity : "info";
30
+ const where = f.file ? f.file + (f.line ? `:${f.line}` : "") : "";
31
+ const evidence = f.evidence
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
+ : "";
34
+ const rule = typeof f.id === "string" && RULE_ID.test(f.id) ? `<a class="f-rule" href="https://misconfig.ai/rules#${f.id}" target="_blank" rel="noopener noreferrer">${f.id}</a>` : "";
35
+ const meta = [f.tool ? `<span>Affects ${esc(f.tool)}</span>` : "", rule].filter(Boolean).join("");
36
+ return `<details class="finding sev-${sev}"${id ? ` id="${esc(id)}"` : ""}${OPEN.has(sev) ? " open" : ""}>
37
+ <summary><span class="sq" aria-hidden="true"></span><span class="f-title">${esc(f.title)}</span>${where ? `<span class="f-where">${esc(where)}</span>` : ""}</summary>
38
+ <div class="f-body">
39
+ <p><b>Why it matters.</b> ${esc(f.why)}</p>
40
+ <p><b>Fix.</b> ${esc(f.fix)}</p>
41
+ ${evidence}
42
+ ${meta ? `<p class="f-meta">${meta}</p>` : ""}
43
+ </div>
44
+ </details>`;
45
+ }
46
+
47
+ // What the levels mean and how the score is worked out, folded away under
48
+ // one line.
49
+ function legendHtml() {
50
+ return `<details class="legend">
51
+ <summary>What the levels mean</summary>
52
+ <dl>${SEVERITIES.map((s) => `<div><dt><span class="sq sev-${s}" aria-hidden="true"></span>${LABEL[s]}</dt><dd>${esc(LEVELS[s])}</dd></div>`).join("")}</dl>
53
+ <p>${esc(SCORING)}</p>
54
+ <p><a href="https://misconfig.ai/rules" target="_blank" rel="noopener noreferrer">Every rule, what it checks and how to fix it</a></p>
55
+ </details>`;
56
+ }
57
+
58
+ const points = (n) => `${n} ${n === 1 ? "point" : "points"}`;
59
+ const FIX_FIRST_MAX = 12;
60
+
61
+ // The rules to fix, most points first, each linked to its first finding.
62
+ function fixFirstHtml(findings, anchorOf) {
63
+ const { rules, total } = pointsOff(findings);
64
+ if (!rules.length) return "";
65
+ const off = Math.round(total);
66
+ const score = Math.max(0, 100 - off);
67
+ const shown = rules.slice(0, FIX_FIRST_MAX);
68
+ const rest = rules.length - shown.length;
69
+ const item = (r) => {
70
+ const f = r.findings[0];
71
+ const where = f.file ? f.file + (f.line ? `:${f.line}` : "") : "";
72
+ const more = r.findings.length > 1 ? `<span class="ff-more">and ${r.findings.length - 1} more like it</span>` : "";
73
+ return `<li class="sev-${r.severity}"><span class="sq" aria-hidden="true"></span><span class="ff-main"><a href="#${anchorOf.get(f)}">${esc(f.title)}</a>${more}${where ? `<span class="ff-where">${esc(where)}</span>` : ""}</span><span class="ff-points">${points(Math.round(r.points))}</span></li>`;
74
+ };
75
+ return `<section class="fix-first" aria-labelledby="fix-first-title">
76
+ <h3 id="fix-first-title">Where to start</h3>
77
+ <p>${off >= 100 ? `Together these take off ${points(off)}, more than the 100 a check starts with, so the score is 0.` : `Together these take off ${points(off)}, for a score of ${score}.`} Each fix gives its points back.</p>
78
+ <ol>${shown.map(item).join("")}</ol>
79
+ ${rest > 0 ? `<p class="ff-rest">Plus ${rest} smaller ${rest === 1 ? "one" : "ones"} in the list below.</p>` : ""}
80
+ </section>`;
81
+ }
82
+
83
+ // What to fix first, then the findings in groups, worst first, after the
84
+ // legend. In each group, findings in the same file sit together, so a file
85
+ // can be fixed in one pass.
86
+ export function findingsHtml(findings) {
87
+ const groups = SEVERITIES.map((sev) => [
88
+ sev,
89
+ findings
90
+ .filter((f) => f.severity === sev)
91
+ .map((f, i) => [f, i])
92
+ .sort(([a, i], [b, j]) => (a.file ?? "\uffff").localeCompare(b.file ?? "\uffff") || (a.line ?? 0) - (b.line ?? 0) || i - j)
93
+ .map(([f]) => f),
94
+ ]).filter(([, group]) => group.length);
95
+ const anchorOf = new Map();
96
+ for (const [, group] of groups) for (const f of group) anchorOf.set(f, `finding-${anchorOf.size + 1}`);
97
+ return (
98
+ fixFirstHtml(findings, anchorOf) +
99
+ legendHtml() +
100
+ groups
101
+ .map(
102
+ ([sev, group]) => `<section class="group">
103
+ <h3 class="group-title"><span class="sq sev-${sev}" aria-hidden="true"></span>${LABEL[sev]}<span class="group-count">${group.length}</span></h3>
104
+ ${group.map((f) => findingHtml(f, anchorOf.get(f))).join("")}
105
+ </section>`,
106
+ )
107
+ .join("")
108
+ );
109
+ }