@goosetools/goose-tools 0.0.0-stage → 0.1.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/README.md +98 -2
- package/bin/goose-tools.js +61 -0
- package/lib/check/src/agent.js +90 -0
- package/lib/check/src/analyze.js +311 -0
- package/lib/check/src/client.js +136 -0
- package/lib/check/src/copy.js +355 -0
- package/lib/check/src/fixes.js +153 -0
- package/lib/check/src/frame.js +92 -0
- package/lib/check/src/guard.js +441 -0
- package/lib/check/src/index.js +18 -0
- package/lib/check/src/mcp-http.js +169 -0
- package/lib/check/src/mcp.js +153 -0
- package/lib/check/src/scan.js +55 -0
- package/lib/check/src/stack.js +61 -0
- package/lib/check/src/tlds.js +3 -0
- package/lib/check/src/view.js +130 -0
- package/lib/check/src/worker.js +257 -0
- package/lib/engine/src/bots.js +146 -0
- package/lib/engine/src/directives.js +131 -0
- package/lib/engine/src/exposure.js +70 -0
- package/lib/engine/src/frontend.js +157 -0
- package/lib/engine/src/headers.js +76 -0
- package/lib/engine/src/hidden-text.js +425 -0
- package/lib/engine/src/html.js +794 -0
- package/lib/engine/src/index.js +20 -0
- package/lib/engine/src/php.js +316 -0
- package/lib/engine/src/policies.js +234 -0
- package/lib/engine/src/reach.js +199 -0
- package/lib/engine/src/robots.js +275 -0
- package/lib/engine/src/secrets.js +142 -0
- package/lib/engine/src/signals.js +144 -0
- package/lib/rules/data/bots.json.js +1 -0
- package/lib/rules/data/exposure.json.js +1 -0
- package/lib/rules/data/frontend.json.js +1 -0
- package/lib/rules/data/headers.json.js +1 -0
- package/lib/rules/data/secrets.json.js +1 -0
- package/lib/ui/LICENSE-Inter.txt +93 -0
- package/lib/ui/assets.js +5 -0
- package/package.json +37 -4
- package/src/local.js +61 -0
- package/src/mcp.js +61 -0
- package/src/setup.js +395 -0
- package/src/site/auth.js +287 -0
- package/src/site/beacon.js +462 -0
- package/src/site/collect.js +484 -0
- package/src/site/handler.js +405 -0
- package/src/site/index.js +88 -0
- package/src/site/limits.js +48 -0
- package/src/site/pages.js +75 -0
- package/src/site/qr.js +318 -0
- package/src/site/reports.js +1117 -0
- package/src/site/source.js +68 -0
- package/src/site/store-pg.js +225 -0
- package/src/site/store.js +249 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* goosetools.app/mcp: the check's MCP server (mcp.js) over Streamable HTTP, for chat apps that connect
|
|
3
|
+
* to a server address (Claude, ChatGPT). Stateless: no sessions, every POST answered on its own, JSON
|
|
4
|
+
* responses only (no SSE stream, since a check sends nothing before its result).
|
|
5
|
+
*
|
|
6
|
+
* Transport rules (MCP 2026-07-28, basic/transports/streamable-http):
|
|
7
|
+
* - POST only. GET and DELETE get 405. A notification gets 202 with no body.
|
|
8
|
+
* - An Origin header that is present and not allowed gets 403.
|
|
9
|
+
* - Modern requests: MCP-Protocol-Version must match _meta, Mcp-Method must match the method, and
|
|
10
|
+
* tools/call needs Mcp-Name matching the tool (Base64 form decoded). Otherwise 400 with -32020.
|
|
11
|
+
* An unsupported version is 400 with -32022; an unknown method is 404 with -32601.
|
|
12
|
+
* - Legacy requests (2025-11-25 and earlier): initialize is answered without a session id. Later
|
|
13
|
+
* requests carry MCP-Protocol-Version; one without it is taken as 2025-03-26, as the spec allows.
|
|
14
|
+
*
|
|
15
|
+
* CPU: the free Workers plan lists 10 ms a request. Warm, the check takes about 0.03 ms a KB of HTML
|
|
16
|
+
* on a laptop; cold (the first run in an isolate, which is most runs at low traffic) it costs several
|
|
17
|
+
* times that. Measured with wrangler tail on 2026-11-24, 18 calls: 3 to 182 ms of CPU, every outcome
|
|
18
|
+
* "ok" (none stopped for CPU). To keep the cost down, this server checks pages up to MCP_MAX_PAGE_KB
|
|
19
|
+
* (256 KB), reads up to MCP_MAX_SCRIPT_KB (1 MB) of scripts, and stops reading one byte past each limit.
|
|
20
|
+
* A larger page is sent to goosetools.app/check, which runs in the visitor's browser. Both limits are
|
|
21
|
+
* vars in wrangler.jsonc.
|
|
22
|
+
*/
|
|
23
|
+
import { answer, fail, isModern, MODERN, LEGACY, V } from './mcp.js';
|
|
24
|
+
import { runCheck, CheckError } from './client.js';
|
|
25
|
+
import { handle, FETCH_PATH, MAX_SUBREQUESTS } from './worker.js';
|
|
26
|
+
|
|
27
|
+
export const MCP_PATH = '/mcp';
|
|
28
|
+
export const VERSION = '0.1.0';
|
|
29
|
+
const MAX_BODY = 64 * 1024;
|
|
30
|
+
const ORIGINS = ['https://goosetools.app'];
|
|
31
|
+
const CODES = { headerMismatch: -32020 };
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {object} Env
|
|
35
|
+
* @property {{limit: (o: {key: string}) => Promise<{success: boolean}>}} [MCP_RATE_LIMITER] Checks a minute per address.
|
|
36
|
+
* @property {string} [MCP_MAX_PAGE_KB]
|
|
37
|
+
* @property {string} [MCP_MAX_SCRIPT_KB]
|
|
38
|
+
* @property {string} [ALLOWED_ORIGINS] Extra origins, comma-separated, for local development.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {Request} request
|
|
43
|
+
* @param {Env} env
|
|
44
|
+
* @param {{fetchImpl?: typeof fetch}} [deps] For tests.
|
|
45
|
+
* @returns {Promise<Response>}
|
|
46
|
+
*/
|
|
47
|
+
export async function handleMcp(request, env = {}, deps = {}) {
|
|
48
|
+
const origin = request.headers.get('origin');
|
|
49
|
+
const allowed = [...ORIGINS, ...(env.ALLOWED_ORIGINS || '').split(',').map((s) => s.trim()).filter(Boolean)];
|
|
50
|
+
if (origin && !allowed.includes(origin)) return json(403, fail(null, -32600, 'Origin not allowed'));
|
|
51
|
+
if (request.method !== 'POST') return new Response(null, { status: 405, headers: { allow: 'POST' } });
|
|
52
|
+
|
|
53
|
+
let msg;
|
|
54
|
+
try {
|
|
55
|
+
const raw = await request.text();
|
|
56
|
+
if (raw.length > MAX_BODY) return json(413, fail(null, -32600, 'Request too large'));
|
|
57
|
+
msg = JSON.parse(raw);
|
|
58
|
+
} catch {
|
|
59
|
+
return json(400, fail(null, -32700, 'Parse error'));
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(msg)) return json(400, fail(null, -32600, 'Batches are not supported'));
|
|
62
|
+
if (!msg || typeof msg !== 'object') return json(400, fail(null, -32600, 'Invalid request'));
|
|
63
|
+
// A notification, or a response to nothing this server sent: accepted, no body.
|
|
64
|
+
if (msg.id === undefined || (msg.method === undefined && ('result' in msg || 'error' in msg))) return new Response(null, { status: 202 });
|
|
65
|
+
|
|
66
|
+
const h = (name) => request.headers.get(name);
|
|
67
|
+
/** @type {string} */
|
|
68
|
+
let legacy = '2025-03-26';
|
|
69
|
+
if (isModern(msg)) {
|
|
70
|
+
const mismatch = headerMismatch(msg, h);
|
|
71
|
+
if (mismatch) return json(400, fail(msg.id, CODES.headerMismatch, `Header mismatch: ${mismatch}`));
|
|
72
|
+
} else {
|
|
73
|
+
const asked = h('mcp-protocol-version');
|
|
74
|
+
if (asked && MODERN.includes(asked)) return json(400, fail(msg.id, -32602, 'Missing _meta fields: protocolVersion and clientCapabilities are required.'));
|
|
75
|
+
if (asked && !LEGACY.includes(asked)) return json(400, fail(msg.id, -32600, `Unsupported protocol version: ${asked}`));
|
|
76
|
+
if (asked) legacy = asked;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const kb = (v, d) => (Number(v) > 0 ? Number(v) : d) * 1024;
|
|
80
|
+
const check = async (/** @type {string} */ url) => {
|
|
81
|
+
if (env.MCP_RATE_LIMITER) {
|
|
82
|
+
const { success } = await env.MCP_RATE_LIMITER.limit({ key: h('cf-connecting-ip') || 'unknown' });
|
|
83
|
+
if (!success) throw new CheckError('rate_limited');
|
|
84
|
+
}
|
|
85
|
+
const maxPageBytes = kb(env.MCP_MAX_PAGE_KB, 256);
|
|
86
|
+
const maxScriptBytes = kb(env.MCP_MAX_SCRIPT_KB, 1024);
|
|
87
|
+
const site = shared(deps.fetchImpl ?? globalThis.fetch.bind(globalThis), MAX_SUBREQUESTS);
|
|
88
|
+
// Reading stops one byte past each limit: a larger page is refused without reading all of it.
|
|
89
|
+
const limits = { fetchImpl: site, cache: null, pageMaxBytes: maxPageBytes + 1, scriptMaxBytes: maxScriptBytes + 1 };
|
|
90
|
+
const endpoint = (/** @type {string} */ path, /** @type {RequestInit} */ init) => handle(new Request('https://goosetools.app' + path, init), {}, {}, limits);
|
|
91
|
+
return runCheck(url, { fetchImpl: /** @type {any} */ (endpoint), endpoint: FETCH_PATH, maxPageBytes, maxScriptBytes });
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
let res;
|
|
95
|
+
try {
|
|
96
|
+
res = await answer(msg, { version: VERSION, check, legacy });
|
|
97
|
+
} catch {
|
|
98
|
+
return json(500, fail(msg.id, -32603, 'Internal error'));
|
|
99
|
+
}
|
|
100
|
+
if (!res) return new Response(null, { status: 202 });
|
|
101
|
+
return json(statusOf(res), res);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Why the mirrored headers do not match the body, or ''.
|
|
106
|
+
* @param {any} msg
|
|
107
|
+
* @param {(name: string) => string | null} h
|
|
108
|
+
*/
|
|
109
|
+
function headerMismatch(msg, h) {
|
|
110
|
+
const version = h('mcp-protocol-version');
|
|
111
|
+
if (!version) return 'MCP-Protocol-Version is missing';
|
|
112
|
+
if (version !== msg.params._meta[V]) return `MCP-Protocol-Version ${version} does not match the body`;
|
|
113
|
+
const method = h('mcp-method');
|
|
114
|
+
if (!method) return 'Mcp-Method is missing';
|
|
115
|
+
if (method !== msg.method) return `Mcp-Method ${method} does not match the body`;
|
|
116
|
+
if (msg.method === 'tools/call') {
|
|
117
|
+
const name = h('mcp-name');
|
|
118
|
+
if (name === null) return 'Mcp-Name is missing';
|
|
119
|
+
const decoded = decodeHeader(name);
|
|
120
|
+
if (decoded === null) return 'Mcp-Name is not valid';
|
|
121
|
+
if (decoded !== msg.params.name) return `Mcp-Name does not match the body`;
|
|
122
|
+
}
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A header value, with the =?base64?...?= form decoded.
|
|
128
|
+
* @param {string} v
|
|
129
|
+
* @returns {string | null}
|
|
130
|
+
*/
|
|
131
|
+
export function decodeHeader(v) {
|
|
132
|
+
const m = /^=\?base64\?([A-Za-z0-9+/=]*)\?=$/.exec(v);
|
|
133
|
+
if (!m) return v;
|
|
134
|
+
try {
|
|
135
|
+
const bin = atob(m[1]);
|
|
136
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(Uint8Array.from(bin, (c) => c.charCodeAt(0)));
|
|
137
|
+
} catch {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** @param {any} res */
|
|
143
|
+
function statusOf(res) {
|
|
144
|
+
if (!res.error) return 200;
|
|
145
|
+
const c = res.error.code;
|
|
146
|
+
if (c === -32601) return 404;
|
|
147
|
+
if (c === -32022 || c === -32020 || c === -32700 || c === -32600) return 400;
|
|
148
|
+
if (c === -32602 && /^Missing _meta/.test(res.error.message)) return 400;
|
|
149
|
+
return 200;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* One fetch budget for the whole check: both calls together stay under the Free plan's 50 subrequests.
|
|
154
|
+
* @param {typeof fetch} f
|
|
155
|
+
* @param {number} max
|
|
156
|
+
* @returns {typeof fetch}
|
|
157
|
+
*/
|
|
158
|
+
function shared(f, max) {
|
|
159
|
+
let n = 0;
|
|
160
|
+
return /** @type {typeof fetch} */ ((input, init) => (++n > max ? Promise.reject(new Error('subrequest budget')) : f(input, init)));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @param {number} status
|
|
165
|
+
* @param {object} body
|
|
166
|
+
*/
|
|
167
|
+
function json(status, body) {
|
|
168
|
+
return new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });
|
|
169
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The check as an MCP server: one read-only tool, check_site. Shared by both transports:
|
|
3
|
+
* - stdio, in the npm package (`npx @goosetools/goose-tools mcp`, package/src/mcp.js);
|
|
4
|
+
* - Streamable HTTP, at goosetools.app/mcp for chat apps (mcp-http.js).
|
|
5
|
+
*
|
|
6
|
+
* Both protocol eras are served (MCP 2026-07-28, "Versioning and Compatibility"):
|
|
7
|
+
* - Modern (2026-07-28): every request carries _meta io.modelcontextprotocol/protocolVersion and
|
|
8
|
+
* clientCapabilities, server/discover is implemented, and results carry resultType "complete"
|
|
9
|
+
* and serverInfo in _meta.
|
|
10
|
+
* - Legacy (2025-11-25 and earlier): an initialize handshake, then requests without _meta.
|
|
11
|
+
*/
|
|
12
|
+
import { CheckError } from './client.js';
|
|
13
|
+
import { addressProblem } from './copy.js';
|
|
14
|
+
import { forAgent, asText } from './agent.js';
|
|
15
|
+
|
|
16
|
+
export const MODERN = ['2026-07-28'];
|
|
17
|
+
export const LEGACY = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
|
|
18
|
+
export const V = 'io.modelcontextprotocol/protocolVersion';
|
|
19
|
+
export const CAPS = 'io.modelcontextprotocol/clientCapabilities';
|
|
20
|
+
const SERVER_INFO = 'io.modelcontextprotocol/serverInfo';
|
|
21
|
+
const MISSING_META = 'Missing _meta fields: protocolVersion and clientCapabilities are required.';
|
|
22
|
+
|
|
23
|
+
export const INSTRUCTIONS =
|
|
24
|
+
'check_site runs the free Goose Tools check on one public page: search and AI crawler access, page text without JavaScript, robots.txt and sitemap, HTTPS, security headers and secret keys in public JavaScript. Each finding has its fix for the detected stack. Apply fixes in the code, let the owner review and deploy, then run check_site again to confirm.';
|
|
25
|
+
|
|
26
|
+
export const TOOL = {
|
|
27
|
+
name: 'check_site',
|
|
28
|
+
title: 'Check a site',
|
|
29
|
+
description:
|
|
30
|
+
"Run the free Goose Tools check on one public page, for example https://yourproduct.dev/. Finds what keeps search engines and AI answers (ChatGPT, Claude, Perplexity, Bing, Google) out, missing security headers and secret keys in the page's JavaScript. Returns each finding with why it matters and the fix for the site's stack, plus what passed. Reads only public files, the same ones any browser can get. Changes nothing.",
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
url: { type: 'string', description: 'The page to check. A full address or a domain, for example yourproduct.dev.' },
|
|
35
|
+
},
|
|
36
|
+
required: ['url'],
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
},
|
|
39
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Why a check did not run, in words an agent can pass on. */
|
|
43
|
+
function refusal(e) {
|
|
44
|
+
if (e instanceof CheckError || (e && e.name === 'CheckError')) {
|
|
45
|
+
if (e.code === 'too_large') return 'This page is too large to check here. Check it at https://goosetools.app/check instead.';
|
|
46
|
+
return addressProblem(e.code);
|
|
47
|
+
}
|
|
48
|
+
return `The check could not run: ${(e && e.message) || 'unknown error'}.`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether a message is a modern request (protocol version in _meta).
|
|
53
|
+
* @param {any} msg
|
|
54
|
+
*/
|
|
55
|
+
export function isModern(msg) {
|
|
56
|
+
const meta = msg && msg.params && msg.params._meta;
|
|
57
|
+
return Boolean(meta && typeof meta === 'object' && V in meta);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {object} Options
|
|
62
|
+
* @property {string} version The server's version.
|
|
63
|
+
* @property {(url: string) => Promise<any>} check Runs the check; resolves to check/src/view.js output.
|
|
64
|
+
* @property {string | null} legacy The legacy version in force for requests without _meta, or null
|
|
65
|
+
* when an initialize must come first (stdio, before the handshake).
|
|
66
|
+
* @property {(id: unknown) => boolean} [cancelled] Whether the client cancelled this request.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Answer one JSON-RPC message.
|
|
71
|
+
* @param {any} msg
|
|
72
|
+
* @param {Options} o
|
|
73
|
+
* @returns {Promise<object | null>} The response, or null for a notification or a cancelled call.
|
|
74
|
+
*/
|
|
75
|
+
export async function answer(msg, o) {
|
|
76
|
+
if (!msg || typeof msg !== 'object' || msg.jsonrpc !== '2.0' || typeof msg.method !== 'string') {
|
|
77
|
+
if (msg && typeof msg === 'object' && msg.id !== undefined && msg.method === undefined && ('result' in msg || 'error' in msg)) return null; // a response to nothing we sent
|
|
78
|
+
return fail(msg && typeof msg === 'object' ? msg.id : null, -32600, 'Invalid request');
|
|
79
|
+
}
|
|
80
|
+
const { id, method, params } = msg;
|
|
81
|
+
if (id === undefined) return null; // notifications get no reply
|
|
82
|
+
const serverInfo = { name: 'goose-tools', title: 'Goose Tools', version: o.version };
|
|
83
|
+
const modern = isModern(msg);
|
|
84
|
+
const reply = (result) => ({ jsonrpc: '2.0', id, result: modern ? { resultType: 'complete', ...result, _meta: { [SERVER_INFO]: serverInfo } } : result });
|
|
85
|
+
|
|
86
|
+
if (modern) {
|
|
87
|
+
const meta = params._meta;
|
|
88
|
+
if (typeof meta[V] !== 'string' || !(CAPS in meta)) return fail(id, -32602, MISSING_META);
|
|
89
|
+
if (!MODERN.includes(meta[V])) return fail(id, -32022, 'Unsupported protocol version', { supported: [...MODERN, ...LEGACY], requested: meta[V] });
|
|
90
|
+
switch (method) {
|
|
91
|
+
case 'server/discover':
|
|
92
|
+
return reply({ supportedVersions: [...MODERN, ...LEGACY], capabilities: { tools: {} }, instructions: INSTRUCTIONS });
|
|
93
|
+
case 'ping':
|
|
94
|
+
return reply({});
|
|
95
|
+
case 'tools/list':
|
|
96
|
+
return reply({ tools: [TOOL] });
|
|
97
|
+
case 'tools/call':
|
|
98
|
+
return callTool(id, params, o, reply);
|
|
99
|
+
default:
|
|
100
|
+
return fail(id, -32601, `Method not found: ${method}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
switch (method) {
|
|
105
|
+
case 'initialize': {
|
|
106
|
+
const asked = params && params.protocolVersion;
|
|
107
|
+
return reply({ protocolVersion: LEGACY.includes(asked) ? asked : LEGACY[0], capabilities: { tools: {} }, serverInfo, instructions: INSTRUCTIONS });
|
|
108
|
+
}
|
|
109
|
+
case 'ping':
|
|
110
|
+
return reply({});
|
|
111
|
+
case 'tools/list':
|
|
112
|
+
return o.legacy ? reply({ tools: [TOOL] }) : fail(id, -32602, MISSING_META);
|
|
113
|
+
case 'tools/call':
|
|
114
|
+
return o.legacy ? callTool(id, params, o, reply) : fail(id, -32602, MISSING_META);
|
|
115
|
+
case 'server/discover':
|
|
116
|
+
return fail(id, -32602, MISSING_META);
|
|
117
|
+
default:
|
|
118
|
+
return fail(id, -32601, `Method not found: ${method}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @param {unknown} id
|
|
124
|
+
* @param {any} params
|
|
125
|
+
* @param {Options} o
|
|
126
|
+
* @param {(result: object) => object} reply
|
|
127
|
+
*/
|
|
128
|
+
async function callTool(id, params, o, reply) {
|
|
129
|
+
if (!params || params.name !== TOOL.name) return fail(id, -32602, `Unknown tool: ${params && params.name}`);
|
|
130
|
+
const args = params.arguments;
|
|
131
|
+
if (!args || typeof args.url !== 'string' || !args.url.trim()) {
|
|
132
|
+
return reply({ content: [{ type: 'text', text: 'Send url, the page to check, for example yourproduct.dev.' }], isError: true });
|
|
133
|
+
}
|
|
134
|
+
let result;
|
|
135
|
+
try {
|
|
136
|
+
result = forAgent(await o.check(args.url), o.version);
|
|
137
|
+
} catch (e) {
|
|
138
|
+
if (o.cancelled && o.cancelled(id)) return null;
|
|
139
|
+
return reply({ content: [{ type: 'text', text: refusal(e) }], isError: true });
|
|
140
|
+
}
|
|
141
|
+
if (o.cancelled && o.cancelled(id)) return null;
|
|
142
|
+
return reply({ content: [{ type: 'text', text: asText(result) }], structuredContent: result, isError: false });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @param {unknown} id
|
|
147
|
+
* @param {number} code
|
|
148
|
+
* @param {string} message
|
|
149
|
+
* @param {unknown} [data]
|
|
150
|
+
*/
|
|
151
|
+
export function fail(id, code, message, data) {
|
|
152
|
+
return { jsonrpc: '2.0', id: id ?? null, error: { code, message, ...(data === undefined ? {} : { data }) } };
|
|
153
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scanning screen's checklist: one row per check, built from a finished result (view.js).
|
|
3
|
+
* Every row shows what the check found. Nothing here is made up for effect: the screen only paces
|
|
4
|
+
* how fast real rows appear.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Crawler tokens as the scorecards name them, and what each one feeds (engine/src/reach.js). */
|
|
8
|
+
const ENGINE = { 'OAI-SearchBot': 'ChatGPT search', 'Claude-SearchBot': 'Claude', PerplexityBot: 'Perplexity', Bingbot: 'Bing and Copilot', Googlebot: 'Google Search' };
|
|
9
|
+
|
|
10
|
+
/** Result words per row kind and state (approved 2026-11-20). */
|
|
11
|
+
const SAYS = {
|
|
12
|
+
crawler: { ok: 'Allowed', risk: "Can't read this page", unknown: "Couldn't check" },
|
|
13
|
+
html_text: { ok: 'Found', attention: 'Empty before JavaScript runs', risk: 'Empty before JavaScript runs' },
|
|
14
|
+
hidden: { ok: 'None', attention: 'Found' },
|
|
15
|
+
sitemap: { ok: 'Listed', attention: 'Not listed', unknown: "Couldn't check" },
|
|
16
|
+
agree: { ok: 'Agree', attention: 'Disagree', unknown: "Couldn't check" },
|
|
17
|
+
hsts: { ok: 'Sent', attention: 'Needs a fix', unknown: "Couldn't check" },
|
|
18
|
+
header: { ok: 'Sent', attention: 'Missing' },
|
|
19
|
+
key: { ok: 'None found', risk: 'Found', unknown: "Couldn't check" },
|
|
20
|
+
};
|
|
21
|
+
const LABEL = { html_text: 'Text in the HTML', hidden: 'Hidden text', sitemap: 'Sitemap', agree: 'AI signals', hsts: 'Strict-Transport-Security' };
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {object} ScanRow
|
|
25
|
+
* @property {string} group Part label, as on the scorecards.
|
|
26
|
+
* @property {string} label What was checked.
|
|
27
|
+
* @property {'ok'|'attention'|'risk'|'unknown'} state
|
|
28
|
+
* @property {string} says What was found.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {ReturnType<typeof import('./view.js').view>} v
|
|
33
|
+
* @returns {{rows: ScanRow[], counts: {urgent: number, recommended: number, unchecked: number, passed: number}}}
|
|
34
|
+
*/
|
|
35
|
+
export function scanRows(v) {
|
|
36
|
+
/** @type {ScanRow[]} */
|
|
37
|
+
const rows = [{ group: 'Page', label: 'Reading the page', state: v.unreadable ? 'unknown' : 'ok', says: v.unreadable ? "Couldn't read it" : v.page.stack.length ? v.page.stack.join(' on ') : 'Read' }];
|
|
38
|
+
if (!v.unreadable) {
|
|
39
|
+
for (const part of [...v.seo.parts, ...v.security.parts]) {
|
|
40
|
+
for (const a of part.axes) {
|
|
41
|
+
const kind = part.id === 'reach' ? 'crawler' : part.id === 'headers' ? 'header' : part.id === 'keys' ? 'key' : a.id;
|
|
42
|
+
const label = part.id === 'reach' ? ENGINE[a.label] ?? a.label : LABEL[a.id] ?? a.label;
|
|
43
|
+
rows.push({ group: part.label, label, state: a.state, says: SAYS[kind]?.[a.state] ?? '' });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const fixes = v.unreadable ? [] : [...v.seo.fixes, ...v.security.fixes];
|
|
48
|
+
const counts = {
|
|
49
|
+
urgent: fixes.filter((f) => f.state === 'risk').length,
|
|
50
|
+
recommended: fixes.filter((f) => f.state === 'attention').length,
|
|
51
|
+
unchecked: v.unreadable ? 1 : fixes.filter((f) => f.state === 'unknown').length,
|
|
52
|
+
passed: rows.filter((r) => r.state === 'ok').length - 1,
|
|
53
|
+
};
|
|
54
|
+
return { rows, counts };
|
|
55
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a site is built with and where it is served from, so each finding shows the fix for that
|
|
3
|
+
* stack. Read from the page's HTML and response headers only. A guess, never a claim: when
|
|
4
|
+
* nothing matches, the fix steps fall back to the general ones.
|
|
5
|
+
*
|
|
6
|
+
* Signals used (each a default output of the tool named):
|
|
7
|
+
* - Next.js: /_next/static/, __NEXT_DATA__, <div id="__next">.
|
|
8
|
+
* - Nuxt: /_nuxt/, <div id="__nuxt">.
|
|
9
|
+
* - Astro: /_astro/, <meta name="generator" content="Astro ...">.
|
|
10
|
+
* - SvelteKit: /_app/immutable/.
|
|
11
|
+
* - Gatsby: <div id="___gatsby">.
|
|
12
|
+
* - Hugo, Jekyll, Eleventy: their generator meta tag.
|
|
13
|
+
* - Vite: a module script from /assets/ (Vite's default build folder). React when the page has
|
|
14
|
+
* <div id="root">, Vue when <div id="app">.
|
|
15
|
+
* - Hosts: cf-ray (Cloudflare), x-vercel-id (Vercel), fly-request-id
|
|
16
|
+
* (Fly.io), x-amz-cf-id (CloudFront), and the Server header (GitHub Pages, Caddy, nginx, Apache).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} html
|
|
21
|
+
* @param {Headers} headers
|
|
22
|
+
* @returns {{framework: string | null, host: string | null, cloudflare: boolean}}
|
|
23
|
+
*/
|
|
24
|
+
export function detect(html, headers) {
|
|
25
|
+
return { framework: framework(html), host: host(headers), cloudflare: headers.has('cf-ray') };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @param {string} html */
|
|
29
|
+
function framework(html) {
|
|
30
|
+
const head = html.slice(0, 200000);
|
|
31
|
+
const generator = /<meta[^>]+name=["']generator["'][^>]+content=["']([^"']+)/i.exec(head)?.[1] ?? /<meta[^>]+content=["']([^"']+)["'][^>]+name=["']generator["']/i.exec(head)?.[1] ?? '';
|
|
32
|
+
if (/\/_next\/static\/|__NEXT_DATA__|id=["']__next["']/.test(head)) return 'next';
|
|
33
|
+
if (/\/_nuxt\/|id=["']__nuxt["']/.test(head)) return 'nuxt';
|
|
34
|
+
if (/\/_astro\//.test(head) || /^Astro\b/i.test(generator)) return 'astro';
|
|
35
|
+
if (/\/_app\/immutable\//.test(head)) return 'sveltekit';
|
|
36
|
+
if (/id=["']___gatsby["']/.test(head)) return 'gatsby';
|
|
37
|
+
if (/^Hugo\b/i.test(generator)) return 'hugo';
|
|
38
|
+
if (/^Jekyll\b/i.test(generator)) return 'jekyll';
|
|
39
|
+
if (/^Eleventy\b/i.test(generator)) return 'eleventy';
|
|
40
|
+
if (/<script[^>]+type=["']module["'][^>]+src=["'][^"']*\/assets\/[^"']+\.js/i.test(head) || /<script[^>]+src=["'][^"']*\/assets\/[^"']+\.js["'][^>]+type=["']module["']/i.test(head)) {
|
|
41
|
+
if (/id=["']root["']/.test(head)) return 'vite-react';
|
|
42
|
+
if (/id=["']app["']/.test(head)) return 'vite-vue';
|
|
43
|
+
return 'vite';
|
|
44
|
+
}
|
|
45
|
+
if (!/<script\b/i.test(head)) return 'static';
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @param {Headers} headers */
|
|
50
|
+
function host(headers) {
|
|
51
|
+
const server = (headers.get('server') || '').toLowerCase();
|
|
52
|
+
if (headers.has('x-vercel-id') || server === 'vercel') return 'vercel';
|
|
53
|
+
if (headers.has('fly-request-id')) return 'fly';
|
|
54
|
+
if (server === 'github.com') return 'github-pages';
|
|
55
|
+
if (headers.has('x-amz-cf-id')) return 'cloudfront';
|
|
56
|
+
if (server.startsWith('caddy')) return 'caddy';
|
|
57
|
+
if (server.startsWith('nginx')) return 'nginx';
|
|
58
|
+
if (server.startsWith('apache')) return 'apache';
|
|
59
|
+
if (server === 'cloudflare') return 'cloudflare';
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// Generated by check/dev/update-tlds.mjs from https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
|
2
|
+
// Version 2026112000, Last Updated Fri Nov 20 07:07:01 2026 UTC. 1436 TLDs, lowercase; internationalized TLDs in punycode (xn--), as the URL parser returns them.
|
|
3
|
+
export const TLDS = new Set("aaa aarp abb abbott abbvie abc able abogado abudhabi ac academy accenture accountant accountants aco actor ad ads adult ae aeg aero aetna af afl africa ag agakhan agency ai aig airbus airforce airtel akdn al alibaba alipay allfinanz allstate ally alsace alstom am amazon americanexpress americanfamily amex amfam amica amsterdam analytics android anquan anz ao aol apartments app apple aq aquarelle ar arab aramco archi army arpa art arte as asda asia associates at athleta attorney au auction audi audible audio auspost author auto autos aw aws ax axa az azure ba baby baidu banamex band bank bar barcelona barclaycard barclays barefoot bargains baseball basketball bauhaus bayern bb bbc bbt bbva bcg bcn bd be beats beauty beer berlin best bestbuy bet bf bg bh bharti bi bible bid bike bing bingo bio biz bj black blackfriday blockbuster blog bloomberg blue bm bms bmw bn bnpparibas bo boats boehringer bofa bom bond boo book booking bosch bostik boston bot boutique box br bradesco bridgestone broadway broker brother brussels bs bt build builders business buy buzz bv bw by bz bzh ca cab cafe cal call calvinklein cam camera camp canon capetown capital capitalone car caravan cards care career careers cars casa case cash casino cat catering catholic cba cbn cbre cc cd center ceo cern cf cfa cfd cg ch chanel channel charity chase chat cheap chintai christmas chrome church ci cipriani circle cisco citadel citi citic city ck cl claims cleaning click clinic clinique clothing cloud club clubmed cm cn co coach codes coffee college cologne com commbank community company compare computer comsec condos construction consulting contact contractors cooking cool coop corsica country coupon coupons courses cpa cr credit creditcard creditunion cricket crown crs cruise cruises cu cuisinella cv cw cx cy cymru cyou cz dad dance data date dating datsun day dclk dds de deal dealer deals degree delivery dell deloitte delta democrat dental dentist desi design dev dhl diamonds diet digital direct directory discount discover dish diy dj dk dm dnp do docs doctor dog domains dot download drive dtv dubai dupont durban dvag dvr dz earth eat ec eco edeka edu education ee eg email emerck energy engineer engineering enterprises epson equipment er ericsson erni es esq estate et eu eurovision eus events exchange expert exposed express extraspace fage fail fairwinds faith family fan fans farm farmers fashion fast fedex feedback ferrari ferrero fi fidelity fido film final finance financial fire firestone firmdale fish fishing fit fitness fj fk flickr flights flir florist flowers fly fm fo foo food football ford forex forsale forum foundation fox fr free fresenius frl frogans frontier ftr fujitsu fun fund furniture futbol fyi ga gal gallery gallo gallup game games gap garden gay gb gbiz gd gdn ge gea gent genting george gf gg ggee gh gi gift gifts gives giving gl glass gle global globo gm gmail gmbh gmo gmx gn godaddy gold goldpoint golf goodyear goog google gop got gov gp gq gr grainger graphics gratis green gripe grocery group gs gt gu gucci guge guide guitars guru gw gy hair hamburg hangout haus hbo hdfc hdfcbank health healthcare help here hermes hiphop hisamitsu hitachi hiv hk hkt hm hn hockey holdings holiday homedepot homegoods homes homesense honda horse hospital host hosting hot hotels hotmail house how hr hsbc ht hu hughes hyatt hyundai ibm icbc ice icu id ie ieee ifm ikano il im imamat imdb immo immobilien in inc industries infiniti info ing ink institute insurance insure int international intuit investments io ipiranga iq ir irish is ismaili ist istanbul it itau itv jaguar java jcb je jeep jetzt jewelry jio jll jm jmp jnj jo jobs joburg jot joy jp jpmorgan jprs juegos kaufen kddi ke kerryhotels kerryproperties kfh kg kh ki kia kids kim kindle kitchen kiwi km kn koeln komatsu kosher kp kpmg kpn kr krd kred kuokgroup kw ky kyoto kz la lacaixa lamborghini lamer land landrover lanxess lasalle lat latino latrobe law lawyer lb lc lds lease leclerc lefrak legal lego lexus lgbt li lidl life lifeinsurance lifestyle lighting like lilly limited limo lincoln link live living lk llc llp loan loans locker locus lol london lotte lotto love lpl lplfinancial lr ls lt ltd ltda lu lundbeck luxe luxury lv ly ma madrid maif maison makeup man management mango map market marketing markets marriott marshalls mattel mba mc mckinsey md me med media meet melbourne meme memorial men menu merck merckmsd mg mh miami microsoft mil mini mint mit mitsubishi mk ml mlb mls mm mma mn mo mobi mobile moda moe moi mom monash money monster mormon mortgage moscow moto motorcycles mov movie mp mq mr ms msd mt mtn mtr mu museum music mv mw mx my mz na nab nagoya name navy nba nc ne nec net netbank netflix network neustar new news next nextdirect nexus nf nfl ng ngo nhk ni nico nike nikon ninja nissan nissay nl no nokia norton now nowruz nowtv np nr nra nrw ntt nu nyc nz obi observer office okinawa olayan olayangroup ollo om omega one ong onl online ooo open oracle orange org organic origins osaka otsuka ott ovh pa page panasonic paris pars partners parts party pay pccw pe pet pf pfizer pg ph pharmacy phd philips phone photo photography photos physio pics pictet pictures pid pin ping pink pioneer pizza pk pl place play playstation plumbing plus pm pn pnc pohl poker politie porn post pr praxi press prime pro prod productions prof progressive promo properties property protection pru prudential ps pt pub pw pwc py qa qpon quebec quest racing radio re read realestate realtor realty recipes red redumbrella rehab reise reisen reit reliance ren rent rentals repair report republican rest restaurant review reviews rexroth rich richardli ricoh ril rio rip ro rocks rodeo rogers room rs rsvp ru rugby ruhr run rw rwe ryukyu sa saarland safe safety sakura sale salon samsclub samsung sandvik sandvikcoromant sanofi sap sarl sas save saxo sb sbi sbs sc scb schaeffler schmidt scholarships school schule schwarz science scot sd se search seat secure security seek select sener services seven sew sex sexy sfr sg sh shangrila sharp shell shia shiksha shoes shop shopping shouji show si silk sina singles site sj sk ski skin sky skype sl sling sm smart smile sn sncf so soccer social softbank software sohu solar solutions song sony soy spa space sport spot sr srl ss st stada staples star statebank statefarm stc stcgroup stockholm storage store stream studio study style su sucks supplies supply support surf surgery suzuki sv swatch swiss sx sy sydney systems sz tab taipei talk taobao target tatamotors tatar tattoo tax taxi tc tci td tdk team tech technology tel temasek tennis teva tf tg th thd theater theatre tiaa tickets tienda tips tires tirol tj tjmaxx tjx tk tkmaxx tl tm tmall tn to today tokyo tools top toray toshiba total tours town toyota toys tr trade trading training travel travelers travelersinsurance trust trv tt tube tui tunes tushu tv tvs tw tz ua ubank ubs ug uk unicom university uno uol ups us uy uz va vacations vana vanguard vc ve vegas ventures verisign versicherung vet vg vi viajes video vig viking villas vin vip virgin visa vision viva vivo vlaanderen vn vodka volvo vote voting voto voyage vu wales walmart walter wang wanggou watch watches weather weatherchannel web webcam weber website wed wedding weibo weir wf whoswho wien wiki williamhill win windows wine winners wme woodside work works world wow ws wtc wtf xbox xerox xihuan xin xn--11b4c3d xn--1ck2e1b xn--1qqw23a xn--2scrj9c xn--30rr7y xn--3bst00m xn--3ds443g xn--3e0b707e xn--3hcrj9c xn--3pxu8k xn--42c2d9a xn--45br5cyl xn--45brj9c xn--45q11c xn--4dbrk0ce xn--4gbrim xn--54b7fta0cc xn--55qw42g xn--55qx5d xn--5su34j936bgsg xn--5tzm5g xn--6frz82g xn--6qq986b3xl xn--80adxhks xn--80ao21a xn--80aqecdr1a xn--80asehdb xn--80aswg xn--8y0a063a xn--90a3ac xn--90ae xn--90ais xn--9dbq2a xn--9et52u xn--9krt00a xn--b4w605ferd xn--bck1b9a5dre4c xn--c1avg xn--c2br7g xn--cck2b3b xn--cckwcxetd xn--cg4bki xn--clchc0ea0b2g2a9gcd xn--czr694b xn--czrs0t xn--czru2d xn--d1acj3b xn--d1alf xn--e1a4c xn--eckvdtc9d xn--efvy88h xn--fct429k xn--fhbei xn--fiq228c5hs xn--fiq64b xn--fiqs8s xn--fiqz9s xn--fjq720a xn--flw351e xn--fpcrj9c3d xn--fzc2c9e2c xn--fzys8d69uvgm xn--g2xx48c xn--gckr3f0f xn--gecrj9c xn--gk3at1e xn--h2breg3eve xn--h2brj9c xn--h2brj9c8c xn--hxt814e xn--i1b6b1a6a2e xn--imr513n xn--io0a7i xn--j1aef xn--j1amh xn--j6w193g xn--jlq480n2rg xn--jvr189m xn--kcrx77d1x4a xn--kprw13d xn--kpry57d xn--kput3i xn--l1acc xn--lgbbat1ad8j xn--mgb9awbf xn--mgba3a3ejt xn--mgba3a4f16a xn--mgba7c0bbn0a xn--mgbaam7a8h xn--mgbab2bd xn--mgbah1a3hjkrd xn--mgbai9azgqp6j xn--mgbayh7gpa xn--mgbbh1a xn--mgbbh1a71e xn--mgbc0a9azcg xn--mgbca7dzdo xn--mgbcpq6gpa1a xn--mgberp4a5d4ar xn--mgbgu82a xn--mgbi4ecexp xn--mgbpl2fh xn--mgbt3dhd xn--mgbtx2b xn--mgbx4cd0ab xn--mix891f xn--mk1bu44c xn--mxtq1m xn--ngbc5azd xn--ngbe9e0a xn--ngbrx xn--node xn--nqv7f xn--nqv7fs00ema xn--nyqy26a xn--o3cw4h xn--ogbpf8fl xn--otu796d xn--p1acf xn--p1ai xn--pgbs0dh xn--pssy2u xn--q7ce6a xn--q9jyb4c xn--qcka1pmc xn--qxa6a xn--qxam xn--rhqv96g xn--rovu88b xn--rvc1e0am3e xn--s9brj9c xn--ses554g xn--t60b56a xn--tckwe xn--tiq49xqyj xn--unup4y xn--vermgensberater-ctb xn--vermgensberatung-pwb xn--vhquv xn--vuq861b xn--w4r85el8fhu5dnra xn--w4rs40l xn--wgbh1c xn--wgbl6a xn--xhq521b xn--xkc2al3hye2a xn--xkc2dl3a5ee0h xn--y9a3aq xn--yfro4i67o xn--ygbi2ammx xn--zfr164b xxx xyz yachts yahoo yamaxun yandex ye yodobashi yoga yokohama you youtube yt yun za zappos zara zero zip zm zone zuerich zw".split(' '));
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A check result, shaped for the approved results page: the SEO/AEO and Security overviews, each
|
|
3
|
+
* with scorecard parts, What to do rows, What passed groups, a headline and Information.
|
|
4
|
+
*
|
|
5
|
+
* States are the plugin's: ok, attention (Recommended), risk (Urgent), unknown (Couldn't check).
|
|
6
|
+
*/
|
|
7
|
+
import * as copy from './copy.js';
|
|
8
|
+
import { fixSteps } from './fixes.js';
|
|
9
|
+
|
|
10
|
+
const STATE = { urgent: 'risk', recommended: 'attention', unchecked: 'unknown' };
|
|
11
|
+
|
|
12
|
+
/** Scorecard parts and their axes (labels approved 2026-11-20). */
|
|
13
|
+
const PARTS = {
|
|
14
|
+
reach: { label: 'Crawlers', caption: 'crawlers allowed', group: 'AI and search reach' },
|
|
15
|
+
text: { label: 'Page text', caption: 'checks passed', group: 'Text without JavaScript' },
|
|
16
|
+
robots: { label: 'robots.txt', caption: 'checks passed', group: 'robots.txt and sitemap' },
|
|
17
|
+
https: { label: 'HTTPS', caption: 'checks passed', group: 'HTTPS' /* approved 2026-11-20 */ },
|
|
18
|
+
headers: { label: 'Headers', caption: 'headers sent', group: 'Security headers' },
|
|
19
|
+
keys: { label: 'Keys in JS', caption: 'checks passed', group: 'Keys in public JavaScript' },
|
|
20
|
+
};
|
|
21
|
+
const ENGINE_AXES = [['OAI-SearchBot', 'oai'], ['Claude-SearchBot', 'claude'], ['PerplexityBot', 'pplx'], ['Bingbot', 'bing'], ['Googlebot', 'google']];
|
|
22
|
+
const HEADER_AXES = [['X-Frame-Options', 'xfo'], ['X-Content-Type-Options', 'xcto'], ['Referrer-Policy', 'referrer']];
|
|
23
|
+
const KEY_AXES = [['supabase_service_role', 'supabase', 'Supabase service_role'], ['openai', 'openai', 'OpenAI API key'], ['stripe', 'stripe', 'Stripe secret key']];
|
|
24
|
+
|
|
25
|
+
const FRAMEWORK = { next: 'Next.js', nuxt: 'Nuxt', astro: 'Astro', sveltekit: 'SvelteKit', gatsby: 'Gatsby', hugo: 'Hugo', jekyll: 'Jekyll', eleventy: 'Eleventy', 'vite-react': 'Vite and React', 'vite-vue': 'Vite and Vue', vite: 'Vite', static: 'Static HTML' };
|
|
26
|
+
const HOST = { cloudflare: 'Cloudflare', vercel: 'Vercel', fly: 'Fly.io', 'github-pages': 'GitHub Pages', cloudfront: 'Amazon CloudFront', caddy: 'Caddy', nginx: 'nginx', apache: 'Apache' };
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {import('./analyze.js').Result} r
|
|
30
|
+
* @param {number} checkedAt Unix seconds.
|
|
31
|
+
*/
|
|
32
|
+
export function view(r, checkedAt) {
|
|
33
|
+
const path = r.url ? new URL(r.url).pathname : '/';
|
|
34
|
+
const ctx = { path, cloudflare: Boolean(r.stack.cloudflare), host: r.host, stack: r.stack };
|
|
35
|
+
const has = (id, pred = () => true) => r.findings.find((f) => f.id === id && pred(f));
|
|
36
|
+
const passed = (id, pred = () => true) => r.passed.find((p) => p.id === id && pred(p));
|
|
37
|
+
|
|
38
|
+
const axis = (id, label, state) => ({ id, label, state, passed: state === 'ok' ? 1 : 0, total: 1, before: {} });
|
|
39
|
+
const stateOf = (f) => (f ? STATE[f.level] ?? 'ok' : 'ok');
|
|
40
|
+
const robotsDown = has('robots_unreadable');
|
|
41
|
+
|
|
42
|
+
const reach = ENGINE_AXES.map(([token, id]) => {
|
|
43
|
+
if (robotsDown) return axis(id, token, 'unknown');
|
|
44
|
+
const refused = has('crawlers_refused', (f) => f.data.engines.some((e) => e.token === token));
|
|
45
|
+
const noindex = has('noindex', (f) => f.data.engines.some((e) => e.token === token));
|
|
46
|
+
return axis(id, token, refused || noindex ? 'risk' : 'ok');
|
|
47
|
+
});
|
|
48
|
+
const text = [axis('html_text', 'Text in the HTML', stateOf(has('empty_page'))), axis('hidden', 'No hidden text', stateOf(has('hidden_text')))];
|
|
49
|
+
const robots = [
|
|
50
|
+
axis('sitemap', 'Sitemap listed', robotsDown ? 'unknown' : stateOf(has('sitemap_missing'))),
|
|
51
|
+
axis('agree', 'Signals agree', robotsDown ? 'unknown' : stateOf(has('signals_disagree'))),
|
|
52
|
+
];
|
|
53
|
+
const https = [axis('hsts', 'Strict-Transport-Security', stateOf(has('hsts')))];
|
|
54
|
+
const missing = has('headers_missing')?.data.missing ?? [];
|
|
55
|
+
const headers = HEADER_AXES.map(([name, id]) => axis(id, name, missing.includes(name) ? 'attention' : 'ok'));
|
|
56
|
+
const unread = has('scripts_unread');
|
|
57
|
+
const keys = KEY_AXES.map(([type, id, label]) => axis(id, label, has('key_leaked', (f) => f.data.type === type) ? 'risk' : unread ? 'unknown' : 'ok'));
|
|
58
|
+
|
|
59
|
+
const part = (id, axes) => {
|
|
60
|
+
const ok = axes.filter((a) => a.state === 'ok').length;
|
|
61
|
+
const state = axes.some((a) => a.state === 'risk') ? 'risk' : ok === axes.length ? 'ok' : axes.some((a) => a.state === 'attention') ? 'attention' : 'unknown';
|
|
62
|
+
return { id, label: PARTS[id].label, caption: PARTS[id].caption, axes, passed: ok, total: axes.length, state, before: {} };
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const rows = (areas) =>
|
|
66
|
+
r.findings
|
|
67
|
+
.filter((f) => areas.includes(f.area) && f.level !== 'info' && !(f.id === 'robots_unreadable' || f.id === 'scripts_unread' || f.id === 'page_unreadable'))
|
|
68
|
+
.map((f) => {
|
|
69
|
+
const t = copy.todo(f, ctx);
|
|
70
|
+
const steps = fixSteps(f, ctx);
|
|
71
|
+
return { id: f.id + (f.id === 'key_leaked' ? '-' + f.data.type : ''), state: STATE[f.level], title: t.title, verdict: t.verdict, found: t.found, pro: t.pro, code: steps.html, button: t.button, cloudflare: Boolean(steps.cloudflare && ctx.cloudflare) };
|
|
72
|
+
});
|
|
73
|
+
const unchecked = (areas) =>
|
|
74
|
+
r.findings
|
|
75
|
+
.filter((f) => areas.includes(f.area) && (f.id === 'robots_unreadable' || f.id === 'scripts_unread'))
|
|
76
|
+
.map((f) => ({
|
|
77
|
+
id: f.id,
|
|
78
|
+
state: 'unknown',
|
|
79
|
+
title: f.id === 'robots_unreadable' ? "Couldn't read robots.txt" /* approved 2026-11-20 */ : "Couldn't read some scripts" /* approved 2026-11-20 */,
|
|
80
|
+
verdict: f.id === 'robots_unreadable' ? `${copy.reason(f.data)} Crawler access was not checked.` /* approved 2026-11-20 */ : `${f.data.unread.length} of the page's scripts couldn't be read. Keys in them were not checked.` /* approved 2026-11-20 */,
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
const axesOf = { reach, text, robots, https, headers, keys };
|
|
84
|
+
const groups = (areas) =>
|
|
85
|
+
areas
|
|
86
|
+
.map((a) => {
|
|
87
|
+
const ax = axesOf[a];
|
|
88
|
+
const items = r.passed.filter((p) => p.area === a && !p.data.info).map(copy.passLine).filter(Boolean);
|
|
89
|
+
if (!items.length) return null;
|
|
90
|
+
const g = { part: a, name: PARTS[a].group, passed: ax.filter((x) => x.state === 'ok').length, total: ax.length, items };
|
|
91
|
+
if (a === 'reach' && items.length === ENGINE_AXES.length) g.lede = `robots.txt allows every search and answer crawler checked. The ${path === '/' ? 'home page' : 'page'} has no noindex.`; // approved
|
|
92
|
+
if (a === 'reach') {
|
|
93
|
+
const u = passed('user_fetchers');
|
|
94
|
+
if (u && u.data.allowed.length === 3 && !u.data.refused.length) g.note = 'ChatGPT-User, Claude-User and Perplexity-User are allowed too. They fetch a page when a person asks for it.'; // approved
|
|
95
|
+
}
|
|
96
|
+
if (a === 'keys') {
|
|
97
|
+
const k = passed('no_key');
|
|
98
|
+
if (k) g.lede = copy.scriptsLede(k.data.scripts, k.data.bytes, k.data.inline);
|
|
99
|
+
}
|
|
100
|
+
return g;
|
|
101
|
+
})
|
|
102
|
+
.filter(Boolean);
|
|
103
|
+
|
|
104
|
+
const seoFindings = r.findings.filter((f) => ['reach', 'text', 'robots'].includes(f.area) && f.level !== 'info');
|
|
105
|
+
const secFindings = r.findings.filter((f) => ['https', 'headers', 'keys'].includes(f.area));
|
|
106
|
+
const worstState = (fs) => (fs.some((f) => f.level === 'urgent') ? 'risk' : fs.some((f) => f.level === 'recommended') ? 'attention' : fs.some((f) => f.level === 'unchecked') ? 'unknown' : 'ok');
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
page: {
|
|
110
|
+
url: r.url,
|
|
111
|
+
host: r.host,
|
|
112
|
+
checkedAt,
|
|
113
|
+
stack: [FRAMEWORK[r.stack.framework], r.stack.host && r.stack.host !== 'cloudflare' ? HOST[r.stack.host] + (r.stack.cloudflare ? ' behind Cloudflare' : '') : r.stack.cloudflare ? 'Cloudflare' : null].filter(Boolean),
|
|
114
|
+
},
|
|
115
|
+
unreadable: r.state === 'unchecked' ? copy.reason(r.findings[0].data) : null,
|
|
116
|
+
seo: {
|
|
117
|
+
parts: [part('reach', reach), part('text', text), part('robots', robots)],
|
|
118
|
+
fixes: [...rows(['reach', 'text', 'robots']), ...unchecked(['reach', 'text', 'robots'])],
|
|
119
|
+
groups: groups(['reach', 'text', 'robots']),
|
|
120
|
+
headline: { state: worstState(seoFindings), text: copy.seoHeadline(seoFindings[0] ?? null, path) },
|
|
121
|
+
info: r.findings.filter((f) => f.level === 'info').map((f) => copy.info(f, ctx)).filter(Boolean),
|
|
122
|
+
},
|
|
123
|
+
security: {
|
|
124
|
+
parts: [part('https', https), part('headers', headers), part('keys', keys)],
|
|
125
|
+
fixes: [...rows(['https', 'headers', 'keys']), ...unchecked(['https', 'headers', 'keys'])],
|
|
126
|
+
groups: groups(['https', 'headers', 'keys']),
|
|
127
|
+
headline: { state: worstState(secFindings), text: copy.securityHeadline(secFindings) },
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|