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,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V01: bounded HTTP response-delivery evidence. All observations are one
|
|
3
|
+
* point in time; the analyzer does not identify verified crawlers or causes.
|
|
4
|
+
* Deliberately never returns raw URL paths, headers, Location or challenge IDs.
|
|
5
|
+
*/
|
|
6
|
+
import { safeHttpResourceUrl } from "./non-html-directives.js";
|
|
7
|
+
export const MAX_DELIVERY_HOPS = 4;
|
|
8
|
+
export const MAX_DELIVERY_FINDINGS = 12;
|
|
9
|
+
export const MAX_DELIVERY_HEADER_VALUE_BYTES = 512;
|
|
10
|
+
export const MAX_DELIVERY_TOTAL_HEADER_BYTES = 8_192;
|
|
11
|
+
export const DELIVERY_HEADER_NAMES = [
|
|
12
|
+
"age", "cache-control", "cf-cache-status", "cf-mitigated", "cf-ray",
|
|
13
|
+
"content-type", "location", "retry-after", "server", "x-cache",
|
|
14
|
+
];
|
|
15
|
+
export const DELIVERY_FINDING_CODES = [
|
|
16
|
+
"http_forbidden", "http_rate_limited", "http_server_error",
|
|
17
|
+
"http_client_error", "cloudflare_challenge", "redirect_missing_location",
|
|
18
|
+
"redirect_invalid_location", "redirect_query_target", "redirect_cross_origin",
|
|
19
|
+
"redirect_https_downgrade", "redirect_observation_mismatch",
|
|
20
|
+
"redirect_loop", "redirect_incomplete", "redirect_chain_long",
|
|
21
|
+
];
|
|
22
|
+
const redirectStatuses = new Set([301, 302, 303, 307, 308]);
|
|
23
|
+
const allowedHeaders = new Set(DELIVERY_HEADER_NAMES);
|
|
24
|
+
const cacheStates = new Set(["HIT", "MISS", "BYPASS", "DYNAMIC", "EXPIRED", "STALE"]);
|
|
25
|
+
const probeLimits = [
|
|
26
|
+
"One bounded HTTP observation, not historical availability or a Googlebot fetch.",
|
|
27
|
+
"Only selected response-header flags are reported; cache status and edge headers do not establish root cause.",
|
|
28
|
+
"Challenge detection relies on response signals, not JavaScript execution or an authenticated browser.",
|
|
29
|
+
];
|
|
30
|
+
export function emptyDeliveryReview(scope = "caller_supplied_http_observations") {
|
|
31
|
+
return {
|
|
32
|
+
scope, hops_observed: 0, redirects_observed: 0,
|
|
33
|
+
errors_observed: 0, challenges_observed: 0,
|
|
34
|
+
redirect_chain_complete: false, coverage_limited: true,
|
|
35
|
+
limitations: probeLimits, hops: [], total_findings: 0,
|
|
36
|
+
findings: [], findings_truncated: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function statusKind(status) {
|
|
40
|
+
if (status === 403)
|
|
41
|
+
return "forbidden";
|
|
42
|
+
if (status === 429)
|
|
43
|
+
return "rate_limited";
|
|
44
|
+
if (status >= 500)
|
|
45
|
+
return "server_error";
|
|
46
|
+
if (status >= 400)
|
|
47
|
+
return "client_error";
|
|
48
|
+
if (redirectStatuses.has(status))
|
|
49
|
+
return "redirect";
|
|
50
|
+
if (status >= 200 && status < 300)
|
|
51
|
+
return "success";
|
|
52
|
+
return "other";
|
|
53
|
+
}
|
|
54
|
+
function safeIntegerHeader(value) {
|
|
55
|
+
if (value === undefined || !/^\d{1,9}$/.test(value.trim()))
|
|
56
|
+
return undefined;
|
|
57
|
+
const result = Number(value);
|
|
58
|
+
return Number.isSafeInteger(result) ? result : undefined;
|
|
59
|
+
}
|
|
60
|
+
function cacheDirectives(value) {
|
|
61
|
+
const directives = [];
|
|
62
|
+
let start = 0, quoted = false, escaped = false;
|
|
63
|
+
for (let i = 0; i < value.length; i++) {
|
|
64
|
+
const char = value[i];
|
|
65
|
+
if (escaped) {
|
|
66
|
+
escaped = false;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (char === "\\" && quoted) {
|
|
70
|
+
escaped = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (char === '"') {
|
|
74
|
+
quoted = !quoted;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (char === "," && !quoted) {
|
|
78
|
+
directives.push(value.slice(start, i).trim().toLowerCase());
|
|
79
|
+
start = i + 1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
directives.push(value.slice(start).trim().toLowerCase());
|
|
83
|
+
return directives;
|
|
84
|
+
}
|
|
85
|
+
function parseHeaders(record) {
|
|
86
|
+
const headers = Object.create(null);
|
|
87
|
+
if (!record)
|
|
88
|
+
return headers;
|
|
89
|
+
for (const [name, value] of Object.entries(record)) {
|
|
90
|
+
const key = name.toLowerCase();
|
|
91
|
+
if (!allowedHeaders.has(key) || typeof value !== "string" ||
|
|
92
|
+
/[\r\n\u0000]/u.test(value) ||
|
|
93
|
+
new TextEncoder().encode(value).byteLength > MAX_DELIVERY_HEADER_VALUE_BYTES ||
|
|
94
|
+
Object.hasOwn(headers, key)) {
|
|
95
|
+
throw new Error("HTTP delivery headers must use unique approved names and bounded single-line values");
|
|
96
|
+
}
|
|
97
|
+
headers[key] = value;
|
|
98
|
+
}
|
|
99
|
+
return headers;
|
|
100
|
+
}
|
|
101
|
+
function classifyTarget(current, location) {
|
|
102
|
+
if (location === undefined || !location.trim())
|
|
103
|
+
return { state: "missing" };
|
|
104
|
+
try {
|
|
105
|
+
const parsed = new URL(location, current);
|
|
106
|
+
if (!["http:", "https:"].includes(parsed.protocol) || parsed.username ||
|
|
107
|
+
parsed.password || parsed.port) {
|
|
108
|
+
return { state: "invalid" };
|
|
109
|
+
}
|
|
110
|
+
if (parsed.search || parsed.hash) {
|
|
111
|
+
return { state: "query_target" };
|
|
112
|
+
}
|
|
113
|
+
if (!safeHttpResourceUrl(parsed.href))
|
|
114
|
+
return { state: "invalid" };
|
|
115
|
+
if (current.protocol === "https:" && parsed.protocol === "http:") {
|
|
116
|
+
return { state: "https_downgrade", target: parsed.href };
|
|
117
|
+
}
|
|
118
|
+
if (current.origin !== parsed.origin) {
|
|
119
|
+
return { state: "cross_origin", target: parsed.href };
|
|
120
|
+
}
|
|
121
|
+
return { state: "same_origin", target: parsed.href };
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return { state: "invalid" };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Caller-controlled records and live-captured headers are subject to identical validation. */
|
|
128
|
+
export function analyzeHttpDelivery(observations, scope = "caller_supplied_http_observations") {
|
|
129
|
+
if (!Array.isArray(observations) || observations.length < 1 ||
|
|
130
|
+
observations.length > MAX_DELIVERY_HOPS) {
|
|
131
|
+
throw new Error("Provide between one and four ordered HTTP delivery hops");
|
|
132
|
+
}
|
|
133
|
+
let totalHeaderBytes = 0;
|
|
134
|
+
let origin;
|
|
135
|
+
const urls = [];
|
|
136
|
+
const headers = [];
|
|
137
|
+
for (const hop of observations) {
|
|
138
|
+
const safe = safeHttpResourceUrl(hop.url);
|
|
139
|
+
if (!safe)
|
|
140
|
+
throw new Error("HTTP hop URLs must be safe query-free HTTP(S) labels");
|
|
141
|
+
const url = new URL(safe);
|
|
142
|
+
if (origin && url.origin !== origin)
|
|
143
|
+
throw new Error("HTTP delivery hops must stay on one origin");
|
|
144
|
+
origin = url.origin;
|
|
145
|
+
if (!Number.isInteger(hop.status_code) || hop.status_code < 100 || hop.status_code > 599 ||
|
|
146
|
+
(hop.method !== undefined && hop.method !== "GET" && hop.method !== "HEAD")) {
|
|
147
|
+
throw new Error("HTTP delivery hop status or method is invalid");
|
|
148
|
+
}
|
|
149
|
+
const parsed = parseHeaders(hop.headers);
|
|
150
|
+
totalHeaderBytes += Object.entries(parsed).reduce((bytes, [name, value]) => bytes + name.length + new TextEncoder().encode(value).byteLength, 0);
|
|
151
|
+
if (totalHeaderBytes > MAX_DELIVERY_TOTAL_HEADER_BYTES) {
|
|
152
|
+
throw new Error("HTTP delivery response headers exceed the total input bound");
|
|
153
|
+
}
|
|
154
|
+
urls.push(url);
|
|
155
|
+
headers.push(parsed);
|
|
156
|
+
}
|
|
157
|
+
const output = emptyDeliveryReview(scope);
|
|
158
|
+
const addFinding = (hop, code, severity, message) => {
|
|
159
|
+
output.total_findings += 1;
|
|
160
|
+
if (output.findings.length < MAX_DELIVERY_FINDINGS) {
|
|
161
|
+
output.findings.push({ hop, code, severity, message });
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
output.findings_truncated = true;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
output.hops_observed = observations.length;
|
|
168
|
+
output.final_http_status = observations[observations.length - 1].status_code;
|
|
169
|
+
output.redirect_chain_complete = true;
|
|
170
|
+
const visited = new Set();
|
|
171
|
+
for (let index = 0; index < observations.length; index += 1) {
|
|
172
|
+
const entry = observations[index];
|
|
173
|
+
const url = urls[index];
|
|
174
|
+
const head = headers[index];
|
|
175
|
+
const hopNumber = index + 1;
|
|
176
|
+
const status = statusKind(entry.status_code);
|
|
177
|
+
const redirect = status === "redirect";
|
|
178
|
+
const target = redirect ? classifyTarget(url, head.location) : { state: "none" };
|
|
179
|
+
const next = urls[index + 1];
|
|
180
|
+
if (next && !redirect) {
|
|
181
|
+
throw new Error("Each non-final HTTP hop must be a redirect response");
|
|
182
|
+
}
|
|
183
|
+
const nextMatches = Boolean(next && target.target === next.href);
|
|
184
|
+
if (redirect && nextMatches)
|
|
185
|
+
output.redirects_observed += 1;
|
|
186
|
+
if (redirect && !nextMatches)
|
|
187
|
+
output.redirect_chain_complete = false;
|
|
188
|
+
if (visited.has(url.href) ||
|
|
189
|
+
(redirect && target.target !== undefined && visited.has(target.target))) {
|
|
190
|
+
addFinding(hopNumber, "redirect_loop", "warning", "The redirect chain points to a previously observed response URL.");
|
|
191
|
+
}
|
|
192
|
+
visited.add(url.href);
|
|
193
|
+
const cfChallenge = head["cf-mitigated"]?.trim().toLowerCase() === "challenge";
|
|
194
|
+
// Cache-Control extension values may contain quoted commas and directive-like text.
|
|
195
|
+
const control = cacheDirectives(head["cache-control"] ?? "");
|
|
196
|
+
const cacheRaw = head["cf-cache-status"]?.trim().toUpperCase() ??
|
|
197
|
+
(/\bHIT\b/i.test(head["x-cache"] ?? "") ? "HIT" :
|
|
198
|
+
/\bMISS\b/i.test(head["x-cache"] ?? "") ? "MISS" : "");
|
|
199
|
+
const maxAgeMatch = control.map((part) => /^max-age\s*=\s*(\d{1,9})$/u.exec(part))
|
|
200
|
+
.find((match) => match !== null);
|
|
201
|
+
const maxAge = safeIntegerHeader(maxAgeMatch?.[1]);
|
|
202
|
+
const age = safeIntegerHeader(head.age);
|
|
203
|
+
const retryAfter = safeIntegerHeader(head["retry-after"]);
|
|
204
|
+
const hop = {
|
|
205
|
+
hop: hopNumber, status, status_code: entry.status_code,
|
|
206
|
+
method: entry.method ?? "unspecified", https: url.protocol === "https:",
|
|
207
|
+
redirect_target: target.state, next_hop_observed: nextMatches,
|
|
208
|
+
cache_state: cacheStates.has(cacheRaw)
|
|
209
|
+
? cacheRaw.toLowerCase()
|
|
210
|
+
: cacheRaw ? "other" : "unknown",
|
|
211
|
+
cache_no_store: control.includes("no-store"),
|
|
212
|
+
cache_no_cache: control.some((part) => /^no-cache(?:\s*=|$)/u.test(part)),
|
|
213
|
+
cache_private: control.some((part) => /^private(?:\s*=|$)/u.test(part)),
|
|
214
|
+
...(maxAge === undefined ? {} : { cache_max_age_seconds: maxAge }),
|
|
215
|
+
...(age === undefined ? {} : { age_seconds: age }),
|
|
216
|
+
retry_after_present: head["retry-after"] !== undefined,
|
|
217
|
+
...(retryAfter === undefined ? {} : { retry_after_seconds: retryAfter }),
|
|
218
|
+
cf_challenge: cfChallenge, cf_ray_present: Boolean(head["cf-ray"]),
|
|
219
|
+
cloudflare_server: (head.server ?? "").toLowerCase().includes("cloudflare"),
|
|
220
|
+
content_type_html: /^(text\/html|application\/xhtml\+xml)\b/i.test(head["content-type"] ?? ""),
|
|
221
|
+
};
|
|
222
|
+
output.hops.push(hop);
|
|
223
|
+
if (entry.status_code >= 400)
|
|
224
|
+
output.errors_observed += 1;
|
|
225
|
+
if (cfChallenge)
|
|
226
|
+
output.challenges_observed += 1;
|
|
227
|
+
if (cfChallenge)
|
|
228
|
+
addFinding(hopNumber, "cloudflare_challenge", "warning", "Cloudflare reported a challenge response (cf-mitigated: challenge).");
|
|
229
|
+
if (status === "forbidden")
|
|
230
|
+
addFinding(hopNumber, "http_forbidden", "warning", "Observed HTTP 403; this response cannot be used as an indexable page.");
|
|
231
|
+
else if (status === "rate_limited")
|
|
232
|
+
addFinding(hopNumber, "http_rate_limited", "warning", "Observed HTTP 429 rate limiting; verify whether the condition is transient.");
|
|
233
|
+
else if (status === "server_error")
|
|
234
|
+
addFinding(hopNumber, "http_server_error", "warning", "Observed an HTTP 5xx server-side failure.");
|
|
235
|
+
else if (status === "client_error")
|
|
236
|
+
addFinding(hopNumber, "http_client_error", "warning", "Observed a non-403, non-429 HTTP 4xx response.");
|
|
237
|
+
if (redirect) {
|
|
238
|
+
const targetCodes = {
|
|
239
|
+
missing: "redirect_missing_location", invalid: "redirect_invalid_location",
|
|
240
|
+
query_target: "redirect_query_target", cross_origin: "redirect_cross_origin",
|
|
241
|
+
https_downgrade: "redirect_https_downgrade",
|
|
242
|
+
};
|
|
243
|
+
const code = targetCodes[target.state];
|
|
244
|
+
if (code)
|
|
245
|
+
addFinding(hopNumber, code, "warning", "Redirect target is " + target.state.replaceAll("_", " ") + "; it was not verified as a safe in-origin next hop.");
|
|
246
|
+
if (next && !nextMatches)
|
|
247
|
+
addFinding(hopNumber, "redirect_observation_mismatch", "warning", "The next supplied hop does not match the declared Location destination.");
|
|
248
|
+
if (!nextMatches && !next)
|
|
249
|
+
addFinding(hopNumber, "redirect_incomplete", "info", "The redirect destination was not observed in this sample.");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (output.redirects_observed > 2)
|
|
253
|
+
addFinding(output.hops_observed, "redirect_chain_long", "info", "More than two followed redirect hops increase crawl work; review the chain.");
|
|
254
|
+
return output;
|
|
255
|
+
}
|
|
256
|
+
/** Only allowlisted header values are captured, with no request cookies or body. */
|
|
257
|
+
export function deliveryResponseHeaders(headers) {
|
|
258
|
+
const result = Object.create(null);
|
|
259
|
+
for (const name of DELIVERY_HEADER_NAMES) {
|
|
260
|
+
const value = headers.get(name);
|
|
261
|
+
if (value !== null) {
|
|
262
|
+
// Excessively long response headers are not passed through to the analyzer.
|
|
263
|
+
result[name] = new TextEncoder().encode(value).byteLength <= MAX_DELIVERY_HEADER_VALUE_BYTES
|
|
264
|
+
? value : "";
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=http-delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-delivery.js","sourceRoot":"","sources":["../../../src/modules/http-crawl/http-delivery.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,CAAC;AACnD,MAAM,CAAC,MAAM,+BAA+B,GAAG,KAAK,CAAC;AACrD,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ;IACnE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS;CACtD,CAAC;AAEX,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB;IAC1D,mBAAmB,EAAE,sBAAsB,EAAE,2BAA2B;IACxE,2BAA2B,E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kBAAkB,GAAG,CAAC;QAAE,UAAU,CAAC,MAAM,CAAC,aAAa,EAAE,qBAAqB,EAAE,MAAM,EAC/F,6EAA6E,CAAC,CAAC;IACjF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,uBAAuB,CAAC,OAAgB;IACtD,MAAM,MAAM,GAA2B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3D,KAAK,MAAM,IAAI,IAAI,qBAAqB,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,4EAA4E;YAC5E,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,IAAI,+BAA+B;gBAC1F,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * V01: bounded HTTP response-delivery evidence. All observations are one\n * point in time; the analyzer does not identify verified crawlers or causes.\n * Deliberately never returns raw URL paths, headers, Location or challenge IDs.\n */\nimport { safeHttpResourceUrl } from \"./non-html-directives.js\";\n\nexport const MAX_DELIVERY_HOPS = 4;\nexport const MAX_DELIVERY_FINDINGS = 12;\nexport const MAX_DELIVERY_HEADER_VALUE_BYTES = 512;\nexport const MAX_DELIVERY_TOTAL_HEADER_BYTES = 8_192;\nexport const DELIVERY_HEADER_NAMES = [\n \"age\", \"cache-control\", \"cf-cache-status\", \"cf-mitigated\", \"cf-ray\",\n \"content-type\", \"location\", \"retry-after\", \"server\", \"x-cache\",\n] as const;\n\nexport const DELIVERY_FINDING_CODES = [\n \"http_forbidden\", \"http_rate_limited\", \"http_server_error\",\n \"http_client_error\", \"cloudflare_challenge\", \"redirect_missing_location\",\n \"redirect_invalid_location\", \"redirect_query_target\", \"redirect_cross_origin\",\n \"redirect_https_downgrade\", \"redirect_observation_mismatch\",\n \"redirect_loop\", \"redirect_incomplete\", \"redirect_chain_long\",\n] as const;\nexport type DeliveryFindingCode = typeof DELIVERY_FINDING_CODES[number];\nexport type DeliveryStatus = \"success\" | \"redirect\" | \"forbidden\" | \"rate_limited\" |\n \"server_error\" | \"client_error\" | \"other\";\nexport type DeliveryRedirectTarget = \"none\" | \"same_origin\" | \"cross_origin\" |\n \"https_downgrade\" | \"query_target\" | \"invalid\" | \"missing\";\nexport type DeliveryCacheState = \"hit\" | \"miss\" | \"bypass\" | \"dynamic\" |\n \"expired\" | \"stale\" | \"other\" | \"unknown\";\n\nexport interface DeliveryInputHop {\n url: string;\n status_code: number;\n method?: \"GET\" | \"HEAD\";\n headers?: Record<string, string>;\n}\n\nexport interface DeliveryHop {\n hop: number;\n status_code: number;\n status: DeliveryStatus;\n method: \"GET\" | \"HEAD\" | \"unspecified\";\n https: boolean;\n redirect_target: DeliveryRedirectTarget;\n next_hop_observed: boolean;\n cache_state: DeliveryCacheState;\n cache_no_store: boolean;\n cache_no_cache: boolean;\n cache_private: boolean;\n cache_max_age_seconds?: number;\n age_seconds?: number;\n retry_after_present: boolean;\n retry_after_seconds?: number;\n cf_challenge: boolean;\n cf_ray_present: boolean;\n cloudflare_server: boolean;\n content_type_html: boolean;\n}\n\nexport interface DeliveryFinding {\n hop: number;\n code: DeliveryFindingCode;\n severity: \"warning\" | \"info\";\n message: string;\n}\n\nexport interface DeliveryReview {\n scope: \"live_public_http_probe\" | \"caller_supplied_http_observations\";\n hops_observed: number;\n redirects_observed: number;\n final_http_status?: number;\n errors_observed: number;\n challenges_observed: number;\n redirect_chain_complete: boolean;\n coverage_limited: true;\n limitations: string[];\n hops: DeliveryHop[];\n total_findings: number;\n findings: DeliveryFinding[];\n findings_truncated: boolean;\n error?: string;\n}\n\nconst redirectStatuses = new Set([301, 302, 303, 307, 308]);\nconst allowedHeaders = new Set<string>(DELIVERY_HEADER_NAMES);\nconst cacheStates = new Set([\"HIT\", \"MISS\", \"BYPASS\", \"DYNAMIC\", \"EXPIRED\", \"STALE\"]);\nconst probeLimits = [\n \"One bounded HTTP observation, not historical availability or a Googlebot fetch.\",\n \"Only selected response-header flags are reported; cache status and edge headers do not establish root cause.\",\n \"Challenge detection relies on response signals, not JavaScript execution or an authenticated browser.\",\n];\n\nexport function emptyDeliveryReview(\n scope: DeliveryReview[\"scope\"] = \"caller_supplied_http_observations\",\n): DeliveryReview {\n return {\n scope, hops_observed: 0, redirects_observed: 0,\n errors_observed: 0, challenges_observed: 0,\n redirect_chain_complete: false, coverage_limited: true,\n limitations: probeLimits, hops: [], total_findings: 0,\n findings: [], findings_truncated: false,\n };\n}\n\nfunction statusKind(status: number): DeliveryStatus {\n if (status === 403) return \"forbidden\";\n if (status === 429) return \"rate_limited\";\n if (status >= 500) return \"server_error\";\n if (status >= 400) return \"client_error\";\n if (redirectStatuses.has(status)) return \"redirect\";\n if (status >= 200 && status < 300) return \"success\";\n return \"other\";\n}\n\nfunction safeIntegerHeader(value: string | undefined): number | undefined {\n if (value === undefined || !/^\\d{1,9}$/.test(value.trim())) return undefined;\n const result = Number(value);\n return Number.isSafeInteger(result) ? result : undefined;\n}\n\nfunction cacheDirectives(value: string): string[] {\n const directives: string[] = [];\n let start = 0, quoted = false, escaped = false;\n for (let i = 0; i < value.length; i++) {\n const char = value[i];\n if (escaped) { escaped = false; continue; }\n if (char === \"\\\\\" && quoted) { escaped = true; continue; }\n if (char === '\"') { quoted = !quoted; continue; }\n if (char === \",\" && !quoted) {\n directives.push(value.slice(start, i).trim().toLowerCase());\n start = i + 1;\n }\n }\n directives.push(value.slice(start).trim().toLowerCase());\n return directives;\n}\n\nfunction parseHeaders(record: Record<string, string> | undefined): Record<string, string> {\n const headers: Record<string, string> = Object.create(null);\n if (!record) return headers;\n for (const [name, value] of Object.entries(record)) {\n const key = name.toLowerCase();\n if (!allowedHeaders.has(key) || typeof value !== \"string\" ||\n /[\\r\\n\\u0000]/u.test(value) ||\n new TextEncoder().encode(value).byteLength > MAX_DELIVERY_HEADER_VALUE_BYTES ||\n Object.hasOwn(headers, key)) {\n throw new Error(\"HTTP delivery headers must use unique approved names and bounded single-line values\");\n }\n headers[key] = value;\n }\n return headers;\n}\n\nfunction classifyTarget(current: URL, location: string | undefined):\n { state: DeliveryRedirectTarget; target?: string } {\n if (location === undefined || !location.trim()) return { state: \"missing\" };\n try {\n const parsed = new URL(location, current);\n if (![\"http:\", \"https:\"].includes(parsed.protocol) || parsed.username ||\n parsed.password || parsed.port) {\n return { state: \"invalid\" };\n }\n if (parsed.search || parsed.hash) {\n return { state: \"query_target\" };\n }\n if (!safeHttpResourceUrl(parsed.href)) return { state: \"invalid\" };\n if (current.protocol === \"https:\" && parsed.protocol === \"http:\") {\n return { state: \"https_downgrade\", target: parsed.href };\n }\n if (current.origin !== parsed.origin) {\n return { state: \"cross_origin\", target: parsed.href };\n }\n return { state: \"same_origin\", target: parsed.href };\n } catch {\n return { state: \"invalid\" };\n }\n}\n\n/** Caller-controlled records and live-captured headers are subject to identical validation. */\nexport function analyzeHttpDelivery(\n observations: DeliveryInputHop[],\n scope: DeliveryReview[\"scope\"] = \"caller_supplied_http_observations\",\n): DeliveryReview {\n if (!Array.isArray(observations) || observations.length < 1 ||\n observations.length > MAX_DELIVERY_HOPS) {\n throw new Error(\"Provide between one and four ordered HTTP delivery hops\");\n }\n\n let totalHeaderBytes = 0;\n let origin: string | undefined;\n const urls: URL[] = [];\n const headers: Record<string, string>[] = [];\n for (const hop of observations) {\n const safe = safeHttpResourceUrl(hop.url);\n if (!safe) throw new Error(\"HTTP hop URLs must be safe query-free HTTP(S) labels\");\n const url = new URL(safe);\n if (origin && url.origin !== origin) throw new Error(\"HTTP delivery hops must stay on one origin\");\n origin = url.origin;\n if (!Number.isInteger(hop.status_code) || hop.status_code < 100 || hop.status_code > 599 ||\n (hop.method !== undefined && hop.method !== \"GET\" && hop.method !== \"HEAD\")) {\n throw new Error(\"HTTP delivery hop status or method is invalid\");\n }\n const parsed = parseHeaders(hop.headers);\n totalHeaderBytes += Object.entries(parsed).reduce((bytes, [name, value]) =>\n bytes + name.length + new TextEncoder().encode(value).byteLength, 0);\n if (totalHeaderBytes > MAX_DELIVERY_TOTAL_HEADER_BYTES) {\n throw new Error(\"HTTP delivery response headers exceed the total input bound\");\n }\n urls.push(url);\n headers.push(parsed);\n }\n\n const output = emptyDeliveryReview(scope);\n const addFinding = (hop: number, code: DeliveryFindingCode, severity: \"warning\" | \"info\", message: string) => {\n output.total_findings += 1;\n if (output.findings.length < MAX_DELIVERY_FINDINGS) {\n output.findings.push({ hop, code, severity, message });\n } else {\n output.findings_truncated = true;\n }\n };\n output.hops_observed = observations.length;\n output.final_http_status = observations[observations.length - 1].status_code;\n output.redirect_chain_complete = true;\n const visited = new Set<string>();\n for (let index = 0; index < observations.length; index += 1) {\n const entry = observations[index];\n const url = urls[index];\n const head = headers[index];\n const hopNumber = index + 1;\n const status = statusKind(entry.status_code);\n const redirect = status === \"redirect\";\n const target = redirect ? classifyTarget(url, head.location) : { state: \"none\" as const };\n const next = urls[index + 1];\n if (next && !redirect) {\n throw new Error(\"Each non-final HTTP hop must be a redirect response\");\n }\n const nextMatches = Boolean(next && target.target === next.href);\n if (redirect && nextMatches) output.redirects_observed += 1;\n if (redirect && !nextMatches) output.redirect_chain_complete = false;\n if (visited.has(url.href) ||\n (redirect && target.target !== undefined && visited.has(target.target))) {\n addFinding(hopNumber, \"redirect_loop\", \"warning\",\n \"The redirect chain points to a previously observed response URL.\");\n }\n visited.add(url.href);\n\n const cfChallenge = head[\"cf-mitigated\"]?.trim().toLowerCase() === \"challenge\";\n // Cache-Control extension values may contain quoted commas and directive-like text.\n const control = cacheDirectives(head[\"cache-control\"] ?? \"\");\n const cacheRaw = head[\"cf-cache-status\"]?.trim().toUpperCase() ??\n (/\\bHIT\\b/i.test(head[\"x-cache\"] ?? \"\") ? \"HIT\" :\n /\\bMISS\\b/i.test(head[\"x-cache\"] ?? \"\") ? \"MISS\" : \"\");\n const maxAgeMatch = control.map((part) => /^max-age\\s*=\\s*(\\d{1,9})$/u.exec(part))\n .find((match) => match !== null);\n const maxAge = safeIntegerHeader(maxAgeMatch?.[1]);\n const age = safeIntegerHeader(head.age);\n const retryAfter = safeIntegerHeader(head[\"retry-after\"]);\n const hop: DeliveryHop = {\n hop: hopNumber, status, status_code: entry.status_code,\n method: entry.method ?? \"unspecified\", https: url.protocol === \"https:\",\n redirect_target: target.state, next_hop_observed: nextMatches,\n cache_state: cacheStates.has(cacheRaw)\n ? cacheRaw.toLowerCase() as DeliveryCacheState\n : cacheRaw ? \"other\" : \"unknown\",\n cache_no_store: control.includes(\"no-store\"),\n cache_no_cache: control.some((part) => /^no-cache(?:\\s*=|$)/u.test(part)),\n cache_private: control.some((part) => /^private(?:\\s*=|$)/u.test(part)),\n ...(maxAge === undefined ? {} : { cache_max_age_seconds: maxAge }),\n ...(age === undefined ? {} : { age_seconds: age }),\n retry_after_present: head[\"retry-after\"] !== undefined,\n ...(retryAfter === undefined ? {} : { retry_after_seconds: retryAfter }),\n cf_challenge: cfChallenge, cf_ray_present: Boolean(head[\"cf-ray\"]),\n cloudflare_server: (head.server ?? \"\").toLowerCase().includes(\"cloudflare\"),\n content_type_html: /^(text\\/html|application\\/xhtml\\+xml)\\b/i.test(head[\"content-type\"] ?? \"\"),\n };\n output.hops.push(hop);\n if (entry.status_code >= 400) output.errors_observed += 1;\n if (cfChallenge) output.challenges_observed += 1;\n\n if (cfChallenge) addFinding(hopNumber, \"cloudflare_challenge\", \"warning\",\n \"Cloudflare reported a challenge response (cf-mitigated: challenge).\");\n if (status === \"forbidden\") addFinding(hopNumber, \"http_forbidden\", \"warning\",\n \"Observed HTTP 403; this response cannot be used as an indexable page.\");\n else if (status === \"rate_limited\") addFinding(hopNumber, \"http_rate_limited\", \"warning\",\n \"Observed HTTP 429 rate limiting; verify whether the condition is transient.\");\n else if (status === \"server_error\") addFinding(hopNumber, \"http_server_error\", \"warning\",\n \"Observed an HTTP 5xx server-side failure.\");\n else if (status === \"client_error\") addFinding(hopNumber, \"http_client_error\", \"warning\",\n \"Observed a non-403, non-429 HTTP 4xx response.\");\n if (redirect) {\n const targetCodes: Partial<Record<DeliveryRedirectTarget, DeliveryFindingCode>> = {\n missing: \"redirect_missing_location\", invalid: \"redirect_invalid_location\",\n query_target: \"redirect_query_target\", cross_origin: \"redirect_cross_origin\",\n https_downgrade: \"redirect_https_downgrade\",\n };\n const code = targetCodes[target.state];\n if (code) addFinding(hopNumber, code, \"warning\",\n \"Redirect target is \" + target.state.replaceAll(\"_\", \" \") + \"; it was not verified as a safe in-origin next hop.\");\n if (next && !nextMatches) addFinding(hopNumber, \"redirect_observation_mismatch\", \"warning\",\n \"The next supplied hop does not match the declared Location destination.\");\n if (!nextMatches && !next) addFinding(hopNumber, \"redirect_incomplete\", \"info\",\n \"The redirect destination was not observed in this sample.\");\n }\n }\n if (output.redirects_observed > 2) addFinding(output.hops_observed, \"redirect_chain_long\", \"info\",\n \"More than two followed redirect hops increase crawl work; review the chain.\");\n return output;\n}\n\n/** Only allowlisted header values are captured, with no request cookies or body. */\nexport function deliveryResponseHeaders(headers: Headers): Record<string, string> {\n const result: Record<string, string> = Object.create(null);\n for (const name of DELIVERY_HEADER_NAMES) {\n const value = headers.get(name);\n if (value !== null) {\n // Excessively long response headers are not passed through to the analyzer.\n result[name] = new TextEncoder().encode(value).byteLength <= MAX_DELIVERY_HEADER_VALUE_BYTES\n ? value : \"\";\n }\n }\n return result;\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare const MAX_SECURITY_PAGES = 8;
|
|
2
|
+
export declare const MAX_SECURITY_FINDINGS = 12;
|
|
3
|
+
export declare const MAX_SECURITY_HEADER_BYTES = 2048;
|
|
4
|
+
export declare const MAX_SECURITY_HEADER_VALUES = 4;
|
|
5
|
+
export declare const MAX_SECURITY_HEADER_TOTAL_BYTES = 24000;
|
|
6
|
+
export declare const MAX_SECURITY_HTML_BYTES = 120000;
|
|
7
|
+
export declare const MAX_SECURITY_TOTAL_HTML_BYTES = 300000;
|
|
8
|
+
export declare const MAX_SECURITY_DOM_ELEMENTS = 400;
|
|
9
|
+
export declare const MAX_SECURITY_RESOURCE_DECLARATIONS = 160;
|
|
10
|
+
export declare const SECURITY_HSTS_STATES: readonly ["absent", "enabled", "disabled", "invalid", "conflicting", "http_ignored"];
|
|
11
|
+
export type HstsState = typeof SECURITY_HSTS_STATES[number];
|
|
12
|
+
export declare const SECURITY_CSP_STATES: readonly ["absent", "enforced", "report_only", "both", "meta_only"];
|
|
13
|
+
export type CspState = typeof SECURITY_CSP_STATES[number];
|
|
14
|
+
export declare const SECURITY_FINDING_CODES: readonly ["http_success_without_redirect", "http_redirect_not_https", "http_redirect_unresolved", "hsts_missing_observation", "hsts_disabled", "hsts_invalid", "hsts_conflicting", "hsts_http_ignored", "csp_report_only", "csp_unobserved", "weak_referrer_policy", "nosniff_unobserved", "frame_protection_unobserved", "mixed_blockable", "mixed_upgradable_candidate", "insecure_form_action", "insecure_base_href", "html_sampling_limited", "non_success_response"];
|
|
15
|
+
export type SecurityFindingCode = typeof SECURITY_FINDING_CODES[number];
|
|
16
|
+
export interface SecurityPageObservation {
|
|
17
|
+
url: string;
|
|
18
|
+
status_code: number;
|
|
19
|
+
location?: string;
|
|
20
|
+
strict_transport_security?: string[];
|
|
21
|
+
content_security_policy?: string[];
|
|
22
|
+
content_security_policy_report_only?: string[];
|
|
23
|
+
referrer_policy?: string;
|
|
24
|
+
x_content_type_options?: string;
|
|
25
|
+
x_frame_options?: string;
|
|
26
|
+
htmlContent?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface SecurityPageEvidence {
|
|
29
|
+
page: number;
|
|
30
|
+
scheme: "http" | "https";
|
|
31
|
+
status_code: number;
|
|
32
|
+
https_redirect_declared: boolean;
|
|
33
|
+
insecure_redirect_declared: boolean;
|
|
34
|
+
unresolved_redirect: boolean;
|
|
35
|
+
hsts_state: HstsState;
|
|
36
|
+
hsts_include_subdomains: boolean;
|
|
37
|
+
hsts_preload_declared: boolean;
|
|
38
|
+
csp_state: CspState;
|
|
39
|
+
csp_upgrade_insecure_requests: boolean;
|
|
40
|
+
referrer_policy_observed: boolean;
|
|
41
|
+
weak_referrer_policy: boolean;
|
|
42
|
+
nosniff_observed: boolean;
|
|
43
|
+
frame_protection_observed: boolean;
|
|
44
|
+
html_supplied: boolean;
|
|
45
|
+
mixed_blockable_declarations: number;
|
|
46
|
+
mixed_upgradable_declarations: number;
|
|
47
|
+
insecure_form_actions: number;
|
|
48
|
+
mixed_ip_host_declarations: number;
|
|
49
|
+
insecure_base_href: boolean;
|
|
50
|
+
declarations_truncated: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface SecurityFinding {
|
|
53
|
+
page: number;
|
|
54
|
+
code: SecurityFindingCode;
|
|
55
|
+
severity: "warning" | "info";
|
|
56
|
+
message: string;
|
|
57
|
+
}
|
|
58
|
+
export interface HttpsSecurityReview {
|
|
59
|
+
scope: "caller_supplied_https_security_evidence_only";
|
|
60
|
+
pages_sampled: number;
|
|
61
|
+
http_observations: number;
|
|
62
|
+
https_observations: number;
|
|
63
|
+
https_redirect_declarations: number;
|
|
64
|
+
http_without_secure_redirect: number;
|
|
65
|
+
https_without_hsts_observation: number;
|
|
66
|
+
hsts_disabled_or_invalid: number;
|
|
67
|
+
enforced_csp_observations: number;
|
|
68
|
+
report_only_csp_observations: number;
|
|
69
|
+
mixed_blockable_declarations: number;
|
|
70
|
+
mixed_upgradable_declarations: number;
|
|
71
|
+
insecure_form_actions: number;
|
|
72
|
+
pages_with_truncated_html: number;
|
|
73
|
+
coverage_limited: true;
|
|
74
|
+
limitations: string[];
|
|
75
|
+
pages: SecurityPageEvidence[];
|
|
76
|
+
total_findings: number;
|
|
77
|
+
findings: SecurityFinding[];
|
|
78
|
+
findings_truncated: boolean;
|
|
79
|
+
error?: string;
|
|
80
|
+
}
|
|
81
|
+
export declare function emptyHttpsSecurityReview(): HttpsSecurityReview;
|
|
82
|
+
export type SecurityHtmlLoader = (html: string) => unknown;
|
|
83
|
+
/** Audit supplied observations; no network or filesystem effects, no echoed inputs. */
|
|
84
|
+
export declare function analyzeHttpsSecurity(pages: SecurityPageObservation[], loadHtml: SecurityHtmlLoader): HttpsSecurityReview;
|