mcp-web-validator 1.3.51 → 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 +41 -0
- package/README.md +64 -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 +2508 -2
- package/dist/index.js.map +1 -1
- 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,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V03 - bounded, static crawler-access matrix (robots.txt + page directives).
|
|
3
|
+
*
|
|
4
|
+
* A profile is a robots product-token simulation, NOT an authenticated crawl.
|
|
5
|
+
* It never requests, returns, or stores raw URL paths, HTML or header values.
|
|
6
|
+
*/
|
|
7
|
+
import { load } from "cheerio";
|
|
8
|
+
import { safeHttpResourceUrl } from "./non-html-directives.js";
|
|
9
|
+
export const CRAWLER_PROFILES = [
|
|
10
|
+
"googlebot-smartphone", "googlebot-desktop", "googlebot-news",
|
|
11
|
+
"googlebot-image", "bingbot", "gptbot",
|
|
12
|
+
];
|
|
13
|
+
export const MAX_CRAWLER_PAGES = 8;
|
|
14
|
+
export const MAX_CRAWLER_FINDINGS = 24;
|
|
15
|
+
export const MAX_CRAWLER_ROBOTS_BYTES = 64_000;
|
|
16
|
+
export const MAX_CRAWLER_HTML_BYTES = 150_000;
|
|
17
|
+
export const MAX_CRAWLER_TOTAL_HTML_BYTES = 300_000;
|
|
18
|
+
export const MAX_CRAWLER_ROBOT_RULES = 2_000;
|
|
19
|
+
export const CRAWLER_ACCESS_STATES = ["allowed", "disallowed", "unknown"];
|
|
20
|
+
export const CRAWLER_INDEXING_STATES = [
|
|
21
|
+
"explicit_noindex", "no_noindex_observed", "unknown",
|
|
22
|
+
];
|
|
23
|
+
export const CRAWLER_FINDING_CODES = [
|
|
24
|
+
"crawler_disallowed", "explicit_noindex", "blocked_with_noindex",
|
|
25
|
+
"robots_unavailable", "indexing_observation_missing",
|
|
26
|
+
"page_http_error", "conflicting_indexing_directives",
|
|
27
|
+
"x_robots_scope_ambiguous", "robots_rules_truncated",
|
|
28
|
+
];
|
|
29
|
+
const profileTokens = {
|
|
30
|
+
"googlebot-smartphone": "googlebot",
|
|
31
|
+
"googlebot-desktop": "googlebot",
|
|
32
|
+
"googlebot-news": "googlebot-news",
|
|
33
|
+
"googlebot-image": "googlebot-image",
|
|
34
|
+
"bingbot": "bingbot",
|
|
35
|
+
"gptbot": "gptbot",
|
|
36
|
+
};
|
|
37
|
+
const warnings = [
|
|
38
|
+
"Profiles simulate published robots product tokens, not actual requests from or authentication of search crawlers.",
|
|
39
|
+
"Robots.txt affects crawl permission; robots meta and X-Robots-Tag express indexing preferences only when the crawler can fetch the page.",
|
|
40
|
+
"No snippet verifies an engine's selected canonical, indexing verdict, real crawler user-agent handling, JavaScript rendering or historical behavior.",
|
|
41
|
+
"Ambiguous folded X-Robots-Tag scopes and unavailable robots/pages are reported as uncertain, not assumed allowed.",
|
|
42
|
+
];
|
|
43
|
+
const encoder = new TextEncoder();
|
|
44
|
+
function bytes(text) { return encoder.encode(text).byteLength; }
|
|
45
|
+
export function emptyCrawlerAccessReview(scope = "caller_supplied_crawler_evidence") {
|
|
46
|
+
return {
|
|
47
|
+
scope,
|
|
48
|
+
pages_observed: 0, profiles_checked: 0, rows_checked: 0,
|
|
49
|
+
robots_rules_used: 0, robots_rules_truncated: false,
|
|
50
|
+
robots_unavailable: true, crawler_disallowed_rows: 0,
|
|
51
|
+
noindex_declared_rows: 0, unknown_access_rows: 0,
|
|
52
|
+
unknown_indexing_rows: 0, scope_ambiguous_rows: 0,
|
|
53
|
+
coverage_limited: true, limitations: warnings, rows: [],
|
|
54
|
+
total_findings: 0, findings: [], findings_truncated: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Percent-encoded unreserved ASCII is equivalent to literal bytes (RFC 9309). */
|
|
58
|
+
function normalizedRobotsValue(value) {
|
|
59
|
+
const withEscapes = value.replace(/%([0-9a-fA-F]{2})/g, (_, hex) => {
|
|
60
|
+
const ch = String.fromCharCode(Number.parseInt(hex, 16));
|
|
61
|
+
return /^[A-Za-z0-9._~-]$/.test(ch) ? ch : "%" + hex.toUpperCase();
|
|
62
|
+
});
|
|
63
|
+
return withEscapes.replace(/[^\x00-\x7f]/gu, (ch) => Array.from(encoder.encode(ch), (byte) => "%" + byte.toString(16).toUpperCase().padStart(2, "0")).join(""));
|
|
64
|
+
}
|
|
65
|
+
/** Iterative glob matcher: bounded linear/backtracking behavior, no attacker regex. */
|
|
66
|
+
function matchesRobots(path, rawPattern) {
|
|
67
|
+
if (!rawPattern)
|
|
68
|
+
return false;
|
|
69
|
+
const target = normalizedRobotsValue(path);
|
|
70
|
+
const rule = normalizedRobotsValue(rawPattern);
|
|
71
|
+
const anchored = rule.endsWith("$");
|
|
72
|
+
const pattern = anchored ? rule.slice(0, -1) : rule;
|
|
73
|
+
let position = 0;
|
|
74
|
+
let rulePosition = 0;
|
|
75
|
+
let wildcard = -1;
|
|
76
|
+
let wildcardEnd = 0;
|
|
77
|
+
while (position < target.length) {
|
|
78
|
+
if (!anchored && rulePosition === pattern.length)
|
|
79
|
+
return true;
|
|
80
|
+
if (rulePosition < pattern.length && pattern[rulePosition] === target[position]) {
|
|
81
|
+
position++;
|
|
82
|
+
rulePosition++;
|
|
83
|
+
}
|
|
84
|
+
else if (rulePosition < pattern.length && pattern[rulePosition] === "*") {
|
|
85
|
+
wildcard = rulePosition++;
|
|
86
|
+
wildcardEnd = position;
|
|
87
|
+
}
|
|
88
|
+
else if (wildcard >= 0) {
|
|
89
|
+
rulePosition = wildcard + 1;
|
|
90
|
+
position = ++wildcardEnd;
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
while (rulePosition < pattern.length && pattern[rulePosition] === "*")
|
|
96
|
+
rulePosition++;
|
|
97
|
+
return rulePosition === pattern.length;
|
|
98
|
+
}
|
|
99
|
+
function parseRobots(content) {
|
|
100
|
+
const groups = [];
|
|
101
|
+
let current = { agents: [], rules: [] };
|
|
102
|
+
let hasRules = false;
|
|
103
|
+
let count = 0;
|
|
104
|
+
let truncated = false;
|
|
105
|
+
const flush = () => {
|
|
106
|
+
if (current.agents.length)
|
|
107
|
+
groups.push(current);
|
|
108
|
+
current = { agents: [], rules: [] };
|
|
109
|
+
hasRules = false;
|
|
110
|
+
};
|
|
111
|
+
for (const raw of content.split(/\r\n|\r|\n/)) {
|
|
112
|
+
const line = raw.split("#", 1)[0]?.trim() ?? "";
|
|
113
|
+
const colon = line.indexOf(":");
|
|
114
|
+
if (colon < 1)
|
|
115
|
+
continue;
|
|
116
|
+
const directive = line.slice(0, colon).trim().toLowerCase();
|
|
117
|
+
const value = line.slice(colon + 1).trim();
|
|
118
|
+
if (directive === "user-agent") {
|
|
119
|
+
if (hasRules)
|
|
120
|
+
flush();
|
|
121
|
+
if (/^(\*|[a-z0-9_.-]{1,80})$/i.test(value) && current.agents.length < 24) {
|
|
122
|
+
current.agents.push(value.toLowerCase());
|
|
123
|
+
}
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if ((directive === "allow" || directive === "disallow") &&
|
|
127
|
+
current.agents.length > 0 && value.length <= 512) {
|
|
128
|
+
count++;
|
|
129
|
+
if (count <= MAX_CRAWLER_ROBOT_RULES) {
|
|
130
|
+
current.rules.push({ allow: directive === "allow", pattern: value });
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
truncated = true;
|
|
134
|
+
hasRules = true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
flush();
|
|
138
|
+
return { groups, truncated, count };
|
|
139
|
+
}
|
|
140
|
+
function chosenRules(groups, token) {
|
|
141
|
+
let specificity = -1;
|
|
142
|
+
const selected = [];
|
|
143
|
+
for (const group of groups) {
|
|
144
|
+
const score = group.agents.reduce((best, agent) => Math.max(best, agent === "*" ? 0 : (token.includes(agent) ? agent.length : -1)), -1);
|
|
145
|
+
if (score > specificity) {
|
|
146
|
+
specificity = score;
|
|
147
|
+
selected.length = 0;
|
|
148
|
+
if (score >= 0)
|
|
149
|
+
selected.push(group);
|
|
150
|
+
}
|
|
151
|
+
else if (score >= 0 && score === specificity)
|
|
152
|
+
selected.push(group);
|
|
153
|
+
}
|
|
154
|
+
return { matched: specificity >= 0, rules: selected.flatMap((g) => g.rules) };
|
|
155
|
+
}
|
|
156
|
+
function robotDecision(url, rules) {
|
|
157
|
+
const path = url.pathname + url.search;
|
|
158
|
+
let winner;
|
|
159
|
+
let best = -1;
|
|
160
|
+
for (const rule of rules) {
|
|
161
|
+
if (!matchesRobots(path, rule.pattern))
|
|
162
|
+
continue;
|
|
163
|
+
const normalized = normalizedRobotsValue(rule.pattern);
|
|
164
|
+
const specificity = normalized.replace(/%[0-9A-F]{2}/g, "X")
|
|
165
|
+
.replace(/\*/g, "").replace(/\$$/, "").length;
|
|
166
|
+
if (!winner || specificity > best || (specificity === best && rule.allow)) {
|
|
167
|
+
winner = rule;
|
|
168
|
+
best = specificity;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return { allowed: winner?.allow ?? true,
|
|
172
|
+
rule: winner ? (winner.allow ? "allow" : "disallow") : "none" };
|
|
173
|
+
}
|
|
174
|
+
/** Guard the service's own fetches without impersonating a real crawler. */
|
|
175
|
+
export function isAllowedForFetcher(robotsTxt, url, serviceToken = "digestseo-web-validator") {
|
|
176
|
+
if (typeof robotsTxt !== "string" || bytes(robotsTxt) > MAX_CRAWLER_ROBOTS_BYTES) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
const safe = safeHttpResourceUrl(url);
|
|
180
|
+
if (!safe || !/^[a-z0-9._-]{1,80}$/i.test(serviceToken))
|
|
181
|
+
return undefined;
|
|
182
|
+
const parsed = parseRobots(robotsTxt);
|
|
183
|
+
if (parsed.truncated)
|
|
184
|
+
return undefined;
|
|
185
|
+
const selected = chosenRules(parsed.groups, serviceToken.toLowerCase());
|
|
186
|
+
return robotDecision(new URL(safe), selected.rules).allowed;
|
|
187
|
+
}
|
|
188
|
+
function hasIndexToken(value, token) {
|
|
189
|
+
return value.split(/[,;\s]+/).some((part) => part.trim().toLowerCase() === token ||
|
|
190
|
+
(token === "noindex" && part.trim().toLowerCase() === "none"));
|
|
191
|
+
}
|
|
192
|
+
function extractMeta(html) {
|
|
193
|
+
const result = new Map();
|
|
194
|
+
if (html === undefined)
|
|
195
|
+
return result;
|
|
196
|
+
const $ = load(html);
|
|
197
|
+
$("meta[name][content]").each((_, element) => {
|
|
198
|
+
const name = ($(element).attr("name") ?? "").trim().toLowerCase();
|
|
199
|
+
if (name !== "robots" && !Object.values(profileTokens).includes(name))
|
|
200
|
+
return;
|
|
201
|
+
const content = $(element).attr("content") ?? "";
|
|
202
|
+
const current = result.get(name) ?? { index: false, noindex: false };
|
|
203
|
+
current.index ||= hasIndexToken(content, "index");
|
|
204
|
+
current.noindex ||= hasIndexToken(content, "noindex");
|
|
205
|
+
result.set(name, current);
|
|
206
|
+
});
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
/** Treat each supplied header value as potentially folded; avoid guessing global scope. */
|
|
210
|
+
function extractHeader(headers, profile) {
|
|
211
|
+
const result = { index: false, noindex: false, scopeAmbiguous: false };
|
|
212
|
+
if (!headers)
|
|
213
|
+
return result;
|
|
214
|
+
const token = profileTokens[profile];
|
|
215
|
+
for (const raw of headers) {
|
|
216
|
+
let scope = "all";
|
|
217
|
+
let hasScoped = false;
|
|
218
|
+
for (const part of raw.split(",")) {
|
|
219
|
+
let value = part.trim().toLowerCase();
|
|
220
|
+
if (!value)
|
|
221
|
+
continue;
|
|
222
|
+
const m = /^([a-z][a-z0-9._-]*):\s*(.*)$/.exec(value);
|
|
223
|
+
// Values with colons such as max-snippet do not designate an agent.
|
|
224
|
+
if (m && !["max-snippet", "max-image-preview", "max-video-preview", "unavailable_after"].includes(m[1])) {
|
|
225
|
+
scope = m[1];
|
|
226
|
+
hasScoped = true;
|
|
227
|
+
value = m[2].trim();
|
|
228
|
+
}
|
|
229
|
+
else if (hasScoped && scope !== token && (value === "noindex" || value === "none")) {
|
|
230
|
+
// Folded values may represent a second global header field.
|
|
231
|
+
result.scopeAmbiguous = true;
|
|
232
|
+
}
|
|
233
|
+
if (scope === "all" || token === scope) {
|
|
234
|
+
result.noindex ||= hasIndexToken(value, "noindex");
|
|
235
|
+
result.index ||= hasIndexToken(value, "index");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
function metaDirective(collected, profile) {
|
|
242
|
+
const global = collected.get("robots");
|
|
243
|
+
const specific = collected.get(profileTokens[profile]);
|
|
244
|
+
return {
|
|
245
|
+
index: Boolean(global?.index || specific?.index),
|
|
246
|
+
noindex: Boolean(global?.noindex || specific?.noindex),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
export function analyzeCrawlerAccess(input, scope = "caller_supplied_crawler_evidence") {
|
|
250
|
+
if (!input || typeof input !== "object" || !safeHttpResourceUrl(input.site_url)) {
|
|
251
|
+
throw new Error("Use one safe public query-free site URL.");
|
|
252
|
+
}
|
|
253
|
+
const origin = new URL(input.site_url).origin;
|
|
254
|
+
if (!Array.isArray(input.pages) || input.pages.length < 1 || input.pages.length > MAX_CRAWLER_PAGES) {
|
|
255
|
+
throw new Error("Supply one to eight same-origin page observations.");
|
|
256
|
+
}
|
|
257
|
+
const profiles = input.profiles ?? [...CRAWLER_PROFILES];
|
|
258
|
+
if (!Array.isArray(profiles) || profiles.length < 1 || profiles.length > CRAWLER_PROFILES.length ||
|
|
259
|
+
new Set(profiles).size !== profiles.length ||
|
|
260
|
+
profiles.some((profile) => !CRAWLER_PROFILES.includes(profile))) {
|
|
261
|
+
throw new Error("Crawler profile selection contains unknown or repeated values.");
|
|
262
|
+
}
|
|
263
|
+
if (input.robots_status_code !== undefined &&
|
|
264
|
+
(!Number.isInteger(input.robots_status_code) ||
|
|
265
|
+
input.robots_status_code < 100 || input.robots_status_code > 599)) {
|
|
266
|
+
throw new Error("Invalid robots.txt HTTP status.");
|
|
267
|
+
}
|
|
268
|
+
if (input.robots_txt !== undefined &&
|
|
269
|
+
(bytes(input.robots_txt) > MAX_CRAWLER_ROBOTS_BYTES ||
|
|
270
|
+
(input.robots_status_code !== undefined && (input.robots_status_code < 200 || input.robots_status_code >= 300)))) {
|
|
271
|
+
throw new Error("Robots content is oversized or inconsistent with the supplied status.");
|
|
272
|
+
}
|
|
273
|
+
const results = [];
|
|
274
|
+
let htmlBytes = 0;
|
|
275
|
+
for (const page of input.pages) {
|
|
276
|
+
const safe = safeHttpResourceUrl(page.url);
|
|
277
|
+
if (!safe || new URL(safe).origin !== origin) {
|
|
278
|
+
throw new Error("All page URL labels must belong to the same origin and have no query/credentials.");
|
|
279
|
+
}
|
|
280
|
+
if (page.status_code !== undefined &&
|
|
281
|
+
(!Number.isInteger(page.status_code) || page.status_code < 100 || page.status_code > 599)) {
|
|
282
|
+
throw new Error("Invalid HTTP page status.");
|
|
283
|
+
}
|
|
284
|
+
if (page.html !== undefined) {
|
|
285
|
+
const size = bytes(page.html);
|
|
286
|
+
htmlBytes += size;
|
|
287
|
+
if (size > MAX_CRAWLER_HTML_BYTES || htmlBytes > MAX_CRAWLER_TOTAL_HTML_BYTES) {
|
|
288
|
+
throw new Error("HTML samples exceed the static input byte caps.");
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (page.x_robots_tag !== undefined &&
|
|
292
|
+
(!Array.isArray(page.x_robots_tag) || page.x_robots_tag.length > 8 ||
|
|
293
|
+
page.x_robots_tag.some((part) => typeof part !== "string" || bytes(part) > 512))) {
|
|
294
|
+
throw new Error("X-Robots-Tag lines must be a small bounded list.");
|
|
295
|
+
}
|
|
296
|
+
results.push({ url: new URL(safe), html: page.html,
|
|
297
|
+
headers: page.x_robots_tag, status: page.status_code });
|
|
298
|
+
}
|
|
299
|
+
const parsed = input.robots_txt === undefined
|
|
300
|
+
? { groups: [], truncated: false, count: 0 }
|
|
301
|
+
: parseRobots(input.robots_txt);
|
|
302
|
+
const review = emptyCrawlerAccessReview(scope);
|
|
303
|
+
review.pages_observed = results.length;
|
|
304
|
+
review.profiles_checked = profiles.length;
|
|
305
|
+
review.robots_status_code = input.robots_status_code;
|
|
306
|
+
review.robots_rules_used = Math.min(parsed.count, MAX_CRAWLER_ROBOT_RULES);
|
|
307
|
+
review.robots_rules_truncated = parsed.truncated;
|
|
308
|
+
const robotsStatus = input.robots_status_code;
|
|
309
|
+
const absent = input.robots_txt === undefined && robotsStatus === undefined;
|
|
310
|
+
const noRobotsDocument = robotsStatus !== undefined && robotsStatus >= 400 &&
|
|
311
|
+
robotsStatus < 500 && robotsStatus !== 429;
|
|
312
|
+
const unavailable = (robotsStatus !== undefined && (robotsStatus === 429 || robotsStatus >= 500 ||
|
|
313
|
+
(robotsStatus >= 300 && robotsStatus < 400) ||
|
|
314
|
+
robotsStatus < 200)) ||
|
|
315
|
+
(input.robots_txt === undefined && !noRobotsDocument);
|
|
316
|
+
review.robots_unavailable = unavailable || absent;
|
|
317
|
+
function pushFinding(code, severity, page, profile, message) {
|
|
318
|
+
review.total_findings++;
|
|
319
|
+
if (review.findings.length < MAX_CRAWLER_FINDINGS) {
|
|
320
|
+
review.findings.push({ code, severity, page, profile, message });
|
|
321
|
+
}
|
|
322
|
+
else
|
|
323
|
+
review.findings_truncated = true;
|
|
324
|
+
}
|
|
325
|
+
for (let i = 0; i < results.length; i++) {
|
|
326
|
+
const page = results[i];
|
|
327
|
+
const metas = extractMeta(page.html);
|
|
328
|
+
for (const profile of profiles) {
|
|
329
|
+
const selected = chosenRules(parsed.groups, profileTokens[profile]);
|
|
330
|
+
let robotsAccess;
|
|
331
|
+
let rule = "unknown";
|
|
332
|
+
if (parsed.truncated || unavailable ||
|
|
333
|
+
(noRobotsDocument && robotsStatus !== 404 && robotsStatus !== 410 &&
|
|
334
|
+
!profile.startsWith("googlebot"))) {
|
|
335
|
+
robotsAccess = "unknown";
|
|
336
|
+
}
|
|
337
|
+
else if (input.robots_txt !== undefined || noRobotsDocument) {
|
|
338
|
+
const decision = robotDecision(page.url, selected.rules);
|
|
339
|
+
rule = decision.rule;
|
|
340
|
+
robotsAccess = decision.allowed ? "allowed" : "disallowed";
|
|
341
|
+
}
|
|
342
|
+
else
|
|
343
|
+
robotsAccess = "unknown";
|
|
344
|
+
const meta = metaDirective(metas, profile);
|
|
345
|
+
const header = extractHeader(page.headers, profile);
|
|
346
|
+
const noindex = meta.noindex || header.noindex;
|
|
347
|
+
const explicitIndex = meta.index || header.index;
|
|
348
|
+
const conflict = noindex && explicitIndex;
|
|
349
|
+
const pageHttpOk = page.status === undefined || (page.status >= 200 && page.status < 300);
|
|
350
|
+
const indexingKnown = page.html !== undefined && page.headers !== undefined;
|
|
351
|
+
const indexingState = noindex
|
|
352
|
+
? "explicit_noindex"
|
|
353
|
+
: (!pageHttpOk || !indexingKnown ? "unknown" : "no_noindex_observed");
|
|
354
|
+
const indexingSource = meta.noindex || meta.index
|
|
355
|
+
? (header.noindex || header.index ? "both" : "meta")
|
|
356
|
+
: (header.noindex || header.index ? "header" : "none");
|
|
357
|
+
const row = {
|
|
358
|
+
page: i + 1, profile, robots_access: robotsAccess,
|
|
359
|
+
robots_rule: rule, robots_group_matched: selected.matched,
|
|
360
|
+
indexing_state: indexingState, indexing_source: indexingSource,
|
|
361
|
+
explicit_index_directive: explicitIndex,
|
|
362
|
+
conflicting_index_directives: conflict,
|
|
363
|
+
x_robots_scope_ambiguous: header.scopeAmbiguous,
|
|
364
|
+
...(page.status === undefined ? {} : { page_http_status: page.status }),
|
|
365
|
+
static_html_examined: page.html !== undefined,
|
|
366
|
+
effective_access: robotsAccess === "disallowed" ? "crawl_disallowed"
|
|
367
|
+
: robotsAccess === "allowed" && noindex ? "crawl_allowed_noindex_declared"
|
|
368
|
+
: robotsAccess === "allowed" && indexingState === "no_noindex_observed"
|
|
369
|
+
? "crawl_allowed_no_noindex_observed" : "unverified",
|
|
370
|
+
};
|
|
371
|
+
review.rows.push(row);
|
|
372
|
+
if (robotsAccess === "disallowed") {
|
|
373
|
+
review.crawler_disallowed_rows++;
|
|
374
|
+
pushFinding("crawler_disallowed", "warning", i + 1, profile, "The supplied robots.txt rule set disallows this crawler product token on this page.");
|
|
375
|
+
}
|
|
376
|
+
if (robotsAccess === "unknown") {
|
|
377
|
+
review.unknown_access_rows++;
|
|
378
|
+
pushFinding(parsed.truncated ? "robots_rules_truncated" : "robots_unavailable", "info", i + 1, profile, "Robots access cannot be established from complete applicable evidence.");
|
|
379
|
+
}
|
|
380
|
+
if (noindex) {
|
|
381
|
+
review.noindex_declared_rows++;
|
|
382
|
+
pushFinding("explicit_noindex", "warning", i + 1, profile, "A supplied meta or HTTP directive explicitly declares noindex for this profile.");
|
|
383
|
+
if (robotsAccess === "disallowed")
|
|
384
|
+
pushFinding("blocked_with_noindex", "info", i + 1, profile, "Robots disallow may stop this crawler from seeing the page's noindex instruction.");
|
|
385
|
+
}
|
|
386
|
+
if (indexingState === "unknown") {
|
|
387
|
+
review.unknown_indexing_rows++;
|
|
388
|
+
pushFinding("indexing_observation_missing", "info", i + 1, profile, "No complete indexability directive observation was provided for this page.");
|
|
389
|
+
}
|
|
390
|
+
if (page.status !== undefined && page.status >= 400) {
|
|
391
|
+
pushFinding("page_http_error", "warning", i + 1, profile, "The supplied HTTP response status is an error, irrespective of robots rules.");
|
|
392
|
+
}
|
|
393
|
+
if (conflict)
|
|
394
|
+
pushFinding("conflicting_indexing_directives", "warning", i + 1, profile, "Index and noindex are declared together; noindex should be treated as restrictive.");
|
|
395
|
+
if (header.scopeAmbiguous) {
|
|
396
|
+
review.scope_ambiguous_rows++;
|
|
397
|
+
pushFinding("x_robots_scope_ambiguous", "info", i + 1, profile, "A folded X-Robots-Tag value has ambiguous scope and should be verified against raw server headers.");
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
review.rows_checked = review.rows.length;
|
|
402
|
+
return review;
|
|
403
|
+
}
|
|
404
|
+
//# sourceMappingURL=crawler-access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crawler-access.js","sourceRoot":"","sources":["../../../src/modules/http-crawl/crawler-access.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,sBAAsB,EAAE,mBAAmB,EAAE,gBAAgB;IAC7D,iBAAiB,EAAE,SAAS,EAAE,QAAQ;CAC9B,CAAC;AAEX,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAC/C,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAC9C,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AACpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAC7C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,SAAS,CAAU,CAAC;AACnF,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,kBAAkB,EAAE,qBAAqB,EAAE,SAAS;CAC5C,CAAC;AACX,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,oBAAoB,EAAE,kBAAkB,EAAE,sBAAsB;IAChE,oBAAoB,EAAE,8BAA8B;IACpD,iBAAiB,EAAE,iCAAiC;IACpD,0BAA0B,EAAE,wBAAwB;CAC5C,CAAC;AAkEX,MAAM,aAAa,GAAmC;IACpD,sBAAsB,EAAE,WAAW;IACnC,mBAAmB,EAAE,WAAW;IAChC,gBAAgB,EAAE,gBAAgB;IAClC,iBAAiB,EAAE,iBAAiB;IACpC,SAAS,EAAE,SAAS;IACpB,QAAQ,EAAE,Q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,EAAE,OAAO,EAAE,oFAAoF,CAAC,CAAC;YACxG,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;gBAC1B,MAAM,CAAC,oBAAoB,EAAE,CAAC;gBAC9B,WAAW,CAAC,0BAA0B,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAC5D,oGAAoG,CAAC,CAAC;YAC1G,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * V03 - bounded, static crawler-access matrix (robots.txt + page directives).\n *\n * A profile is a robots product-token simulation, NOT an authenticated crawl.\n * It never requests, returns, or stores raw URL paths, HTML or header values.\n */\nimport { load } from \"cheerio\";\nimport { safeHttpResourceUrl } from \"./non-html-directives.js\";\n\nexport const CRAWLER_PROFILES = [\n \"googlebot-smartphone\", \"googlebot-desktop\", \"googlebot-news\",\n \"googlebot-image\", \"bingbot\", \"gptbot\",\n] as const;\nexport type CrawlerProfile = typeof CRAWLER_PROFILES[number];\nexport const MAX_CRAWLER_PAGES = 8;\nexport const MAX_CRAWLER_FINDINGS = 24;\nexport const MAX_CRAWLER_ROBOTS_BYTES = 64_000;\nexport const MAX_CRAWLER_HTML_BYTES = 150_000;\nexport const MAX_CRAWLER_TOTAL_HTML_BYTES = 300_000;\nexport const MAX_CRAWLER_ROBOT_RULES = 2_000;\nexport const CRAWLER_ACCESS_STATES = [\"allowed\", \"disallowed\", \"unknown\"] as const;\nexport const CRAWLER_INDEXING_STATES = [\n \"explicit_noindex\", \"no_noindex_observed\", \"unknown\",\n] as const;\nexport const CRAWLER_FINDING_CODES = [\n \"crawler_disallowed\", \"explicit_noindex\", \"blocked_with_noindex\",\n \"robots_unavailable\", \"indexing_observation_missing\",\n \"page_http_error\", \"conflicting_indexing_directives\",\n \"x_robots_scope_ambiguous\", \"robots_rules_truncated\",\n] as const;\nexport type CrawlerFindingCode = typeof CRAWLER_FINDING_CODES[number];\nexport type CrawlerAccessState = typeof CRAWLER_ACCESS_STATES[number];\nexport type CrawlerIndexingState = typeof CRAWLER_INDEXING_STATES[number];\n\nexport interface CrawlerAccessPage {\n url: string;\n status_code?: number;\n html?: string;\n x_robots_tag?: string[];\n}\nexport interface CrawlerAccessInput {\n site_url: string;\n robots_txt?: string;\n robots_status_code?: number;\n pages: CrawlerAccessPage[];\n profiles?: CrawlerProfile[];\n}\nexport interface CrawlerAccessRow {\n page: number;\n profile: CrawlerProfile;\n robots_access: CrawlerAccessState;\n robots_rule: \"allow\" | \"disallow\" | \"none\" | \"unknown\";\n robots_group_matched: boolean;\n indexing_state: CrawlerIndexingState;\n indexing_source: \"meta\" | \"header\" | \"both\" | \"none\";\n explicit_index_directive: boolean;\n conflicting_index_directives: boolean;\n x_robots_scope_ambiguous: boolean;\n page_http_status?: number;\n static_html_examined: boolean;\n effective_access: \"crawl_disallowed\" | \"crawl_allowed_noindex_declared\" |\n \"crawl_allowed_no_noindex_observed\" | \"unverified\";\n}\nexport interface CrawlerAccessFinding {\n code: CrawlerFindingCode;\n severity: \"warning\" | \"info\";\n page: number;\n profile: CrawlerProfile;\n message: string;\n}\nexport interface CrawlerAccessReview {\n scope: \"caller_supplied_crawler_evidence\" | \"live_public_crawler_probe\";\n pages_observed: number;\n profiles_checked: number;\n rows_checked: number;\n robots_status_code?: number;\n robots_rules_used: number;\n robots_rules_truncated: boolean;\n robots_unavailable: boolean;\n crawler_disallowed_rows: number;\n noindex_declared_rows: number;\n unknown_access_rows: number;\n unknown_indexing_rows: number;\n scope_ambiguous_rows: number;\n coverage_limited: true;\n limitations: string[];\n rows: CrawlerAccessRow[];\n total_findings: number;\n findings: CrawlerAccessFinding[];\n findings_truncated: boolean;\n error?: string;\n}\n\ntype RobotRule = { allow: boolean; pattern: string };\ntype RobotGroup = { agents: string[]; rules: RobotRule[] };\nconst profileTokens: Record<CrawlerProfile, string> = {\n \"googlebot-smartphone\": \"googlebot\",\n \"googlebot-desktop\": \"googlebot\",\n \"googlebot-news\": \"googlebot-news\",\n \"googlebot-image\": \"googlebot-image\",\n \"bingbot\": \"bingbot\",\n \"gptbot\": \"gptbot\",\n};\nconst warnings: CrawlerAccessReview[\"limitations\"] = [\n \"Profiles simulate published robots product tokens, not actual requests from or authentication of search crawlers.\",\n \"Robots.txt affects crawl permission; robots meta and X-Robots-Tag express indexing preferences only when the crawler can fetch the page.\",\n \"No snippet verifies an engine's selected canonical, indexing verdict, real crawler user-agent handling, JavaScript rendering or historical behavior.\",\n \"Ambiguous folded X-Robots-Tag scopes and unavailable robots/pages are reported as uncertain, not assumed allowed.\",\n];\nconst encoder = new TextEncoder();\nfunction bytes(text: string): number { return encoder.encode(text).byteLength; }\n\nexport function emptyCrawlerAccessReview(\n scope: CrawlerAccessReview[\"scope\"] = \"caller_supplied_crawler_evidence\",\n): CrawlerAccessReview {\n return {\n scope,\n pages_observed: 0, profiles_checked: 0, rows_checked: 0,\n robots_rules_used: 0, robots_rules_truncated: false,\n robots_unavailable: true, crawler_disallowed_rows: 0,\n noindex_declared_rows: 0, unknown_access_rows: 0,\n unknown_indexing_rows: 0, scope_ambiguous_rows: 0,\n coverage_limited: true, limitations: warnings, rows: [],\n total_findings: 0, findings: [], findings_truncated: false,\n };\n}\n\n/** Percent-encoded unreserved ASCII is equivalent to literal bytes (RFC 9309). */\nfunction normalizedRobotsValue(value: string): string {\n const withEscapes = value.replace(/%([0-9a-fA-F]{2})/g, (_, hex: string) => {\n const ch = String.fromCharCode(Number.parseInt(hex, 16));\n return /^[A-Za-z0-9._~-]$/.test(ch) ? ch : \"%\" + hex.toUpperCase();\n });\n return withEscapes.replace(/[^\\x00-\\x7f]/gu, (ch) =>\n Array.from(encoder.encode(ch), (byte) => \"%\" + byte.toString(16).toUpperCase().padStart(2, \"0\")).join(\"\"));\n}\n\n/** Iterative glob matcher: bounded linear/backtracking behavior, no attacker regex. */\nfunction matchesRobots(path: string, rawPattern: string): boolean {\n if (!rawPattern) return false;\n const target = normalizedRobotsValue(path);\n const rule = normalizedRobotsValue(rawPattern);\n const anchored = rule.endsWith(\"$\");\n const pattern = anchored ? rule.slice(0, -1) : rule;\n let position = 0;\n let rulePosition = 0;\n let wildcard = -1;\n let wildcardEnd = 0;\n while (position < target.length) {\n if (!anchored && rulePosition === pattern.length) return true;\n if (rulePosition < pattern.length && pattern[rulePosition] === target[position]) {\n position++;\n rulePosition++;\n } else if (rulePosition < pattern.length && pattern[rulePosition] === \"*\") {\n wildcard = rulePosition++;\n wildcardEnd = position;\n } else if (wildcard >= 0) {\n rulePosition = wildcard + 1;\n position = ++wildcardEnd;\n } else return false;\n }\n while (rulePosition < pattern.length && pattern[rulePosition] === \"*\") rulePosition++;\n return rulePosition === pattern.length;\n}\n\nfunction parseRobots(content: string): { groups: RobotGroup[]; truncated: boolean; count: number } {\n const groups: RobotGroup[] = [];\n let current: RobotGroup = { agents: [], rules: [] };\n let hasRules = false;\n let count = 0;\n let truncated = false;\n const flush = () => {\n if (current.agents.length) groups.push(current);\n current = { agents: [], rules: [] };\n hasRules = false;\n };\n for (const raw of content.split(/\\r\\n|\\r|\\n/)) {\n const line = raw.split(\"#\", 1)[0]?.trim() ?? \"\";\n const colon = line.indexOf(\":\");\n if (colon < 1) continue;\n const directive = line.slice(0, colon).trim().toLowerCase();\n const value = line.slice(colon + 1).trim();\n if (directive === \"user-agent\") {\n if (hasRules) flush();\n if (/^(\\*|[a-z0-9_.-]{1,80})$/i.test(value) && current.agents.length < 24) {\n current.agents.push(value.toLowerCase());\n }\n continue;\n }\n if ((directive === \"allow\" || directive === \"disallow\") &&\n current.agents.length > 0 && value.length <= 512) {\n count++;\n if (count <= MAX_CRAWLER_ROBOT_RULES) {\n current.rules.push({ allow: directive === \"allow\", pattern: value });\n } else truncated = true;\n hasRules = true;\n }\n }\n flush();\n return { groups, truncated, count };\n}\n\nfunction chosenRules(groups: RobotGroup[], token: string): {\n matched: boolean; rules: RobotRule[];\n} {\n let specificity = -1;\n const selected: RobotGroup[] = [];\n for (const group of groups) {\n const score = group.agents.reduce((best, agent) =>\n Math.max(best, agent === \"*\" ? 0 : (token.includes(agent) ? agent.length : -1)), -1);\n if (score > specificity) {\n specificity = score;\n selected.length = 0;\n if (score >= 0) selected.push(group);\n } else if (score >= 0 && score === specificity) selected.push(group);\n }\n return { matched: specificity >= 0, rules: selected.flatMap((g) => g.rules) };\n}\n\nfunction robotDecision(url: URL, rules: RobotRule[]): { allowed: boolean; rule: \"allow\" | \"disallow\" | \"none\" } {\n const path = url.pathname + url.search;\n let winner: RobotRule | undefined;\n let best = -1;\n for (const rule of rules) {\n if (!matchesRobots(path, rule.pattern)) continue;\n const normalized = normalizedRobotsValue(rule.pattern);\n const specificity = normalized.replace(/%[0-9A-F]{2}/g, \"X\")\n .replace(/\\*/g, \"\").replace(/\\$$/, \"\").length;\n if (!winner || specificity > best || (specificity === best && rule.allow)) {\n winner = rule;\n best = specificity;\n }\n }\n return { allowed: winner?.allow ?? true,\n rule: winner ? (winner.allow ? \"allow\" : \"disallow\") : \"none\" };\n}\n\n/** Guard the service's own fetches without impersonating a real crawler. */\nexport function isAllowedForFetcher(\n robotsTxt: string, url: string, serviceToken = \"digestseo-web-validator\",\n): boolean | undefined {\n if (typeof robotsTxt !== \"string\" || bytes(robotsTxt) > MAX_CRAWLER_ROBOTS_BYTES) {\n return undefined;\n }\n const safe = safeHttpResourceUrl(url);\n if (!safe || !/^[a-z0-9._-]{1,80}$/i.test(serviceToken)) return undefined;\n const parsed = parseRobots(robotsTxt);\n if (parsed.truncated) return undefined;\n const selected = chosenRules(parsed.groups, serviceToken.toLowerCase());\n return robotDecision(new URL(safe), selected.rules).allowed;\n}\n\ntype DirectiveSet = {\n noindex: boolean; index: boolean; scopeAmbiguous: boolean;\n};\nfunction hasIndexToken(value: string, token: \"noindex\" | \"index\"): boolean {\n return value.split(/[,;\\s]+/).some((part) => part.trim().toLowerCase() === token ||\n (token === \"noindex\" && part.trim().toLowerCase() === \"none\"));\n}\nfunction extractMeta(html: string | undefined): Map<string, { index: boolean; noindex: boolean }> {\n const result = new Map<string, { index: boolean; noindex: boolean }>();\n if (html === undefined) return result;\n const $ = load(html);\n $(\"meta[name][content]\").each((_, element) => {\n const name = ($(element).attr(\"name\") ?? \"\").trim().toLowerCase();\n if (name !== \"robots\" && !Object.values(profileTokens).includes(name)) return;\n const content = $(element).attr(\"content\") ?? \"\";\n const current = result.get(name) ?? { index: false, noindex: false };\n current.index ||= hasIndexToken(content, \"index\");\n current.noindex ||= hasIndexToken(content, \"noindex\");\n result.set(name, current);\n });\n return result;\n}\n\n/** Treat each supplied header value as potentially folded; avoid guessing global scope. */\nfunction extractHeader(headers: string[] | undefined, profile: CrawlerProfile): DirectiveSet {\n const result: DirectiveSet = { index: false, noindex: false, scopeAmbiguous: false };\n if (!headers) return result;\n const token = profileTokens[profile];\n for (const raw of headers) {\n let scope = \"all\";\n let hasScoped = false;\n for (const part of raw.split(\",\")) {\n let value = part.trim().toLowerCase();\n if (!value) continue;\n const m = /^([a-z][a-z0-9._-]*):\\s*(.*)$/.exec(value);\n // Values with colons such as max-snippet do not designate an agent.\n if (m && ![\"max-snippet\", \"max-image-preview\", \"max-video-preview\", \"unavailable_after\"].includes(m[1])) {\n scope = m[1];\n hasScoped = true;\n value = m[2].trim();\n } else if (hasScoped && scope !== token && (value === \"noindex\" || value === \"none\")) {\n // Folded values may represent a second global header field.\n result.scopeAmbiguous = true;\n }\n if (scope === \"all\" || token === scope) {\n result.noindex ||= hasIndexToken(value, \"noindex\");\n result.index ||= hasIndexToken(value, \"index\");\n }\n }\n }\n return result;\n}\n\nfunction metaDirective(\n collected: Map<string, { index: boolean; noindex: boolean }>,\n profile: CrawlerProfile,\n): { index: boolean; noindex: boolean } {\n const global = collected.get(\"robots\");\n const specific = collected.get(profileTokens[profile]);\n return {\n index: Boolean(global?.index || specific?.index),\n noindex: Boolean(global?.noindex || specific?.noindex),\n };\n}\n\nexport function analyzeCrawlerAccess(\n input: CrawlerAccessInput,\n scope: CrawlerAccessReview[\"scope\"] = \"caller_supplied_crawler_evidence\",\n): CrawlerAccessReview {\n if (!input || typeof input !== \"object\" || !safeHttpResourceUrl(input.site_url)) {\n throw new Error(\"Use one safe public query-free site URL.\");\n }\n const origin = new URL(input.site_url).origin;\n if (!Array.isArray(input.pages) || input.pages.length < 1 || input.pages.length > MAX_CRAWLER_PAGES) {\n throw new Error(\"Supply one to eight same-origin page observations.\");\n }\n const profiles = input.profiles ?? [...CRAWLER_PROFILES];\n if (!Array.isArray(profiles) || profiles.length < 1 || profiles.length > CRAWLER_PROFILES.length ||\n new Set(profiles).size !== profiles.length ||\n profiles.some((profile) => !CRAWLER_PROFILES.includes(profile))) {\n throw new Error(\"Crawler profile selection contains unknown or repeated values.\");\n }\n if (input.robots_status_code !== undefined &&\n (!Number.isInteger(input.robots_status_code) ||\n input.robots_status_code < 100 || input.robots_status_code > 599)) {\n throw new Error(\"Invalid robots.txt HTTP status.\");\n }\n if (input.robots_txt !== undefined &&\n (bytes(input.robots_txt) > MAX_CRAWLER_ROBOTS_BYTES ||\n (input.robots_status_code !== undefined && (\n input.robots_status_code < 200 || input.robots_status_code >= 300)))) {\n throw new Error(\"Robots content is oversized or inconsistent with the supplied status.\");\n }\n const results: Array<{ url: URL; html?: string; headers?: string[]; status?: number }> = [];\n let htmlBytes = 0;\n for (const page of input.pages) {\n const safe = safeHttpResourceUrl(page.url);\n if (!safe || new URL(safe).origin !== origin) {\n throw new Error(\"All page URL labels must belong to the same origin and have no query/credentials.\");\n }\n if (page.status_code !== undefined &&\n (!Number.isInteger(page.status_code) || page.status_code < 100 || page.status_code > 599)) {\n throw new Error(\"Invalid HTTP page status.\");\n }\n if (page.html !== undefined) {\n const size = bytes(page.html);\n htmlBytes += size;\n if (size > MAX_CRAWLER_HTML_BYTES || htmlBytes > MAX_CRAWLER_TOTAL_HTML_BYTES) {\n throw new Error(\"HTML samples exceed the static input byte caps.\");\n }\n }\n if (page.x_robots_tag !== undefined &&\n (!Array.isArray(page.x_robots_tag) || page.x_robots_tag.length > 8 ||\n page.x_robots_tag.some((part) => typeof part !== \"string\" || bytes(part) > 512))) {\n throw new Error(\"X-Robots-Tag lines must be a small bounded list.\");\n }\n results.push({ url: new URL(safe), html: page.html,\n headers: page.x_robots_tag, status: page.status_code });\n }\n\n const parsed = input.robots_txt === undefined\n ? { groups: [] as RobotGroup[], truncated: false, count: 0 }\n : parseRobots(input.robots_txt);\n const review = emptyCrawlerAccessReview(scope);\n review.pages_observed = results.length;\n review.profiles_checked = profiles.length;\n review.robots_status_code = input.robots_status_code;\n review.robots_rules_used = Math.min(parsed.count, MAX_CRAWLER_ROBOT_RULES);\n review.robots_rules_truncated = parsed.truncated;\n const robotsStatus = input.robots_status_code;\n const absent = input.robots_txt === undefined && robotsStatus === undefined;\n const noRobotsDocument = robotsStatus !== undefined && robotsStatus >= 400 &&\n robotsStatus < 500 && robotsStatus !== 429;\n const unavailable = (robotsStatus !== undefined && (\n robotsStatus === 429 || robotsStatus >= 500 ||\n (robotsStatus >= 300 && robotsStatus < 400) ||\n robotsStatus < 200)) ||\n (input.robots_txt === undefined && !noRobotsDocument);\n review.robots_unavailable = unavailable || absent;\n function pushFinding(code: CrawlerFindingCode, severity: \"warning\" | \"info\",\n page: number, profile: CrawlerProfile, message: string) {\n review.total_findings++;\n if (review.findings.length < MAX_CRAWLER_FINDINGS) {\n review.findings.push({ code, severity, page, profile, message });\n } else review.findings_truncated = true;\n }\n\n for (let i = 0; i < results.length; i++) {\n const page = results[i];\n const metas = extractMeta(page.html);\n for (const profile of profiles) {\n const selected = chosenRules(parsed.groups, profileTokens[profile]);\n let robotsAccess: CrawlerAccessState;\n let rule: CrawlerAccessRow[\"robots_rule\"] = \"unknown\";\n if (parsed.truncated || unavailable ||\n (noRobotsDocument && robotsStatus !== 404 && robotsStatus !== 410 &&\n !profile.startsWith(\"googlebot\"))) {\n robotsAccess = \"unknown\";\n } else if (input.robots_txt !== undefined || noRobotsDocument) {\n const decision = robotDecision(page.url, selected.rules);\n rule = decision.rule;\n robotsAccess = decision.allowed ? \"allowed\" : \"disallowed\";\n } else robotsAccess = \"unknown\";\n\n const meta = metaDirective(metas, profile);\n const header = extractHeader(page.headers, profile);\n const noindex = meta.noindex || header.noindex;\n const explicitIndex = meta.index || header.index;\n const conflict = noindex && explicitIndex;\n const pageHttpOk = page.status === undefined || (page.status >= 200 && page.status < 300);\n const indexingKnown = page.html !== undefined && page.headers !== undefined;\n const indexingState: CrawlerIndexingState = noindex\n ? \"explicit_noindex\"\n : (!pageHttpOk || !indexingKnown ? \"unknown\" : \"no_noindex_observed\");\n const indexingSource: CrawlerAccessRow[\"indexing_source\"] =\n meta.noindex || meta.index\n ? (header.noindex || header.index ? \"both\" : \"meta\")\n : (header.noindex || header.index ? \"header\" : \"none\");\n\n const row: CrawlerAccessRow = {\n page: i + 1, profile, robots_access: robotsAccess,\n robots_rule: rule, robots_group_matched: selected.matched,\n indexing_state: indexingState, indexing_source: indexingSource,\n explicit_index_directive: explicitIndex,\n conflicting_index_directives: conflict,\n x_robots_scope_ambiguous: header.scopeAmbiguous,\n ...(page.status === undefined ? {} : { page_http_status: page.status }),\n static_html_examined: page.html !== undefined,\n effective_access: robotsAccess === \"disallowed\" ? \"crawl_disallowed\"\n : robotsAccess === \"allowed\" && noindex ? \"crawl_allowed_noindex_declared\"\n : robotsAccess === \"allowed\" && indexingState === \"no_noindex_observed\"\n ? \"crawl_allowed_no_noindex_observed\" : \"unverified\",\n };\n review.rows.push(row);\n if (robotsAccess === \"disallowed\") {\n review.crawler_disallowed_rows++;\n pushFinding(\"crawler_disallowed\", \"warning\", i + 1, profile,\n \"The supplied robots.txt rule set disallows this crawler product token on this page.\");\n }\n if (robotsAccess === \"unknown\") {\n review.unknown_access_rows++;\n pushFinding(parsed.truncated ? \"robots_rules_truncated\" : \"robots_unavailable\",\n \"info\", i + 1, profile, \"Robots access cannot be established from complete applicable evidence.\");\n }\n if (noindex) {\n review.noindex_declared_rows++;\n pushFinding(\"explicit_noindex\", \"warning\", i + 1, profile,\n \"A supplied meta or HTTP directive explicitly declares noindex for this profile.\");\n if (robotsAccess === \"disallowed\") pushFinding(\"blocked_with_noindex\", \"info\",\n i + 1, profile, \"Robots disallow may stop this crawler from seeing the page's noindex instruction.\");\n }\n if (indexingState === \"unknown\") {\n review.unknown_indexing_rows++;\n pushFinding(\"indexing_observation_missing\", \"info\", i + 1, profile,\n \"No complete indexability directive observation was provided for this page.\");\n }\n if (page.status !== undefined && page.status >= 400) {\n pushFinding(\"page_http_error\", \"warning\", i + 1, profile,\n \"The supplied HTTP response status is an error, irrespective of robots rules.\");\n }\n if (conflict) pushFinding(\"conflicting_indexing_directives\", \"warning\",\n i + 1, profile, \"Index and noindex are declared together; noindex should be treated as restrictive.\");\n if (header.scopeAmbiguous) {\n review.scope_ambiguous_rows++;\n pushFinding(\"x_robots_scope_ambiguous\", \"info\", i + 1, profile,\n \"A folded X-Robots-Tag value has ambiguous scope and should be verified against raw server headers.\");\n }\n }\n }\n review.rows_checked = review.rows.length;\n return review;\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { fetchPublicHttp } from "../../network.js";
|
|
2
|
+
import { analyzeHttpDelivery, deliveryResponseHeaders } from "./http-delivery.js";
|
|
3
|
+
import { safeHttpResourceUrl } from "./non-html-directives.js";
|
|
4
|
+
/** Live point-in-time HTTP diagnostic, with DNS-pinned public target validation. */
|
|
5
|
+
export async function probeHttpDelivery(input) {
|
|
6
|
+
const safe = safeHttpResourceUrl(input);
|
|
7
|
+
if (!safe)
|
|
8
|
+
throw new Error("Provide a public, query-free HTTP(S) URL.");
|
|
9
|
+
const initial = new URL(safe);
|
|
10
|
+
const observations = [];
|
|
11
|
+
try {
|
|
12
|
+
const { response } = await fetchPublicHttp(safe, {
|
|
13
|
+
method: "GET",
|
|
14
|
+
headers: { accept: "*/*", "user-agent": "mcp-web-validator-http-diagnostics/1" },
|
|
15
|
+
timeoutMs: 12_000,
|
|
16
|
+
maxRedirects: 3,
|
|
17
|
+
allowRedirect: (next, current) => next.origin === initial.origin && Boolean(safeHttpResourceUrl(next.href)) &&
|
|
18
|
+
!(current.protocol === "https:" && next.protocol === "http:"),
|
|
19
|
+
onResponse: (url, response) => {
|
|
20
|
+
observations.push({
|
|
21
|
+
url: url.href, status_code: response.status, method: "GET",
|
|
22
|
+
headers: deliveryResponseHeaders(response.headers),
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
try {
|
|
27
|
+
await response.body?.cancel();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// The peer may have closed the stream already.
|
|
31
|
+
}
|
|
32
|
+
return analyzeHttpDelivery(observations, "live_public_http_probe");
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
if (observations.length > 0) {
|
|
36
|
+
const report = analyzeHttpDelivery(observations, "live_public_http_probe");
|
|
37
|
+
report.error = "The redirect chain could not be completed within safe URL, DNS and timeout limits.";
|
|
38
|
+
report.redirect_chain_complete = false;
|
|
39
|
+
return report;
|
|
40
|
+
}
|
|
41
|
+
throw new Error("The public HTTP delivery probe failed or exceeded its timeout.");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=http-delivery-probe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-delivery-probe.js","sourceRoot":"","sources":["../../../src/modules/http-crawl/http-delivery-probe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAA8C,MAAM,oBAAoB,CAAC;AAC9H,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAAa;IACnD,MAAM,IAAI,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;I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,MAAM,MAAM,GAAG,mBAAmB,CAAC,YAAY,EAAE,wBAAwB,CAAC,CAAC;YAC3E,MAAM,CAAC,KAAK,GAAG,oFAAoF,CAAC;YACpG,MAAM,CAAC,uBAAuB,GAAG,KAAK,CAAC;YACvC,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACpF,CAAC;AACH,CAAC","sourcesContent":["import { fetchPublicHttp } from \"../../network.js\";\nimport { analyzeHttpDelivery, deliveryResponseHeaders, type DeliveryInputHop, type DeliveryReview } from \"./http-delivery.js\";\nimport { safeHttpResourceUrl } from \"./non-html-directives.js\";\n\n/** Live point-in-time HTTP diagnostic, with DNS-pinned public target validation. */\nexport async function probeHttpDelivery(input: string): Promise<DeliveryReview> {\n const safe = safeHttpResourceUrl(input);\n if (!safe) throw new Error(\"Provide a public, query-free HTTP(S) URL.\");\n const initial = new URL(safe);\n const observations: DeliveryInputHop[] = [];\n try {\n const { response } = await fetchPublicHttp(safe, {\n method: \"GET\",\n headers: { accept: \"*/*\", \"user-agent\": \"mcp-web-validator-http-diagnostics/1\" },\n timeoutMs: 12_000,\n maxRedirects: 3,\n allowRedirect: (next, current) =>\n next.origin === initial.origin && Boolean(safeHttpResourceUrl(next.href)) &&\n !(current.protocol === \"https:\" && next.protocol === \"http:\"),\n onResponse: (url, response) => {\n observations.push({\n url: url.href, status_code: response.status, method: \"GET\",\n headers: deliveryResponseHeaders(response.headers),\n });\n },\n });\n try {\n await response.body?.cancel();\n } catch {\n // The peer may have closed the stream already.\n }\n return analyzeHttpDelivery(observations, \"live_public_http_probe\");\n } catch {\n if (observations.length > 0) {\n const report = analyzeHttpDelivery(observations, \"live_public_http_probe\");\n report.error = \"The redirect chain could not be completed within safe URL, DNS and timeout limits.\";\n report.redirect_chain_complete = false;\n return report;\n }\n throw new Error(\"The public HTTP delivery probe failed or exceeded its timeout.\");\n }\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export declare const MAX_DELIVERY_HOPS = 4;
|
|
2
|
+
export declare const MAX_DELIVERY_FINDINGS = 12;
|
|
3
|
+
export declare const MAX_DELIVERY_HEADER_VALUE_BYTES = 512;
|
|
4
|
+
export declare const MAX_DELIVERY_TOTAL_HEADER_BYTES = 8192;
|
|
5
|
+
export declare const DELIVERY_HEADER_NAMES: readonly ["age", "cache-control", "cf-cache-status", "cf-mitigated", "cf-ray", "content-type", "location", "retry-after", "server", "x-cache"];
|
|
6
|
+
export declare const DELIVERY_FINDING_CODES: readonly ["http_forbidden", "http_rate_limited", "http_server_error", "http_client_error", "cloudflare_challenge", "redirect_missing_location", "redirect_invalid_location", "redirect_query_target", "redirect_cross_origin", "redirect_https_downgrade", "redirect_observation_mismatch", "redirect_loop", "redirect_incomplete", "redirect_chain_long"];
|
|
7
|
+
export type DeliveryFindingCode = typeof DELIVERY_FINDING_CODES[number];
|
|
8
|
+
export type DeliveryStatus = "success" | "redirect" | "forbidden" | "rate_limited" | "server_error" | "client_error" | "other";
|
|
9
|
+
export type DeliveryRedirectTarget = "none" | "same_origin" | "cross_origin" | "https_downgrade" | "query_target" | "invalid" | "missing";
|
|
10
|
+
export type DeliveryCacheState = "hit" | "miss" | "bypass" | "dynamic" | "expired" | "stale" | "other" | "unknown";
|
|
11
|
+
export interface DeliveryInputHop {
|
|
12
|
+
url: string;
|
|
13
|
+
status_code: number;
|
|
14
|
+
method?: "GET" | "HEAD";
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
export interface DeliveryHop {
|
|
18
|
+
hop: number;
|
|
19
|
+
status_code: number;
|
|
20
|
+
status: DeliveryStatus;
|
|
21
|
+
method: "GET" | "HEAD" | "unspecified";
|
|
22
|
+
https: boolean;
|
|
23
|
+
redirect_target: DeliveryRedirectTarget;
|
|
24
|
+
next_hop_observed: boolean;
|
|
25
|
+
cache_state: DeliveryCacheState;
|
|
26
|
+
cache_no_store: boolean;
|
|
27
|
+
cache_no_cache: boolean;
|
|
28
|
+
cache_private: boolean;
|
|
29
|
+
cache_max_age_seconds?: number;
|
|
30
|
+
age_seconds?: number;
|
|
31
|
+
retry_after_present: boolean;
|
|
32
|
+
retry_after_seconds?: number;
|
|
33
|
+
cf_challenge: boolean;
|
|
34
|
+
cf_ray_present: boolean;
|
|
35
|
+
cloudflare_server: boolean;
|
|
36
|
+
content_type_html: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface DeliveryFinding {
|
|
39
|
+
hop: number;
|
|
40
|
+
code: DeliveryFindingCode;
|
|
41
|
+
severity: "warning" | "info";
|
|
42
|
+
message: string;
|
|
43
|
+
}
|
|
44
|
+
export interface DeliveryReview {
|
|
45
|
+
scope: "live_public_http_probe" | "caller_supplied_http_observations";
|
|
46
|
+
hops_observed: number;
|
|
47
|
+
redirects_observed: number;
|
|
48
|
+
final_http_status?: number;
|
|
49
|
+
errors_observed: number;
|
|
50
|
+
challenges_observed: number;
|
|
51
|
+
redirect_chain_complete: boolean;
|
|
52
|
+
coverage_limited: true;
|
|
53
|
+
limitations: string[];
|
|
54
|
+
hops: DeliveryHop[];
|
|
55
|
+
total_findings: number;
|
|
56
|
+
findings: DeliveryFinding[];
|
|
57
|
+
findings_truncated: boolean;
|
|
58
|
+
error?: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function emptyDeliveryReview(scope?: DeliveryReview["scope"]): DeliveryReview;
|
|
61
|
+
/** Caller-controlled records and live-captured headers are subject to identical validation. */
|
|
62
|
+
export declare function analyzeHttpDelivery(observations: DeliveryInputHop[], scope?: DeliveryReview["scope"]): DeliveryReview;
|
|
63
|
+
/** Only allowlisted header values are captured, with no request cookies or body. */
|
|
64
|
+
export declare function deliveryResponseHeaders(headers: Headers): Record<string, string>;
|