seo-supervisor 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +16 -3
- package/CHANGELOG.md +430 -0
- package/NOTICE +7 -0
- package/README.md +230 -25
- package/agents/seo-auditor.md +16 -0
- package/agents/seo-reviewer.md +16 -0
- package/bin/agents.mjs +194 -29
- package/bin/extras.mjs +422 -0
- package/bin/prompt.mjs +34 -14
- package/bin/seo-supervisor.mjs +386 -53
- package/commands/seo-audit.md +29 -3
- package/commands/seo-brief.md +28 -0
- package/commands/seo-connect.md +27 -0
- package/commands/seo-fix.md +24 -3
- package/commands/seo-grow.md +26 -0
- package/commands/seo-launch.md +17 -3
- package/commands/seo-review.md +13 -1
- package/commands/seo-rewrite.md +25 -0
- package/commands/seo-setup.md +17 -1
- package/commands/seo-watch.md +28 -0
- package/hooks/hooks.json +117 -0
- package/package.json +20 -7
- package/skills/seo-supervisor/NOTICE +7 -0
- package/skills/seo-supervisor/SKILL.md +302 -21
- package/skills/seo-supervisor/audience.md +61 -0
- package/skills/seo-supervisor/examples/drafts/security.md +41 -0
- package/skills/seo-supervisor/examples/hooks/README.md +28 -0
- package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
- package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
- package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
- package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
- package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
- package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
- package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
- package/skills/seo-supervisor/examples/sample-audit.json +94 -2
- package/skills/seo-supervisor/examples/sample-report.html +111 -61
- package/skills/seo-supervisor/examples/sample-report.md +147 -44
- package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
- package/skills/seo-supervisor/examples/snippets.md +648 -1
- package/skills/seo-supervisor/grow.md +342 -0
- package/skills/seo-supervisor/og-images.md +85 -0
- package/skills/seo-supervisor/page-types.md +124 -0
- package/skills/seo-supervisor/planning.md +19 -7
- package/skills/seo-supervisor/profile-template.md +41 -0
- package/skills/seo-supervisor/report-format.md +177 -10
- package/skills/seo-supervisor/rewrite.md +59 -0
- package/skills/seo-supervisor/rules/ai-search.md +65 -12
- package/skills/seo-supervisor/rules/content.md +33 -9
- package/skills/seo-supervisor/rules/crawl-index.md +33 -6
- package/skills/seo-supervisor/rules/internal-linking.md +49 -6
- package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
- package/skills/seo-supervisor/rules/media.md +13 -1
- package/skills/seo-supervisor/rules/metadata.md +41 -9
- package/skills/seo-supervisor/rules/performance.md +50 -5
- package/skills/seo-supervisor/rules/rendering.md +39 -2
- package/skills/seo-supervisor/rules/search-intent.md +32 -0
- package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
- package/skills/seo-supervisor/rules/structured-data.md +37 -14
- package/skills/seo-supervisor/rules/trust-security.md +25 -2
- package/skills/seo-supervisor/rules/urls.md +10 -2
- package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
- package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
- package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
- package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
- package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
- package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
- package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
- package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
- package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
- package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
- package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
- package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
- package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
- package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
- package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
- package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
- package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
- package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
- package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
- package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
- package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
- package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
- package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
- package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
- package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
- package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
- package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
- package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
- package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
- package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
- package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
- package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
- package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
- package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
- package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
- package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
- package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
- package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
- package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
- package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
- package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
- package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
- package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
- package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
- package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
- package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
- package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
- package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
- package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
- package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
- package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
- package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
- package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
- package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
- package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
- package/skills/seo-supervisor/scripts/google.mjs +1341 -0
- package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
- package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
- package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
- package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
- package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
- package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
- package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
- package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
- package/skills/seo-supervisor/scripts/guard.mjs +74 -0
- package/skills/seo-supervisor/scripts/images.mjs +408 -0
- package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
- package/skills/seo-supervisor/scripts/issues.mjs +217 -0
- package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
- package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
- package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
- package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
- package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
- package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
- package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
- package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
- package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
- package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
- package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
- package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
- package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
- package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
- package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
- package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
- package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
- package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
- package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
- package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
- package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
- package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
- package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
- package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
- package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
- package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
- package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
- package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
- package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
- package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
- package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
- package/skills/seo-supervisor/scripts/osm.mjs +359 -0
- package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
- package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
- package/skills/seo-supervisor/scripts/report/client.js +37 -0
- package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
- package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
- package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
- package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
- package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
- package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
- package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
- package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
- package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
- package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
- package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
- package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
- package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
- package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
- package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
- package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
- package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
- package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
- package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
- package/skills/seo-supervisor/scripts/report/styles.css +223 -0
- package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
- package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
- package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
- package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
- package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
- package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
- package/skills/seo-supervisor/site-types/content.md +34 -1
- package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
- package/skills/seo-supervisor/site-types/local-business.md +96 -6
- package/skills/seo-supervisor/site-types/services.md +46 -0
- package/skills/seo-supervisor/site-types/tools.md +3 -3
- package/skills/seo-supervisor/strategy.md +232 -0
- package/skills/seo-supervisor/troubleshooting.md +56 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Core Web Vitals from PageSpeed Insights (CrUX field data plus a lab run) and the CrUX History API. The crawler
|
|
3
|
+
// calls it only with --outside, for public URLs.
|
|
4
|
+
import { sleep } from "./crawl.mjs";
|
|
5
|
+
|
|
6
|
+
export const CHECKS = {
|
|
7
|
+
"cwv-fail": [
|
|
8
|
+
"PERF-01",
|
|
9
|
+
"high",
|
|
10
|
+
n => `${n} page type(s) fail Core Web Vitals for real visitors`,
|
|
11
|
+
"Google measures loading (LCP), responsiveness (INP) and layout stability (CLS) on real Chrome visits. Pages that fail rank lower in close calls and lose visitors who wait.",
|
|
12
|
+
"Start with the failing metric: LCP (hero image size and priority, server response), INP (long JavaScript tasks, heavy third parties) or CLS (image dimensions, late-loading banners).",
|
|
13
|
+
],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const PSI_ENDPOINT = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed";
|
|
17
|
+
// The key goes in the X-Goog-Api-Key header, not ?key=, where it would end up in logs and proxies. Every Google API
|
|
18
|
+
// accepts the header, though PageSpeed's and CrUX's docs show ?key=.
|
|
19
|
+
// https://cloud.google.com/docs/authentication/api-keys-use
|
|
20
|
+
const keyed = key => (key ? { "X-Goog-Api-Key": key } : {});
|
|
21
|
+
export const CRUX_HISTORY_ENDPOINT = "https://chromeuxreport.googleapis.com/v1/records:queryHistoryRecord";
|
|
22
|
+
|
|
23
|
+
// The four parts of an image LCP as CrUX names them, in the order they happen.
|
|
24
|
+
const LCP_PARTS = {
|
|
25
|
+
ttfb: "largest_contentful_paint_image_time_to_first_byte",
|
|
26
|
+
loadDelay: "largest_contentful_paint_image_resource_load_delay",
|
|
27
|
+
loadDuration: "largest_contentful_paint_image_resource_load_duration",
|
|
28
|
+
renderDelay: "largest_contentful_paint_image_element_render_delay",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const TREND = { lcp: "largest_contentful_paint", inp: "interaction_to_next_paint", cls: "cumulative_layout_shift" };
|
|
32
|
+
const day = d => (d?.year ? `${d.year}-${String(d.month).padStart(2, "0")}-${String(d.day).padStart(2, "0")}` : null);
|
|
33
|
+
// p75s over CrUX History's 25 weekly periods, as [first, last] per metric, plus the latest LCP parts in ms. With page,
|
|
34
|
+
// target is a URL rather than an origin. avg4 averages the first and last four weeks with data, steadier than single
|
|
35
|
+
// weeks. https://developer.chrome.com/docs/crux/history-api
|
|
36
|
+
export async function speedTrend(
|
|
37
|
+
target,
|
|
38
|
+
{ key, endpoint = CRUX_HISTORY_ENDPOINT, fetchFn = fetch, formFactor = "PHONE", page = false },
|
|
39
|
+
) {
|
|
40
|
+
const r = await fetchFn(new URL(endpoint).href, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: { "content-type": "application/json", ...keyed(key) },
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
[page ? "url" : "origin"]: target,
|
|
45
|
+
formFactor,
|
|
46
|
+
metrics: [...Object.values(TREND), ...Object.values(LCP_PARTS)],
|
|
47
|
+
}),
|
|
48
|
+
signal: AbortSignal.timeout(30000),
|
|
49
|
+
});
|
|
50
|
+
if (!r.ok)
|
|
51
|
+
return {
|
|
52
|
+
note: `CrUX history${page ? ` for ${target}` : formFactor === "PHONE" ? "" : ` (${formFactor.toLowerCase()})`}: ${r.status === 404 ? `not enough Chrome visits to this ${page ? "page" : "site"} for a trend` : `answered ${r.status}${r.status === 403 ? " (enable the Chrome UX Report API for this key)" : ""}`}.`,
|
|
53
|
+
};
|
|
54
|
+
const rec = /** @type {any} */ (await r.json()).record || {},
|
|
55
|
+
m = rec.metrics || {},
|
|
56
|
+
periods = rec.collectionPeriods || [];
|
|
57
|
+
// A period with too few visits is null: skipped, never read as 0.
|
|
58
|
+
const weekly = s =>
|
|
59
|
+
(s?.percentilesTimeseries?.p75s || []).map(x => (x == null || isNaN(Number(x)) ? null : Number(x)));
|
|
60
|
+
const ends = s => {
|
|
61
|
+
const xs = weekly(s).filter(x => x != null);
|
|
62
|
+
return xs.length ? [xs[0], xs[xs.length - 1]] : null;
|
|
63
|
+
};
|
|
64
|
+
const mean = (xs, k) => {
|
|
65
|
+
const v = xs.reduce((a, b) => a + b, 0) / xs.length;
|
|
66
|
+
return k === "cls" ? Math.round(v * 100) / 100 : Math.round(v);
|
|
67
|
+
};
|
|
68
|
+
const avg4 = Object.fromEntries(
|
|
69
|
+
Object.entries(TREND).flatMap(([k, id]) => {
|
|
70
|
+
const xs = weekly(m[id]).filter(x => x != null);
|
|
71
|
+
return xs.length >= 8 ? [[k, [mean(xs.slice(0, 4), k), mean(xs.slice(-4), k)]]] : [];
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
const latest = Object.entries(LCP_PARTS).map(([k, name]) => [k, m[name]?.percentilesTimeseries?.p75s?.at(-1)]);
|
|
75
|
+
const lcpBreakdown = latest.every(([, v]) => v != null) && {
|
|
76
|
+
source: "real visitors",
|
|
77
|
+
url: target,
|
|
78
|
+
...Object.fromEntries(latest.map(([k, v]) => [k, Math.round(Number(v))])),
|
|
79
|
+
};
|
|
80
|
+
const last = day(periods.at(-1)?.lastDate) ? periods.at(-1) : null;
|
|
81
|
+
return {
|
|
82
|
+
trend: {
|
|
83
|
+
weeks: periods.length,
|
|
84
|
+
...Object.fromEntries(Object.entries(TREND).map(([k, id]) => [k, ends(m[id])])),
|
|
85
|
+
avg4,
|
|
86
|
+
series: Object.fromEntries(Object.entries(TREND).map(([k, id]) => [k, weekly(m[id])])),
|
|
87
|
+
periods: periods.map(p => day(p.lastDate)),
|
|
88
|
+
...(last ? { period: { from: day(last.firstDate), to: day(last.lastDate) } } : {}),
|
|
89
|
+
},
|
|
90
|
+
...(lcpBreakdown ? { lcpBreakdown } : {}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// LCP subparts from a Lighthouse 13 report, in ms. A text LCP has no image to wait for or download.
|
|
95
|
+
export function labLcpParts(audits) {
|
|
96
|
+
const rows = (audits?.["lcp-breakdown-insight"]?.details?.items || []).find(t => t.type === "table")?.items || [];
|
|
97
|
+
const ms = s => Math.round(rows.find(r => r.subpart === s)?.duration ?? 0);
|
|
98
|
+
return rows.some(r => r.subpart === "timeToFirstByte")
|
|
99
|
+
? {
|
|
100
|
+
ttfb: ms("timeToFirstByte"),
|
|
101
|
+
loadDelay: ms("resourceLoadDelay"),
|
|
102
|
+
loadDuration: ms("resourceLoadDuration"),
|
|
103
|
+
renderDelay: ms("elementRenderDelay"),
|
|
104
|
+
}
|
|
105
|
+
: null;
|
|
106
|
+
}
|
|
107
|
+
// The LCP node of a Lighthouse 13 run, its image from the snippet's src or first srcset candidate, and the discovery
|
|
108
|
+
// checklist: priorityHinted (fetchpriority="high", images only), eagerlyLoaded (not lazy, or preloaded) and
|
|
109
|
+
// requestDiscoverable (started by a preload or the HTML, not CSS or a script).
|
|
110
|
+
// https://github.com/GoogleChrome/lighthouse/blob/main/core/audits/insights/lcp-discovery-insight.js
|
|
111
|
+
export function labLcpElement(audits) {
|
|
112
|
+
const items = id => audits?.[id]?.details?.items || [];
|
|
113
|
+
const n = [...items("lcp-breakdown-insight"), ...items("lcp-discovery-insight")].find(i => i?.type === "node");
|
|
114
|
+
if (!n) return null;
|
|
115
|
+
const tag = typeof n.snippet === "string" ? n.snippet : "",
|
|
116
|
+
attr = k => new RegExp(`\\s${k}\\s*=\\s*"([^"]*)"`, "i").exec(tag)?.[1]?.replace(/&/g, "&");
|
|
117
|
+
const src = /^<img\b/i.test(tag) ? attr("src") || attr("srcset")?.trim().split(/\s+/)[0] : null;
|
|
118
|
+
const check = items("lcp-discovery-insight").find(i => i?.type === "checklist")?.items,
|
|
119
|
+
bool = k => (typeof check?.[k]?.value === "boolean" ? check[k].value : undefined);
|
|
120
|
+
const hinted = bool("priorityHinted"),
|
|
121
|
+
eager = bool("eagerlyLoaded"),
|
|
122
|
+
discoverable = bool("requestDiscoverable");
|
|
123
|
+
return {
|
|
124
|
+
element: String(n.nodeLabel || n.selector || tag).slice(0, 200),
|
|
125
|
+
...(src ? { src: src.slice(0, 300) } : {}),
|
|
126
|
+
...(hinted !== undefined ? { fetchpriorityHigh: hinted } : {}),
|
|
127
|
+
...(eager !== undefined ? { eager } : {}),
|
|
128
|
+
...(discoverable !== undefined ? { discoverable } : {}),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// Lab runs ({ url, lcpParts }): the home page's breakdown, else the first one.
|
|
132
|
+
export function labLcpBreakdown(runs) {
|
|
133
|
+
const l = runs.filter(x => x.lcpParts),
|
|
134
|
+
x = l.find(x => new URL(x.url).pathname === "/") || l[0];
|
|
135
|
+
return x ? { source: "lab", url: x.url, ...x.lcpParts } : null;
|
|
136
|
+
}
|
|
137
|
+
// Good up to the first number, poor above the second, at p75 on phone and desktop alike.
|
|
138
|
+
// https://web.dev/articles/defining-core-web-vitals-thresholds
|
|
139
|
+
export const BANDS = { lcp: [2500, 4000], inp: [200, 500], cls: [0.1, 0.25] };
|
|
140
|
+
export const LIMITS = Object.fromEntries(Object.entries(BANDS).map(([k, [good]]) => [k, good]));
|
|
141
|
+
// FCP and TTFB aren't Core Web Vitals, so they stay out of BANDS and never count toward passing or the
|
|
142
|
+
// since-last-audit comparison.
|
|
143
|
+
// https://web.dev/articles/fcp
|
|
144
|
+
// https://web.dev/articles/ttfb
|
|
145
|
+
export const OTHER_BANDS = { fcp: [1800, 3000], ttfb: [800, 1800] };
|
|
146
|
+
export const band = (metric, value) => {
|
|
147
|
+
const [good, poor] = BANDS[metric] || OTHER_BANDS[metric];
|
|
148
|
+
return value <= good ? "good" : value <= poor ? "needs improvement" : "poor";
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// PageSpeed reports CLS × 100. shares holds each metric's good, needs-improvement and poor proportions.
|
|
152
|
+
const PSI_METRICS = {
|
|
153
|
+
lcp: "LARGEST_CONTENTFUL_PAINT_MS",
|
|
154
|
+
inp: "INTERACTION_TO_NEXT_PAINT",
|
|
155
|
+
cls: "CUMULATIVE_LAYOUT_SHIFT_SCORE",
|
|
156
|
+
fcp: "FIRST_CONTENTFUL_PAINT_MS",
|
|
157
|
+
ttfb: "EXPERIMENTAL_TIME_TO_FIRST_BYTE",
|
|
158
|
+
};
|
|
159
|
+
const cwv = m => {
|
|
160
|
+
if (!m?.LARGEST_CONTENTFUL_PAINT_MS) return null;
|
|
161
|
+
const shares = Object.fromEntries(
|
|
162
|
+
Object.entries(PSI_METRICS).flatMap(([k, id]) => {
|
|
163
|
+
const d = m[id]?.distributions;
|
|
164
|
+
return Array.isArray(d) && d.length === 3
|
|
165
|
+
? [[k, d.map(b => Math.round((Number(b?.proportion) || 0) * 1000) / 1000)]]
|
|
166
|
+
: [];
|
|
167
|
+
}),
|
|
168
|
+
);
|
|
169
|
+
const fcp = m.FIRST_CONTENTFUL_PAINT_MS?.percentile,
|
|
170
|
+
ttfb = m.EXPERIMENTAL_TIME_TO_FIRST_BYTE?.percentile;
|
|
171
|
+
return {
|
|
172
|
+
lcp: m.LARGEST_CONTENTFUL_PAINT_MS.percentile,
|
|
173
|
+
inp: m.INTERACTION_TO_NEXT_PAINT?.percentile ?? null,
|
|
174
|
+
cls: m.CUMULATIVE_LAYOUT_SHIFT_SCORE ? m.CUMULATIVE_LAYOUT_SHIFT_SCORE.percentile / 100 : null,
|
|
175
|
+
...(fcp != null ? { fcp } : {}),
|
|
176
|
+
...(ttfb != null ? { ttfb } : {}),
|
|
177
|
+
...(Object.keys(shares).length ? { shares } : {}),
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
export const passes = v =>
|
|
181
|
+
v.lcp <= LIMITS.lcp && (v.inp == null || v.inp <= LIMITS.inp) && (v.cls == null || v.cls <= LIMITS.cls);
|
|
182
|
+
export const fmtCwv = v =>
|
|
183
|
+
[
|
|
184
|
+
`LCP ${(v.lcp / 1000).toFixed(1)} s`,
|
|
185
|
+
v.inp != null && `INP ${Math.round(v.inp)} ms`,
|
|
186
|
+
v.cls != null && `CLS ${Math.round(v.cls * 100) / 100}`,
|
|
187
|
+
]
|
|
188
|
+
.filter(Boolean)
|
|
189
|
+
.join(" · ");
|
|
190
|
+
|
|
191
|
+
// The home page plus one URL per first path segment, up to 10.
|
|
192
|
+
export function sampleUrls(urls, max = 10) {
|
|
193
|
+
const seen = new Set(),
|
|
194
|
+
out = [];
|
|
195
|
+
for (const u of urls) {
|
|
196
|
+
const seg = new URL(u).pathname.split("/")[1] || "";
|
|
197
|
+
if (seen.has(seg)) continue;
|
|
198
|
+
seen.add(seg);
|
|
199
|
+
out.push(u);
|
|
200
|
+
}
|
|
201
|
+
return out.sort((a, b) => new URL(a).pathname.length - new URL(b).pathname.length).slice(0, max);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// For --desktop the crawler passes a no-op add, since PERF-01 judges phones.
|
|
205
|
+
export async function checkSpeed(urls, { add, endpoint = PSI_ENDPOINT, key, fetchFn = fetch, strategy = "mobile" }) {
|
|
206
|
+
const samples = [],
|
|
207
|
+
notes = [],
|
|
208
|
+
PSI = strategy === "mobile" ? "PageSpeed" : `PageSpeed (${strategy})`;
|
|
209
|
+
let limited = false;
|
|
210
|
+
for (const url of urls) {
|
|
211
|
+
if (limited) break;
|
|
212
|
+
const q = new URL(endpoint);
|
|
213
|
+
// Performance only. PageSpeed has no agentic browsing category; lighthouse.mjs runs that one locally.
|
|
214
|
+
// https://developers.google.com/speed/docs/insights/rest/v5/pagespeedapi/runpagespeed
|
|
215
|
+
q.searchParams.set("url", url);
|
|
216
|
+
q.searchParams.set("strategy", strategy);
|
|
217
|
+
q.searchParams.set("category", "performance");
|
|
218
|
+
let data = null;
|
|
219
|
+
for (let attempt = 0; attempt < 2 && !data; attempt++) {
|
|
220
|
+
try {
|
|
221
|
+
const r = await fetchFn(q.href, { headers: keyed(key), signal: AbortSignal.timeout(90000) });
|
|
222
|
+
if (r.status === 429 && attempt === 0) {
|
|
223
|
+
await sleep(5000);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (r.status === 429) {
|
|
227
|
+
limited = true;
|
|
228
|
+
notes.push(
|
|
229
|
+
`${PSI} refused the request (rate limit${key ? "" : ": requests without an API key share a daily quota that is usually used up"}). Speed wasn't checked.`,
|
|
230
|
+
);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
if (!r.ok) {
|
|
234
|
+
notes.push(`${PSI}: ${url} answered ${r.status}.`);
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
data = /** @type {any} */ (await r.json());
|
|
238
|
+
} catch (e) {
|
|
239
|
+
notes.push(`${PSI}: ${url} failed (${e.message}).`);
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (!data) continue;
|
|
244
|
+
const le = data.loadingExperience;
|
|
245
|
+
const field = le && !le.origin_fallback ? cwv(le.metrics) : null,
|
|
246
|
+
origin = cwv(data.originLoadingExperience?.metrics);
|
|
247
|
+
const a = data.lighthouseResult?.audits || {};
|
|
248
|
+
const lcpParts = labLcpParts(a),
|
|
249
|
+
lcpElement = labLcpElement(a),
|
|
250
|
+
version = data.lighthouseResult?.lighthouseVersion;
|
|
251
|
+
const lab = {
|
|
252
|
+
lcp: a["largest-contentful-paint"]?.numericValue ?? null,
|
|
253
|
+
cls: a["cumulative-layout-shift"]?.numericValue ?? null,
|
|
254
|
+
tbt: a["total-blocking-time"]?.numericValue ?? null,
|
|
255
|
+
...(lcpParts ? { lcpParts } : {}),
|
|
256
|
+
...(lcpElement ? { lcpElement } : {}),
|
|
257
|
+
...(typeof version === "string" ? { version } : {}),
|
|
258
|
+
};
|
|
259
|
+
samples.push({ url, field, origin, lab });
|
|
260
|
+
if (field && !passes(field)) add("cwv-fail", url, `${fmtCwv(field)} (75th percentile of real ${strategy} visits)`);
|
|
261
|
+
else if (!field && lab.lcp != null)
|
|
262
|
+
notes.push(
|
|
263
|
+
`${PSI}: no real-user data for ${url} yet; lab run: LCP ${(lab.lcp / 1000).toFixed(1)} s, CLS ${Math.round((lab.cls || 0) * 100) / 100}, TBT ${Math.round(lab.tbt || 0)} ms.`,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return { samples, notes, limited };
|
|
267
|
+
}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Small technical checks the crawler runs (sitemaps, links, images, head tags, headings, security headers and cookies).
|
|
3
|
+
|
|
4
|
+
export const CHECKS = {
|
|
5
|
+
"sitemap-duplicate-urls": [
|
|
6
|
+
"MAP-01",
|
|
7
|
+
"low",
|
|
8
|
+
n => `${n} sitemap file(s) list the same URL more than once`,
|
|
9
|
+
"The same address appears twice in one sitemap, or in two regular sitemaps. The copy adds nothing, takes one of the file's 50,000 places, and usually means two parts of the sitemap code list the same pages; when the copies give different lastmod dates, at least one is wrong. A page listed again in an image, video or news sitemap is fine.",
|
|
10
|
+
"Build the sitemap from one list of pages, and when it's split into several files, give each page to exactly one of them.",
|
|
11
|
+
],
|
|
12
|
+
// https://support.google.com/webmasters/answer/7451001
|
|
13
|
+
"sitemap-index-nested": [
|
|
14
|
+
"MAP-01",
|
|
15
|
+
"low",
|
|
16
|
+
n => `${n} sitemap index(es) are listed inside another sitemap index`,
|
|
17
|
+
"A sitemap index may list only sitemaps, not other sitemap indexes. Search Console reports a nested one as an error (“Nested sitemap indexes”), so the sitemaps it lists may not be read through it.",
|
|
18
|
+
"List every sitemap file directly in one top-level sitemap index (and reference that in robots.txt), and remove the entry that points at the other index.",
|
|
19
|
+
],
|
|
20
|
+
// https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
|
|
21
|
+
"video-sitemap-tags": [
|
|
22
|
+
"MAP-01",
|
|
23
|
+
"low",
|
|
24
|
+
n => `${n} video sitemap(s) have videos without Google's required tags`,
|
|
25
|
+
"Each `<video:video>` entry needs `<video:thumbnail_loc>`, `<video:title>`, `<video:description>` (at most 2,048 characters) and either `<video:content_loc>` or `<video:player_loc>`. Google can't use an entry that lacks one, so the video may not appear in video results.",
|
|
26
|
+
"Generate each entry from the video record: the thumbnail URL, the title and description shown on the page, and the URL of the video file (`content_loc`, which Google prefers) or of its player (`player_loc`).",
|
|
27
|
+
],
|
|
28
|
+
// https://developers.google.com/search/docs/crawling-indexing/sitemaps/image-sitemaps
|
|
29
|
+
"image-sitemap-tags": [
|
|
30
|
+
"MAP-01",
|
|
31
|
+
"low",
|
|
32
|
+
n => `${n} image sitemap(s) have image entries Google can't use`,
|
|
33
|
+
"Each `<image:image>` needs an `<image:loc>` with the image's URL, and one page may list at most 1,000 images. An entry without the URL tells Google nothing.",
|
|
34
|
+
"Give every `<image:image>` its `<image:loc>`, and list at most 1,000 images per page, the ones that matter most.",
|
|
35
|
+
],
|
|
36
|
+
// https://developers.google.com/search/docs/crawling-indexing/url-structure
|
|
37
|
+
"sitemap-session-ids": [
|
|
38
|
+
"MAP-02",
|
|
39
|
+
"low",
|
|
40
|
+
n => `${n} sitemap URL(s) contain a session ID or a #fragment`,
|
|
41
|
+
"A session ID gives the same page a new address for every visitor, so search engines crawl copies of it; Google asks sites to keep session IDs out of URLs. Google ignores everything after `#`, so a #fragment URL is only a copy of the page without it.",
|
|
42
|
+
"List the plain URL of each page: drop the session parameter (keep sessions in a cookie) and the #fragment.",
|
|
43
|
+
],
|
|
44
|
+
// https://www.sitemaps.org/protocol.html
|
|
45
|
+
"sitemap-url-too-long": [
|
|
46
|
+
"MAP-02",
|
|
47
|
+
"low",
|
|
48
|
+
n => `${n} sitemap URL(s) are 2,048 characters or longer`,
|
|
49
|
+
"The sitemap protocol requires every URL to be under 2,048 characters, so a longer one breaks the format. An address that long is usually a filter or tracking URL that shouldn't be listed at all.",
|
|
50
|
+
"List the page's short canonical URL instead, or leave the URL out of the sitemap.",
|
|
51
|
+
],
|
|
52
|
+
// https://developers.google.com/search/docs/crawling-indexing/url-structure
|
|
53
|
+
"url-unencoded": [
|
|
54
|
+
"URL-01",
|
|
55
|
+
"low",
|
|
56
|
+
n => `${n} page(s) link to addresses with unencoded spaces or non-ASCII letters`,
|
|
57
|
+
"Web addresses may only contain plain ASCII characters, so spaces and letters such as é or ü must be percent-encoded (`/caf%C3%A9/` for `/café/`), as Google recommends. Browsers quietly fix such links, but other tools, apps and email clients often break them.",
|
|
58
|
+
"Build links with the framework's URL helper or `encodeURI()`, and use hyphens instead of spaces in slugs.",
|
|
59
|
+
],
|
|
60
|
+
// https://web.dev/articles/serve-responsive-images
|
|
61
|
+
"img-no-srcset": [
|
|
62
|
+
"PERF-08",
|
|
63
|
+
"low",
|
|
64
|
+
n => `${n} page(s) send large images at full size to every screen (no srcset)`,
|
|
65
|
+
"These images are over 1,000 px wide (from their `width` attribute) with no `srcset`, so phones download the full desktop size. web.dev says that can use 2–4 times the data needed, and it slows the page. 1,000 px is this skill's working level, not a Google threshold.",
|
|
66
|
+
"Give large images a `srcset` with three to five widths and a `sizes` attribute, or use the framework's image component (such as Next.js `<Image>`), which writes them.",
|
|
67
|
+
],
|
|
68
|
+
// https://web.dev/articles/browser-level-image-lazy-loading
|
|
69
|
+
"img-not-lazy": [
|
|
70
|
+
"PERF-03",
|
|
71
|
+
"low",
|
|
72
|
+
n => `${n} page(s) load images far down the page straight away`,
|
|
73
|
+
"From the 11th image on, which is usually below a phone's first screen, these images have no `loading` attribute, so the browser fetches them all at once and they compete with the first images for bandwidth. web.dev advises `loading=\"lazy\"` for images outside the first screen. The 11th image is this skill's working level, as the crawler can't see the layout.",
|
|
74
|
+
'Add `loading="lazy"` to images further down the page. Keep it off the first few images, and never put it on the main image.',
|
|
75
|
+
],
|
|
76
|
+
// Open Graph allows repeated og:image as an array; Google applies the more restrictive robots rule.
|
|
77
|
+
// https://ogp.me/#array
|
|
78
|
+
// https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag
|
|
79
|
+
"duplicate-head-tags": [
|
|
80
|
+
"META-03",
|
|
81
|
+
"low",
|
|
82
|
+
n => `${n} page(s) have the same head tag more than once`,
|
|
83
|
+
"Two meta descriptions, robots tags, viewports or og:title tags on one page usually mean the layout and the page, or two SEO plugins, both set them. Search engines and link previews then pick one or combine them (Google applies the strictest robots rule), so the result may not be the one you meant. Several og:image tags are fine: Open Graph allows a list of images.",
|
|
84
|
+
"Set each tag in one place, the shared metadata helper, and remove the copy from the layout or the second plugin.",
|
|
85
|
+
],
|
|
86
|
+
// https://www.w3.org/TR/WCAG22/#headings-and-labels
|
|
87
|
+
"heading-only-number": [
|
|
88
|
+
"CONTENT-02",
|
|
89
|
+
"low",
|
|
90
|
+
n => `${n} page(s) have headings that are only a number`,
|
|
91
|
+
"A heading such as “250+” or “01” says nothing about the section under it. Screen readers list headings so visitors can skim, search engines read them for the page's topics, and WCAG asks that headings describe their section. Years aren't counted.",
|
|
92
|
+
"Put the words in the heading (“250+ boilers fitted”), or show the number as styled text and keep headings for the section titles.",
|
|
93
|
+
],
|
|
94
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
|
|
95
|
+
"cookie-flags": [
|
|
96
|
+
"TRUST-01",
|
|
97
|
+
"low",
|
|
98
|
+
n => `${n} cookie(s) the server sets lack Secure, HttpOnly or SameSite`,
|
|
99
|
+
"These cookies come in the server's `Set-Cookie` headers on its pages. Without `Secure` a cookie can travel over plain HTTP, without `HttpOnly` any script on the page (an injected one too) can read it, and without `SameSite` some browsers send it along with requests from other sites. Cookies that scripts set themselves (analytics, consent) aren't checked, and `Secure` is checked only on an HTTPS crawl.",
|
|
100
|
+
"Set `Secure; HttpOnly; SameSite=Lax` in the framework's session and cookie settings. Leave `HttpOnly` off only for a cookie a script must read, such as a CSRF token the page's JavaScript sends back (those are skipped).",
|
|
101
|
+
],
|
|
102
|
+
// https://hstspreload.org
|
|
103
|
+
"hsts-short": [
|
|
104
|
+
"TRUST-01",
|
|
105
|
+
"low",
|
|
106
|
+
() => "HSTS lasts less than a year",
|
|
107
|
+
"The `Strict-Transport-Security` header's `max-age` is under 31,536,000 seconds (one year: this skill's own line, the HSTS preload list's minimum). Browsers forget the HTTPS-only rule sooner, so a returning visitor's first request can go over plain HTTP again.",
|
|
108
|
+
"Once HTTPS works on every page and subdomain, raise it to `max-age=31536000` or more (`63072000`, two years, is common). hstspreload.org advises getting there in stages (5 minutes, a week, a month), checking for broken pages at each one. Joining the preload list itself is optional, and hstspreload.org doesn't recommend it.",
|
|
109
|
+
],
|
|
110
|
+
// https://www.w3.org/TR/referrer-policy/#referrer-policy-unsafe-url
|
|
111
|
+
"referrer-unsafe": [
|
|
112
|
+
"TRUST-01",
|
|
113
|
+
"low",
|
|
114
|
+
n => `${n} page(s) set Referrer-Policy: unsafe-url`,
|
|
115
|
+
"With `unsafe-url` the page's full address, path and query included, goes to every site it links to or loads from, even over plain HTTP. The W3C standard calls it unsafe for that reason: it leaks addresses from HTTPS pages to insecure sites.",
|
|
116
|
+
'Use `strict-origin-when-cross-origin` in the `Referrer-Policy` header (or `<meta name="referrer">`), or remove the setting.',
|
|
117
|
+
],
|
|
118
|
+
"csp-weak": [
|
|
119
|
+
"TRUST-01",
|
|
120
|
+
"low",
|
|
121
|
+
() => "The Content-Security-Policy doesn't stop injected scripts",
|
|
122
|
+
"The policy is there, but it lets scripts run inline or from any site, or leaves plugins or the page's `<base>` tag open, so a script an attacker slips into the page can still run. These are the gaps Google's CSP Evaluator reports. A `'nonce-…'` or `'sha256-…'` source makes browsers ignore `'unsafe-inline'`, and `'strict-dynamic'` makes them ignore host and `https:` sources, so those fallbacks for old browsers aren't counted.",
|
|
123
|
+
"Move to a strict policy, as web.dev's \"Mitigate cross-site scripting with a strict CSP\" shows: `script-src 'nonce-{random}' 'strict-dynamic'; object-src 'none'; base-uri 'none'`, with a new nonce on every response (Next.js, Rails and Django can add it). Try it as `Content-Security-Policy-Report-Only` first.",
|
|
124
|
+
],
|
|
125
|
+
"hsts-invalid": [
|
|
126
|
+
"TRUST-01",
|
|
127
|
+
"low",
|
|
128
|
+
() => "The Strict-Transport-Security header is broken, so browsers ignore it",
|
|
129
|
+
"RFC 6797, the HSTS standard, says every directive may appear only once and `max-age` is required, and browsers must ignore a header that breaks these rules. The site then has no HSTS at all, whatever the header says.",
|
|
130
|
+
"Send exactly one header with each directive once, such as `Strict-Transport-Security: max-age=31536000; includeSubDomains`. When the server and the CDN both add one, remove it from one of them.",
|
|
131
|
+
],
|
|
132
|
+
"hsts-no-subdomains": [
|
|
133
|
+
"TRUST-01",
|
|
134
|
+
"low",
|
|
135
|
+
() => "HSTS doesn't cover subdomains (no includeSubDomains)",
|
|
136
|
+
"Without `includeSubDomains`, a subdomain such as `shop.` or an old `mail.` can still be opened over plain HTTP, where a cookie set for the whole domain can be read or changed. hstspreload.org's HSTS advice includes it at every step.",
|
|
137
|
+
"Check that every subdomain works over HTTPS first (the directive switches HTTP off for all of them), then add `includeSubDomains`: `Strict-Transport-Security: max-age=31536000; includeSubDomains`.",
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
// Not low like the rest, so the crawler adds it to its catalog itself: the version may already be patched.
|
|
141
|
+
export const SERVER_CHECK = {
|
|
142
|
+
"server-known-holes": [
|
|
143
|
+
"TRUST-01",
|
|
144
|
+
"needs-decision",
|
|
145
|
+
() => "The web server's version has known critical security holes",
|
|
146
|
+
'The `Server` header names a version that its maker\'s security advisories list with a critical hole (Apache\'s "critical", nginx\'s "major", their highest ratings). Linux distributions and hosts often fix holes without changing the version number, so it may already be patched; a hacked server can serve spam and malware, which gets pages flagged or dropped from search.',
|
|
147
|
+
"Ask the host or whoever runs the server whether this version is patched, and update it if not. Then hide the version: `ServerTokens Prod` in Apache, `server_tokens off;` in nginx.",
|
|
148
|
+
],
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// ---------- Content-Security-Policy ----------
|
|
152
|
+
// The gaps Google's CSP Evaluator flags: 'unsafe-inline' without a nonce or hash (browsers ignore it beside one),
|
|
153
|
+
// 'unsafe-eval', any-host script sources without 'strict-dynamic' (which makes browsers ignore them), no script or
|
|
154
|
+
// object limit, and no base-uri on a nonce policy (or a hash one with 'strict-dynamic').
|
|
155
|
+
// https://github.com/google/csp-evaluator
|
|
156
|
+
// https://web.dev/articles/strict-csp
|
|
157
|
+
const directives = policy =>
|
|
158
|
+
new Map(
|
|
159
|
+
policy
|
|
160
|
+
.split(";")
|
|
161
|
+
.map(d => d.trim().split(/\s+/))
|
|
162
|
+
.filter(([n]) => n)
|
|
163
|
+
.map(([n, ...v]) => [n.toLowerCase(), v.map(s => (/^'(nonce|sha\d+)-/i.test(s) ? s : s.toLowerCase()))]),
|
|
164
|
+
);
|
|
165
|
+
function policyGaps(policy) {
|
|
166
|
+
const d = directives(policy),
|
|
167
|
+
scripts = d.get("script-src") ?? d.get("default-src"),
|
|
168
|
+
out = [];
|
|
169
|
+
if (!scripts) out.push("no script-src or default-src, so scripts aren't limited");
|
|
170
|
+
else {
|
|
171
|
+
const keyed = scripts.some(s => /^'(nonce|sha\d+)-/i.test(s)),
|
|
172
|
+
dynamic = scripts.includes("'strict-dynamic'");
|
|
173
|
+
if (scripts.includes("'unsafe-inline'") && !keyed) out.push("scripts may run inline ('unsafe-inline')");
|
|
174
|
+
if (scripts.includes("'unsafe-eval'")) out.push("scripts may run eval() ('unsafe-eval')");
|
|
175
|
+
const any = dynamic
|
|
176
|
+
? []
|
|
177
|
+
: scripts.filter(s => ["*", "http:", "https:", "data:", "http://*", "https://*"].includes(s));
|
|
178
|
+
if (any.length) out.push(`scripts may load from any site (${any.join(", ")})`);
|
|
179
|
+
if (!d.has("base-uri") && scripts.some(s => /^'nonce-/i.test(s) || (dynamic && /^'sha\d+-/i.test(s))))
|
|
180
|
+
out.push("no base-uri, so an injected <base> tag can move the page's scripts");
|
|
181
|
+
}
|
|
182
|
+
if (!(d.get("object-src") ?? d.get("default-src"))?.length)
|
|
183
|
+
out.push("no object-src or default-src, so plugins aren't limited");
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
/** What a Content-Security-Policy header value leaves open, in plain words ([] for none). Several policies all apply,
|
|
187
|
+
* so a gap counts only when every policy has it. */
|
|
188
|
+
export function cspProblems(header) {
|
|
189
|
+
const each = String(header || "")
|
|
190
|
+
.split(",")
|
|
191
|
+
.filter(p => p.trim())
|
|
192
|
+
.map(policyGaps);
|
|
193
|
+
return each.length ? each.reduce((a, b) => a.filter(x => b.includes(x))) : [];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ---------- Strict-Transport-Security ----------
|
|
197
|
+
// Browsers use only the first header field (8.1). In it each directive may appear once, max-age (whole seconds, quotes
|
|
198
|
+
// allowed) is required, unknown directives are ignored, and a field that breaks the syntax is ignored whole (6.1).
|
|
199
|
+
// https://www.rfc-editor.org/rfc/rfc6797#section-6.1
|
|
200
|
+
// The preload list needs max-age of at least 31536000, includeSubDomains and preload, but hstspreload.org recommends
|
|
201
|
+
// against preloading, so findings advise HSTS and never the list. https://hstspreload.org
|
|
202
|
+
// fetch joins repeated fields with ", ", which this syntax never contains, so the first field ends at the first comma.
|
|
203
|
+
const TOKEN = /^[!#$%&'*+.^_`|~\w-]+$/;
|
|
204
|
+
export function hstsRead(header) {
|
|
205
|
+
const seen = new Map();
|
|
206
|
+
let invalid = null;
|
|
207
|
+
for (const part of String(header || "")
|
|
208
|
+
.split(",")[0]
|
|
209
|
+
.split(";")
|
|
210
|
+
.map(p => p.trim())
|
|
211
|
+
.filter(Boolean)) {
|
|
212
|
+
const [, name, value] = part.match(/^([^=\s]+)\s*(?:=\s*(.*))?$/) || [];
|
|
213
|
+
if (!name || !TOKEN.test(name) || (value != null && !/^("[^"]*"|[!#$%&'*+.^_`|~\w-]+)$/.test(value))) {
|
|
214
|
+
invalid ||= "it doesn't follow the header's syntax (directives separated by ;)";
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const key = name.toLowerCase();
|
|
218
|
+
if (seen.has(key)) invalid ||= `${name} appears twice`;
|
|
219
|
+
seen.set(key, value?.replace(/^"|"$/g, "") ?? "");
|
|
220
|
+
}
|
|
221
|
+
const raw = seen.get("max-age"),
|
|
222
|
+
maxAge = raw != null && /^\d+$/.test(raw) ? Number(raw) : null;
|
|
223
|
+
if (raw == null) invalid ||= "there's no max-age, which is required";
|
|
224
|
+
else if (maxAge == null) invalid ||= "max-age isn't a whole number of seconds";
|
|
225
|
+
const includeSubDomains = seen.has("includesubdomains"),
|
|
226
|
+
preload = seen.has("preload");
|
|
227
|
+
const missing = [
|
|
228
|
+
!(maxAge >= 31536000) && "a max-age of at least 31536000",
|
|
229
|
+
!includeSubDomains && "includeSubDomains",
|
|
230
|
+
!preload && "preload",
|
|
231
|
+
].filter(Boolean);
|
|
232
|
+
return { maxAge, includeSubDomains, preload, invalid, missing };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ---------- mixed content ----------
|
|
236
|
+
// What an https page loads: stylesheets, preloads and scripts, which browsers block, and media, embeds and frames,
|
|
237
|
+
// which they upgrade or block. Links, canonicals and icons aren't loads here. upgrade-insecure-requests in a page or
|
|
238
|
+
// header CSP makes the browser fetch them all over https.
|
|
239
|
+
// https://www.w3.org/TR/mixed-content/
|
|
240
|
+
// https://www.w3.org/TR/upgrade-insecure-requests/
|
|
241
|
+
/** @type {[string, string, (l: Record<string, string>) => string | null][]} */
|
|
242
|
+
const LOADS = [
|
|
243
|
+
[
|
|
244
|
+
"link",
|
|
245
|
+
"href",
|
|
246
|
+
l => {
|
|
247
|
+
const rel = (l.rel || "").toLowerCase().split(/\s+/);
|
|
248
|
+
return rel.includes("stylesheet")
|
|
249
|
+
? "stylesheet"
|
|
250
|
+
: rel.some(r => r === "preload" || r === "modulepreload")
|
|
251
|
+
? "preload"
|
|
252
|
+
: null;
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
["script", "src", () => "script"],
|
|
256
|
+
["img", "src", () => "image"],
|
|
257
|
+
["img", "srcset", () => "image"],
|
|
258
|
+
["video", "src", () => "video"],
|
|
259
|
+
["video", "poster", () => "image"],
|
|
260
|
+
["source", "src", () => "media"],
|
|
261
|
+
["source", "srcset", () => "image"],
|
|
262
|
+
["track", "src", () => "media"],
|
|
263
|
+
["audio", "src", () => "audio"],
|
|
264
|
+
["embed", "src", () => "embed"],
|
|
265
|
+
["object", "data", () => "embed"],
|
|
266
|
+
["iframe", "src", () => "frame"],
|
|
267
|
+
];
|
|
268
|
+
const attrsOf = tag =>
|
|
269
|
+
Object.fromEntries(
|
|
270
|
+
[...tag.matchAll(/([^\s=/>"']+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g)]
|
|
271
|
+
.slice(1)
|
|
272
|
+
.map(m => [m[1].toLowerCase(), m[2] ?? m[3] ?? m[4] ?? ""]),
|
|
273
|
+
);
|
|
274
|
+
/** The http:// files an https page loads, as { kind, url } in document order. cspHeader is the page's CSP header,
|
|
275
|
+
* if any. */
|
|
276
|
+
export function insecureResources(html, cspHeader = "") {
|
|
277
|
+
const doc = String(html)
|
|
278
|
+
.replace(/<!--[\s\S]*?-->/g, " ")
|
|
279
|
+
.replace(/(<(script|style|template|noscript)\b[^>]*>)[\s\S]*?<\/\2>/gi, "$1");
|
|
280
|
+
const metaCsp = [...doc.matchAll(/<meta\b[^>]*>/gi)]
|
|
281
|
+
.map(m => attrsOf(m[0]))
|
|
282
|
+
.filter(m => /^content-security-policy$/i.test(m["http-equiv"] || ""))
|
|
283
|
+
.map(m => m.content || "");
|
|
284
|
+
if ([cspHeader, ...metaCsp].some(c => /(^|[;,\s])upgrade-insecure-requests(\s*[;,]|\s*$)/i.test(c || ""))) return [];
|
|
285
|
+
const out = [];
|
|
286
|
+
for (const m of doc.matchAll(/<(link|script|img|video|source|track|audio|embed|object|iframe)\b[^>]*>/gi)) {
|
|
287
|
+
const a = attrsOf(m[0]),
|
|
288
|
+
name = m[1].toLowerCase();
|
|
289
|
+
for (const [tag, attr, kindOf] of LOADS) {
|
|
290
|
+
const kind = tag === name && a[attr] && kindOf(a);
|
|
291
|
+
if (kind)
|
|
292
|
+
for (const url of attr === "srcset" ? a[attr].split(",").map(c => c.trim().split(/\s+/)[0]) : [a[attr].trim()])
|
|
293
|
+
if (/^http:\/\//i.test(url)) out.push({ kind, url });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ---------- server software ----------
|
|
300
|
+
// Versions the maker's own advisories list with a hole at its top rating (Apache's "critical", nginx's "major").
|
|
301
|
+
// Checked 2026-11-21; CHECK AGAIN BY 2027-05-21, and add or drop versions. Apache httpd and nginx only; add PHP, IIS
|
|
302
|
+
// and others when a vendor advisory rates one of their versions critical.
|
|
303
|
+
// https://httpd.apache.org/security/vulnerabilities_24.html
|
|
304
|
+
// https://nginx.org/en/security_advisories.html
|
|
305
|
+
const v = s => s.split(".").map(Number),
|
|
306
|
+
lt = (a, b) => {
|
|
307
|
+
const x = v(a),
|
|
308
|
+
y = v(b);
|
|
309
|
+
for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] < y[i];
|
|
310
|
+
return false;
|
|
311
|
+
};
|
|
312
|
+
const within = (ver, from, to) => !lt(ver, from) && !lt(to, ver);
|
|
313
|
+
const HOLES = {
|
|
314
|
+
Apache: [
|
|
315
|
+
{ id: "CVE-2021-41773", what: "path traversal and file disclosure", hits: x => x === "2.4.49", fixed: "2.4.50" },
|
|
316
|
+
{
|
|
317
|
+
id: "CVE-2021-42013",
|
|
318
|
+
what: "path traversal and remote code execution",
|
|
319
|
+
hits: x => within(x, "2.4.49", "2.4.50"),
|
|
320
|
+
fixed: "2.4.51",
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
id: "CVE-2026-119618",
|
|
324
|
+
what: "heap corruption and remote code execution in mod_http2",
|
|
325
|
+
hits: x => within(x, "2.4.55", "2.4.70"),
|
|
326
|
+
fixed: "2.4.71",
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
nginx: [
|
|
330
|
+
// Not vulnerable: 1.31.9+ and the stable 1.30.7+.
|
|
331
|
+
{
|
|
332
|
+
id: "CVE-2026-123007",
|
|
333
|
+
what: "memory corruption in HTTP/2 flow control",
|
|
334
|
+
hits: x => within(x, "1.9.5", "1.31.8") && !within(x, "1.30.7", "1.30.999"),
|
|
335
|
+
fixed: "1.30.7 or 1.31.9",
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
};
|
|
339
|
+
// A distribution's build (Apache/2.4.62 (Ubuntu)) is skipped: distributions patch without changing the version.
|
|
340
|
+
const DISTRO =
|
|
341
|
+
/\((?:Ubuntu|Debian|Red Hat|CentOS|Fedora|Rocky|AlmaLinux|Amazon|Oracle|SUSE|Linux\/SUSE|openSUSE|Raspbian|Gentoo|Mageia)/i;
|
|
342
|
+
/** The Server header's software and its listed holes ({ name, cves: [{ id, what, fixed }] }), or null. */
|
|
343
|
+
export function serverHoles(server) {
|
|
344
|
+
const m = String(server || "").match(/^(Apache|nginx)\/(\d+\.\d+\.\d+)\b/i);
|
|
345
|
+
if (!m || DISTRO.test(server)) return null;
|
|
346
|
+
const sw = m[1].toLowerCase() === "nginx" ? "nginx" : "Apache",
|
|
347
|
+
cves = HOLES[sw].filter(h => h.hits(m[2])).map(({ id, what, fixed }) => ({ id, what, fixed }));
|
|
348
|
+
return cves.length ? { name: `${sw === "Apache" ? "Apache httpd" : "nginx"} ${m[2]}`, cves } : null;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// What a Set-Cookie header leaves out: Secure (judged only on HTTPS, as a local dev server leaves it off on purpose),
|
|
352
|
+
// HttpOnly (except on a CSRF token, which a script has to read) and SameSite. A cookie being deleted needs nothing.
|
|
353
|
+
export function cookieProblems(header, { https }) {
|
|
354
|
+
const [pair, ...parts] = header.split(";"),
|
|
355
|
+
name = pair.split("=")[0].trim();
|
|
356
|
+
const at = Object.fromEntries(
|
|
357
|
+
parts.map(p => {
|
|
358
|
+
const i = p.indexOf("=");
|
|
359
|
+
return [(i < 0 ? p : p.slice(0, i)).trim().toLowerCase(), i < 0 ? "" : p.slice(i + 1).trim()];
|
|
360
|
+
}),
|
|
361
|
+
);
|
|
362
|
+
if (("max-age" in at && Number(at["max-age"]) <= 0) || Date.parse(at.expires) < Date.now()) return [];
|
|
363
|
+
return [
|
|
364
|
+
https && !("secure" in at) && "no Secure",
|
|
365
|
+
!("httponly" in at) && !/csrf|xsrf/i.test(name) && "no HttpOnly",
|
|
366
|
+
!("samesite" in at) && "no SameSite",
|
|
367
|
+
].filter(Boolean);
|
|
368
|
+
}
|