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,297 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Live-origin HTTPS checks (certificate, redirects, HSTS), run only with --check-live against the production origin.
|
|
3
|
+
import tls from "node:tls";
|
|
4
|
+
|
|
5
|
+
export const CHECKS = {
|
|
6
|
+
"cert-untrusted": [
|
|
7
|
+
"TRUST-07",
|
|
8
|
+
"blocker",
|
|
9
|
+
() => "The HTTPS certificate isn't trusted",
|
|
10
|
+
"Browsers show a full-page security warning and search engines may not crawl the site over HTTPS.",
|
|
11
|
+
"Install a certificate from a trusted authority with its full chain (most hosts and CDNs do this automatically).",
|
|
12
|
+
],
|
|
13
|
+
"cert-expired": [
|
|
14
|
+
"TRUST-07",
|
|
15
|
+
"blocker",
|
|
16
|
+
() => "The HTTPS certificate has expired or expires within 2 days",
|
|
17
|
+
"Once it expires, every visitor gets a security warning and crawlers stop fetching pages.",
|
|
18
|
+
"Renew the certificate now and turn on automatic renewal.",
|
|
19
|
+
],
|
|
20
|
+
"cert-expiring": [
|
|
21
|
+
"TRUST-07",
|
|
22
|
+
"high",
|
|
23
|
+
() => "The HTTPS certificate expires soon",
|
|
24
|
+
"Less than a third of its lifetime (and under 30 days) is left, which usually means automatic renewal has stopped working.",
|
|
25
|
+
"Check the renewal job or the host's certificate settings and renew it.",
|
|
26
|
+
],
|
|
27
|
+
"cert-host-mismatch": [
|
|
28
|
+
"TRUST-07",
|
|
29
|
+
"blocker",
|
|
30
|
+
n => `The HTTPS certificate doesn't cover ${n} of the site's host names`,
|
|
31
|
+
"Visitors who type the other host (with or without www) get a security warning before any redirect can happen.",
|
|
32
|
+
"Issue the certificate for both the apex and the www host, then redirect one to the other.",
|
|
33
|
+
],
|
|
34
|
+
"https-unreachable": [
|
|
35
|
+
"TRUST-07",
|
|
36
|
+
"high",
|
|
37
|
+
() => "The HTTPS server refused the connection or timed out",
|
|
38
|
+
"Nobody could open the site over HTTPS during the check: the server or CDN refused the connection, dropped it or didn't answer in time. If it keeps happening, Google crawls less and pages drop out of search.",
|
|
39
|
+
"Check that the server or CDN is up and accepts connections on port 443, and that no firewall or rate limit blocks them. Run the check again to tell a lasting fault from a passing one.",
|
|
40
|
+
],
|
|
41
|
+
"https-missing": [
|
|
42
|
+
"TRUST-07",
|
|
43
|
+
"high",
|
|
44
|
+
() => "The site has no working HTTPS",
|
|
45
|
+
"Nothing answers with HTTPS for this host name: the server speaks only plain http://, or has no certificate set up for this name. Browsers mark every page “Not secure” and https:// links to the site fail.",
|
|
46
|
+
"Turn on HTTPS for this host name at the host or CDN (most issue a free certificate automatically), then redirect http:// to https:// with a 301.",
|
|
47
|
+
],
|
|
48
|
+
"http-not-redirected": [
|
|
49
|
+
"URL-03",
|
|
50
|
+
"high",
|
|
51
|
+
() => "http:// doesn't redirect to https://",
|
|
52
|
+
"The site is reachable on plain HTTP, so two versions exist and visitors can land on the insecure one.",
|
|
53
|
+
"Redirect every http:// URL to its https:// version with a 301 at the server or CDN.",
|
|
54
|
+
],
|
|
55
|
+
"http-redirect-hops": [
|
|
56
|
+
"URL-03",
|
|
57
|
+
"medium",
|
|
58
|
+
() => "http:// takes more than one redirect to reach https://",
|
|
59
|
+
"Every extra hop slows the first visit and loses a little signal.",
|
|
60
|
+
"Redirect http:// straight to the final https:// host in one 301.",
|
|
61
|
+
],
|
|
62
|
+
"host-not-redirected": [
|
|
63
|
+
"URL-03",
|
|
64
|
+
"high",
|
|
65
|
+
() => "The other host (with or without www) shows the site instead of redirecting",
|
|
66
|
+
"The site answers on both host names, so every page exists twice. Links and ranking signals split between the two, and Google picks one of them itself.",
|
|
67
|
+
"Redirect every URL on the other host to the same path on the preferred host with a 301, at the DNS host, CDN or server.",
|
|
68
|
+
],
|
|
69
|
+
"host-redirect-hops": [
|
|
70
|
+
"URL-03",
|
|
71
|
+
"medium",
|
|
72
|
+
() => "The other host takes more than one redirect to reach the preferred host",
|
|
73
|
+
"Every extra hop slows the visit and loses a little signal. (An http:// to https:// step on the same host first is fine.)",
|
|
74
|
+
"Redirect the other host straight to https:// on the preferred host in one 301.",
|
|
75
|
+
],
|
|
76
|
+
"host-redirect-drops-path": [
|
|
77
|
+
"URL-03",
|
|
78
|
+
"medium",
|
|
79
|
+
() => "The other host sends deeper pages to the home page",
|
|
80
|
+
"Links to pages on the other host (often old links with or without www) land on the home page instead of the page they named, so visitors get lost and Google treats them as soft 404s.",
|
|
81
|
+
"Keep the path when redirecting: `www.example.com/pricing/` must go to `example.com/pricing/`.",
|
|
82
|
+
],
|
|
83
|
+
"redirect-temporary": [
|
|
84
|
+
"URL-03",
|
|
85
|
+
"medium",
|
|
86
|
+
n => `${n} redirect(s) to the main https:// host are temporary (302, 303 or 307)`,
|
|
87
|
+
"A temporary redirect tells search engines the old address may come back, so they can keep the http:// or other-host address in results and pass less signal to the real one.",
|
|
88
|
+
"Make the redirect permanent: a 301 or 308 at the server or CDN.",
|
|
89
|
+
],
|
|
90
|
+
// One id for a missing header, from this live check or, without --check-live, from the crawled https home page.
|
|
91
|
+
"no-hsts": [
|
|
92
|
+
"TRUST-01",
|
|
93
|
+
"low",
|
|
94
|
+
() => "The site sends no Strict-Transport-Security header",
|
|
95
|
+
"Without HSTS, browsers can still make a first plain-HTTP request that can be intercepted.",
|
|
96
|
+
"Send `Strict-Transport-Security: max-age=31536000; includeSubDomains` from the server or CDN, once every subdomain works over HTTPS. hstspreload.org advises getting there in stages (`max-age=300`, then a week, then a month), checking for broken pages at each one.",
|
|
97
|
+
],
|
|
98
|
+
"tls-old-versions": [
|
|
99
|
+
"TRUST-01",
|
|
100
|
+
"low",
|
|
101
|
+
() => "The live site still accepts the old TLS 1.0 or 1.1",
|
|
102
|
+
"These versions have known weaknesses and were retired by the standard's own authors in 2021 (RFC 8996: they must not be used). Leaving them on only helps an attacker force a weaker connection.",
|
|
103
|
+
"Turn off TLS 1.0 and 1.1 in the server or CDN's TLS settings and keep TLS 1.2 and 1.3.",
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const DAY = 864e5;
|
|
108
|
+
const TEMPORARY = new Set([302, 303, 307]);
|
|
109
|
+
|
|
110
|
+
// The peer certificate of host:port, with whether it's trusted for that host name.
|
|
111
|
+
export function tlsCert(host, port = 443, timeoutMs = 10000) {
|
|
112
|
+
return new Promise((ok, fail) => {
|
|
113
|
+
const socket = tls.connect({ host, port, servername: host, rejectUnauthorized: false, timeout: timeoutMs }, () => {
|
|
114
|
+
const c = socket.getPeerCertificate();
|
|
115
|
+
ok({
|
|
116
|
+
authorized: socket.authorized,
|
|
117
|
+
authorizationError: socket.authorizationError ? String(socket.authorizationError) : null,
|
|
118
|
+
valid_from: c.valid_from,
|
|
119
|
+
valid_to: c.valid_to,
|
|
120
|
+
subjectaltname: c.subjectaltname || "",
|
|
121
|
+
});
|
|
122
|
+
socket.end();
|
|
123
|
+
});
|
|
124
|
+
socket.on("timeout", () => {
|
|
125
|
+
socket.destroy();
|
|
126
|
+
fail(Object.assign(new Error("timed out"), { code: "ETIMEDOUT" }));
|
|
127
|
+
});
|
|
128
|
+
socket.on("error", fail);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Node offers TLS 1.0 and 1.1 only with min and max version pinned to them and the OpenSSL security level at 0. A
|
|
133
|
+
// failed or timed-out handshake counts as refused, so a flaky connection never raises a finding.
|
|
134
|
+
// https://nodejs.org/api/tls.html#openssl-security-level
|
|
135
|
+
const accepts = (host, port, version, timeoutMs) =>
|
|
136
|
+
new Promise(ok => {
|
|
137
|
+
const socket = tls.connect(
|
|
138
|
+
{
|
|
139
|
+
host,
|
|
140
|
+
port,
|
|
141
|
+
servername: host,
|
|
142
|
+
rejectUnauthorized: false,
|
|
143
|
+
minVersion: version,
|
|
144
|
+
maxVersion: version,
|
|
145
|
+
ciphers: "DEFAULT@SECLEVEL=0",
|
|
146
|
+
timeout: timeoutMs,
|
|
147
|
+
},
|
|
148
|
+
() => {
|
|
149
|
+
ok(socket.getProtocol() === version);
|
|
150
|
+
socket.end();
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
socket.on("timeout", () => {
|
|
154
|
+
socket.destroy();
|
|
155
|
+
ok(false);
|
|
156
|
+
});
|
|
157
|
+
socket.on("error", () => ok(false));
|
|
158
|
+
});
|
|
159
|
+
export async function oldTlsVersions(host, port = 443, timeoutMs = 10000) {
|
|
160
|
+
const out = [];
|
|
161
|
+
for (const v of ["TLSv1", "TLSv1.1"]) if (await accepts(host, port, v, timeoutMs)) out.push(v);
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
const TLS_NAME = { TLSv1: "TLS 1.0", "TLSv1.1": "TLS 1.1" };
|
|
165
|
+
|
|
166
|
+
const covers = (san, host) =>
|
|
167
|
+
san
|
|
168
|
+
.split(",")
|
|
169
|
+
.map(s => s.trim().replace(/^DNS:/i, "").toLowerCase())
|
|
170
|
+
.some(
|
|
171
|
+
n =>
|
|
172
|
+
n === host ||
|
|
173
|
+
(n.startsWith("*.") && host.endsWith(n.slice(1)) && host.split(".").length === n.split(".").length),
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
// Redirects followed by hand until stop(url) or an answer that isn't one: each hop's status and the URL it came from.
|
|
177
|
+
async function walk(url, fetchFn, stop) {
|
|
178
|
+
const hops = [];
|
|
179
|
+
while (hops.length < 6 && !stop(url)) {
|
|
180
|
+
const r = await fetchFn(url, { redirect: "manual", signal: AbortSignal.timeout(15000) });
|
|
181
|
+
const loc = r.status >= 300 && r.status < 400 ? r.headers.get("location") : null;
|
|
182
|
+
if (!loc) return { hops, url, status: r.status };
|
|
183
|
+
hops.push({ from: url, status: r.status });
|
|
184
|
+
url = new URL(loc, url).href;
|
|
185
|
+
}
|
|
186
|
+
return { hops, url, status: null };
|
|
187
|
+
}
|
|
188
|
+
const trail = w => `${w.hops.map(h => h.status).join(" → ")} → ${w.url}`;
|
|
189
|
+
|
|
190
|
+
export async function checkLive(
|
|
191
|
+
origin,
|
|
192
|
+
{ add, now = Date.now(), connect = tlsCert, oldTls = oldTlsVersions, fetchFn = fetch, path },
|
|
193
|
+
) {
|
|
194
|
+
const notes = [],
|
|
195
|
+
o = new URL(origin),
|
|
196
|
+
host = o.hostname,
|
|
197
|
+
port = Number(o.port) || 443;
|
|
198
|
+
// The www/apex pair only exists for www.X and for a registrable apex (example.com, example.co.uk);
|
|
199
|
+
// a subdomain such as user.github.io or blog.example.com has no www twin to check.
|
|
200
|
+
const labels = host.split("."),
|
|
201
|
+
apex =
|
|
202
|
+
labels.length === 2 ||
|
|
203
|
+
(labels.length === 3 && /^(co|com|org|net|ac|gov|edu)$/.test(labels[1]) && labels[2].length === 2);
|
|
204
|
+
const other = host.startsWith("www.") ? host.slice(4) : apex ? "www." + host : null;
|
|
205
|
+
const temporary = (from, w) => {
|
|
206
|
+
if (w.hops.some(h => TEMPORARY.has(h.status))) add("redirect-temporary", from, trail(w));
|
|
207
|
+
};
|
|
208
|
+
let c, failed;
|
|
209
|
+
try {
|
|
210
|
+
c = await connect(host, port);
|
|
211
|
+
} catch (e) {
|
|
212
|
+
failed = e;
|
|
213
|
+
}
|
|
214
|
+
if (/^(ENOTFOUND|EAI_AGAIN)$/.test(failed?.code)) {
|
|
215
|
+
notes.push(
|
|
216
|
+
`Live check: ${host} doesn't resolve in DNS, so the certificate and redirects couldn't be checked. Check --site-origin, or run --check-live once the site is live.`,
|
|
217
|
+
);
|
|
218
|
+
return { notes, unresolved: true };
|
|
219
|
+
}
|
|
220
|
+
if (c) {
|
|
221
|
+
// Node also calls an expired certificate untrusted; it's reported once, as expired.
|
|
222
|
+
if (!c.authorized && c.authorizationError !== "CERT_HAS_EXPIRED")
|
|
223
|
+
add("cert-untrusted", origin, c.authorizationError || "not trusted");
|
|
224
|
+
const to = Date.parse(c.valid_to),
|
|
225
|
+
from = Date.parse(c.valid_from),
|
|
226
|
+
left = to - now;
|
|
227
|
+
if (left < 2 * DAY) add("cert-expired", origin, `valid until ${c.valid_to}`);
|
|
228
|
+
else if (left < Math.min(isNaN(from) ? Infinity : (to - from) / 3, 30 * DAY))
|
|
229
|
+
add("cert-expiring", origin, `${Math.floor(left / DAY)} days left, valid until ${c.valid_to}`);
|
|
230
|
+
// The other host only matters when it answers; then its certificate must name it.
|
|
231
|
+
let oc = null;
|
|
232
|
+
if (other)
|
|
233
|
+
try {
|
|
234
|
+
oc = await connect(other, port);
|
|
235
|
+
} catch {}
|
|
236
|
+
if (oc && !covers(oc.subjectaltname, other))
|
|
237
|
+
add("cert-host-mismatch", `https://${other}`, `certificate names: ${oc.subjectaltname || "none"}`);
|
|
238
|
+
const old = await oldTls(host, port);
|
|
239
|
+
if (old.length) add("tls-old-versions", origin, `accepts ${old.map(v => TLS_NAME[v]).join(" and ")}`);
|
|
240
|
+
}
|
|
241
|
+
// http:// → https://, with redirects followed by hand to count them.
|
|
242
|
+
let http = null;
|
|
243
|
+
try {
|
|
244
|
+
http = await walk(`http://${host}/`, fetchFn, u => u.startsWith("https:"));
|
|
245
|
+
if (!http.url.startsWith("https:"))
|
|
246
|
+
add("http-not-redirected", `http://${host}/`, http.hops.length ? `ends at ${http.url}` : "answers on plain http");
|
|
247
|
+
else if (http.hops.length > 1)
|
|
248
|
+
add("http-redirect-hops", `http://${host}/`, `${http.hops.length} hops to ${http.url}`);
|
|
249
|
+
temporary(`http://${host}/`, http);
|
|
250
|
+
} catch (e) {
|
|
251
|
+
notes.push(`Live check: http://${host}/ didn't answer (${e.message}).`);
|
|
252
|
+
}
|
|
253
|
+
// No HTTPS connection: no HTTPS at all when port 443 doesn't speak TLS or plain http:// serves the site instead;
|
|
254
|
+
// otherwise the server refused, dropped or didn't answer.
|
|
255
|
+
if (failed) {
|
|
256
|
+
const down =
|
|
257
|
+
/^(ECONNREFUSED|ECONNRESET|ETIMEDOUT|EHOSTUNREACH|ENETUNREACH)$/.test(failed.code) &&
|
|
258
|
+
!(http?.status && !http.url.startsWith("https:"));
|
|
259
|
+
add(down ? "https-unreachable" : "https-missing", origin, failed.message);
|
|
260
|
+
}
|
|
261
|
+
// The other host: its http and https home page, and one deeper page, must reach https on this host in one permanent
|
|
262
|
+
// hop with the path kept. One that doesn't resolve or answer is fine: there's only one host.
|
|
263
|
+
if (other)
|
|
264
|
+
for (const p of ["/", ...(path && path !== "/" ? [path] : [])])
|
|
265
|
+
for (const scheme of ["http", "https"]) {
|
|
266
|
+
const from = `${scheme}://${other}${p}`,
|
|
267
|
+
here = u => {
|
|
268
|
+
const x = new URL(u);
|
|
269
|
+
return x.hostname === host && x.protocol === "https:";
|
|
270
|
+
};
|
|
271
|
+
let w;
|
|
272
|
+
try {
|
|
273
|
+
w = await walk(from, fetchFn, u => here(u) || ![host, other].includes(new URL(u).hostname));
|
|
274
|
+
} catch {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (!here(w.url)) {
|
|
278
|
+
if (new URL(w.url).hostname === other && w.status >= 200 && w.status < 300)
|
|
279
|
+
add(
|
|
280
|
+
"host-not-redirected",
|
|
281
|
+
from,
|
|
282
|
+
w.hops.length ? `ends at ${w.url} (${w.status})` : `answers ${w.status} itself`,
|
|
283
|
+
);
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
// hstspreload.org asks http:// to go to https:// on the same host first, so that step doesn't count.
|
|
287
|
+
const upgrade = scheme === "http" && (w.hops[1]?.from ?? w.url) === `https://${other}${p}`;
|
|
288
|
+
if (w.hops.length - Number(upgrade) > 1) add("host-redirect-hops", from, `${w.hops.length} hops to ${w.url}`);
|
|
289
|
+
if (p !== "/" && new URL(w.url).pathname === "/") add("host-redirect-drops-path", from, `→ ${w.url}`);
|
|
290
|
+
temporary(from, w);
|
|
291
|
+
}
|
|
292
|
+
try {
|
|
293
|
+
const r = await fetchFn(origin + "/", { redirect: "manual", signal: AbortSignal.timeout(15000) });
|
|
294
|
+
if (!r.headers.get("strict-transport-security")) add("no-hsts", origin + "/");
|
|
295
|
+
} catch {}
|
|
296
|
+
return { notes };
|
|
297
|
+
}
|