mcp-web-validator 1.3.50 → 1.3.53
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/CHANGELOG.md +53 -0
- package/README.md +66 -4
- package/dist/audit-history.d.ts +9 -0
- package/dist/audit-history.js +27 -0
- package/dist/audit-history.js.map +1 -1
- package/dist/index.js +2535 -30
- package/dist/index.js.map +1 -1
- package/dist/mcp-bounds.d.ts +11 -0
- package/dist/mcp-bounds.js +68 -0
- package/dist/mcp-bounds.js.map +1 -0
- package/dist/modules/browser-ux/lighthouse-lab-probe.d.ts +21 -0
- package/dist/modules/browser-ux/lighthouse-lab-probe.js +190 -0
- package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -0
- package/dist/modules/browser-ux/lighthouse-lab.d.ts +61 -0
- package/dist/modules/browser-ux/lighthouse-lab.js +98 -0
- package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -0
- package/dist/modules/browser-ux/media-diagnostics.d.ts +41 -0
- package/dist/modules/browser-ux/media-diagnostics.js +183 -0
- package/dist/modules/browser-ux/media-diagnostics.js.map +1 -0
- package/dist/modules/browser-ux/raw-rendered-diff.d.ts +70 -0
- package/dist/modules/browser-ux/raw-rendered-diff.js +262 -0
- package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -0
- package/dist/modules/browser-ux/raw-rendered-probe.d.ts +17 -0
- package/dist/modules/browser-ux/raw-rendered-probe.js +163 -0
- package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -0
- package/dist/modules/browser-ux/resource-failures-probe.d.ts +11 -0
- package/dist/modules/browser-ux/resource-failures-probe.js +231 -0
- package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -0
- package/dist/modules/browser-ux/resource-failures.d.ts +79 -0
- package/dist/modules/browser-ux/resource-failures.js +178 -0
- package/dist/modules/browser-ux/resource-failures.js.map +1 -0
- package/dist/modules/browser-ux/viewport-parity-probe.d.ts +5 -0
- package/dist/modules/browser-ux/viewport-parity-probe.js +307 -0
- package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -0
- package/dist/modules/browser-ux/viewport-parity.d.ts +112 -0
- package/dist/modules/browser-ux/viewport-parity.js +224 -0
- package/dist/modules/browser-ux/viewport-parity.js.map +1 -0
- package/dist/modules/browser-ux/wcag-interactions.d.ts +95 -0
- package/dist/modules/browser-ux/wcag-interactions.js +360 -0
- package/dist/modules/browser-ux/wcag-interactions.js.map +1 -0
- package/dist/modules/change-regression/availability-history-store.d.ts +18 -0
- package/dist/modules/change-regression/availability-history-store.js +168 -0
- package/dist/modules/change-regression/availability-history-store.js.map +1 -0
- package/dist/modules/change-regression/crawler-log-correlation.d.ts +111 -0
- package/dist/modules/change-regression/crawler-log-correlation.js +374 -0
- package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -0
- package/dist/modules/change-regression/google-common-crawler-ip.d.ts +15 -0
- package/dist/modules/change-regression/google-common-crawler-ip.js +129 -0
- package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -0
- package/dist/modules/change-regression/historical-comparisons.d.ts +120 -0
- package/dist/modules/change-regression/historical-comparisons.js +330 -0
- package/dist/modules/change-regression/historical-comparisons.js.map +1 -0
- package/dist/modules/change-regression/production-change-comparison.d.ts +68 -0
- package/dist/modules/change-regression/production-change-comparison.js +214 -0
- package/dist/modules/change-regression/production-change-comparison.js.map +1 -0
- package/dist/modules/change-regression/regression-alerts.d.ts +73 -0
- package/dist/modules/change-regression/regression-alerts.js +183 -0
- package/dist/modules/change-regression/regression-alerts.js.map +1 -0
- package/dist/modules/change-regression/strict-observation-time.d.ts +7 -0
- package/dist/modules/change-regression/strict-observation-time.js +31 -0
- package/dist/modules/change-regression/strict-observation-time.js.map +1 -0
- package/dist/modules/content-schema/citation-methodology-consistency.d.ts +108 -0
- package/dist/modules/content-schema/citation-methodology-consistency.js +360 -0
- package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -0
- package/dist/modules/content-schema/competitor-intent-comparison.d.ts +74 -0
- package/dist/modules/content-schema/competitor-intent-comparison.js +185 -0
- package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -0
- package/dist/modules/content-schema/empty-boilerplate-content.d.ts +36 -0
- package/dist/modules/content-schema/empty-boilerplate-content.js +225 -0
- package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -0
- package/dist/modules/content-schema/extract-citation-methodology.d.ts +6 -0
- package/dist/modules/content-schema/extract-citation-methodology.js +201 -0
- package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -0
- package/dist/modules/content-schema/extract-competitor-intent.d.ts +2 -0
- package/dist/modules/content-schema/extract-competitor-intent.js +140 -0
- package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -0
- package/dist/modules/content-schema/extract-main-content.d.ts +6 -0
- package/dist/modules/content-schema/extract-main-content.js +33 -0
- package/dist/modules/content-schema/extract-main-content.js.map +1 -0
- package/dist/modules/content-schema/extract-metadata-consistency.d.ts +3 -0
- package/dist/modules/content-schema/extract-metadata-consistency.js +62 -0
- package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -0
- package/dist/modules/content-schema/extract-product-claims.d.ts +3 -0
- package/dist/modules/content-schema/extract-product-claims.js +58 -0
- package/dist/modules/content-schema/extract-product-claims.js.map +1 -0
- package/dist/modules/content-schema/extract-structured-data.d.ts +3 -0
- package/dist/modules/content-schema/extract-structured-data.js +25 -0
- package/dist/modules/content-schema/extract-structured-data.js.map +1 -0
- package/dist/modules/content-schema/metadata-consistency.d.ts +66 -0
- package/dist/modules/content-schema/metadata-consistency.js +282 -0
- package/dist/modules/content-schema/metadata-consistency.js.map +1 -0
- package/dist/modules/content-schema/product-claims.d.ts +73 -0
- package/dist/modules/content-schema/product-claims.js +195 -0
- package/dist/modules/content-schema/product-claims.js.map +1 -0
- package/dist/modules/content-schema/same-language-duplicates.d.ts +52 -0
- package/dist/modules/content-schema/same-language-duplicates.js +158 -0
- package/dist/modules/content-schema/same-language-duplicates.js.map +1 -0
- package/dist/modules/content-schema/structured-data-validation.d.ts +37 -0
- package/dist/modules/content-schema/structured-data-validation.js +385 -0
- package/dist/modules/content-schema/structured-data-validation.js.map +1 -0
- package/dist/modules/external-metrics/crux-field-probe.d.ts +10 -0
- package/dist/modules/external-metrics/crux-field-probe.js +113 -0
- package/dist/modules/external-metrics/crux-field-probe.js.map +1 -0
- package/dist/modules/external-metrics/crux-field.d.ts +61 -0
- package/dist/modules/external-metrics/crux-field.js +231 -0
- package/dist/modules/external-metrics/crux-field.js.map +1 -0
- package/dist/modules/http-crawl/availability-observations.d.ts +68 -0
- package/dist/modules/http-crawl/availability-observations.js +206 -0
- package/dist/modules/http-crawl/availability-observations.js.map +1 -0
- package/dist/modules/http-crawl/availability-probe.d.ts +8 -0
- package/dist/modules/http-crawl/availability-probe.js +46 -0
- package/dist/modules/http-crawl/availability-probe.js.map +1 -0
- package/dist/modules/http-crawl/crawler-access-probe.d.ts +6 -0
- package/dist/modules/http-crawl/crawler-access-probe.js +79 -0
- package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -0
- package/dist/modules/http-crawl/crawler-access.d.ts +75 -0
- package/dist/modules/http-crawl/crawler-access.js +404 -0
- package/dist/modules/http-crawl/crawler-access.js.map +1 -0
- package/dist/modules/http-crawl/http-delivery-probe.d.ts +3 -0
- package/dist/modules/http-crawl/http-delivery-probe.js +44 -0
- package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -0
- package/dist/modules/http-crawl/http-delivery.d.ts +64 -0
- package/dist/modules/http-crawl/http-delivery.js +269 -0
- package/dist/modules/http-crawl/http-delivery.js.map +1 -0
- package/dist/modules/http-crawl/https-security.d.ts +84 -0
- package/dist/modules/http-crawl/https-security.js +441 -0
- package/dist/modules/http-crawl/https-security.js.map +1 -0
- package/dist/modules/http-crawl/non-html-directives.d.ts +74 -0
- package/dist/modules/http-crawl/non-html-directives.js +353 -0
- package/dist/modules/http-crawl/non-html-directives.js.map +1 -0
- package/dist/modules/http-crawl/redirect-canonical-chains.d.ts +80 -0
- package/dist/modules/http-crawl/redirect-canonical-chains.js +459 -0
- package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -0
- package/dist/modules/http-crawl/redirect-canonical-probe.d.ts +6 -0
- package/dist/modules/http-crawl/redirect-canonical-probe.js +83 -0
- package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -0
- package/dist/modules/http-crawl/sitemap-inventory-probe.d.ts +8 -0
- package/dist/modules/http-crawl/sitemap-inventory-probe.js +155 -0
- package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -0
- package/dist/modules/http-crawl/sitemap-inventory.d.ts +107 -0
- package/dist/modules/http-crawl/sitemap-inventory.js +557 -0
- package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -0
- package/dist/modules/http-crawl/url-variants.d.ts +86 -0
- package/dist/modules/http-crawl/url-variants.js +379 -0
- package/dist/modules/http-crawl/url-variants.js.map +1 -0
- package/dist/modules/site-architecture/extract-internal-links.d.ts +3 -0
- package/dist/modules/site-architecture/extract-internal-links.js +88 -0
- package/dist/modules/site-architecture/extract-internal-links.js.map +1 -0
- package/dist/modules/site-architecture/extract-multilingual-page.d.ts +2 -0
- package/dist/modules/site-architecture/extract-multilingual-page.js +29 -0
- package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -0
- package/dist/modules/site-architecture/internal-link-graph-probe.d.ts +7 -0
- package/dist/modules/site-architecture/internal-link-graph-probe.js +116 -0
- package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -0
- package/dist/modules/site-architecture/internal-link-graph.d.ts +113 -0
- package/dist/modules/site-architecture/internal-link-graph.js +414 -0
- package/dist/modules/site-architecture/internal-link-graph.js.map +1 -0
- package/dist/modules/site-architecture/internal-link-quality.d.ts +77 -0
- package/dist/modules/site-architecture/internal-link-quality.js +260 -0
- package/dist/modules/site-architecture/internal-link-quality.js.map +1 -0
- package/dist/modules/site-architecture/multilingual-clusters.d.ts +82 -0
- package/dist/modules/site-architecture/multilingual-clusters.js +363 -0
- package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -0
- package/dist/network.d.ts +4 -0
- package/dist/network.js +18 -2
- package/dist/network.js.map +1 -1
- package/dist/presentation.d.ts +53 -0
- package/dist/presentation.js +526 -0
- package/dist/presentation.js.map +1 -1
- package/dist/screenshot.d.ts +2 -1
- package/dist/screenshot.js +4 -2
- package/dist/screenshot.js.map +1 -1
- package/dist/seo-auditor.js +16 -6
- package/dist/seo-auditor.js.map +1 -1
- package/package.json +7 -4
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V04: bounded HTTP redirect and canonical-chain evidence review.
|
|
3
|
+
* Pure offline analyzer shared by Node and Cloudflare Worker MCPs.
|
|
4
|
+
*
|
|
5
|
+
* Original URL strings, source HTML, headers, tokens and query parameters
|
|
6
|
+
* never appear in the report. No crawler/indexing verdict is asserted.
|
|
7
|
+
*/
|
|
8
|
+
import { load } from "cheerio";
|
|
9
|
+
import { safeVariantLabel } from "./url-variants.js";
|
|
10
|
+
import { analyzeCrawlerAccess, MAX_CRAWLER_HTML_BYTES } from "./crawler-access.js";
|
|
11
|
+
export const MAX_CHAIN_HOPS = 8;
|
|
12
|
+
export const MAX_CHAIN_FINDINGS = 24;
|
|
13
|
+
export const MAX_CHAIN_CANONICALS = 4;
|
|
14
|
+
// Match the existing hosted public HTML 1 MiB fetch cap; 150 KB excluded
|
|
15
|
+
// ordinary production pages with embedded application bootstrap data.
|
|
16
|
+
export const MAX_CHAIN_HTML_BYTES = 1_048_576;
|
|
17
|
+
export const MAX_CHAIN_TOTAL_HTML_BYTES = 1_500_000;
|
|
18
|
+
const MAX_CHAIN_URL_BYTES = 1024;
|
|
19
|
+
export const CHAIN_REDIRECT_STATES = [
|
|
20
|
+
"none", "permanent", "temporary",
|
|
21
|
+
];
|
|
22
|
+
export const CHAIN_TARGET_STATES = [
|
|
23
|
+
"none", "next_observed", "loop", "cross_origin",
|
|
24
|
+
"https_downgrade", "query_target", "unobserved",
|
|
25
|
+
"missing", "invalid", "mismatch",
|
|
26
|
+
];
|
|
27
|
+
export const CHAIN_CANONICAL_STATES = [
|
|
28
|
+
"absent", "self", "sampled", "external", "unobserved",
|
|
29
|
+
"conflicting", "invalid", "redirect_target",
|
|
30
|
+
];
|
|
31
|
+
export const CHAIN_INDEXING_STATES = [
|
|
32
|
+
"explicit_noindex", "no_noindex_observed", "unknown",
|
|
33
|
+
];
|
|
34
|
+
export const CHAIN_FINDING_CODES = [
|
|
35
|
+
"redirect_missing_location", "redirect_invalid_target",
|
|
36
|
+
"redirect_loop", "redirect_cross_origin", "redirect_https_downgrade",
|
|
37
|
+
"redirect_query_target", "redirect_observation_mismatch",
|
|
38
|
+
"redirect_chain_unobserved", "redirect_long_chain",
|
|
39
|
+
"redirect_destination_http_error", "redirect_destination_noindex",
|
|
40
|
+
"redirect_destination_robots_blocked", "expected_destination_mismatch",
|
|
41
|
+
"canonical_conflict", "canonical_invalid",
|
|
42
|
+
"canonical_external", "canonical_unobserved",
|
|
43
|
+
"canonical_to_redirect", "canonical_to_http_error",
|
|
44
|
+
"canonical_to_noindex", "canonical_cycle", "canonical_chain",
|
|
45
|
+
"final_status_unverified", "destination_indexing_unverified",
|
|
46
|
+
];
|
|
47
|
+
const limitations = [
|
|
48
|
+
"Observed redirects and canonical declarations are signals, not Google's selected canonical or a live indexing verdict.",
|
|
49
|
+
"An unobserved redirect or canonical target is unknown, not proven missing, broken or wrong.",
|
|
50
|
+
"Only supplied/static HTML and X-Robots-Tag evidence was checked, never rendered JavaScript content.",
|
|
51
|
+
"A different destination is called mismatched only when an expected destination was explicitly provided.",
|
|
52
|
+
];
|
|
53
|
+
const enc = new TextEncoder();
|
|
54
|
+
function bytes(value) { return enc.encode(value).byteLength; }
|
|
55
|
+
function safeAbsoluteLabel(raw) {
|
|
56
|
+
if (typeof raw !== "string" || raw.length > MAX_CHAIN_URL_BYTES ||
|
|
57
|
+
bytes(raw) > MAX_CHAIN_URL_BYTES)
|
|
58
|
+
return null;
|
|
59
|
+
const safe = safeVariantLabel(raw);
|
|
60
|
+
if (!safe)
|
|
61
|
+
return null;
|
|
62
|
+
return new URL(safe);
|
|
63
|
+
}
|
|
64
|
+
function target(raw, base) {
|
|
65
|
+
try {
|
|
66
|
+
if (typeof raw !== "string" || !raw || bytes(raw) > MAX_CHAIN_URL_BYTES ||
|
|
67
|
+
/[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069\\]/u.test(raw) ||
|
|
68
|
+
raw.includes("#"))
|
|
69
|
+
return null;
|
|
70
|
+
const out = new URL(raw, base);
|
|
71
|
+
if (!["http:", "https:"].includes(out.protocol) || out.username || out.password ||
|
|
72
|
+
out.port || out.hash)
|
|
73
|
+
return null;
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function isRedirect(status) {
|
|
81
|
+
return [301, 302, 303, 307, 308].includes(status);
|
|
82
|
+
}
|
|
83
|
+
function redirectState(status) {
|
|
84
|
+
if (status === 301 || status === 308)
|
|
85
|
+
return "permanent";
|
|
86
|
+
if (status === 302 || status === 303 || status === 307)
|
|
87
|
+
return "temporary";
|
|
88
|
+
return "none";
|
|
89
|
+
}
|
|
90
|
+
function shortStatus(status) { return status >= 400 && status <= 599; }
|
|
91
|
+
function htmlCanonicals(html) {
|
|
92
|
+
if (html === undefined)
|
|
93
|
+
return [];
|
|
94
|
+
const $ = load(html);
|
|
95
|
+
const matches = [];
|
|
96
|
+
$("head > link[rel][href]").each((_, el) => {
|
|
97
|
+
const rel = ($(el).attr("rel") ?? "").trim().toLowerCase().split(/\s+/);
|
|
98
|
+
if (rel.includes("canonical"))
|
|
99
|
+
matches.push(($(el).attr("href") ?? "").trim());
|
|
100
|
+
});
|
|
101
|
+
return matches;
|
|
102
|
+
}
|
|
103
|
+
/** Extract rel=canonical hrefs from a bounded HTTP Link field, without echoing them. */
|
|
104
|
+
export function canonicalHrefsFromLinkHeader(value) {
|
|
105
|
+
if (!value || bytes(value) > 8_192)
|
|
106
|
+
return [];
|
|
107
|
+
const found = [];
|
|
108
|
+
for (const part of value.split(/,(?=\s*<)/u)) {
|
|
109
|
+
const uri = /^\s*<([^<>]{1,1024})>/u.exec(part);
|
|
110
|
+
if (!uri)
|
|
111
|
+
continue;
|
|
112
|
+
const parameters = part.slice(uri[0].length);
|
|
113
|
+
let quote;
|
|
114
|
+
let start = -1; // Only semicolon-delimited Link parameters count.
|
|
115
|
+
for (let i = 0; i <= parameters.length; i += 1) {
|
|
116
|
+
const char = parameters[i];
|
|
117
|
+
if (quote && char === "\\" && i + 1 < parameters.length) {
|
|
118
|
+
i += 1;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (char === quote)
|
|
122
|
+
quote = undefined;
|
|
123
|
+
else if (!quote && (char === '"' || char === "'"))
|
|
124
|
+
quote = char;
|
|
125
|
+
if (!quote && (char === ";" || i === parameters.length)) {
|
|
126
|
+
if (start >= 0) {
|
|
127
|
+
const rel = /^rel\s*=\s*(?:"([^"]*)"|'([^']*)'|([^;,\s]+))$/iu.exec(parameters.slice(start, i).trim());
|
|
128
|
+
if (rel && (rel[1] ?? rel[2] ?? rel[3] ?? "")
|
|
129
|
+
.toLowerCase().split(/\s+/u).includes("canonical")) {
|
|
130
|
+
found.push(uri[1]);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
start = i + 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (found.length === MAX_CHAIN_CANONICALS)
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
return found;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The shared V03 crawler matrix intentionally has a smaller per-page cap.
|
|
144
|
+
* For V04's larger bounded HTML sample, preserve *all* applicable meta
|
|
145
|
+
* declarations in a small synthetic document instead of truncating the head.
|
|
146
|
+
* If that reduction cannot be completed, don't certify no-noindex-observed.
|
|
147
|
+
*/
|
|
148
|
+
function metadataOnlyHtml(html) {
|
|
149
|
+
if (bytes(html) <= MAX_CRAWLER_HTML_BYTES)
|
|
150
|
+
return html;
|
|
151
|
+
const $ = load(html);
|
|
152
|
+
const tags = [];
|
|
153
|
+
let total = 0;
|
|
154
|
+
let exceeded = false;
|
|
155
|
+
$("meta[name][content]").each((_, element) => {
|
|
156
|
+
const name = ($(element).attr("name") ?? "").trim().toLowerCase();
|
|
157
|
+
if (name !== "robots" && name !== "googlebot")
|
|
158
|
+
return;
|
|
159
|
+
const markup = $.html(element);
|
|
160
|
+
total += bytes(markup);
|
|
161
|
+
if (tags.length >= 64 || total > 64_000) {
|
|
162
|
+
exceeded = true;
|
|
163
|
+
}
|
|
164
|
+
else
|
|
165
|
+
tags.push(markup);
|
|
166
|
+
});
|
|
167
|
+
return exceeded ? undefined : "<html><head>" + tags.join("") + "</head></html>";
|
|
168
|
+
}
|
|
169
|
+
function googleIndexing(row, url) {
|
|
170
|
+
if (row.html === undefined && row.x_robots_tag === undefined)
|
|
171
|
+
return "unknown";
|
|
172
|
+
if (!(row.status_code >= 200 && row.status_code <= 299))
|
|
173
|
+
return "unknown";
|
|
174
|
+
const compact = row.html === undefined ? undefined : metadataOnlyHtml(row.html);
|
|
175
|
+
const review = analyzeCrawlerAccess({
|
|
176
|
+
site_url: url.origin + "/",
|
|
177
|
+
pages: [{
|
|
178
|
+
url: url.href,
|
|
179
|
+
status_code: row.status_code,
|
|
180
|
+
...(compact === undefined ? {} : { html: compact }),
|
|
181
|
+
...(row.x_robots_tag === undefined ? {} : { x_robots_tag: row.x_robots_tag }),
|
|
182
|
+
}],
|
|
183
|
+
profiles: ["googlebot-desktop"],
|
|
184
|
+
});
|
|
185
|
+
return review.rows[0]?.indexing_state ?? "unknown";
|
|
186
|
+
}
|
|
187
|
+
export function emptyRedirectCanonicalReview(scope = "caller_supplied_redirect_evidence") {
|
|
188
|
+
return {
|
|
189
|
+
scope, hops_observed: 0, redirects_observed: 0, permanent_redirects: 0,
|
|
190
|
+
temporary_redirects: 0, chain_complete: false, loop_detected: false,
|
|
191
|
+
conflicting_canonical_hops: 0, canonical_cycles: 0, canonical_chain_edges: 0,
|
|
192
|
+
nonindexable_destination: false, destination_indexing_state: "unknown",
|
|
193
|
+
coverage_limited: true, limitations, hops: [], total_findings: 0,
|
|
194
|
+
findings: [], findings_truncated: false,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
export function analyzeRedirectCanonicalChains(input, scope = "caller_supplied_redirect_evidence") {
|
|
198
|
+
const source = safeAbsoluteLabel(input?.source_url);
|
|
199
|
+
const records = input?.observations;
|
|
200
|
+
if (!source || !Array.isArray(records) || records.length < 1 ||
|
|
201
|
+
records.length > MAX_CHAIN_HOPS) {
|
|
202
|
+
throw new Error("Provide one to eight ordered HTTP observations and one safe source URL.");
|
|
203
|
+
}
|
|
204
|
+
const expected = input.expected_destination === undefined
|
|
205
|
+
? undefined : safeAbsoluteLabel(input.expected_destination);
|
|
206
|
+
if (input.expected_destination !== undefined && !expected) {
|
|
207
|
+
throw new Error("The expected destination must be a safe URL label.");
|
|
208
|
+
}
|
|
209
|
+
let htmlTotal = 0;
|
|
210
|
+
const urls = records.map((record) => {
|
|
211
|
+
const url = safeAbsoluteLabel(record.url);
|
|
212
|
+
if (!url || !Number.isInteger(record.status_code) ||
|
|
213
|
+
record.status_code < 100 || record.status_code > 599) {
|
|
214
|
+
throw new Error("Each observed hop requires a valid safe URL label and HTTP status.");
|
|
215
|
+
}
|
|
216
|
+
if (record.location !== undefined &&
|
|
217
|
+
(typeof record.location !== "string" || bytes(record.location) > MAX_CHAIN_URL_BYTES)) {
|
|
218
|
+
throw new Error("Oversized redirect Location evidence.");
|
|
219
|
+
}
|
|
220
|
+
if (record.canonicals !== undefined && (!Array.isArray(record.canonicals) ||
|
|
221
|
+
record.canonicals.length > MAX_CHAIN_CANONICALS ||
|
|
222
|
+
record.canonicals.some((c) => typeof c !== "string" || bytes(c) > MAX_CHAIN_URL_BYTES))) {
|
|
223
|
+
throw new Error("Canonical declarations exceed the bounded input format.");
|
|
224
|
+
}
|
|
225
|
+
if (record.html !== undefined) {
|
|
226
|
+
if (typeof record.html !== "string")
|
|
227
|
+
throw new Error("Invalid HTML sample");
|
|
228
|
+
const size = bytes(record.html);
|
|
229
|
+
htmlTotal += size;
|
|
230
|
+
if (size > MAX_CHAIN_HTML_BYTES || htmlTotal > MAX_CHAIN_TOTAL_HTML_BYTES) {
|
|
231
|
+
throw new Error("Source HTML exceeds V04 byte caps.");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (record.x_robots_tag !== undefined &&
|
|
235
|
+
(!Array.isArray(record.x_robots_tag) || record.x_robots_tag.length > 8 ||
|
|
236
|
+
record.x_robots_tag.some((h) => typeof h !== "string" || bytes(h) > 512))) {
|
|
237
|
+
throw new Error("X-Robots-Tag observations exceed the bounded input format.");
|
|
238
|
+
}
|
|
239
|
+
if (record.robots_allowed !== undefined && typeof record.robots_allowed !== "boolean") {
|
|
240
|
+
throw new Error("Invalid robots accessibility observation.");
|
|
241
|
+
}
|
|
242
|
+
return url;
|
|
243
|
+
});
|
|
244
|
+
if (urls[0].href !== source.href) {
|
|
245
|
+
throw new Error("The initial hop must be the specified source URL.");
|
|
246
|
+
}
|
|
247
|
+
const out = emptyRedirectCanonicalReview(scope);
|
|
248
|
+
const indexByUrl = new Map(urls.map((url, idx) => [url.href, idx]));
|
|
249
|
+
const indexingByRow = records.map((record, index) => googleIndexing(record, urls[index]));
|
|
250
|
+
const isObserved = new Set();
|
|
251
|
+
const canonicalLinks = new Map();
|
|
252
|
+
const seenCycles = new Set();
|
|
253
|
+
let consistent = true;
|
|
254
|
+
const add = (hop, code, severity, message) => {
|
|
255
|
+
out.total_findings++;
|
|
256
|
+
if (out.findings.length < MAX_CHAIN_FINDINGS) {
|
|
257
|
+
out.findings.push({ hop, code, severity, message });
|
|
258
|
+
}
|
|
259
|
+
else
|
|
260
|
+
out.findings_truncated = true;
|
|
261
|
+
};
|
|
262
|
+
for (let idx = 0; idx < records.length; idx++) {
|
|
263
|
+
const record = records[idx];
|
|
264
|
+
const url = urls[idx];
|
|
265
|
+
const hop = idx + 1;
|
|
266
|
+
const redirect = isRedirect(record.status_code);
|
|
267
|
+
const next = urls[idx + 1];
|
|
268
|
+
if (next && !redirect) {
|
|
269
|
+
throw new Error("Non-final observations must be redirect HTTP responses.");
|
|
270
|
+
}
|
|
271
|
+
const state = redirectState(record.status_code);
|
|
272
|
+
if (redirect) {
|
|
273
|
+
out.redirects_observed++;
|
|
274
|
+
if (state === "permanent")
|
|
275
|
+
out.permanent_redirects++;
|
|
276
|
+
else
|
|
277
|
+
out.temporary_redirects++;
|
|
278
|
+
}
|
|
279
|
+
let redirect_target = "none";
|
|
280
|
+
let next_hop_observed = false;
|
|
281
|
+
const location = redirect && record.location !== undefined
|
|
282
|
+
? target(record.location, url) : null;
|
|
283
|
+
if (redirect) {
|
|
284
|
+
if (record.location === undefined || record.location.length === 0) {
|
|
285
|
+
redirect_target = "missing";
|
|
286
|
+
add(hop, "redirect_missing_location", "warning", "This HTTP redirect has no usable Location header.");
|
|
287
|
+
consistent = false;
|
|
288
|
+
}
|
|
289
|
+
else if (!location) {
|
|
290
|
+
redirect_target = "invalid";
|
|
291
|
+
add(hop, "redirect_invalid_target", "warning", "This redirect has an invalid or unsafe Location target.");
|
|
292
|
+
consistent = false;
|
|
293
|
+
}
|
|
294
|
+
else if (isObserved.has(location.href) || location.href === url.href) {
|
|
295
|
+
redirect_target = "loop";
|
|
296
|
+
out.loop_detected = true;
|
|
297
|
+
consistent = false;
|
|
298
|
+
add(hop, "redirect_loop", "warning", "The redirect points to a previously observed URL in this chain.");
|
|
299
|
+
}
|
|
300
|
+
else if (next && location.href !== next.href) {
|
|
301
|
+
redirect_target = "mismatch";
|
|
302
|
+
consistent = false;
|
|
303
|
+
add(hop, "redirect_observation_mismatch", "warning", "The next supplied hop does not match the observed Location target.");
|
|
304
|
+
}
|
|
305
|
+
else if (url.protocol === "https:" && location.protocol === "http:") {
|
|
306
|
+
redirect_target = "https_downgrade";
|
|
307
|
+
next_hop_observed = Boolean(next && location.href === next.href);
|
|
308
|
+
add(hop, "redirect_https_downgrade", "warning", "The redirect target downgrades an HTTPS page to HTTP.");
|
|
309
|
+
}
|
|
310
|
+
else if (location.origin !== url.origin) {
|
|
311
|
+
redirect_target = "cross_origin";
|
|
312
|
+
next_hop_observed = Boolean(next && location.href === next.href);
|
|
313
|
+
add(hop, "redirect_cross_origin", "info", "The observed redirect crosses an origin boundary; inspect that destination independently.");
|
|
314
|
+
}
|
|
315
|
+
else if (location.search) {
|
|
316
|
+
redirect_target = "query_target";
|
|
317
|
+
next_hop_observed = Boolean(next && location.href === next.href);
|
|
318
|
+
add(hop, "redirect_query_target", "info", "The target has query parameters; confirm that its destination and content are intended.");
|
|
319
|
+
}
|
|
320
|
+
else if (next && location.href === next.href) {
|
|
321
|
+
redirect_target = "next_observed";
|
|
322
|
+
next_hop_observed = true;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
redirect_target = "unobserved";
|
|
326
|
+
add(hop, "redirect_chain_unobserved", "info", "The redirect destination was not included among the supplied responses.");
|
|
327
|
+
}
|
|
328
|
+
if (next && !next_hop_observed && location?.href !== next.href)
|
|
329
|
+
consistent = false;
|
|
330
|
+
if (!next)
|
|
331
|
+
consistent = false;
|
|
332
|
+
}
|
|
333
|
+
isObserved.add(url.href);
|
|
334
|
+
const declarations = [...(record.canonicals ?? []), ...htmlCanonicals(record.html)];
|
|
335
|
+
let canonical_state = "absent";
|
|
336
|
+
let canonical_target_sampled = false;
|
|
337
|
+
const candidates = declarations.map((declaration) => target(declaration, url));
|
|
338
|
+
if (declarations.length > 0) {
|
|
339
|
+
const good = candidates.filter((candidate) => candidate !== null);
|
|
340
|
+
const distinct = new Set(good.map((candidate) => candidate.href));
|
|
341
|
+
if (distinct.size > 1) {
|
|
342
|
+
canonical_state = "conflicting";
|
|
343
|
+
out.conflicting_canonical_hops++;
|
|
344
|
+
add(hop, "canonical_conflict", "warning", "A single observed response declares different canonical target URLs.");
|
|
345
|
+
}
|
|
346
|
+
else if (good.length !== candidates.length || good.length === 0) {
|
|
347
|
+
canonical_state = "invalid";
|
|
348
|
+
add(hop, "canonical_invalid", "warning", "At least one canonical declaration has an invalid or unsafe URL.");
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
const first = good[0];
|
|
352
|
+
canonical_target_sampled = indexByUrl.has(first.href);
|
|
353
|
+
if (first.href === url.href)
|
|
354
|
+
canonical_state = "self";
|
|
355
|
+
else if (first.origin !== url.origin) {
|
|
356
|
+
canonical_state = "external";
|
|
357
|
+
add(hop, "canonical_external", "info", "The declared canonical target is outside this origin and is not verified here.");
|
|
358
|
+
}
|
|
359
|
+
else if (!canonical_target_sampled) {
|
|
360
|
+
canonical_state = "unobserved";
|
|
361
|
+
add(hop, "canonical_unobserved", "info", "The canonical target is not sampled; its status and indexing state are unknown.");
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
canonical_state = "sampled";
|
|
365
|
+
canonicalLinks.set(idx, first.href);
|
|
366
|
+
const targetIdx = indexByUrl.get(first.href);
|
|
367
|
+
const targetRecord = records[targetIdx];
|
|
368
|
+
if (isRedirect(targetRecord.status_code)) {
|
|
369
|
+
canonical_state = "redirect_target";
|
|
370
|
+
add(hop, "canonical_to_redirect", "warning", "A canonical target is itself an observed HTTP redirect; use its resolved final page.");
|
|
371
|
+
}
|
|
372
|
+
if (shortStatus(targetRecord.status_code)) {
|
|
373
|
+
add(hop, "canonical_to_http_error", "warning", "The canonical points to a sampled HTTP 4xx/5xx response.");
|
|
374
|
+
}
|
|
375
|
+
if (indexingByRow[targetIdx] === "explicit_noindex") {
|
|
376
|
+
add(hop, "canonical_to_noindex", "warning", "The canonical target has an observed Google-applicable noindex declaration.");
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const indexing = indexingByRow[idx];
|
|
382
|
+
out.hops.push({
|
|
383
|
+
hop, status_code: record.status_code,
|
|
384
|
+
redirect_state: state, redirect_target, next_hop_observed,
|
|
385
|
+
canonical_state, canonical_declarations: declarations.length,
|
|
386
|
+
canonical_target_sampled, googlebot_indexing_state: indexing,
|
|
387
|
+
robots_allowed: record.robots_allowed === undefined ? "unknown"
|
|
388
|
+
: record.robots_allowed ? "allowed" : "disallowed",
|
|
389
|
+
static_html_examined: record.html !== undefined,
|
|
390
|
+
x_robots_header_examined: record.x_robots_tag !== undefined,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
// Canonical graph analysis is limited to actually supplied edges. Unknown
|
|
394
|
+
// targets do not become synthetic nodes or asserted errors.
|
|
395
|
+
for (const [start] of canonicalLinks) {
|
|
396
|
+
const traversed = [];
|
|
397
|
+
const seen = new Map();
|
|
398
|
+
let at = start;
|
|
399
|
+
while (at !== undefined) {
|
|
400
|
+
if (seen.has(at)) {
|
|
401
|
+
const cycle = traversed.slice(seen.get(at));
|
|
402
|
+
const key = [...cycle].sort((a, b) => a - b).join(",");
|
|
403
|
+
if (!seenCycles.has(key) && cycle.length > 1) {
|
|
404
|
+
seenCycles.add(key);
|
|
405
|
+
out.canonical_cycles++;
|
|
406
|
+
add(start + 1, "canonical_cycle", "warning", "Two or more sampled pages declare canonical URLs that form a cycle.");
|
|
407
|
+
}
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
if (traversed.length > MAX_CHAIN_HOPS)
|
|
411
|
+
break;
|
|
412
|
+
seen.set(at, traversed.length);
|
|
413
|
+
traversed.push(at);
|
|
414
|
+
const label = canonicalLinks.get(at);
|
|
415
|
+
at = label === undefined ? undefined : indexByUrl.get(label);
|
|
416
|
+
}
|
|
417
|
+
if (traversed.length >= 2 && at === undefined && canonicalLinks.has(traversed[1])) {
|
|
418
|
+
out.canonical_chain_edges++;
|
|
419
|
+
add(start + 1, "canonical_chain", "info", "A canonical target declares a different sampled canonical target; review the canonical chain.");
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const final = records.at(-1);
|
|
423
|
+
const last = out.hops.at(-1);
|
|
424
|
+
out.hops_observed = out.hops.length;
|
|
425
|
+
out.chain_complete = !isRedirect(final.status_code) && !out.loop_detected && consistent;
|
|
426
|
+
if (out.chain_complete) {
|
|
427
|
+
out.final_status_code = final.status_code;
|
|
428
|
+
out.destination_indexing_state = last.googlebot_indexing_state;
|
|
429
|
+
if (expected) {
|
|
430
|
+
out.expected_destination_match = urls.at(-1).href === expected.href;
|
|
431
|
+
if (!out.expected_destination_match) {
|
|
432
|
+
add(records.length, "expected_destination_mismatch", "warning", "The sampled chain resolved to a different URL than the caller's expected destination.");
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (shortStatus(final.status_code)) {
|
|
436
|
+
out.nonindexable_destination = true;
|
|
437
|
+
add(records.length, "redirect_destination_http_error", "warning", "The sampled chain ends at HTTP 4xx/5xx, not an indexable success response.");
|
|
438
|
+
}
|
|
439
|
+
if (last.googlebot_indexing_state === "explicit_noindex") {
|
|
440
|
+
out.nonindexable_destination = true;
|
|
441
|
+
add(records.length, "redirect_destination_noindex", "warning", "The sampled redirect destination declares noindex for Googlebot.");
|
|
442
|
+
}
|
|
443
|
+
if (final.robots_allowed === false) {
|
|
444
|
+
out.nonindexable_destination = true;
|
|
445
|
+
add(records.length, "redirect_destination_robots_blocked", "warning", "The destination is explicitly marked robots-disallowed by caller-supplied evidence.");
|
|
446
|
+
}
|
|
447
|
+
if (last.googlebot_indexing_state === "unknown") {
|
|
448
|
+
add(records.length, "destination_indexing_unverified", "info", "The final response's indexing directives were not fully observed.");
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
add(records.length, "final_status_unverified", "info", "A complete, consistent non-redirect destination response was not observed.");
|
|
453
|
+
}
|
|
454
|
+
if (out.redirects_observed >= 4) {
|
|
455
|
+
add(1, "redirect_long_chain", "info", "This chain contains four or more redirect responses; shorter direct redirects are preferable.");
|
|
456
|
+
}
|
|
457
|
+
return out;
|
|
458
|
+
}
|
|
459
|
+
//# sourceMappingURL=redirect-canonical-chains.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirect-canonical-chains.js","sourceRoot":"","sources":["../../../src/modules/http-crawl/redirect-canonical-chains.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAEnF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAChC,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,yEAAyE;AACzE,sEAAsE;AACtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AAC9C,MAAM,CAAC,MAAM,0BAA0B,GAAG,SAAS,CAAC;AACpD,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACjC,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,MAAM,EAAE,WAAW,EAAE,WAAW;CACxB,CAAC;AACX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc;IAC/C,iBAAiB,EAAE,cAAc,EAAE,YAAY;IAC/C,SAAS,EAAE,SAAS,EAAE,UAAU;CACxB,CAAC;AACX,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY;IACrD,aAAa,EAAE,SAAS,EAAE,iBAAiB;CACnC,CAAC;AACX,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,kBAAkB,EAAE,qBAAqB,EAAE,SAAS;CAC5C,CAAC;AACX,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EAClC,+FAA+F,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * V04: bounded HTTP redirect and canonical-chain evidence review.\n * Pure offline analyzer shared by Node and Cloudflare Worker MCPs.\n *\n * Original URL strings, source HTML, headers, tokens and query parameters\n * never appear in the report. No crawler/indexing verdict is asserted.\n */\nimport { load } from \"cheerio\";\nimport { safeVariantLabel } from \"./url-variants.js\";\nimport { analyzeCrawlerAccess, MAX_CRAWLER_HTML_BYTES } from \"./crawler-access.js\";\n\nexport const MAX_CHAIN_HOPS = 8;\nexport const MAX_CHAIN_FINDINGS = 24;\nexport const MAX_CHAIN_CANONICALS = 4;\n// Match the existing hosted public HTML 1 MiB fetch cap; 150 KB excluded\n// ordinary production pages with embedded application bootstrap data.\nexport const MAX_CHAIN_HTML_BYTES = 1_048_576;\nexport const MAX_CHAIN_TOTAL_HTML_BYTES = 1_500_000;\nconst MAX_CHAIN_URL_BYTES = 1024;\nexport const CHAIN_REDIRECT_STATES = [\n \"none\", \"permanent\", \"temporary\",\n] as const;\nexport const CHAIN_TARGET_STATES = [\n \"none\", \"next_observed\", \"loop\", \"cross_origin\",\n \"https_downgrade\", \"query_target\", \"unobserved\",\n \"missing\", \"invalid\", \"mismatch\",\n] as const;\nexport const CHAIN_CANONICAL_STATES = [\n \"absent\", \"self\", \"sampled\", \"external\", \"unobserved\",\n \"conflicting\", \"invalid\", \"redirect_target\",\n] as const;\nexport const CHAIN_INDEXING_STATES = [\n \"explicit_noindex\", \"no_noindex_observed\", \"unknown\",\n] as const;\nexport const CHAIN_FINDING_CODES = [\n \"redirect_missing_location\", \"redirect_invalid_target\",\n \"redirect_loop\", \"redirect_cross_origin\", \"redirect_https_downgrade\",\n \"redirect_query_target\", \"redirect_observation_mismatch\",\n \"redirect_chain_unobserved\", \"redirect_long_chain\",\n \"redirect_destination_http_error\", \"redirect_destination_noindex\",\n \"redirect_destination_robots_blocked\", \"expected_destination_mismatch\",\n \"canonical_conflict\", \"canonical_invalid\",\n \"canonical_external\", \"canonical_unobserved\",\n \"canonical_to_redirect\", \"canonical_to_http_error\",\n \"canonical_to_noindex\", \"canonical_cycle\", \"canonical_chain\",\n \"final_status_unverified\", \"destination_indexing_unverified\",\n] as const;\n\nexport type ChainRedirectState = typeof CHAIN_REDIRECT_STATES[number];\nexport type ChainTargetState = typeof CHAIN_TARGET_STATES[number];\nexport type ChainCanonicalState = typeof CHAIN_CANONICAL_STATES[number];\nexport type ChainIndexingState = typeof CHAIN_INDEXING_STATES[number];\nexport type ChainFindingCode = typeof CHAIN_FINDING_CODES[number];\n\nexport interface RedirectChainObservation {\n url: string;\n status_code: number;\n location?: string;\n /** Caller-supplied canonical href values, including extracted HTTP Link rel=canonical. */\n canonicals?: string[];\n /** Optional static raw HTML from the HTTP GET (not rendered DOM). */\n html?: string;\n /** [] explicitly means the X-Robots-Tag header was checked and absent. */\n x_robots_tag?: string[];\n /** Actual caller-observed robots accessibility, never inferred from a GET. */\n robots_allowed?: boolean;\n}\n\nexport interface RedirectCanonicalInput {\n source_url: string;\n observations: RedirectChainObservation[];\n expected_destination?: string;\n}\n\nexport interface RedirectCanonicalHop {\n hop: number;\n status_code: number;\n redirect_state: ChainRedirectState;\n redirect_target: ChainTargetState;\n next_hop_observed: boolean;\n canonical_state: ChainCanonicalState;\n canonical_declarations: number;\n canonical_target_sampled: boolean;\n googlebot_indexing_state: ChainIndexingState;\n robots_allowed: \"allowed\" | \"disallowed\" | \"unknown\";\n static_html_examined: boolean;\n x_robots_header_examined: boolean;\n}\n\nexport interface RedirectCanonicalFinding {\n hop: number;\n code: ChainFindingCode;\n severity: \"warning\" | \"info\";\n message: string;\n}\n\nexport interface RedirectCanonicalReview {\n scope: \"caller_supplied_redirect_evidence\" | \"live_public_redirect_probe\";\n hops_observed: number;\n redirects_observed: number;\n permanent_redirects: number;\n temporary_redirects: number;\n chain_complete: boolean;\n loop_detected: boolean;\n final_status_code?: number;\n expected_destination_match?: boolean;\n conflicting_canonical_hops: number;\n canonical_cycles: number;\n canonical_chain_edges: number;\n nonindexable_destination: boolean;\n destination_indexing_state: ChainIndexingState;\n coverage_limited: true;\n limitations: string[];\n hops: RedirectCanonicalHop[];\n total_findings: number;\n findings: RedirectCanonicalFinding[];\n findings_truncated: boolean;\n error?: string;\n}\n\nconst limitations = [\n \"Observed redirects and canonical declarations are signals, not Google's selected canonical or a live indexing verdict.\",\n \"An unobserved redirect or canonical target is unknown, not proven missing, broken or wrong.\",\n \"Only supplied/static HTML and X-Robots-Tag evidence was checked, never rendered JavaScript content.\",\n \"A different destination is called mismatched only when an expected destination was explicitly provided.\",\n];\n\nconst enc = new TextEncoder();\nfunction bytes(value: string): number { return enc.encode(value).byteLength; }\nfunction safeAbsoluteLabel(raw: string): URL | null {\n if (typeof raw !== \"string\" || raw.length > MAX_CHAIN_URL_BYTES ||\n bytes(raw) > MAX_CHAIN_URL_BYTES) return null;\n const safe = safeVariantLabel(raw);\n if (!safe) return null;\n return new URL(safe);\n}\nfunction target(raw: string, base: URL): URL | null {\n try {\n if (typeof raw !== \"string\" || !raw || bytes(raw) > MAX_CHAIN_URL_BYTES ||\n /[\\u0000-\\u001f\\u007f-\\u009f\\u202a-\\u202e\\u2066-\\u2069\\\\]/u.test(raw) ||\n raw.includes(\"#\")) return null;\n const out = new URL(raw, base);\n if (![\"http:\", \"https:\"].includes(out.protocol) || out.username || out.password ||\n out.port || out.hash) return null;\n return out;\n } catch { return null; }\n}\nfunction isRedirect(status: number): boolean {\n return [301, 302, 303, 307, 308].includes(status);\n}\nfunction redirectState(status: number): ChainRedirectState {\n if (status === 301 || status === 308) return \"permanent\";\n if (status === 302 || status === 303 || status === 307) return \"temporary\";\n return \"none\";\n}\nfunction shortStatus(status: number): boolean { return status >= 400 && status <= 599; }\nfunction htmlCanonicals(html: string | undefined): string[] {\n if (html === undefined) return [];\n const $ = load(html);\n const matches: string[] = [];\n $(\"head > link[rel][href]\").each((_, el) => {\n const rel = ($(el).attr(\"rel\") ?? \"\").trim().toLowerCase().split(/\\s+/);\n if (rel.includes(\"canonical\")) matches.push(($(el).attr(\"href\") ?? \"\").trim());\n });\n return matches;\n}\n\n/** Extract rel=canonical hrefs from a bounded HTTP Link field, without echoing them. */\nexport function canonicalHrefsFromLinkHeader(value: string | null): string[] {\n if (!value || bytes(value) > 8_192) return [];\n const found: string[] = [];\n for (const part of value.split(/,(?=\\s*<)/u)) {\n const uri = /^\\s*<([^<>]{1,1024})>/u.exec(part);\n if (!uri) continue;\n const parameters = part.slice(uri[0].length);\n let quote: \"\\\"\" | \"'\" | undefined;\n let start = -1; // Only semicolon-delimited Link parameters count.\n for (let i = 0; i <= parameters.length; i += 1) {\n const char = parameters[i];\n if (quote && char === \"\\\\\" && i + 1 < parameters.length) { i += 1; continue; }\n if (char === quote) quote = undefined;\n else if (!quote && (char === '\"' || char === \"'\")) quote = char;\n if (!quote && (char === \";\" || i === parameters.length)) {\n if (start >= 0) {\n const rel = /^rel\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^;,\\s]+))$/iu.exec(\n parameters.slice(start, i).trim(),\n );\n if (rel && (rel[1] ?? rel[2] ?? rel[3] ?? \"\")\n .toLowerCase().split(/\\s+/u).includes(\"canonical\")) {\n found.push(uri[1]);\n break;\n }\n }\n start = i + 1;\n }\n }\n if (found.length === MAX_CHAIN_CANONICALS) break;\n }\n return found;\n}\n\n/**\n * The shared V03 crawler matrix intentionally has a smaller per-page cap.\n * For V04's larger bounded HTML sample, preserve *all* applicable meta\n * declarations in a small synthetic document instead of truncating the head.\n * If that reduction cannot be completed, don't certify no-noindex-observed.\n */\nfunction metadataOnlyHtml(html: string): string | undefined {\n if (bytes(html) <= MAX_CRAWLER_HTML_BYTES) return html;\n const $ = load(html);\n const tags: string[] = [];\n let total = 0;\n let exceeded = false;\n $(\"meta[name][content]\").each((_, element) => {\n const name = ($(element).attr(\"name\") ?? \"\").trim().toLowerCase();\n if (name !== \"robots\" && name !== \"googlebot\") return;\n const markup = $.html(element);\n total += bytes(markup);\n if (tags.length >= 64 || total > 64_000) {\n exceeded = true;\n } else tags.push(markup);\n });\n return exceeded ? undefined : \"<html><head>\" + tags.join(\"\") + \"</head></html>\";\n}\n\nfunction googleIndexing(row: RedirectChainObservation, url: URL): ChainIndexingState {\n if (row.html === undefined && row.x_robots_tag === undefined) return \"unknown\";\n if (!(row.status_code >= 200 && row.status_code <= 299)) return \"unknown\";\n const compact = row.html === undefined ? undefined : metadataOnlyHtml(row.html);\n const review = analyzeCrawlerAccess({\n site_url: url.origin + \"/\",\n pages: [{\n url: url.href,\n status_code: row.status_code,\n ...(compact === undefined ? {} : { html: compact }),\n ...(row.x_robots_tag === undefined ? {} : { x_robots_tag: row.x_robots_tag }),\n }],\n profiles: [\"googlebot-desktop\"],\n });\n return review.rows[0]?.indexing_state ?? \"unknown\";\n}\n\nexport function emptyRedirectCanonicalReview(\n scope: RedirectCanonicalReview[\"scope\"] = \"caller_supplied_redirect_evidence\",\n): RedirectCanonicalReview {\n return {\n scope, hops_observed: 0, redirects_observed: 0, permanent_redirects: 0,\n temporary_redirects: 0, chain_complete: false, loop_detected: false,\n conflicting_canonical_hops: 0, canonical_cycles: 0, canonical_chain_edges: 0,\n nonindexable_destination: false, destination_indexing_state: \"unknown\",\n coverage_limited: true, limitations, hops: [], total_findings: 0,\n findings: [], findings_truncated: false,\n };\n}\n\nexport function analyzeRedirectCanonicalChains(\n input: RedirectCanonicalInput,\n scope: RedirectCanonicalReview[\"scope\"] = \"caller_supplied_redirect_evidence\",\n): RedirectCanonicalReview {\n const source = safeAbsoluteLabel(input?.source_url);\n const records = input?.observations;\n if (!source || !Array.isArray(records) || records.length < 1 ||\n records.length > MAX_CHAIN_HOPS) {\n throw new Error(\"Provide one to eight ordered HTTP observations and one safe source URL.\");\n }\n const expected = input.expected_destination === undefined\n ? undefined : safeAbsoluteLabel(input.expected_destination);\n if (input.expected_destination !== undefined && !expected) {\n throw new Error(\"The expected destination must be a safe URL label.\");\n }\n let htmlTotal = 0;\n const urls = records.map((record) => {\n const url = safeAbsoluteLabel(record.url);\n if (!url || !Number.isInteger(record.status_code) ||\n record.status_code < 100 || record.status_code > 599) {\n throw new Error(\"Each observed hop requires a valid safe URL label and HTTP status.\");\n }\n if (record.location !== undefined &&\n (typeof record.location !== \"string\" || bytes(record.location) > MAX_CHAIN_URL_BYTES)) {\n throw new Error(\"Oversized redirect Location evidence.\");\n }\n if (record.canonicals !== undefined && (!Array.isArray(record.canonicals) ||\n record.canonicals.length > MAX_CHAIN_CANONICALS ||\n record.canonicals.some((c) => typeof c !== \"string\" || bytes(c) > MAX_CHAIN_URL_BYTES))) {\n throw new Error(\"Canonical declarations exceed the bounded input format.\");\n }\n if (record.html !== undefined) {\n if (typeof record.html !== \"string\") throw new Error(\"Invalid HTML sample\");\n const size = bytes(record.html);\n htmlTotal += size;\n if (size > MAX_CHAIN_HTML_BYTES || htmlTotal > MAX_CHAIN_TOTAL_HTML_BYTES) {\n throw new Error(\"Source HTML exceeds V04 byte caps.\");\n }\n }\n if (record.x_robots_tag !== undefined &&\n (!Array.isArray(record.x_robots_tag) || record.x_robots_tag.length > 8 ||\n record.x_robots_tag.some((h) => typeof h !== \"string\" || bytes(h) > 512))) {\n throw new Error(\"X-Robots-Tag observations exceed the bounded input format.\");\n }\n if (record.robots_allowed !== undefined && typeof record.robots_allowed !== \"boolean\") {\n throw new Error(\"Invalid robots accessibility observation.\");\n }\n return url;\n });\n if (urls[0].href !== source.href) {\n throw new Error(\"The initial hop must be the specified source URL.\");\n }\n\n const out = emptyRedirectCanonicalReview(scope);\n const indexByUrl = new Map(urls.map((url, idx) => [url.href, idx]));\n const indexingByRow = records.map((record, index) => googleIndexing(record, urls[index]));\n const isObserved = new Set<string>();\n const canonicalLinks = new Map<number, string>();\n const seenCycles = new Set<string>();\n let consistent = true;\n const add = (hop: number, code: ChainFindingCode, severity: \"warning\" | \"info\",\n message: string) => {\n out.total_findings++;\n if (out.findings.length < MAX_CHAIN_FINDINGS) {\n out.findings.push({ hop, code, severity, message });\n } else out.findings_truncated = true;\n };\n\n for (let idx = 0; idx < records.length; idx++) {\n const record = records[idx];\n const url = urls[idx];\n const hop = idx + 1;\n const redirect = isRedirect(record.status_code);\n const next = urls[idx + 1];\n if (next && !redirect) {\n throw new Error(\"Non-final observations must be redirect HTTP responses.\");\n }\n const state = redirectState(record.status_code);\n if (redirect) {\n out.redirects_observed++;\n if (state === \"permanent\") out.permanent_redirects++;\n else out.temporary_redirects++;\n }\n\n let redirect_target: ChainTargetState = \"none\";\n let next_hop_observed = false;\n const location = redirect && record.location !== undefined\n ? target(record.location, url) : null;\n if (redirect) {\n if (record.location === undefined || record.location.length === 0) {\n redirect_target = \"missing\";\n add(hop, \"redirect_missing_location\", \"warning\",\n \"This HTTP redirect has no usable Location header.\");\n consistent = false;\n } else if (!location) {\n redirect_target = \"invalid\";\n add(hop, \"redirect_invalid_target\", \"warning\",\n \"This redirect has an invalid or unsafe Location target.\");\n consistent = false;\n } else if (isObserved.has(location.href) || location.href === url.href) {\n redirect_target = \"loop\";\n out.loop_detected = true;\n consistent = false;\n add(hop, \"redirect_loop\", \"warning\",\n \"The redirect points to a previously observed URL in this chain.\");\n } else if (next && location.href !== next.href) {\n redirect_target = \"mismatch\";\n consistent = false;\n add(hop, \"redirect_observation_mismatch\", \"warning\",\n \"The next supplied hop does not match the observed Location target.\");\n } else if (url.protocol === \"https:\" && location.protocol === \"http:\") {\n redirect_target = \"https_downgrade\";\n next_hop_observed = Boolean(next && location.href === next.href);\n add(hop, \"redirect_https_downgrade\", \"warning\",\n \"The redirect target downgrades an HTTPS page to HTTP.\");\n } else if (location.origin !== url.origin) {\n redirect_target = \"cross_origin\";\n next_hop_observed = Boolean(next && location.href === next.href);\n add(hop, \"redirect_cross_origin\", \"info\",\n \"The observed redirect crosses an origin boundary; inspect that destination independently.\");\n } else if (location.search) {\n redirect_target = \"query_target\";\n next_hop_observed = Boolean(next && location.href === next.href);\n add(hop, \"redirect_query_target\", \"info\",\n \"The target has query parameters; confirm that its destination and content are intended.\");\n } else if (next && location.href === next.href) {\n redirect_target = \"next_observed\";\n next_hop_observed = true;\n } else {\n redirect_target = \"unobserved\";\n add(hop, \"redirect_chain_unobserved\", \"info\",\n \"The redirect destination was not included among the supplied responses.\");\n }\n if (next && !next_hop_observed && location?.href !== next.href) consistent = false;\n if (!next) consistent = false;\n }\n isObserved.add(url.href);\n\n const declarations = [...(record.canonicals ?? []), ...htmlCanonicals(record.html)];\n let canonical_state: ChainCanonicalState = \"absent\";\n let canonical_target_sampled = false;\n const candidates = declarations.map((declaration) => target(declaration, url));\n if (declarations.length > 0) {\n const good = candidates.filter((candidate): candidate is URL => candidate !== null);\n const distinct = new Set(good.map((candidate) => candidate.href));\n if (distinct.size > 1) {\n canonical_state = \"conflicting\";\n out.conflicting_canonical_hops++;\n add(hop, \"canonical_conflict\", \"warning\",\n \"A single observed response declares different canonical target URLs.\");\n } else if (good.length !== candidates.length || good.length === 0) {\n canonical_state = \"invalid\";\n add(hop, \"canonical_invalid\", \"warning\",\n \"At least one canonical declaration has an invalid or unsafe URL.\");\n } else {\n const first = good[0];\n canonical_target_sampled = indexByUrl.has(first.href);\n if (first.href === url.href) canonical_state = \"self\";\n else if (first.origin !== url.origin) {\n canonical_state = \"external\";\n add(hop, \"canonical_external\", \"info\",\n \"The declared canonical target is outside this origin and is not verified here.\");\n } else if (!canonical_target_sampled) {\n canonical_state = \"unobserved\";\n add(hop, \"canonical_unobserved\", \"info\",\n \"The canonical target is not sampled; its status and indexing state are unknown.\");\n } else {\n canonical_state = \"sampled\";\n canonicalLinks.set(idx, first.href);\n const targetIdx = indexByUrl.get(first.href)!;\n const targetRecord = records[targetIdx];\n if (isRedirect(targetRecord.status_code)) {\n canonical_state = \"redirect_target\";\n add(hop, \"canonical_to_redirect\", \"warning\",\n \"A canonical target is itself an observed HTTP redirect; use its resolved final page.\");\n }\n if (shortStatus(targetRecord.status_code)) {\n add(hop, \"canonical_to_http_error\", \"warning\",\n \"The canonical points to a sampled HTTP 4xx/5xx response.\");\n }\n if (indexingByRow[targetIdx] === \"explicit_noindex\") {\n add(hop, \"canonical_to_noindex\", \"warning\",\n \"The canonical target has an observed Google-applicable noindex declaration.\");\n }\n }\n }\n }\n\n const indexing = indexingByRow[idx];\n out.hops.push({\n hop, status_code: record.status_code,\n redirect_state: state, redirect_target, next_hop_observed,\n canonical_state, canonical_declarations: declarations.length,\n canonical_target_sampled, googlebot_indexing_state: indexing,\n robots_allowed: record.robots_allowed === undefined ? \"unknown\"\n : record.robots_allowed ? \"allowed\" : \"disallowed\",\n static_html_examined: record.html !== undefined,\n x_robots_header_examined: record.x_robots_tag !== undefined,\n });\n }\n\n // Canonical graph analysis is limited to actually supplied edges. Unknown\n // targets do not become synthetic nodes or asserted errors.\n for (const [start] of canonicalLinks) {\n const traversed: number[] = [];\n const seen = new Map<number, number>();\n let at: number | undefined = start;\n while (at !== undefined) {\n if (seen.has(at)) {\n const cycle = traversed.slice(seen.get(at)!);\n const key = [...cycle].sort((a, b) => a - b).join(\",\");\n if (!seenCycles.has(key) && cycle.length > 1) {\n seenCycles.add(key);\n out.canonical_cycles++;\n add(start + 1, \"canonical_cycle\", \"warning\",\n \"Two or more sampled pages declare canonical URLs that form a cycle.\");\n }\n break;\n }\n if (traversed.length > MAX_CHAIN_HOPS) break;\n seen.set(at, traversed.length);\n traversed.push(at);\n const label = canonicalLinks.get(at);\n at = label === undefined ? undefined : indexByUrl.get(label);\n }\n if (traversed.length >= 2 && at === undefined && canonicalLinks.has(traversed[1])) {\n out.canonical_chain_edges++;\n add(start + 1, \"canonical_chain\", \"info\",\n \"A canonical target declares a different sampled canonical target; review the canonical chain.\");\n }\n }\n\n const final = records.at(-1)!;\n const last = out.hops.at(-1)!;\n out.hops_observed = out.hops.length;\n out.chain_complete = !isRedirect(final.status_code) && !out.loop_detected && consistent;\n if (out.chain_complete) {\n out.final_status_code = final.status_code;\n out.destination_indexing_state = last.googlebot_indexing_state;\n if (expected) {\n out.expected_destination_match = urls.at(-1)!.href === expected.href;\n if (!out.expected_destination_match) {\n add(records.length, \"expected_destination_mismatch\", \"warning\",\n \"The sampled chain resolved to a different URL than the caller's expected destination.\");\n }\n }\n if (shortStatus(final.status_code)) {\n out.nonindexable_destination = true;\n add(records.length, \"redirect_destination_http_error\", \"warning\",\n \"The sampled chain ends at HTTP 4xx/5xx, not an indexable success response.\");\n }\n if (last.googlebot_indexing_state === \"explicit_noindex\") {\n out.nonindexable_destination = true;\n add(records.length, \"redirect_destination_noindex\", \"warning\",\n \"The sampled redirect destination declares noindex for Googlebot.\");\n }\n if (final.robots_allowed === false) {\n out.nonindexable_destination = true;\n add(records.length, \"redirect_destination_robots_blocked\", \"warning\",\n \"The destination is explicitly marked robots-disallowed by caller-supplied evidence.\");\n }\n if (last.googlebot_indexing_state === \"unknown\") {\n add(records.length, \"destination_indexing_unverified\", \"info\",\n \"The final response's indexing directives were not fully observed.\");\n }\n } else {\n add(records.length, \"final_status_unverified\", \"info\",\n \"A complete, consistent non-redirect destination response was not observed.\");\n }\n if (out.redirects_observed >= 4) {\n add(1, \"redirect_long_chain\", \"info\",\n \"This chain contains four or more redirect responses; shorter direct redirects are preferable.\");\n }\n return out;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type RedirectCanonicalReview } from "./redirect-canonical-chains.js";
|
|
2
|
+
/**
|
|
3
|
+
* Live V04: a bounded single URL chain, safely resolved with DNS-pinned
|
|
4
|
+
* outbound HTTP. Bodies are read only on a final 2xx HTML response.
|
|
5
|
+
*/
|
|
6
|
+
export declare function probeRedirectCanonicalChain(url: string, expected_destination?: string): Promise<RedirectCanonicalReview>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { fetchPublicHttp, readResponseText } from "../../network.js";
|
|
2
|
+
import { safeHttpResourceUrl } from "./non-html-directives.js";
|
|
3
|
+
import { analyzeRedirectCanonicalChains, canonicalHrefsFromLinkHeader, MAX_CHAIN_HOPS, MAX_CHAIN_HTML_BYTES, } from "./redirect-canonical-chains.js";
|
|
4
|
+
/**
|
|
5
|
+
* Live V04: a bounded single URL chain, safely resolved with DNS-pinned
|
|
6
|
+
* outbound HTTP. Bodies are read only on a final 2xx HTML response.
|
|
7
|
+
*/
|
|
8
|
+
export async function probeRedirectCanonicalChain(url, expected_destination) {
|
|
9
|
+
const safe = safeHttpResourceUrl(url);
|
|
10
|
+
if (!safe)
|
|
11
|
+
throw new Error("The live chain source must be a safe query-free public URL.");
|
|
12
|
+
const initial = new URL(safe);
|
|
13
|
+
const observations = [];
|
|
14
|
+
let htmlEvidenceLimited = false;
|
|
15
|
+
try {
|
|
16
|
+
const { response, url: final } = await fetchPublicHttp(safe, {
|
|
17
|
+
method: "GET",
|
|
18
|
+
headers: {
|
|
19
|
+
accept: "text/html,application/xhtml+xml;q=0.9,*/*;q=0.1",
|
|
20
|
+
"user-agent": "mcp-web-validator-redirect-diagnostics/1",
|
|
21
|
+
},
|
|
22
|
+
timeoutMs: 12_000,
|
|
23
|
+
maxRedirects: Math.min(5, MAX_CHAIN_HOPS - 1),
|
|
24
|
+
allowRedirect: (next, current) => next.origin === initial.origin && Boolean(safeHttpResourceUrl(next.href)) &&
|
|
25
|
+
!(current.protocol === "https:" && next.protocol === "http:"),
|
|
26
|
+
onResponse: (location, fetched) => {
|
|
27
|
+
observations.push({
|
|
28
|
+
url: location.href,
|
|
29
|
+
status_code: fetched.status,
|
|
30
|
+
...(fetched.headers.has("location")
|
|
31
|
+
? { location: fetched.headers.get("location") ?? "" } : {}),
|
|
32
|
+
canonicals: canonicalHrefsFromLinkHeader(fetched.headers.get("link")),
|
|
33
|
+
x_robots_tag: fetched.headers.has("x-robots-tag")
|
|
34
|
+
? [fetched.headers.get("x-robots-tag") ?? ""] : [],
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
try {
|
|
39
|
+
const mime = response.headers.get("content-type")
|
|
40
|
+
?.split(";", 1)[0].trim().toLowerCase();
|
|
41
|
+
const finalRecord = observations.at(-1);
|
|
42
|
+
if (finalRecord && finalRecord.url === final.href &&
|
|
43
|
+
response.status >= 200 && response.status <= 299 &&
|
|
44
|
+
(mime === "text/html" || mime === "application/xhtml+xml")) {
|
|
45
|
+
try {
|
|
46
|
+
finalRecord.html = await readResponseText(response, MAX_CHAIN_HTML_BYTES);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
htmlEvidenceLimited = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
try {
|
|
55
|
+
await response.body?.cancel();
|
|
56
|
+
}
|
|
57
|
+
catch { /* Response already closed. */ }
|
|
58
|
+
}
|
|
59
|
+
const result = analyzeRedirectCanonicalChains({
|
|
60
|
+
source_url: safe, observations,
|
|
61
|
+
...(expected_destination ? { expected_destination } : {}),
|
|
62
|
+
}, "live_public_redirect_probe");
|
|
63
|
+
if (htmlEvidenceLimited) {
|
|
64
|
+
result.error = "Final HTML could not be inspected within the 1 MiB text/encoding cap.";
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
if (!observations.length) {
|
|
70
|
+
throw new Error("The public HTTP redirect probe failed before any response was observed.");
|
|
71
|
+
}
|
|
72
|
+
const partial = analyzeRedirectCanonicalChains({
|
|
73
|
+
source_url: safe, observations,
|
|
74
|
+
...(expected_destination ? { expected_destination } : {}),
|
|
75
|
+
}, "live_public_redirect_probe");
|
|
76
|
+
partial.error = "The response sequence could not be completed within the public URL, DNS and timeout limits.";
|
|
77
|
+
partial.chain_complete = false;
|
|
78
|
+
partial.final_status_code = undefined;
|
|
79
|
+
partial.expected_destination_match = undefined;
|
|
80
|
+
return partial;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=redirect-canonical-probe.js.map
|