@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,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The check page's client: one check, start to finish, in the visitor's browser.
|
|
3
|
+
*
|
|
4
|
+
* 1. Ask the Worker for the page, robots.txt, sitemap.xml and llms.txt.
|
|
5
|
+
* 2. Ask it for the page's own scripts, when the page loads any.
|
|
6
|
+
* 3. Run every check here (analyze.js) and shape the result for the page (view.js).
|
|
7
|
+
*
|
|
8
|
+
* Nothing leaves the browser except the two requests to the Worker.
|
|
9
|
+
*/
|
|
10
|
+
import { unframe } from './frame.js';
|
|
11
|
+
import { analyze, scriptUrls } from './analyze.js';
|
|
12
|
+
import { view } from './view.js';
|
|
13
|
+
import { validateTarget } from './guard.js';
|
|
14
|
+
|
|
15
|
+
export const ENDPOINT = '/check/fetch';
|
|
16
|
+
|
|
17
|
+
/** A check that could not start or could not reach the Worker. `code` picks the sentence (copy.addressProblem). */
|
|
18
|
+
export class CheckError extends Error {
|
|
19
|
+
/** @param {string} code */
|
|
20
|
+
constructor(code) {
|
|
21
|
+
super(code);
|
|
22
|
+
this.name = 'CheckError';
|
|
23
|
+
this.code = code;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What the visitor typed, as a URL to check. "yourproduct.dev" becomes "https://yourproduct.dev/".
|
|
29
|
+
* @param {string} input
|
|
30
|
+
* @returns {string}
|
|
31
|
+
* @throws {CheckError}
|
|
32
|
+
*/
|
|
33
|
+
export function normalize(input) {
|
|
34
|
+
const raw = String(input ?? '').trim();
|
|
35
|
+
if (!raw || /\s/.test(raw)) throw new CheckError('bad_url');
|
|
36
|
+
// A scheme is kept as typed (the guard refuses anything but http and https); without one, https.
|
|
37
|
+
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw) ? raw : 'https://' + raw;
|
|
38
|
+
const t = validateTarget(withScheme);
|
|
39
|
+
if (!t.ok) {
|
|
40
|
+
// A name with no dot ("yourproduct") is most likely a typo, not a private network. localhost stays as it is.
|
|
41
|
+
const host = (() => {
|
|
42
|
+
try {
|
|
43
|
+
return new URL(withScheme).hostname;
|
|
44
|
+
} catch {
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
48
|
+
// "localhost:3000": the name is the real problem, not the port.
|
|
49
|
+
if (t.code === 'bad_port' && host) {
|
|
50
|
+
const bare = validateTarget('https://' + host + '/');
|
|
51
|
+
if (!bare.ok) throw new CheckError(bare.code);
|
|
52
|
+
}
|
|
53
|
+
const typo = (t.code === 'bad_hostname' || t.code === 'blocked_host') && host && !host.includes('.') && !host.includes(':') && host !== 'localhost';
|
|
54
|
+
throw new CheckError(typo ? 'bad_url' : t.code);
|
|
55
|
+
}
|
|
56
|
+
return t.url.href;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {typeof fetch} fetchImpl
|
|
61
|
+
* @param {string} endpoint
|
|
62
|
+
* @param {object} body
|
|
63
|
+
* @returns {Promise<import('./frame.js').Part[]>}
|
|
64
|
+
* @throws {CheckError}
|
|
65
|
+
*/
|
|
66
|
+
async function call(fetchImpl, endpoint, body) {
|
|
67
|
+
let res;
|
|
68
|
+
try {
|
|
69
|
+
res = await fetchImpl(endpoint, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
70
|
+
} catch {
|
|
71
|
+
throw new CheckError('service');
|
|
72
|
+
}
|
|
73
|
+
if (res.status === 429) throw new CheckError('rate_limited');
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const err = await res.json().catch(() => null);
|
|
76
|
+
const code = err && err.error && typeof err.error.code === 'string' ? err.error.code : 'service';
|
|
77
|
+
throw new CheckError(res.status === 400 ? code : 'service');
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
return unframe(await res.arrayBuffer());
|
|
81
|
+
} catch {
|
|
82
|
+
throw new CheckError('service');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Run one check.
|
|
88
|
+
* @param {string} input What the visitor typed.
|
|
89
|
+
* @param {object} [opts]
|
|
90
|
+
* @param {typeof fetch} [opts.fetchImpl]
|
|
91
|
+
* @param {string} [opts.endpoint]
|
|
92
|
+
* @param {(step: number) => void} [opts.onStep] 0: site files, 1: scripts, 2: the checks.
|
|
93
|
+
* @param {() => number} [opts.now] Unix seconds.
|
|
94
|
+
* @param {number} [opts.maxPageBytes] Refuse a larger page (CheckError too_large). The check page sets none;
|
|
95
|
+
* the chat-app server sets one to stay inside the Workers CPU limit.
|
|
96
|
+
* @param {number} [opts.maxScriptBytes] Scripts past this many bytes in all are left unread (Couldn't check).
|
|
97
|
+
* @returns {Promise<ReturnType<typeof view>>}
|
|
98
|
+
* @throws {CheckError}
|
|
99
|
+
*/
|
|
100
|
+
export async function runCheck(input, opts = {}) {
|
|
101
|
+
const fetchImpl = opts.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
102
|
+
const endpoint = opts.endpoint ?? ENDPOINT;
|
|
103
|
+
const onStep = opts.onStep ?? (() => {});
|
|
104
|
+
const now = opts.now ?? (() => Math.floor(Date.now() / 1000));
|
|
105
|
+
|
|
106
|
+
const url = normalize(input);
|
|
107
|
+
onStep(0);
|
|
108
|
+
const site = await call(fetchImpl, endpoint, { url });
|
|
109
|
+
const page = site.find((p) => p.name === 'page');
|
|
110
|
+
if (opts.maxPageBytes !== undefined && page && !page.error && page.bytes && page.bytes.byteLength > opts.maxPageBytes) throw new CheckError('too_large');
|
|
111
|
+
|
|
112
|
+
onStep(1);
|
|
113
|
+
/** @type {import('./frame.js').Part[] | null} */
|
|
114
|
+
let scripts = [];
|
|
115
|
+
const wanted = page && !page.error ? scriptUrls(page) : [];
|
|
116
|
+
if (wanted.length) {
|
|
117
|
+
try {
|
|
118
|
+
scripts = await call(fetchImpl, endpoint, { url: page.url, scripts: wanted });
|
|
119
|
+
} catch (e) {
|
|
120
|
+
// The site was read; only the scripts were not. Their keys show as Couldn't check.
|
|
121
|
+
scripts = wanted.map((u) => ({ name: 'script', url: u, error: { code: e instanceof CheckError ? e.code : 'service', reason: '' }, bytes: null }));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (opts.maxScriptBytes !== undefined) {
|
|
126
|
+
let used = 0;
|
|
127
|
+
scripts = scripts.map((s) => {
|
|
128
|
+
if (s.error || !s.bytes) return s;
|
|
129
|
+
used += s.bytes.byteLength;
|
|
130
|
+
return used > /** @type {number} */ (opts.maxScriptBytes) ? { ...s, error: { code: 'too_large', reason: '' }, bytes: null } : s;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
onStep(2);
|
|
135
|
+
return view(analyze(site, page && !page.error ? scripts : null), now());
|
|
136
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every sentence the free check shows, keyed by finding id. The analyzer (analyze.js) returns ids
|
|
3
|
+
* and values; this file turns them into words.
|
|
4
|
+
*
|
|
5
|
+
* Status of each entry, in a comment beside it:
|
|
6
|
+
* - approved: shown to the owner in the prototype and approved (2026-11-20). Do not reword.
|
|
7
|
+
* - draft: not yet approved. Nothing marked draft ships before the owner approves it.
|
|
8
|
+
*
|
|
9
|
+
* Rules (owner, standing): short simple sentences, one idea each; American English; no em-dashes;
|
|
10
|
+
* no internal sales terms; the check claims only what it tested ("robots.txt refuses", never
|
|
11
|
+
* "can't read").
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
15
|
+
/** "A", "A and B", "A, B and C". */
|
|
16
|
+
export function list(items) {
|
|
17
|
+
if (items.length <= 1) return items.join('');
|
|
18
|
+
return items.slice(0, -1).join(', ') + ' and ' + items[items.length - 1];
|
|
19
|
+
}
|
|
20
|
+
/** robots.txt names, shortened: "GPTBot, ClaudeBot, Google-Extended and 29 more". */
|
|
21
|
+
export function some(items, shown = 3) {
|
|
22
|
+
return items.length <= shown + 1 ? list(items) : `${items.slice(0, shown).join(', ')} and ${items.length - shown} more`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const STATUS = { 301: 'Moved Permanently', 302: 'Found', 400: 'Bad Request', 401: 'Unauthorized', 403: 'Forbidden', 404: 'Not Found', 410: 'Gone', 429: 'Too Many Requests', 500: 'Internal Server Error', 502: 'Bad Gateway', 503: 'Service Unavailable', 504: 'Gateway Timeout' };
|
|
26
|
+
export const status = (n) => (STATUS[n] ? `${n} ${STATUS[n]}` : String(n));
|
|
27
|
+
|
|
28
|
+
const pagePhrase = (path) => (path === '/' ? 'home page' : 'page');
|
|
29
|
+
/** "the home page" or "this page". */
|
|
30
|
+
export const where = (path) => (path === '/' ? 'the home page' : 'this page');
|
|
31
|
+
const cap = (s) => s[0].toUpperCase() + s.slice(1);
|
|
32
|
+
|
|
33
|
+
/* ------------------------------------------------------------------ Headlines (all approved 2026-11-20) */
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* SEO/AEO headline: the most serious real finding of the reach, text and robots areas.
|
|
37
|
+
* @param {import('./analyze.js').Finding | null} worst
|
|
38
|
+
* @param {string} path
|
|
39
|
+
*/
|
|
40
|
+
export function seoHeadline(worst, path) {
|
|
41
|
+
if (!worst) return `robots.txt allows every search and answer crawler checked on ${where(path)}.`; // approved 2026-11-20
|
|
42
|
+
const d = worst.data;
|
|
43
|
+
switch (worst.id) {
|
|
44
|
+
case 'crawlers_refused':
|
|
45
|
+
return `robots.txt refuses ${list(d.engines.map((e) => e.feeds))} on ${where(path)}.`; // approved 2026-11-20
|
|
46
|
+
case 'noindex':
|
|
47
|
+
return `${cap(where(path))} tells ${d.engines.length === d.total ? 'search engines' : list(d.engines.map((e) => e.feeds))} not to index it.`; // approved 2026-11-20
|
|
48
|
+
case 'empty_page':
|
|
49
|
+
return `ChatGPT and Perplexity see an empty ${pagePhrase(path)}. Their crawlers do not run JavaScript.`; // approved
|
|
50
|
+
case 'sitemap_missing':
|
|
51
|
+
return 'robots.txt lists no sitemap. Crawlers use one to find your pages.'; // approved 2026-11-20
|
|
52
|
+
case 'signals_disagree':
|
|
53
|
+
return 'robots.txt rules and AI signals disagree.'; // approved 2026-11-20
|
|
54
|
+
case 'hidden_text':
|
|
55
|
+
return 'This page has text that visitors cannot see.'; // approved 2026-11-20
|
|
56
|
+
case 'robots_unreadable':
|
|
57
|
+
return "Couldn't read robots.txt. Crawler access was not checked."; // approved 2026-11-20
|
|
58
|
+
default:
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Security headline: a leaked key first, then the headers.
|
|
65
|
+
* @param {import('./analyze.js').Finding[]} findings Security findings, worst first.
|
|
66
|
+
*/
|
|
67
|
+
export function securityHeadline(findings) {
|
|
68
|
+
const keys = findings.filter((f) => f.id === 'key_leaked');
|
|
69
|
+
if (keys.length) {
|
|
70
|
+
return keys.length === 1 ? `${/^[AEIOU]/.test(keys[0].data.label) ? 'An' : 'A'} ${keys[0].data.label} is in this page's public JavaScript.` : `${keys.length} secret keys are in this page's public JavaScript.`; // approved 2026-11-20
|
|
71
|
+
}
|
|
72
|
+
const hsts = findings.find((f) => f.id === 'hsts' && f.level === 'recommended');
|
|
73
|
+
const missing = (findings.find((f) => f.id === 'headers_missing')?.data.missing ?? []).length + (hsts && hsts.data.reason === 'missing' ? 1 : 0);
|
|
74
|
+
const unread = findings.some((f) => f.id === 'scripts_unread');
|
|
75
|
+
const keysLine = unread ? "Some of the page's scripts couldn't be read." : "No secret key was found in the page's JavaScript."; // approved 2026-11-20 (second half approved)
|
|
76
|
+
const weak = hsts && hsts.data.reason !== 'missing' ? (hsts.data.reason === 'short' ? `Strict-Transport-Security lasts only ${duration(hsts.data.maxAge)}. ` : 'Strict-Transport-Security has no valid max-age. ') : ''; // approved 2026-11-20
|
|
77
|
+
if (missing) return `${missing} security ${plural(missing, 'header is', 'headers are')} missing. ${weak}${keysLine}`; // approved for 3
|
|
78
|
+
if (weak) return `${weak}${keysLine}`; // approved 2026-11-20
|
|
79
|
+
return `Every security header checked is sent. ${keysLine}`; // approved 2026-11-20
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* ------------------------------------------------------------------ What to do */
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A row in What to do: title, verdict, found line and the Pro note.
|
|
86
|
+
* @param {import('./analyze.js').Finding} f
|
|
87
|
+
* @param {{path: string, cloudflare: boolean}} ctx
|
|
88
|
+
* @returns {{title: string, verdict: string, found?: string, pro?: string, button?: string}}
|
|
89
|
+
*/
|
|
90
|
+
export function todo(f, ctx) {
|
|
91
|
+
const d = f.data;
|
|
92
|
+
switch (f.id) {
|
|
93
|
+
case 'key_leaked':
|
|
94
|
+
return {
|
|
95
|
+
title: `Revoke the ${d.label}`, // approved 2026-11-20
|
|
96
|
+
verdict: KEY_HARM[d.type] ?? 'Anyone who opens the page can read this key.', // approved 2026-11-20
|
|
97
|
+
found: `Found: ${d.masked} in ${shortUrl(d.script)}, line ${d.line}.`, // approved 2026-11-20
|
|
98
|
+
pro: 'Pro checks every deploy for leaked keys. It alerts you within 5 minutes.', // approved 2026-11-20
|
|
99
|
+
};
|
|
100
|
+
case 'crawlers_refused':
|
|
101
|
+
return {
|
|
102
|
+
title: `Allow ${list(d.engines.map((e) => e.token))} in robots.txt`, // approved 2026-11-20
|
|
103
|
+
verdict: `robots.txt refuses ${list(d.engines.map((e) => e.token))}. ${list(d.engines.map((e) => e.feeds))} cannot use ${where(ctx.path)} in answers.`, // approved 2026-11-20
|
|
104
|
+
found: d.engines[0].rule ? `Found: ${d.engines[0].rule} for ${list(d.engines.map((e) => e.token))}.` : undefined, // approved 2026-11-20
|
|
105
|
+
pro: 'Daily rechecks send an alert when robots.txt changes.', // approved
|
|
106
|
+
};
|
|
107
|
+
case 'noindex':
|
|
108
|
+
return {
|
|
109
|
+
title: `Remove noindex from ${where(ctx.path)}`, // approved 2026-11-20
|
|
110
|
+
verdict: `${cap(where(ctx.path))} tells ${d.engines.length === d.total ? 'search engines' : list(d.engines.map((e) => e.feeds))} not to index it. It cannot show up in their results or answers.`, // approved 2026-11-20
|
|
111
|
+
found: d.where === 'header' ? 'Found: an X-Robots-Tag header with noindex.' : 'Found: a robots meta tag with noindex.', // approved 2026-11-20
|
|
112
|
+
};
|
|
113
|
+
case 'empty_page':
|
|
114
|
+
return {
|
|
115
|
+
title: 'Put the page text in the HTML', // approved
|
|
116
|
+
verdict: 'This page shows almost no text until JavaScript runs. ChatGPT and Perplexity crawlers do not run JavaScript. They see an empty page. Google runs JavaScript, so Google Search sees the text.', // approved
|
|
117
|
+
found: `Found: ${d.chars} ${plural(d.chars, 'character', 'characters')} of body text.${d.root ? ` The body holds one empty <div id="${d.root}">.` : ''}`, // approved with root
|
|
118
|
+
pro: 'Pro checks every deploy. It alerts you within 5 minutes if a page goes empty.', // approved
|
|
119
|
+
};
|
|
120
|
+
case 'sitemap_missing':
|
|
121
|
+
return {
|
|
122
|
+
title: 'List a sitemap in robots.txt', // approved
|
|
123
|
+
verdict: d.robots ? 'robots.txt lists no sitemap. A Sitemap: line there is where crawlers and agents look for one.' /* approved */ : 'The site has no robots.txt and no sitemap. Crawlers and agents look for a Sitemap: line in robots.txt.', // approved 2026-11-20
|
|
124
|
+
found: d.defaultStatus ? `Found: /sitemap.xml returns ${status(d.defaultStatus)}.` /* approved */ : "Found: /sitemap.xml couldn't be read.", // approved 2026-11-20
|
|
125
|
+
};
|
|
126
|
+
case 'hsts':
|
|
127
|
+
if (f.level === 'unchecked') return { title: "Couldn't check Strict-Transport-Security", verdict: 'This page is served over plain HTTP. Strict-Transport-Security works only over HTTPS.' }; // approved 2026-11-20
|
|
128
|
+
return {
|
|
129
|
+
title: d.reason === 'missing' ? 'Turn on Strict-Transport-Security' /* approved */ : 'Fix Strict-Transport-Security', // approved 2026-11-20
|
|
130
|
+
verdict:
|
|
131
|
+
d.reason === 'missing'
|
|
132
|
+
? "This site doesn't send a Strict-Transport-Security header. Browsers may connect without encryption first." // approved
|
|
133
|
+
: d.reason === 'invalid'
|
|
134
|
+
? 'The Strict-Transport-Security header has no valid max-age. Browsers ignore it.' // approved 2026-11-20
|
|
135
|
+
: `Strict-Transport-Security lasts only ${duration(d.maxAge)}. Set max-age to at least 180 days.`, // approved 2026-11-20
|
|
136
|
+
pro: ctx.cloudflare ? 'Pro can turn this on in Cloudflare with one click.' : undefined, // approved
|
|
137
|
+
};
|
|
138
|
+
case 'headers_missing':
|
|
139
|
+
return {
|
|
140
|
+
title: `Add ${list(d.missing)}`, // approved for X-Frame-Options and Referrer-Policy
|
|
141
|
+
verdict: d.missing.map((h) => HEADER_WHY[h]).join(' '), // approved
|
|
142
|
+
found: `Missing: ${d.missing.join(', ')}`, // approved
|
|
143
|
+
pro: ctx.cloudflare ? 'Pro can add these headers in Cloudflare with one click. You can undo it at any time.' : undefined, // approved
|
|
144
|
+
};
|
|
145
|
+
case 'signals_disagree':
|
|
146
|
+
return {
|
|
147
|
+
title: 'Make robots.txt and AI signals agree', // approved 2026-11-20
|
|
148
|
+
verdict: d.ids.map((id) => signalWhy(id, d.values)).filter(Boolean).join(' '), // approved 2026-11-20
|
|
149
|
+
};
|
|
150
|
+
case 'hidden_text':
|
|
151
|
+
return {
|
|
152
|
+
title: 'Remove hidden text', // approved 2026-11-20
|
|
153
|
+
verdict: d.items.some((i) => i.phrase) ? 'This page has text that speaks to AI tools. Visitors cannot see it. Search engines treat hidden text as spam.' : 'This page has text that visitors cannot see. Search engines treat hidden text as spam.', // approved 2026-11-20
|
|
154
|
+
found: `Found: "${d.items[0].text}"`, // approved 2026-11-20
|
|
155
|
+
};
|
|
156
|
+
default:
|
|
157
|
+
return { title: f.id, verdict: '' };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const KEY_HARM = {
|
|
162
|
+
supabase_service_role: 'This key skips row level security. Anyone who opens the page can read and change every table.', // approved 2026-11-20
|
|
163
|
+
openai: 'Anyone who opens the page can use this key. The usage is billed to your OpenAI account.', // approved 2026-11-20
|
|
164
|
+
stripe: 'This secret key can act on your Stripe account. Anyone who opens the page can read it.', // approved 2026-11-20
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const HEADER_WHY = {
|
|
168
|
+
'X-Frame-Options': 'X-Frame-Options stops other sites from showing your pages in a frame.', // approved
|
|
169
|
+
'Referrer-Policy': 'Referrer-Policy controls how much of your page address other sites see.', // approved
|
|
170
|
+
'X-Content-Type-Options': 'X-Content-Type-Options stops browsers from guessing file types.', // approved 2026-11-20
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const SIGNAL_WHO = { 'ai-train': 'training crawlers', search: 'search crawlers', 'ai-input': 'AI search crawlers and user fetchers' };
|
|
174
|
+
/** One disagreement, said plainly. values: the Content-Signal values that apply to every crawler. */
|
|
175
|
+
function signalWhy(id, values = {}) {
|
|
176
|
+
if (id.startsWith('signal_')) {
|
|
177
|
+
const key = id.slice(7);
|
|
178
|
+
return values[key] === 'no'
|
|
179
|
+
? `Content-Signal says ${key}=no. The robots.txt rules still let ${SIGNAL_WHO[key]} in. Crawlers that do not read Content-Signal follow the rules.` // approved 2026-11-20
|
|
180
|
+
: `Content-Signal says ${key}=yes. The robots.txt rules refuse every one of the ${SIGNAL_WHO[key]}.`; // approved 2026-11-20
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
llms_blocked: 'The site publishes llms.txt for AI tools. robots.txt refuses every AI crawler checked.', // approved 2026-11-20
|
|
184
|
+
llms_disallowed: 'robots.txt keeps some AI crawlers from reading llms.txt. The rest of the site is open to them.', // approved 2026-11-20
|
|
185
|
+
llms_opt_out: 'llms.txt asks AI not to use the content. robots.txt lets training crawlers in. Crawlers follow robots.txt.', // approved 2026-11-20
|
|
186
|
+
}[id];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/* ------------------------------------------------------------------ Information (no level) */
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @param {import('./analyze.js').Finding} f
|
|
193
|
+
* @param {{cloudflare: boolean}} ctx
|
|
194
|
+
* @returns {{title: string, line: string, chips?: string[], more?: string} | null}
|
|
195
|
+
*/
|
|
196
|
+
export function info(f, ctx) {
|
|
197
|
+
const d = f.data;
|
|
198
|
+
if (f.id === 'training_refused') {
|
|
199
|
+
return {
|
|
200
|
+
title: d.searchOk ? 'AI training crawlers are refused. ChatGPT search, Claude and Perplexity can still read this page.' /* approved */ : 'AI training crawlers are refused.', // approved 2026-11-20
|
|
201
|
+
line: `robots.txt refuses ${some(d.tokens)}.${ctx.cloudflare && d.contentSignal ? ' Cloudflare manages that part of the file.' : ''}`, // approved (Cloudflare line only when Cloudflare manages it)
|
|
202
|
+
chips: d.tokens.length > 4 ? d.tokens : undefined,
|
|
203
|
+
more: ctx.cloudflare && d.contentSignal ? 'To change it, edit the robots.txt setting in your Cloudflare dashboard.' /* approved */ : 'To change it, edit robots.txt.', // approved 2026-11-20
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (f.id === 'llms') {
|
|
207
|
+
if (d.unchecked) return { title: "Couldn't check llms.txt", line: '/llms.txt did not answer. Nothing requires one.' }; // approved 2026-11-20
|
|
208
|
+
return d.found ? { title: 'llms.txt found', line: '/llms.txt is published. Nothing requires one.' } /* approved 2026-11-20 */ : { title: 'No llms.txt', line: '/llms.txt returns 404 Not Found. Nothing requires one.' }; // approved
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* ------------------------------------------------------------------ Couldn't check */
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Why a page, robots.txt or scripts could not be read.
|
|
217
|
+
* @param {{code: string, status?: number}} p
|
|
218
|
+
*/
|
|
219
|
+
export function reason(p) {
|
|
220
|
+
switch (p.code) {
|
|
221
|
+
case 'timeout':
|
|
222
|
+
return 'The site took more than 10 seconds to answer.'; // approved 2026-11-20
|
|
223
|
+
case 'fetch_failed':
|
|
224
|
+
return 'The site could not be reached.'; // approved 2026-11-20
|
|
225
|
+
case 'too_many_redirects':
|
|
226
|
+
return 'The address redirects more than 5 times.'; // approved 2026-11-20
|
|
227
|
+
case 'not_html':
|
|
228
|
+
return 'The address is not a web page.'; // approved 2026-11-20
|
|
229
|
+
case 'server_error':
|
|
230
|
+
case 'status':
|
|
231
|
+
return `The site answered ${status(p.status)}.`; // approved 2026-11-20
|
|
232
|
+
default:
|
|
233
|
+
return 'The site could not be reached.'; // approved 2026-11-20
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* ------------------------------------------------------------------ What passed */
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* One line in What passed: [bold label, rest, joinWithSpace].
|
|
241
|
+
* @param {import('./analyze.js').Pass} p
|
|
242
|
+
* @returns {[string, string, boolean] | null}
|
|
243
|
+
*/
|
|
244
|
+
export function passLine(p) {
|
|
245
|
+
const d = p.data;
|
|
246
|
+
switch (p.id) {
|
|
247
|
+
case 'engine_allowed':
|
|
248
|
+
return [d.feeds, `(${d.token}): robots.txt allows ${where(d.path ?? '/')}.`, true]; // approved
|
|
249
|
+
case 'page_text':
|
|
250
|
+
return ['Text in the HTML', 'The page text is there before JavaScript runs.', false]; // approved 2026-11-20
|
|
251
|
+
case 'no_hidden_text':
|
|
252
|
+
return ['No hidden text', 'Nothing in the HTML is hidden from visitors or addressed to AI.', false]; // approved
|
|
253
|
+
case 'sitemap':
|
|
254
|
+
return ['Sitemap', d.listed.length ? `robots.txt lists ${d.listed.length === 1 ? shortUrl(d.listed[0]) : d.listed.length + ' sitemaps'}.` : '/sitemap.xml is there. robots.txt does not list it.', false]; // approved 2026-11-20
|
|
255
|
+
case 'signals_agree':
|
|
256
|
+
return [
|
|
257
|
+
'Signals agree',
|
|
258
|
+
d.contentSignal && d.llms
|
|
259
|
+
? 'robots.txt rules, Content-Signal lines and llms.txt agree.' // approved 2026-11-20
|
|
260
|
+
: d.contentSignal
|
|
261
|
+
? 'robots.txt rules and Content-Signal lines agree.' // approved
|
|
262
|
+
: d.llms
|
|
263
|
+
? 'robots.txt rules and llms.txt agree.' // approved 2026-11-20
|
|
264
|
+
: 'Only robots.txt states AI preferences. There is nothing to disagree.', // approved 2026-11-20
|
|
265
|
+
false,
|
|
266
|
+
];
|
|
267
|
+
case 'hsts':
|
|
268
|
+
return ['Strict-Transport-Security', `Sent with max-age ${maxAgeOf(d.value)}.`, false]; // approved 2026-11-20
|
|
269
|
+
case 'header':
|
|
270
|
+
return d.name === 'X-Content-Type-Options'
|
|
271
|
+
? ['X-Content-Type-Options', 'Sent as nosniff. Browsers do not guess file types.', false] // approved
|
|
272
|
+
: d.viaCsp
|
|
273
|
+
? [d.name, 'Content-Security-Policy sets frame-ancestors instead.', false] // approved 2026-11-20
|
|
274
|
+
: [d.name, `Sent as ${d.value}.`, false]; // approved 2026-11-20
|
|
275
|
+
case 'no_key':
|
|
276
|
+
return [KEY_LABEL[d.type], KEY_NONE[d.type], false]; // approved
|
|
277
|
+
default:
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export const KEY_LABEL = { supabase_service_role: 'Supabase service_role key', openai: 'OpenAI API key', stripe: 'Stripe secret key' }; // approved
|
|
283
|
+
const KEY_NONE = {
|
|
284
|
+
supabase_service_role: 'None found. Supabase anon keys are public by design. They are not flagged.', // approved
|
|
285
|
+
openai: 'None found.', // approved
|
|
286
|
+
stripe: 'None found. Publishable keys belong in the browser. They are not flagged.', // approved
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/** "The 1.2 MB app script was read in full." (approved for one script) */
|
|
290
|
+
export function scriptsLede(n, bytes, inline) {
|
|
291
|
+
if (n === 0) return inline ? 'The page loads no scripts from its own site. Its inline scripts were read.' : 'The page loads no scripts.'; // approved 2026-11-20
|
|
292
|
+
const size = bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`;
|
|
293
|
+
return n === 1 ? `The ${size} app script was read in full.` /* approved */ : `${n} scripts, ${size} in all, were read in full.`; // approved 2026-11-20
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* ------------------------------------------------------------------ helpers */
|
|
297
|
+
|
|
298
|
+
function shortUrl(u) {
|
|
299
|
+
try {
|
|
300
|
+
const x = new URL(u);
|
|
301
|
+
return x.pathname === '/' ? 'the page' : x.pathname;
|
|
302
|
+
} catch {
|
|
303
|
+
return u;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function maxAgeOf(v) {
|
|
308
|
+
const m = /max-age\s*=\s*"?(\d+)/i.exec(v || '');
|
|
309
|
+
return m ? duration(Number(m[1])) : 'set';
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Whole days, or hours, minutes or seconds under a day (as frontend.js says it). */
|
|
313
|
+
export function duration(seconds) {
|
|
314
|
+
for (const [unit, size] of [['day', 86400], ['hour', 3600], ['minute', 60]]) {
|
|
315
|
+
const n = Math.floor(seconds / size);
|
|
316
|
+
if (n >= 1) return n === 1 ? `1 ${unit}` : `${n} ${unit}s`;
|
|
317
|
+
}
|
|
318
|
+
return seconds === 1 ? '1 second' : `${seconds} seconds`;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/* ------------------------------------------------------------------ The check page itself */
|
|
322
|
+
|
|
323
|
+
/** Why an address was refused before anything was fetched (codes from guard.js and worker.js). */
|
|
324
|
+
export function addressProblem(code) {
|
|
325
|
+
return (
|
|
326
|
+
{
|
|
327
|
+
bad_url: 'That is not a web address. Try one like yourproduct.dev.', // approved 2026-11-20
|
|
328
|
+
bad_scheme: 'Only http and https addresses can be checked.', // approved 2026-11-20
|
|
329
|
+
credentials: 'Remove the user name and password from the address.', // approved 2026-11-20
|
|
330
|
+
bad_port: 'Only ports 80 and 443 can be checked.', // approved 2026-11-20
|
|
331
|
+
private_address: 'That address is on a private network. The check reads public sites only.', // approved 2026-11-20
|
|
332
|
+
blocked_host: 'That name is for local or private networks. The check reads public sites only.', // approved 2026-11-20
|
|
333
|
+
bad_hostname: 'That name is not a public website.', // approved 2026-11-20
|
|
334
|
+
rate_limited: 'Too many checks in one minute. Wait a minute, then check again.', // approved 2026-11-20
|
|
335
|
+
service: 'The check is not answering right now. Try again in a few minutes.', // approved 2026-11-20
|
|
336
|
+
}[code] ?? 'That is not a web address. Try one like yourproduct.dev.' // approved 2026-11-20
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** The three steps a check takes, in order (approved 2026-11-20). */
|
|
341
|
+
export const STEPS = [
|
|
342
|
+
['The page and its site files', 'The page, robots.txt, sitemap.xml and llms.txt.'], // approved 2026-11-20
|
|
343
|
+
["The page's scripts", 'Only to check for secret keys.'], // approved 2026-11-20
|
|
344
|
+
['The checks', 'They run here, in your browser.'], // approved 2026-11-20
|
|
345
|
+
];
|
|
346
|
+
|
|
347
|
+
/** Empty "What to do" lists, one line per spot so the goose voice stays fresh (approved 2026-11-20). Performance and
|
|
348
|
+
* Insights are for the package dashboard. */
|
|
349
|
+
export const ALL_CLEAR = {
|
|
350
|
+
home: 'Nothing to honk about. No fixes needed right now.',
|
|
351
|
+
seo: 'A goose egg. Zero fixes for search and AI answers.',
|
|
352
|
+
security: 'No ruffled feathers. Nothing to fix in security right now.',
|
|
353
|
+
performance: 'Smooth flying. Every kind of page is fast for real visitors.',
|
|
354
|
+
insights: 'Calm waters. Nothing in your visits needs attention.',
|
|
355
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How to fix each finding, for the stack the check detected. HTML in the approved prototype's
|
|
3
|
+
* markup (gt-steps, gt-code with a Copy button, tabs between ways to fix).
|
|
4
|
+
*
|
|
5
|
+
* Status, in a comment beside each block:
|
|
6
|
+
* - approved: from the approved prototype (2026-11-20), with the site's host filled in.
|
|
7
|
+
* - draft: not yet approved. Nothing marked draft ships before the owner approves it.
|
|
8
|
+
* Facts that still need checking against vendor docs before approval are marked "verify".
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { list } from './copy.js';
|
|
12
|
+
|
|
13
|
+
const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
14
|
+
const mono = (s) => `<span class="gt-mono">${esc(s)}</span>`;
|
|
15
|
+
export const code = (file, text) => `<div class="gt-code"><div class="gt-code__bar"><span>${esc(file)}</span><button type="button" class="gt-copy" data-copy>Copy</button></div><pre><code>${esc(text)}</code></pre></div>`;
|
|
16
|
+
const steps = (items, note) => `<ol class="gt-steps">${items.map((i) => `<li>${i}</li>`).join('\n')}</ol>${note ? `<p class="gt-steps__note">${note}</p>` : ''}`;
|
|
17
|
+
const p = (s) => `<p>${s}</p>`;
|
|
18
|
+
let tabSeq = 0;
|
|
19
|
+
export const tabs = (label, items) => {
|
|
20
|
+
const group = 'fx' + ++tabSeq;
|
|
21
|
+
return `<div class="gs-toggle gs-toggle--compact" role="tablist" aria-label="${esc(label)}">${items.map((t, i) => `<button type="button" role="tab" id="${group}-t${i}" aria-controls="${group}-p${i}" aria-selected="${i === 0}" data-group="${group}">${esc(t.label)}</button>`).join('')}</div>${items.map((t, i) => `<div role="tabpanel" id="${group}-p${i}" aria-labelledby="${group}-t${i}"${i ? ' hidden' : ''}>${t.body}</div>`).join('')}`;
|
|
22
|
+
};
|
|
23
|
+
const lede = (s) => `<p class="gt-steps__lede">${s}</p>`;
|
|
24
|
+
const AGAIN = p('Deploy, then check again.');
|
|
25
|
+
const APACHE_AGAIN = p(`Save. If you changed the virtual host, reload Apache. Then check again.`) + code('Terminal', 'sudo apachectl graceful'); // approved 2026-11-20
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {import('./analyze.js').Finding} f
|
|
29
|
+
* @param {{host: string, cloudflare: boolean, stack: {framework: string|null, host: string|null}}} ctx
|
|
30
|
+
* @returns {{html: string, cloudflare?: boolean}}
|
|
31
|
+
*/
|
|
32
|
+
export function fixSteps(f, ctx) {
|
|
33
|
+
const fw = ctx.stack.framework;
|
|
34
|
+
const host = ctx.stack.host;
|
|
35
|
+
switch (f.id) {
|
|
36
|
+
case 'empty_page':
|
|
37
|
+
if (fw === 'vite-react') return { html: lede('Two ways for Vite and React.') + tabs('Ways to fix', [{ label: 'index.html', body: emptyQuick(ctx) }, { label: 'Prerender', body: EMPTY_PRERENDER }]) }; // approved
|
|
38
|
+
return { html: steps([p('Make the server send this page as HTML, with its text in it. Prerendering at build time or rendering on the server both do that.'), AGAIN]) }; // approved 2026-11-20
|
|
39
|
+
case 'hsts': {
|
|
40
|
+
if (f.level === 'unchecked') return { html: steps([p('Serve the site over HTTPS. Most hosts turn it on in their settings.'), AGAIN]) }; // approved 2026-11-20
|
|
41
|
+
const ways = [];
|
|
42
|
+
const origin = HEADER_WAYS[host] ? host : null;
|
|
43
|
+
if (origin) ways.push({ label: HEADER_WAYS[origin].label, body: HEADER_WAYS[origin].hsts(ctx) });
|
|
44
|
+
if (ctx.cloudflare) ways.push({ label: 'Cloudflare', body: HSTS_CLOUDFLARE }); // approved
|
|
45
|
+
if (!ways.length) ways.push({ label: 'Header', body: steps([p(`Send this header from your server or host on every HTTPS answer.`) + code('Header', 'Strict-Transport-Security: max-age=31536000'), AGAIN]) }); // approved 2026-11-20
|
|
46
|
+
const intro = ways.length > 1 ? lede(`Set it in ${ways.map((w) => w.label).join(' or in ')}. One is enough.`) : ''; // approved wording for two
|
|
47
|
+
return { html: intro + (ways.length > 1 ? tabs('Where to set the header', ways) : ways[0].body), cloudflare: true };
|
|
48
|
+
}
|
|
49
|
+
case 'headers_missing': {
|
|
50
|
+
const missing = f.data.missing;
|
|
51
|
+
const origin = HEADER_WAYS[host] ? host : null;
|
|
52
|
+
if (origin) return { html: HEADER_WAYS[origin].headers(ctx, missing), cloudflare: true };
|
|
53
|
+
return { html: steps([p('Send these headers from your server or host on every answer.') + code('Headers', missing.map((h) => `${h}: ${HEADER_VALUE[h]}`).join('\n')), AGAIN]), cloudflare: true }; // approved 2026-11-20
|
|
54
|
+
}
|
|
55
|
+
case 'sitemap_missing':
|
|
56
|
+
if (fw === 'vite-react' || fw === 'vite-vue' || fw === 'vite') return { html: sitemapVite(ctx) }; // approved
|
|
57
|
+
return {
|
|
58
|
+
html: steps([
|
|
59
|
+
p(`Add ${mono('sitemap.xml')} at the root of the site. List each page in it.`) + code('sitemap.xml', sitemapXml(ctx)),
|
|
60
|
+
(f.data.robots ? p(`Add the Sitemap line to ${mono('robots.txt')}.`) : p(`Add ${mono('robots.txt')} at the root of the site, with this line.`)) + code('robots.txt', `Sitemap: https://${ctx.host}/sitemap.xml`),
|
|
61
|
+
AGAIN,
|
|
62
|
+
]),
|
|
63
|
+
}; // approved 2026-11-20
|
|
64
|
+
case 'key_leaked':
|
|
65
|
+
return { html: steps([p(`Revoke the key ${KEY_DASHBOARD[f.data.type]}. Create a new one. Anyone may have copied the old one.`), p(`Use the new key only in server code, such as an API route or a serverless function. Never put it in a variable starting with ${mono('VITE_')} or ${mono('NEXT_PUBLIC_')}. Those go into public JavaScript.`), AGAIN]) }; // approved 2026-11-20, verify dashboard names
|
|
66
|
+
case 'crawlers_refused':
|
|
67
|
+
return { html: steps([p(`Open ${mono('robots.txt')}. Remove the Disallow lines for ${list(f.data.engines.map((e) => mono(e.token)))}.`), AGAIN], ctx.cloudflare ? 'If Cloudflare manages your robots.txt, change it in the Cloudflare dashboard instead.' : '') }; // approved 2026-11-20, verify Cloudflare label
|
|
68
|
+
case 'noindex':
|
|
69
|
+
return {
|
|
70
|
+
html:
|
|
71
|
+
f.data.where === 'header'
|
|
72
|
+
? steps([p('Find where your server or host adds the X-Robots-Tag header. Remove noindex from it.'), AGAIN]) // approved 2026-11-20
|
|
73
|
+
: steps([p('Remove this tag from the page head.') + code('HTML', '<meta name="robots" content="noindex">'), AGAIN]), // approved 2026-11-20
|
|
74
|
+
};
|
|
75
|
+
case 'hidden_text':
|
|
76
|
+
return { html: steps([p('Remove the hidden text from the page. If visitors should read it, show it.'), AGAIN]) }; // approved 2026-11-20
|
|
77
|
+
case 'signals_disagree':
|
|
78
|
+
return { html: steps([p(`Decide what AI tools may do with your pages. Then make the rules in ${mono('robots.txt')}, its Content-Signal line and ${mono('llms.txt')} say the same.`), AGAIN]) }; // approved 2026-11-20
|
|
79
|
+
default:
|
|
80
|
+
return { html: '' };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const HEADER_VALUE = { 'X-Frame-Options': 'SAMEORIGIN', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'X-Content-Type-Options': 'nosniff' };
|
|
85
|
+
const KEY_DASHBOARD = { supabase_service_role: 'in your Supabase project settings', openai: 'on your OpenAI API keys page', stripe: 'in the Stripe Dashboard' }; // approved 2026-11-20, verify
|
|
86
|
+
|
|
87
|
+
/** Per host: where headers are set. All approved 2026-11-20. */
|
|
88
|
+
const HEADER_WAYS = {
|
|
89
|
+
caddy: {
|
|
90
|
+
label: 'Caddy',
|
|
91
|
+
hsts: (ctx) => steps([p("Add the header line to your site's block in the Caddyfile.") + code('Caddyfile', `${ctx.host} {\n header Strict-Transport-Security "max-age=31536000"\n # your other lines stay as they are\n}`), p('Reload Caddy, then check again.') + code('Terminal', 'caddy reload')]), // approved
|
|
92
|
+
headers: (ctx, missing) => steps([p("Add the header block to your site's block in the Caddyfile.") + code('Caddyfile', `${ctx.host} {\n header {\n${missing.map((h) => ` ${h} "${HEADER_VALUE[h]}"`).join('\n')}\n }\n # your other lines stay as they are\n}`), p('Reload Caddy, then check again.') + code('Terminal', 'caddy reload')]), // approved
|
|
93
|
+
},
|
|
94
|
+
nginx: {
|
|
95
|
+
label: 'nginx',
|
|
96
|
+
hsts: () => steps([p('Add this line to the server block for HTTPS.') + code('nginx.conf', 'add_header Strict-Transport-Security "max-age=31536000" always;'), p('Reload nginx, then check again.') + code('Terminal', 'sudo nginx -s reload')]), // approved 2026-11-20
|
|
97
|
+
headers: (ctx, missing) => steps([p('Add these lines to the server block.') + code('nginx.conf', missing.map((h) => `add_header ${h} "${HEADER_VALUE[h]}" always;`).join('\n')), p('Reload nginx, then check again.') + code('Terminal', 'sudo nginx -s reload')]), // approved 2026-11-20
|
|
98
|
+
},
|
|
99
|
+
apache: {
|
|
100
|
+
label: 'Apache',
|
|
101
|
+
hsts: () => steps([p(`Add this line to the HTTPS virtual host or ${mono('.htaccess')}. It needs mod_headers.`) + code('.htaccess', 'Header always set Strict-Transport-Security "max-age=31536000"'), APACHE_AGAIN]), // approved 2026-11-20
|
|
102
|
+
headers: (ctx, missing) => steps([p(`Add these lines to the virtual host or ${mono('.htaccess')}. They need mod_headers.`) + code('.htaccess', missing.map((h) => `Header always set ${h} "${HEADER_VALUE[h]}"`).join('\n')), APACHE_AGAIN]), // approved 2026-11-20
|
|
103
|
+
},
|
|
104
|
+
vercel: {
|
|
105
|
+
label: 'Vercel',
|
|
106
|
+
hsts: () => steps([p(`Add a headers rule to ${mono('vercel.json')} at the root of the project.`) + code('vercel.json', vercelJson({ 'Strict-Transport-Security': 'max-age=31536000' })), AGAIN]), // approved 2026-11-20
|
|
107
|
+
headers: (ctx, missing) => steps([p(`Add a headers rule to ${mono('vercel.json')} at the root of the project.`) + code('vercel.json', vercelJson(Object.fromEntries(missing.map((h) => [h, HEADER_VALUE[h]])))), AGAIN]), // approved 2026-11-20
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function vercelJson(h) {
|
|
112
|
+
return JSON.stringify({ headers: [{ source: '/(.*)', headers: Object.entries(h).map(([key, value]) => ({ key, value })) }] }, null, 2);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const HSTS_CLOUDFLARE = steps([
|
|
116
|
+
p('In the Cloudflare dashboard, open SSL/TLS, then Edge Certificates.'),
|
|
117
|
+
p('Find HTTP Strict Transport Security (HSTS). Select Enable HSTS, then I understand, then Next.'),
|
|
118
|
+
p('Set Max Age Header to 6 months or more. Save, then check again.'),
|
|
119
|
+
]); // approved
|
|
120
|
+
|
|
121
|
+
function emptyQuick(ctx) {
|
|
122
|
+
// approved
|
|
123
|
+
return steps(
|
|
124
|
+
[
|
|
125
|
+
p(`Open ${mono('index.html')}.`),
|
|
126
|
+
p(`Put the page's main text inside ${mono('<div id="root">')}.`) + code('index.html', `<body>\n <div id="root">\n <h1>Your page title</h1>\n <p>The first lines visitors read.</p>\n </div>\n</body>`),
|
|
127
|
+
p('Deploy, then check again. React replaces this text when the app starts.'),
|
|
128
|
+
],
|
|
129
|
+
'This covers the home page. Prerender covers every route.',
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const EMPTY_PRERENDER = steps([
|
|
134
|
+
p(`Add ${mono('src/entry-server.jsx')}. It renders the app to HTML.`) + code('src/entry-server.jsx', "import { renderToString } from 'react-dom/server'\nimport App from './App'\n\nexport function render() {\n return renderToString(<App />)\n}"),
|
|
135
|
+
p(`Add ${mono('prerender.js')}. It writes that HTML into ${mono('dist/index.html')}.`) +
|
|
136
|
+
code('prerender.js', "import fs from 'node:fs'\nimport { render } from './dist-server/entry-server.js'\n\nconst file = 'dist/index.html'\nconst html = fs.readFileSync(file, 'utf8')\nconst app = `<div id=\"root\">${render()}</div>`\nfs.writeFileSync(file, html.replace('<div id=\"root\"></div>', app))"),
|
|
137
|
+
p('Run both after the normal build.') + code('package.json', '"scripts": {\n "build": "vite build && npm run ssr && node prerender.js",\n "ssr": "vite build --ssr src/entry-server.jsx --outDir dist-server"\n}'),
|
|
138
|
+
p(`Switch ${mono('src/main.jsx')} from ${mono('createRoot')} to ${mono('hydrateRoot')}.`) + code('src/main.jsx', "import { hydrateRoot } from 'react-dom/client'\nimport App from './App'\n\nhydrateRoot(document.getElementById('root'), <App />)"),
|
|
139
|
+
p('Deploy, then check again.'),
|
|
140
|
+
]); // approved
|
|
141
|
+
|
|
142
|
+
function sitemapXml(ctx) {
|
|
143
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n <url><loc>https://${ctx.host}/</loc></url>\n</urlset>`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function sitemapVite(ctx) {
|
|
147
|
+
// approved
|
|
148
|
+
return steps([
|
|
149
|
+
p(`Add ${mono('public/sitemap.xml')}. Vite copies the public folder into the build.`) + code('public/sitemap.xml', sitemapXml(ctx)),
|
|
150
|
+
p(`Add the Sitemap line to ${mono('public/robots.txt')}.`) + code('public/robots.txt', `Sitemap: https://${ctx.host}/sitemap.xml`),
|
|
151
|
+
p('Deploy, then check again.'),
|
|
152
|
+
]);
|
|
153
|
+
}
|