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.
Files changed (175) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +66 -4
  3. package/dist/audit-history.d.ts +9 -0
  4. package/dist/audit-history.js +27 -0
  5. package/dist/audit-history.js.map +1 -1
  6. package/dist/index.js +2535 -30
  7. package/dist/index.js.map +1 -1
  8. package/dist/mcp-bounds.d.ts +11 -0
  9. package/dist/mcp-bounds.js +68 -0
  10. package/dist/mcp-bounds.js.map +1 -0
  11. package/dist/modules/browser-ux/lighthouse-lab-probe.d.ts +21 -0
  12. package/dist/modules/browser-ux/lighthouse-lab-probe.js +190 -0
  13. package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -0
  14. package/dist/modules/browser-ux/lighthouse-lab.d.ts +61 -0
  15. package/dist/modules/browser-ux/lighthouse-lab.js +98 -0
  16. package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -0
  17. package/dist/modules/browser-ux/media-diagnostics.d.ts +41 -0
  18. package/dist/modules/browser-ux/media-diagnostics.js +183 -0
  19. package/dist/modules/browser-ux/media-diagnostics.js.map +1 -0
  20. package/dist/modules/browser-ux/raw-rendered-diff.d.ts +70 -0
  21. package/dist/modules/browser-ux/raw-rendered-diff.js +262 -0
  22. package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -0
  23. package/dist/modules/browser-ux/raw-rendered-probe.d.ts +17 -0
  24. package/dist/modules/browser-ux/raw-rendered-probe.js +163 -0
  25. package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -0
  26. package/dist/modules/browser-ux/resource-failures-probe.d.ts +11 -0
  27. package/dist/modules/browser-ux/resource-failures-probe.js +231 -0
  28. package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -0
  29. package/dist/modules/browser-ux/resource-failures.d.ts +79 -0
  30. package/dist/modules/browser-ux/resource-failures.js +178 -0
  31. package/dist/modules/browser-ux/resource-failures.js.map +1 -0
  32. package/dist/modules/browser-ux/viewport-parity-probe.d.ts +5 -0
  33. package/dist/modules/browser-ux/viewport-parity-probe.js +307 -0
  34. package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -0
  35. package/dist/modules/browser-ux/viewport-parity.d.ts +112 -0
  36. package/dist/modules/browser-ux/viewport-parity.js +224 -0
  37. package/dist/modules/browser-ux/viewport-parity.js.map +1 -0
  38. package/dist/modules/browser-ux/wcag-interactions.d.ts +95 -0
  39. package/dist/modules/browser-ux/wcag-interactions.js +360 -0
  40. package/dist/modules/browser-ux/wcag-interactions.js.map +1 -0
  41. package/dist/modules/change-regression/availability-history-store.d.ts +18 -0
  42. package/dist/modules/change-regression/availability-history-store.js +168 -0
  43. package/dist/modules/change-regression/availability-history-store.js.map +1 -0
  44. package/dist/modules/change-regression/crawler-log-correlation.d.ts +111 -0
  45. package/dist/modules/change-regression/crawler-log-correlation.js +374 -0
  46. package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -0
  47. package/dist/modules/change-regression/google-common-crawler-ip.d.ts +15 -0
  48. package/dist/modules/change-regression/google-common-crawler-ip.js +129 -0
  49. package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -0
  50. package/dist/modules/change-regression/historical-comparisons.d.ts +120 -0
  51. package/dist/modules/change-regression/historical-comparisons.js +330 -0
  52. package/dist/modules/change-regression/historical-comparisons.js.map +1 -0
  53. package/dist/modules/change-regression/production-change-comparison.d.ts +68 -0
  54. package/dist/modules/change-regression/production-change-comparison.js +214 -0
  55. package/dist/modules/change-regression/production-change-comparison.js.map +1 -0
  56. package/dist/modules/change-regression/regression-alerts.d.ts +73 -0
  57. package/dist/modules/change-regression/regression-alerts.js +183 -0
  58. package/dist/modules/change-regression/regression-alerts.js.map +1 -0
  59. package/dist/modules/change-regression/strict-observation-time.d.ts +7 -0
  60. package/dist/modules/change-regression/strict-observation-time.js +31 -0
  61. package/dist/modules/change-regression/strict-observation-time.js.map +1 -0
  62. package/dist/modules/content-schema/citation-methodology-consistency.d.ts +108 -0
  63. package/dist/modules/content-schema/citation-methodology-consistency.js +360 -0
  64. package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -0
  65. package/dist/modules/content-schema/competitor-intent-comparison.d.ts +74 -0
  66. package/dist/modules/content-schema/competitor-intent-comparison.js +185 -0
  67. package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -0
  68. package/dist/modules/content-schema/empty-boilerplate-content.d.ts +36 -0
  69. package/dist/modules/content-schema/empty-boilerplate-content.js +225 -0
  70. package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -0
  71. package/dist/modules/content-schema/extract-citation-methodology.d.ts +6 -0
  72. package/dist/modules/content-schema/extract-citation-methodology.js +201 -0
  73. package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -0
  74. package/dist/modules/content-schema/extract-competitor-intent.d.ts +2 -0
  75. package/dist/modules/content-schema/extract-competitor-intent.js +140 -0
  76. package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -0
  77. package/dist/modules/content-schema/extract-main-content.d.ts +6 -0
  78. package/dist/modules/content-schema/extract-main-content.js +33 -0
  79. package/dist/modules/content-schema/extract-main-content.js.map +1 -0
  80. package/dist/modules/content-schema/extract-metadata-consistency.d.ts +3 -0
  81. package/dist/modules/content-schema/extract-metadata-consistency.js +62 -0
  82. package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -0
  83. package/dist/modules/content-schema/extract-product-claims.d.ts +3 -0
  84. package/dist/modules/content-schema/extract-product-claims.js +58 -0
  85. package/dist/modules/content-schema/extract-product-claims.js.map +1 -0
  86. package/dist/modules/content-schema/extract-structured-data.d.ts +3 -0
  87. package/dist/modules/content-schema/extract-structured-data.js +25 -0
  88. package/dist/modules/content-schema/extract-structured-data.js.map +1 -0
  89. package/dist/modules/content-schema/metadata-consistency.d.ts +66 -0
  90. package/dist/modules/content-schema/metadata-consistency.js +282 -0
  91. package/dist/modules/content-schema/metadata-consistency.js.map +1 -0
  92. package/dist/modules/content-schema/product-claims.d.ts +73 -0
  93. package/dist/modules/content-schema/product-claims.js +195 -0
  94. package/dist/modules/content-schema/product-claims.js.map +1 -0
  95. package/dist/modules/content-schema/same-language-duplicates.d.ts +52 -0
  96. package/dist/modules/content-schema/same-language-duplicates.js +158 -0
  97. package/dist/modules/content-schema/same-language-duplicates.js.map +1 -0
  98. package/dist/modules/content-schema/structured-data-validation.d.ts +37 -0
  99. package/dist/modules/content-schema/structured-data-validation.js +385 -0
  100. package/dist/modules/content-schema/structured-data-validation.js.map +1 -0
  101. package/dist/modules/external-metrics/crux-field-probe.d.ts +10 -0
  102. package/dist/modules/external-metrics/crux-field-probe.js +113 -0
  103. package/dist/modules/external-metrics/crux-field-probe.js.map +1 -0
  104. package/dist/modules/external-metrics/crux-field.d.ts +61 -0
  105. package/dist/modules/external-metrics/crux-field.js +231 -0
  106. package/dist/modules/external-metrics/crux-field.js.map +1 -0
  107. package/dist/modules/http-crawl/availability-observations.d.ts +68 -0
  108. package/dist/modules/http-crawl/availability-observations.js +206 -0
  109. package/dist/modules/http-crawl/availability-observations.js.map +1 -0
  110. package/dist/modules/http-crawl/availability-probe.d.ts +8 -0
  111. package/dist/modules/http-crawl/availability-probe.js +46 -0
  112. package/dist/modules/http-crawl/availability-probe.js.map +1 -0
  113. package/dist/modules/http-crawl/crawler-access-probe.d.ts +6 -0
  114. package/dist/modules/http-crawl/crawler-access-probe.js +79 -0
  115. package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -0
  116. package/dist/modules/http-crawl/crawler-access.d.ts +75 -0
  117. package/dist/modules/http-crawl/crawler-access.js +404 -0
  118. package/dist/modules/http-crawl/crawler-access.js.map +1 -0
  119. package/dist/modules/http-crawl/http-delivery-probe.d.ts +3 -0
  120. package/dist/modules/http-crawl/http-delivery-probe.js +44 -0
  121. package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -0
  122. package/dist/modules/http-crawl/http-delivery.d.ts +64 -0
  123. package/dist/modules/http-crawl/http-delivery.js +269 -0
  124. package/dist/modules/http-crawl/http-delivery.js.map +1 -0
  125. package/dist/modules/http-crawl/https-security.d.ts +84 -0
  126. package/dist/modules/http-crawl/https-security.js +441 -0
  127. package/dist/modules/http-crawl/https-security.js.map +1 -0
  128. package/dist/modules/http-crawl/non-html-directives.d.ts +74 -0
  129. package/dist/modules/http-crawl/non-html-directives.js +353 -0
  130. package/dist/modules/http-crawl/non-html-directives.js.map +1 -0
  131. package/dist/modules/http-crawl/redirect-canonical-chains.d.ts +80 -0
  132. package/dist/modules/http-crawl/redirect-canonical-chains.js +459 -0
  133. package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -0
  134. package/dist/modules/http-crawl/redirect-canonical-probe.d.ts +6 -0
  135. package/dist/modules/http-crawl/redirect-canonical-probe.js +83 -0
  136. package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -0
  137. package/dist/modules/http-crawl/sitemap-inventory-probe.d.ts +8 -0
  138. package/dist/modules/http-crawl/sitemap-inventory-probe.js +155 -0
  139. package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -0
  140. package/dist/modules/http-crawl/sitemap-inventory.d.ts +107 -0
  141. package/dist/modules/http-crawl/sitemap-inventory.js +557 -0
  142. package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -0
  143. package/dist/modules/http-crawl/url-variants.d.ts +86 -0
  144. package/dist/modules/http-crawl/url-variants.js +379 -0
  145. package/dist/modules/http-crawl/url-variants.js.map +1 -0
  146. package/dist/modules/site-architecture/extract-internal-links.d.ts +3 -0
  147. package/dist/modules/site-architecture/extract-internal-links.js +88 -0
  148. package/dist/modules/site-architecture/extract-internal-links.js.map +1 -0
  149. package/dist/modules/site-architecture/extract-multilingual-page.d.ts +2 -0
  150. package/dist/modules/site-architecture/extract-multilingual-page.js +29 -0
  151. package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -0
  152. package/dist/modules/site-architecture/internal-link-graph-probe.d.ts +7 -0
  153. package/dist/modules/site-architecture/internal-link-graph-probe.js +116 -0
  154. package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -0
  155. package/dist/modules/site-architecture/internal-link-graph.d.ts +113 -0
  156. package/dist/modules/site-architecture/internal-link-graph.js +414 -0
  157. package/dist/modules/site-architecture/internal-link-graph.js.map +1 -0
  158. package/dist/modules/site-architecture/internal-link-quality.d.ts +77 -0
  159. package/dist/modules/site-architecture/internal-link-quality.js +260 -0
  160. package/dist/modules/site-architecture/internal-link-quality.js.map +1 -0
  161. package/dist/modules/site-architecture/multilingual-clusters.d.ts +82 -0
  162. package/dist/modules/site-architecture/multilingual-clusters.js +363 -0
  163. package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -0
  164. package/dist/network.d.ts +4 -0
  165. package/dist/network.js +18 -2
  166. package/dist/network.js.map +1 -1
  167. package/dist/presentation.d.ts +53 -0
  168. package/dist/presentation.js +526 -0
  169. package/dist/presentation.js.map +1 -1
  170. package/dist/screenshot.d.ts +2 -1
  171. package/dist/screenshot.js +4 -2
  172. package/dist/screenshot.js.map +1 -1
  173. package/dist/seo-auditor.js +16 -6
  174. package/dist/seo-auditor.js.map +1 -1
  175. package/package.json +7 -4
@@ -0,0 +1,441 @@
1
+ /**
2
+ * P1-13: bounded, offline HTTPS and security evidence from caller-observed
3
+ * HTTP response headers and optional static HTML. Shared by local/Worker.
4
+ * No requests, TLS handshake, certificate inspection or browser execution.
5
+ */
6
+ import { safeHttpResourceUrl } from "./non-html-directives.js";
7
+ export const MAX_SECURITY_PAGES = 8;
8
+ export const MAX_SECURITY_FINDINGS = 12;
9
+ export const MAX_SECURITY_HEADER_BYTES = 2_048;
10
+ export const MAX_SECURITY_HEADER_VALUES = 4;
11
+ export const MAX_SECURITY_HEADER_TOTAL_BYTES = 24_000;
12
+ export const MAX_SECURITY_HTML_BYTES = 120_000;
13
+ export const MAX_SECURITY_TOTAL_HTML_BYTES = 300_000;
14
+ export const MAX_SECURITY_DOM_ELEMENTS = 400;
15
+ export const MAX_SECURITY_RESOURCE_DECLARATIONS = 160;
16
+ export const SECURITY_HSTS_STATES = [
17
+ "absent", "enabled", "disabled", "invalid", "conflicting", "http_ignored",
18
+ ];
19
+ export const SECURITY_CSP_STATES = [
20
+ "absent", "enforced", "report_only", "both", "meta_only",
21
+ ];
22
+ export const SECURITY_FINDING_CODES = [
23
+ "http_success_without_redirect", "http_redirect_not_https", "http_redirect_unresolved",
24
+ "hsts_missing_observation", "hsts_disabled", "hsts_invalid", "hsts_conflicting",
25
+ "hsts_http_ignored", "csp_report_only", "csp_unobserved",
26
+ "weak_referrer_policy", "nosniff_unobserved", "frame_protection_unobserved",
27
+ "mixed_blockable", "mixed_upgradable_candidate", "insecure_form_action",
28
+ "insecure_base_href", "html_sampling_limited", "non_success_response",
29
+ ];
30
+ export function emptyHttpsSecurityReview() {
31
+ return {
32
+ scope: "caller_supplied_https_security_evidence_only",
33
+ pages_sampled: 0, http_observations: 0, https_observations: 0,
34
+ https_redirect_declarations: 0, http_without_secure_redirect: 0,
35
+ https_without_hsts_observation: 0, hsts_disabled_or_invalid: 0,
36
+ enforced_csp_observations: 0, report_only_csp_observations: 0,
37
+ mixed_blockable_declarations: 0, mixed_upgradable_declarations: 0,
38
+ insecure_form_actions: 0, pages_with_truncated_html: 0,
39
+ coverage_limited: true,
40
+ limitations: ["The supplied HTTP/HTML observations could not be reviewed within the evidence limits."],
41
+ pages: [], total_findings: 0, findings: [], findings_truncated: false,
42
+ };
43
+ }
44
+ const MAX_TEXT_BYTES = new TextEncoder();
45
+ function headerBytes(value) {
46
+ if (value === undefined)
47
+ return 0;
48
+ if (typeof value !== "string" || /[\r\n\u0000]/u.test(value) ||
49
+ MAX_TEXT_BYTES.encode(value).byteLength > MAX_SECURITY_HEADER_BYTES) {
50
+ throw new Error("Unsupported or oversized observed HTTP header value");
51
+ }
52
+ return MAX_TEXT_BYTES.encode(value).byteLength;
53
+ }
54
+ function headersBytes(values) {
55
+ if (values === undefined)
56
+ return 0;
57
+ if (!Array.isArray(values) || values.length > MAX_SECURITY_HEADER_VALUES) {
58
+ throw new Error("Too many repeated header observations");
59
+ }
60
+ return values.reduce((total, value) => total + headerBytes(value), 0);
61
+ }
62
+ function parseHsts(values) {
63
+ const policies = [];
64
+ for (const raw of values) {
65
+ const sections = raw.split(";").map((s) => s.trim()).filter(Boolean);
66
+ const ages = sections
67
+ .map((part) => /^max-age\s*=\s*(?:"(\d+)"|(\d+))$/iu.exec(part))
68
+ .filter((match) => Boolean(match));
69
+ const declaredAges = sections.filter((part) => /^max-age\b/iu.test(part));
70
+ if (ages.length !== 1 || declaredAges.length !== 1) {
71
+ policies.push(null);
72
+ continue;
73
+ }
74
+ const age = ages[0][1] || ages[0][2];
75
+ const normalized = String(BigInt(age));
76
+ const includeSubdomains = sections.some((part) => /^includeSubDomains$/iu.test(part));
77
+ const preload = sections.some((part) => /^preload$/iu.test(part));
78
+ policies.push({ maxAge: normalized, includeSubdomains, preload });
79
+ }
80
+ if (policies.some((policy) => policy === null)) {
81
+ return { state: "invalid", includeSubdomains: false, preload: false };
82
+ }
83
+ const normalized = policies;
84
+ const unique = new Set(normalized.map((policy) => policy.maxAge + "/" + policy.includeSubdomains + "/" + policy.preload));
85
+ if (unique.size > 1)
86
+ return { state: "conflicting", includeSubdomains: false, preload: false };
87
+ return {
88
+ state: normalized[0].maxAge === "0" ? "disabled" : "enabled",
89
+ includeSubdomains: normalized[0].includeSubdomains,
90
+ preload: normalized[0].preload,
91
+ };
92
+ }
93
+ function hasCspDirective(values, directive) {
94
+ return values.some((value) => value.split(";").some((part) => part.trim().split(/\s+/u)[0]?.toLowerCase() === directive));
95
+ }
96
+ function isHttpIpHost(url) {
97
+ return url.hostname.startsWith("[") || /^\d+\.\d+\.\d+\.\d+$/u.test(url.hostname);
98
+ }
99
+ function insecureUrl(value, base) {
100
+ if (!value || /[\u0000-\u001f\u007f]/u.test(value))
101
+ return undefined;
102
+ try {
103
+ const result = new URL(value.trim(), base);
104
+ return result.protocol === "http:" && result.hostname ? result : undefined;
105
+ }
106
+ catch {
107
+ return undefined;
108
+ }
109
+ }
110
+ /**
111
+ * Only static HTML declarations. Excludes JS-computed requests, dynamic CSS,
112
+ * browser upgrades and enforcement. URL contents are never returned.
113
+ */
114
+ function inspectStaticHtml(html, pageUrl, loadHtml) {
115
+ const result = {
116
+ blockable: 0, upgradable: 0, forms: 0,
117
+ ipHosts: 0, insecureBase: false, truncated: false, metaCsp: [],
118
+ };
119
+ const $ = loadHtml(html);
120
+ const meta = $("head meta[http-equiv]").toArray();
121
+ for (const element of meta.slice(0, 12)) {
122
+ if (($(element).attr("http-equiv") || "").toLowerCase() === "content-security-policy") {
123
+ const content = $(element).attr("content");
124
+ if (content)
125
+ result.metaCsp.push(content.slice(0, MAX_SECURITY_HEADER_BYTES));
126
+ }
127
+ }
128
+ const baseTag = $("head base[href]").first().attr("href");
129
+ let effectiveBase = pageUrl;
130
+ if (baseTag) {
131
+ try {
132
+ const base = new URL(baseTag.trim(), pageUrl);
133
+ if (base.protocol === "http:" || base.protocol === "https:") {
134
+ effectiveBase = base.href;
135
+ result.insecureBase = base.protocol === "http:";
136
+ }
137
+ }
138
+ catch {
139
+ // A malformed base does not establish a different origin.
140
+ }
141
+ }
142
+ const nodes = $("html *").toArray();
143
+ if (nodes.length > MAX_SECURITY_DOM_ELEMENTS)
144
+ result.truncated = true;
145
+ let declarations = 0;
146
+ function add(raw, mode) {
147
+ if (raw === undefined || declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS) {
148
+ if (raw !== undefined)
149
+ result.truncated = true;
150
+ return;
151
+ }
152
+ declarations++;
153
+ const target = insecureUrl(raw, effectiveBase);
154
+ if (!target)
155
+ return;
156
+ if (mode === "form")
157
+ result.forms++;
158
+ else if (mode === "blockable" || isHttpIpHost(target)) {
159
+ result.blockable++;
160
+ if (mode === "upgradable")
161
+ result.ipHosts++;
162
+ }
163
+ else
164
+ result.upgradable++;
165
+ }
166
+ function srcset(raw) {
167
+ if (!raw)
168
+ return;
169
+ // Only URL tokens from ordinary static srcset candidates are inspected.
170
+ // Data URLs and advanced CSS image-set parsing are not claimed as complete.
171
+ for (const candidate of raw.split(",").slice(0, MAX_SECURITY_RESOURCE_DECLARATIONS + 1)) {
172
+ const value = candidate.trim().split(/\s+/u)[0];
173
+ if (value)
174
+ add(value, "blockable");
175
+ if (declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS)
176
+ break;
177
+ }
178
+ if (raw.split(",").length > MAX_SECURITY_RESOURCE_DECLARATIONS)
179
+ result.truncated = true;
180
+ }
181
+ function css(raw) {
182
+ if (!raw)
183
+ return;
184
+ const urls = /url\(\s*(?:"([^"]*)"|'([^']*)'|([^\s)]+))\s*\)/giu;
185
+ let match;
186
+ while ((match = urls.exec(raw))) {
187
+ add(match[1] ?? match[2] ?? match[3], "blockable");
188
+ if (declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS)
189
+ break;
190
+ }
191
+ const imports = /@import\s+["'](https?:[^"'\s]+)["']/giu;
192
+ while ((match = imports.exec(raw))) {
193
+ add(match[1], "blockable");
194
+ if (declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS)
195
+ break;
196
+ }
197
+ }
198
+ for (const element of nodes.slice(0, MAX_SECURITY_DOM_ELEMENTS)) {
199
+ if (declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS) {
200
+ result.truncated = true;
201
+ break;
202
+ }
203
+ const tag = element !== null && typeof element === "object" && "tagName" in element
204
+ ? String(element.tagName).toLowerCase() : "";
205
+ const node = $(element);
206
+ if (node.closest("template").length > 0)
207
+ continue;
208
+ if (tag === "form")
209
+ add(node.attr("action"), "form");
210
+ else if (tag === "button" || tag === "input")
211
+ add(node.attr("formaction"), "form");
212
+ else if (tag === "script" || tag === "iframe" || tag === "frame" ||
213
+ tag === "embed" || tag === "track")
214
+ add(node.attr("src"), "blockable");
215
+ else if (tag === "object")
216
+ add(node.attr("data"), "blockable");
217
+ else if (tag === "link") {
218
+ const rel = (node.attr("rel") || "").toLowerCase().split(/\s+/u);
219
+ if (rel.some((item) => ["stylesheet", "preload", "modulepreload", "icon", "manifest"].includes(item))) {
220
+ add(node.attr("href"), "blockable");
221
+ }
222
+ }
223
+ else if (tag === "img") {
224
+ add(node.attr("src"), "upgradable");
225
+ srcset(node.attr("srcset"));
226
+ }
227
+ else if (tag === "audio" || tag === "video") {
228
+ add(node.attr("src"), "upgradable");
229
+ if (tag === "video")
230
+ add(node.attr("poster"), "upgradable");
231
+ }
232
+ else if (tag === "source") {
233
+ if (node.parent().is("audio,video"))
234
+ add(node.attr("src"), "upgradable");
235
+ srcset(node.attr("srcset"));
236
+ }
237
+ if (tag === "style")
238
+ css(node.html() ?? undefined);
239
+ css(node.attr("style"));
240
+ }
241
+ return result;
242
+ }
243
+ /** Audit supplied observations; no network or filesystem effects, no echoed inputs. */
244
+ export function analyzeHttpsSecurity(pages, loadHtml) {
245
+ if (!Array.isArray(pages) || pages.length < 1 || pages.length > MAX_SECURITY_PAGES) {
246
+ throw new Error("One to eight supplied HTTP security observations are required");
247
+ }
248
+ let totalHeaders = 0;
249
+ let totalHtml = 0;
250
+ let host;
251
+ const urls = new Set();
252
+ const review = emptyHttpsSecurityReview();
253
+ const all = [];
254
+ review.limitations = [
255
+ "Only caller-supplied response/header and static HTML observations are evaluated; no TLS handshake, redirect following, certificate chain, DNS, server request, browser enforcement or actual security posture is verified.",
256
+ "A missing header here does not prove it is absent in production, nor does one observed HSTS header establish browser preload/state, subdomain coverage or preload-list inclusion.",
257
+ "Insecure resource declarations are static review leads: browsers may upgrade or block them; external CSS/JS, dynamically generated requests, full srcset/CSS parsing, runtime form submission and cross-viewport behavior are not inspected.",
258
+ "At most 8 same-host pages, 400 HTML elements and 160 resource candidates per page are sampled, with 12 prioritized findings; no raw headers, paths, HTML, credentials or URL tokens are returned.",
259
+ ];
260
+ function finding(page, code, severity, message) {
261
+ all.push({ page, code, severity, message });
262
+ }
263
+ pages.forEach((record, index) => {
264
+ const page = index + 1;
265
+ const safe = safeHttpResourceUrl(record.url);
266
+ if (!safe)
267
+ throw new Error("Unsafe HTTP(S) observation URL label");
268
+ const current = new URL(safe);
269
+ if (host === undefined)
270
+ host = current.hostname;
271
+ if (current.hostname !== host || urls.has(safe)) {
272
+ throw new Error("All HTTP security observations must have the same host and unique URL labels");
273
+ }
274
+ urls.add(safe);
275
+ if (!Number.isSafeInteger(record.status_code) || record.status_code < 100 || record.status_code > 599) {
276
+ throw new Error("Unsupported HTTP response status");
277
+ }
278
+ totalHeaders += headerBytes(record.location)
279
+ + headerBytes(record.referrer_policy)
280
+ + headerBytes(record.x_content_type_options)
281
+ + headerBytes(record.x_frame_options)
282
+ + headersBytes(record.strict_transport_security)
283
+ + headersBytes(record.content_security_policy)
284
+ + headersBytes(record.content_security_policy_report_only);
285
+ if (totalHeaders > MAX_SECURITY_HEADER_TOTAL_BYTES) {
286
+ throw new Error("Aggregate HTTP header observation byte limit exceeded");
287
+ }
288
+ if (record.htmlContent !== undefined) {
289
+ if (typeof record.htmlContent !== "string" || !record.htmlContent.trim()) {
290
+ throw new Error("Supplied HTML must be nonempty when present");
291
+ }
292
+ const bytes = MAX_TEXT_BYTES.encode(record.htmlContent).byteLength;
293
+ totalHtml += bytes;
294
+ if (bytes > MAX_SECURITY_HTML_BYTES || totalHtml > MAX_SECURITY_TOTAL_HTML_BYTES) {
295
+ throw new Error("HTML observation byte limit exceeded");
296
+ }
297
+ }
298
+ const scheme = current.protocol === "http:" ? "http" : "https";
299
+ // 304 is a conditional cache response, not a navigation redirect.
300
+ // Only the common Location-redirecting statuses are classified here.
301
+ const redirects = [301, 302, 303, 307, 308].includes(record.status_code);
302
+ const location = record.location?.trim();
303
+ let redirectTarget;
304
+ if (redirects && location) {
305
+ try {
306
+ const parsed = new URL(location, safe);
307
+ redirectTarget = (!["http:", "https:"].includes(parsed.protocol) ||
308
+ parsed.username || parsed.password || !parsed.hostname)
309
+ ? "unresolved" : parsed.protocol === "https:" ? "https" : "http";
310
+ }
311
+ catch {
312
+ redirectTarget = "unresolved";
313
+ }
314
+ }
315
+ else if (redirects)
316
+ redirectTarget = "unresolved";
317
+ const hstsHeaders = record.strict_transport_security ?? [];
318
+ const hsts = hstsHeaders.length ? parseHsts(hstsHeaders) : null;
319
+ const hstsState = !hsts ? "absent" : scheme === "http" ?
320
+ "http_ignored" : hsts.state;
321
+ const enforced = (record.content_security_policy ?? []).filter((value) => value.trim());
322
+ const reports = (record.content_security_policy_report_only ?? []).filter((value) => value.trim());
323
+ const staticHtml = record.htmlContent !== undefined && scheme === "https"
324
+ ? inspectStaticHtml(record.htmlContent, safe, loadHtml) : undefined;
325
+ const metaCsp = staticHtml?.metaCsp ?? [];
326
+ const cspState = (enforced.length || metaCsp.length) && reports.length ? "both"
327
+ : enforced.length ? "enforced" : metaCsp.length ? "meta_only"
328
+ : reports.length ? "report_only" : "absent";
329
+ const cspUpgrade = hasCspDirective(enforced, "upgrade-insecure-requests") ||
330
+ hasCspDirective(metaCsp, "upgrade-insecure-requests");
331
+ const frameAncestors = hasCspDirective(enforced, "frame-ancestors");
332
+ const referrer = (record.referrer_policy ?? "").trim().toLowerCase();
333
+ const recognizedReferrers = new Set([
334
+ "no-referrer", "no-referrer-when-downgrade", "same-origin", "origin",
335
+ "strict-origin", "origin-when-cross-origin", "strict-origin-when-cross-origin", "unsafe-url",
336
+ ]);
337
+ // Comma-separated Referrer-Policy is a fallback list; the last
338
+ // recognized policy wins, not the first or any weak token.
339
+ const effectiveReferrer = referrer.split(",").map((item) => item.trim())
340
+ .filter((item) => recognizedReferrers.has(item)).at(-1);
341
+ const weakReferrer = effectiveReferrer === "unsafe-url" ||
342
+ effectiveReferrer === "no-referrer-when-downgrade";
343
+ const xframe = (record.x_frame_options ?? "").trim().toLowerCase();
344
+ const evidence = {
345
+ page, scheme, status_code: record.status_code,
346
+ https_redirect_declared: scheme === "http" && redirects && redirectTarget === "https",
347
+ insecure_redirect_declared: scheme === "http" && redirects && redirectTarget === "http",
348
+ unresolved_redirect: scheme === "http" && redirects && redirectTarget === "unresolved",
349
+ hsts_state: hstsState,
350
+ hsts_include_subdomains: Boolean(hsts && hstsState === "enabled" && hsts.includeSubdomains),
351
+ hsts_preload_declared: Boolean(hsts && hstsState === "enabled" && hsts.preload),
352
+ csp_state: cspState, csp_upgrade_insecure_requests: cspUpgrade,
353
+ referrer_policy_observed: referrer.length > 0,
354
+ weak_referrer_policy: weakReferrer,
355
+ nosniff_observed: (record.x_content_type_options ?? "").trim().toLowerCase() === "nosniff",
356
+ frame_protection_observed: frameAncestors || ["deny", "sameorigin"].includes(xframe),
357
+ html_supplied: record.htmlContent !== undefined,
358
+ mixed_blockable_declarations: staticHtml?.blockable ?? 0,
359
+ mixed_upgradable_declarations: staticHtml?.upgradable ?? 0,
360
+ insecure_form_actions: staticHtml?.forms ?? 0,
361
+ mixed_ip_host_declarations: staticHtml?.ipHosts ?? 0,
362
+ insecure_base_href: staticHtml?.insecureBase ?? false,
363
+ declarations_truncated: staticHtml?.truncated ?? false,
364
+ };
365
+ review.pages.push(evidence);
366
+ review.pages_sampled++;
367
+ if (scheme === "https")
368
+ review.https_observations++;
369
+ else
370
+ review.http_observations++;
371
+ if (evidence.https_redirect_declared)
372
+ review.https_redirect_declarations++;
373
+ if (scheme === "http" && !evidence.https_redirect_declared) {
374
+ review.http_without_secure_redirect++;
375
+ if (redirects)
376
+ finding(page, evidence.insecure_redirect_declared ? "http_redirect_not_https" : "http_redirect_unresolved", "warning", "The supplied HTTP redirect did not declare an unambiguous HTTPS destination.");
377
+ else if (record.status_code >= 200 && record.status_code < 300) {
378
+ finding(page, "http_success_without_redirect", "warning", "The supplied HTTP observation returned a success response rather than an observed HTTPS redirect.");
379
+ }
380
+ }
381
+ if (hstsState === "absent" && scheme === "https") {
382
+ review.https_without_hsts_observation++;
383
+ finding(page, "hsts_missing_observation", "info", "No HSTS header was supplied for this HTTPS response; existing browser HSTS state is unknown.");
384
+ }
385
+ else if (hstsState === "disabled" || hstsState === "invalid" || hstsState === "conflicting") {
386
+ review.hsts_disabled_or_invalid++;
387
+ const code = hstsState === "disabled" ? "hsts_disabled" :
388
+ hstsState === "invalid" ? "hsts_invalid" : "hsts_conflicting";
389
+ finding(page, code, "warning", "Supplied HTTPS HSTS directives do not establish one unambiguous enabled max-age policy.");
390
+ }
391
+ else if (hstsState === "http_ignored") {
392
+ finding(page, "hsts_http_ignored", "info", "HSTS sent over plain HTTP is ignored by browsers; HTTPS observations are needed.");
393
+ }
394
+ if (enforced.length || metaCsp.length)
395
+ review.enforced_csp_observations++;
396
+ if (reports.length && !enforced.length && !metaCsp.length)
397
+ review.report_only_csp_observations++;
398
+ if (scheme === "https" && cspState === "report_only") {
399
+ finding(page, "csp_report_only", "info", "Only CSP Report-Only headers were supplied; they do not enforce a protection policy.");
400
+ }
401
+ else if (scheme === "https" && cspState === "absent") {
402
+ finding(page, "csp_unobserved", "info", "No enforced CSP header or meta declaration was supplied; this is a review lead, not a confirmed vulnerability.");
403
+ }
404
+ if (weakReferrer)
405
+ finding(page, "weak_referrer_policy", "warning", "The observed Referrer-Policy may disclose more navigation context than intended.");
406
+ if (scheme === "https" && !evidence.nosniff_observed) {
407
+ finding(page, "nosniff_unobserved", "info", "X-Content-Type-Options: nosniff was not supplied; inspect effective response headers.");
408
+ }
409
+ if (scheme === "https" && !evidence.frame_protection_observed) {
410
+ finding(page, "frame_protection_unobserved", "info", "No enforced CSP frame-ancestors or supported X-Frame-Options was supplied; determine intended framing.");
411
+ }
412
+ if (evidence.mixed_blockable_declarations) {
413
+ finding(page, "mixed_blockable", "warning", "The supplied HTTPS HTML declares potentially blockable HTTP subresources; browser enforcement was not tested.");
414
+ }
415
+ if (evidence.mixed_upgradable_declarations) {
416
+ finding(page, "mixed_upgradable_candidate", "info", "The supplied HTTPS HTML declares HTTP image/media resources that browsers may upgrade automatically.");
417
+ }
418
+ if (evidence.insecure_form_actions) {
419
+ finding(page, "insecure_form_action", "warning", "The supplied HTTPS HTML declares form actions targeting HTTP; no form was submitted.");
420
+ }
421
+ if (evidence.insecure_base_href) {
422
+ finding(page, "insecure_base_href", "warning", "An HTTP base href in supplied HTTPS HTML may change resolution of relative resource and form URLs.");
423
+ }
424
+ if (evidence.declarations_truncated) {
425
+ review.pages_with_truncated_html++;
426
+ finding(page, "html_sampling_limited", "info", "The static resource-declaration sampling budget was reached; additional markup was not evaluated.");
427
+ }
428
+ if (record.status_code >= 400)
429
+ finding(page, "non_success_response", "info", "The supplied response was non-successful; header and markup observations may not represent the intended page.");
430
+ review.mixed_blockable_declarations += evidence.mixed_blockable_declarations;
431
+ review.mixed_upgradable_declarations += evidence.mixed_upgradable_declarations;
432
+ review.insecure_form_actions += evidence.insecure_form_actions;
433
+ });
434
+ all.sort((a, b) => (a.severity === b.severity ? 0 : a.severity === "warning" ? -1 : 1) ||
435
+ a.page - b.page || a.code.localeCompare(b.code));
436
+ review.total_findings = all.length;
437
+ review.findings = all.slice(0, MAX_SECURITY_FINDINGS);
438
+ review.findings_truncated = all.length > MAX_SECURITY_FINDINGS;
439
+ return review;
440
+ }
441
+ //# sourceMappingURL=https-security.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"https-security.js","sourceRoot":"","sources":["../../../src/modules/http-crawl/https-security.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAC/C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAC5C,MAAM,CAAC,MAAM,+BAA+B,GAAG,MAAM,CAAC;AACtD,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC;AAC/C,MAAM,CAAC,MAAM,6BAA6B,GAAG,OAAO,CAAC;AACrD,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAC7C,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AkB,GAAG,GAAG,CAAC,MAAM,GAAG,qBAAqB,CAAC;IAC/D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * P1-13: bounded, offline HTTPS and security evidence from caller-observed\n * HTTP response headers and optional static HTML. Shared by local/Worker.\n * No requests, TLS handshake, certificate inspection or browser execution.\n */\nimport { safeHttpResourceUrl } from \"./non-html-directives.js\";\n\nexport const MAX_SECURITY_PAGES = 8;\nexport const MAX_SECURITY_FINDINGS = 12;\nexport const MAX_SECURITY_HEADER_BYTES = 2_048;\nexport const MAX_SECURITY_HEADER_VALUES = 4;\nexport const MAX_SECURITY_HEADER_TOTAL_BYTES = 24_000;\nexport const MAX_SECURITY_HTML_BYTES = 120_000;\nexport const MAX_SECURITY_TOTAL_HTML_BYTES = 300_000;\nexport const MAX_SECURITY_DOM_ELEMENTS = 400;\nexport const MAX_SECURITY_RESOURCE_DECLARATIONS = 160;\n\nexport const SECURITY_HSTS_STATES = [\n \"absent\", \"enabled\", \"disabled\", \"invalid\", \"conflicting\", \"http_ignored\",\n] as const;\nexport type HstsState = typeof SECURITY_HSTS_STATES[number];\nexport const SECURITY_CSP_STATES = [\n \"absent\", \"enforced\", \"report_only\", \"both\", \"meta_only\",\n] as const;\nexport type CspState = typeof SECURITY_CSP_STATES[number];\nexport const SECURITY_FINDING_CODES = [\n \"http_success_without_redirect\", \"http_redirect_not_https\", \"http_redirect_unresolved\",\n \"hsts_missing_observation\", \"hsts_disabled\", \"hsts_invalid\", \"hsts_conflicting\",\n \"hsts_http_ignored\", \"csp_report_only\", \"csp_unobserved\",\n \"weak_referrer_policy\", \"nosniff_unobserved\", \"frame_protection_unobserved\",\n \"mixed_blockable\", \"mixed_upgradable_candidate\", \"insecure_form_action\",\n \"insecure_base_href\", \"html_sampling_limited\", \"non_success_response\",\n] as const;\nexport type SecurityFindingCode = typeof SECURITY_FINDING_CODES[number];\n\nexport interface SecurityPageObservation {\n url: string;\n status_code: number;\n location?: string;\n strict_transport_security?: string[];\n content_security_policy?: string[];\n content_security_policy_report_only?: string[];\n referrer_policy?: string;\n x_content_type_options?: string;\n x_frame_options?: string;\n htmlContent?: string;\n}\nexport interface SecurityPageEvidence {\n page: number;\n scheme: \"http\" | \"https\";\n status_code: number;\n https_redirect_declared: boolean;\n insecure_redirect_declared: boolean;\n unresolved_redirect: boolean;\n hsts_state: HstsState;\n hsts_include_subdomains: boolean;\n hsts_preload_declared: boolean;\n csp_state: CspState;\n csp_upgrade_insecure_requests: boolean;\n referrer_policy_observed: boolean;\n weak_referrer_policy: boolean;\n nosniff_observed: boolean;\n frame_protection_observed: boolean;\n html_supplied: boolean;\n mixed_blockable_declarations: number;\n mixed_upgradable_declarations: number;\n insecure_form_actions: number;\n mixed_ip_host_declarations: number;\n insecure_base_href: boolean;\n declarations_truncated: boolean;\n}\nexport interface SecurityFinding {\n page: number;\n code: SecurityFindingCode;\n severity: \"warning\" | \"info\";\n message: string;\n}\nexport interface HttpsSecurityReview {\n scope: \"caller_supplied_https_security_evidence_only\";\n pages_sampled: number;\n http_observations: number;\n https_observations: number;\n https_redirect_declarations: number;\n http_without_secure_redirect: number;\n https_without_hsts_observation: number;\n hsts_disabled_or_invalid: number;\n enforced_csp_observations: number;\n report_only_csp_observations: number;\n mixed_blockable_declarations: number;\n mixed_upgradable_declarations: number;\n insecure_form_actions: number;\n pages_with_truncated_html: number;\n coverage_limited: true;\n limitations: string[];\n pages: SecurityPageEvidence[];\n total_findings: number;\n findings: SecurityFinding[];\n findings_truncated: boolean;\n error?: string;\n}\n\nexport function emptyHttpsSecurityReview(): HttpsSecurityReview {\n return {\n scope: \"caller_supplied_https_security_evidence_only\",\n pages_sampled: 0, http_observations: 0, https_observations: 0,\n https_redirect_declarations: 0, http_without_secure_redirect: 0,\n https_without_hsts_observation: 0, hsts_disabled_or_invalid: 0,\n enforced_csp_observations: 0, report_only_csp_observations: 0,\n mixed_blockable_declarations: 0, mixed_upgradable_declarations: 0,\n insecure_form_actions: 0, pages_with_truncated_html: 0,\n coverage_limited: true,\n limitations: [\"The supplied HTTP/HTML observations could not be reviewed within the evidence limits.\"],\n pages: [], total_findings: 0, findings: [], findings_truncated: false,\n };\n}\n\nconst MAX_TEXT_BYTES = new TextEncoder();\nfunction headerBytes(value: string | undefined): number {\n if (value === undefined) return 0;\n if (typeof value !== \"string\" || /[\\r\\n\\u0000]/u.test(value) ||\n MAX_TEXT_BYTES.encode(value).byteLength > MAX_SECURITY_HEADER_BYTES) {\n throw new Error(\"Unsupported or oversized observed HTTP header value\");\n }\n return MAX_TEXT_BYTES.encode(value).byteLength;\n}\nfunction headersBytes(values: string[] | undefined): number {\n if (values === undefined) return 0;\n if (!Array.isArray(values) || values.length > MAX_SECURITY_HEADER_VALUES) {\n throw new Error(\"Too many repeated header observations\");\n }\n return values.reduce((total, value) => total + headerBytes(value), 0);\n}\n\nfunction parseHsts(values: string[]): {\n state: \"enabled\" | \"disabled\" | \"invalid\" | \"conflicting\";\n includeSubdomains: boolean; preload: boolean;\n} {\n const policies: Array<{ maxAge: string; includeSubdomains: boolean; preload: boolean } | null> = [];\n for (const raw of values) {\n const sections = raw.split(\";\").map((s) => s.trim()).filter(Boolean);\n const ages = sections\n .map((part) => /^max-age\\s*=\\s*(?:\"(\\d+)\"|(\\d+))$/iu.exec(part))\n .filter((match) => Boolean(match));\n const declaredAges = sections.filter((part) => /^max-age\\b/iu.test(part));\n if (ages.length !== 1 || declaredAges.length !== 1) {\n policies.push(null);\n continue;\n }\n const age = ages[0]![1] || ages[0]![2];\n const normalized = String(BigInt(age));\n const includeSubdomains = sections.some((part) => /^includeSubDomains$/iu.test(part));\n const preload = sections.some((part) => /^preload$/iu.test(part));\n policies.push({ maxAge: normalized, includeSubdomains, preload });\n }\n if (policies.some((policy) => policy === null)) {\n return { state: \"invalid\", includeSubdomains: false, preload: false };\n }\n const normalized = policies as Exclude<typeof policies[number], null>[];\n const unique = new Set(normalized.map((policy) =>\n policy.maxAge + \"/\" + policy.includeSubdomains + \"/\" + policy.preload));\n if (unique.size > 1) return { state: \"conflicting\", includeSubdomains: false, preload: false };\n return {\n state: normalized[0].maxAge === \"0\" ? \"disabled\" : \"enabled\",\n includeSubdomains: normalized[0].includeSubdomains,\n preload: normalized[0].preload,\n };\n}\n\nfunction hasCspDirective(values: string[], directive: string): boolean {\n return values.some((value) => value.split(\";\").some((part) =>\n part.trim().split(/\\s+/u)[0]?.toLowerCase() === directive));\n}\nfunction isHttpIpHost(url: URL): boolean {\n return url.hostname.startsWith(\"[\") || /^\\d+\\.\\d+\\.\\d+\\.\\d+$/u.test(url.hostname);\n}\nfunction insecureUrl(value: string, base: string): URL | undefined {\n if (!value || /[\\u0000-\\u001f\\u007f]/u.test(value)) return undefined;\n try {\n const result = new URL(value.trim(), base);\n return result.protocol === \"http:\" && result.hostname ? result : undefined;\n } catch {\n return undefined;\n }\n}\n\ninterface StaticDeclarations {\n blockable: number;\n upgradable: number;\n forms: number;\n ipHosts: number;\n insecureBase: boolean;\n truncated: boolean;\n metaCsp: string[];\n}\n\n// The same pure analyzer is imported from both Node and the hosted Worker.\n// Each runtime passes its OWN installed Cheerio loader, avoiding a hidden\n// dependency on a sibling package's node_modules (hosted-only CI installs).\n// Keep only the tiny structural API needed by the shared static inspector.\ninterface SecurityHtmlSelection {\n attr(name: string): string | undefined;\n toArray(): unknown[];\n first(): SecurityHtmlSelection;\n parent(): SecurityHtmlSelection;\n closest(selector: string): SecurityHtmlSelection;\n is(selector: string): boolean;\n html(): string | null;\n readonly length: number;\n}\ntype SecurityHtmlQuery = (selector: unknown) => SecurityHtmlSelection;\nexport type SecurityHtmlLoader = (html: string) => unknown;\n/**\n * Only static HTML declarations. Excludes JS-computed requests, dynamic CSS,\n * browser upgrades and enforcement. URL contents are never returned.\n */\nfunction inspectStaticHtml(html: string, pageUrl: string, loadHtml: SecurityHtmlLoader): StaticDeclarations {\n const result: StaticDeclarations = {\n blockable: 0, upgradable: 0, forms: 0,\n ipHosts: 0, insecureBase: false, truncated: false, metaCsp: [],\n };\n const $ = loadHtml(html) as SecurityHtmlQuery;\n const meta = $(\"head meta[http-equiv]\").toArray();\n for (const element of meta.slice(0, 12)) {\n if (($(element).attr(\"http-equiv\") || \"\").toLowerCase() === \"content-security-policy\") {\n const content = $(element).attr(\"content\");\n if (content) result.metaCsp.push(content.slice(0, MAX_SECURITY_HEADER_BYTES));\n }\n }\n const baseTag = $(\"head base[href]\").first().attr(\"href\");\n let effectiveBase = pageUrl;\n if (baseTag) {\n try {\n const base = new URL(baseTag.trim(), pageUrl);\n if (base.protocol === \"http:\" || base.protocol === \"https:\") {\n effectiveBase = base.href;\n result.insecureBase = base.protocol === \"http:\";\n }\n } catch {\n // A malformed base does not establish a different origin.\n }\n }\n const nodes = $(\"html *\").toArray();\n if (nodes.length > MAX_SECURITY_DOM_ELEMENTS) result.truncated = true;\n let declarations = 0;\n function add(raw: string | undefined, mode: \"blockable\" | \"upgradable\" | \"form\"): void {\n if (raw === undefined || declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS) {\n if (raw !== undefined) result.truncated = true;\n return;\n }\n declarations++;\n const target = insecureUrl(raw, effectiveBase);\n if (!target) return;\n if (mode === \"form\") result.forms++;\n else if (mode === \"blockable\" || isHttpIpHost(target)) {\n result.blockable++;\n if (mode === \"upgradable\") result.ipHosts++;\n } else result.upgradable++;\n }\n function srcset(raw: string | undefined) {\n if (!raw) return;\n // Only URL tokens from ordinary static srcset candidates are inspected.\n // Data URLs and advanced CSS image-set parsing are not claimed as complete.\n for (const candidate of raw.split(\",\").slice(0, MAX_SECURITY_RESOURCE_DECLARATIONS + 1)) {\n const value = candidate.trim().split(/\\s+/u)[0];\n if (value) add(value, \"blockable\");\n if (declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS) break;\n }\n if (raw.split(\",\").length > MAX_SECURITY_RESOURCE_DECLARATIONS) result.truncated = true;\n }\n function css(raw: string | undefined) {\n if (!raw) return;\n const urls = /url\\(\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s)]+))\\s*\\)/giu;\n let match: RegExpExecArray | null;\n while ((match = urls.exec(raw))) {\n add(match[1] ?? match[2] ?? match[3], \"blockable\");\n if (declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS) break;\n }\n const imports = /@import\\s+[\"'](https?:[^\"'\\s]+)[\"']/giu;\n while ((match = imports.exec(raw))) {\n add(match[1], \"blockable\");\n if (declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS) break;\n }\n }\n for (const element of nodes.slice(0, MAX_SECURITY_DOM_ELEMENTS)) {\n if (declarations >= MAX_SECURITY_RESOURCE_DECLARATIONS) {\n result.truncated = true; break;\n }\n const tag = element !== null && typeof element === \"object\" && \"tagName\" in element\n ? String(element.tagName).toLowerCase() : \"\";\n const node = $(element);\n if (node.closest(\"template\").length > 0) continue;\n if (tag === \"form\") add(node.attr(\"action\"), \"form\");\n else if (tag === \"button\" || tag === \"input\") add(node.attr(\"formaction\"), \"form\");\n else if (tag === \"script\" || tag === \"iframe\" || tag === \"frame\" ||\n tag === \"embed\" || tag === \"track\") add(node.attr(\"src\"), \"blockable\");\n else if (tag === \"object\") add(node.attr(\"data\"), \"blockable\");\n else if (tag === \"link\") {\n const rel = (node.attr(\"rel\") || \"\").toLowerCase().split(/\\s+/u);\n if (rel.some((item) => [\"stylesheet\", \"preload\", \"modulepreload\", \"icon\", \"manifest\"].includes(item))) {\n add(node.attr(\"href\"), \"blockable\");\n }\n } else if (tag === \"img\") {\n add(node.attr(\"src\"), \"upgradable\");\n srcset(node.attr(\"srcset\"));\n } else if (tag === \"audio\" || tag === \"video\") {\n add(node.attr(\"src\"), \"upgradable\");\n if (tag === \"video\") add(node.attr(\"poster\"), \"upgradable\");\n } else if (tag === \"source\") {\n if (node.parent().is(\"audio,video\")) add(node.attr(\"src\"), \"upgradable\");\n srcset(node.attr(\"srcset\"));\n }\n if (tag === \"style\") css(node.html() ?? undefined);\n css(node.attr(\"style\"));\n }\n return result;\n}\n\n/** Audit supplied observations; no network or filesystem effects, no echoed inputs. */\nexport function analyzeHttpsSecurity(\n pages: SecurityPageObservation[], loadHtml: SecurityHtmlLoader,\n): HttpsSecurityReview {\n if (!Array.isArray(pages) || pages.length < 1 || pages.length > MAX_SECURITY_PAGES) {\n throw new Error(\"One to eight supplied HTTP security observations are required\");\n }\n let totalHeaders = 0;\n let totalHtml = 0;\n let host: string | undefined;\n const urls = new Set<string>();\n const review = emptyHttpsSecurityReview();\n const all: SecurityFinding[] = [];\n review.limitations = [\n \"Only caller-supplied response/header and static HTML observations are evaluated; no TLS handshake, redirect following, certificate chain, DNS, server request, browser enforcement or actual security posture is verified.\",\n \"A missing header here does not prove it is absent in production, nor does one observed HSTS header establish browser preload/state, subdomain coverage or preload-list inclusion.\",\n \"Insecure resource declarations are static review leads: browsers may upgrade or block them; external CSS/JS, dynamically generated requests, full srcset/CSS parsing, runtime form submission and cross-viewport behavior are not inspected.\",\n \"At most 8 same-host pages, 400 HTML elements and 160 resource candidates per page are sampled, with 12 prioritized findings; no raw headers, paths, HTML, credentials or URL tokens are returned.\",\n ];\n function finding(page: number, code: SecurityFindingCode, severity: \"warning\" | \"info\", message: string) {\n all.push({ page, code, severity, message });\n }\n pages.forEach((record, index) => {\n const page = index + 1;\n const safe = safeHttpResourceUrl(record.url);\n if (!safe) throw new Error(\"Unsafe HTTP(S) observation URL label\");\n const current = new URL(safe);\n if (host === undefined) host = current.hostname;\n if (current.hostname !== host || urls.has(safe)) {\n throw new Error(\"All HTTP security observations must have the same host and unique URL labels\");\n }\n urls.add(safe);\n if (!Number.isSafeInteger(record.status_code) || record.status_code < 100 || record.status_code > 599) {\n throw new Error(\"Unsupported HTTP response status\");\n }\n totalHeaders += headerBytes(record.location)\n + headerBytes(record.referrer_policy)\n + headerBytes(record.x_content_type_options)\n + headerBytes(record.x_frame_options)\n + headersBytes(record.strict_transport_security)\n + headersBytes(record.content_security_policy)\n + headersBytes(record.content_security_policy_report_only);\n if (totalHeaders > MAX_SECURITY_HEADER_TOTAL_BYTES) {\n throw new Error(\"Aggregate HTTP header observation byte limit exceeded\");\n }\n if (record.htmlContent !== undefined) {\n if (typeof record.htmlContent !== \"string\" || !record.htmlContent.trim()) {\n throw new Error(\"Supplied HTML must be nonempty when present\");\n }\n const bytes = MAX_TEXT_BYTES.encode(record.htmlContent).byteLength;\n totalHtml += bytes;\n if (bytes > MAX_SECURITY_HTML_BYTES || totalHtml > MAX_SECURITY_TOTAL_HTML_BYTES) {\n throw new Error(\"HTML observation byte limit exceeded\");\n }\n }\n\n const scheme = current.protocol === \"http:\" ? \"http\" : \"https\";\n // 304 is a conditional cache response, not a navigation redirect.\n // Only the common Location-redirecting statuses are classified here.\n const redirects = [301, 302, 303, 307, 308].includes(record.status_code);\n const location = record.location?.trim();\n let redirectTarget: \"http\" | \"https\" | \"unresolved\" | undefined;\n if (redirects && location) {\n try {\n const parsed = new URL(location, safe);\n redirectTarget = (![\"http:\", \"https:\"].includes(parsed.protocol) ||\n parsed.username || parsed.password || !parsed.hostname)\n ? \"unresolved\" : parsed.protocol === \"https:\" ? \"https\" : \"http\";\n } catch { redirectTarget = \"unresolved\"; }\n } else if (redirects) redirectTarget = \"unresolved\";\n const hstsHeaders = record.strict_transport_security ?? [];\n const hsts = hstsHeaders.length ? parseHsts(hstsHeaders) : null;\n const hstsState: HstsState = !hsts ? \"absent\" : scheme === \"http\" ?\n \"http_ignored\" : hsts.state;\n const enforced = (record.content_security_policy ?? []).filter((value) => value.trim());\n const reports = (record.content_security_policy_report_only ?? []).filter((value) => value.trim());\n const staticHtml = record.htmlContent !== undefined && scheme === \"https\"\n ? inspectStaticHtml(record.htmlContent, safe, loadHtml) : undefined;\n const metaCsp = staticHtml?.metaCsp ?? [];\n const cspState: CspState = (enforced.length || metaCsp.length) && reports.length ? \"both\"\n : enforced.length ? \"enforced\" : metaCsp.length ? \"meta_only\"\n : reports.length ? \"report_only\" : \"absent\";\n const cspUpgrade = hasCspDirective(enforced, \"upgrade-insecure-requests\") ||\n hasCspDirective(metaCsp, \"upgrade-insecure-requests\");\n const frameAncestors = hasCspDirective(enforced, \"frame-ancestors\");\n const referrer = (record.referrer_policy ?? \"\").trim().toLowerCase();\n const recognizedReferrers = new Set([\n \"no-referrer\", \"no-referrer-when-downgrade\", \"same-origin\", \"origin\",\n \"strict-origin\", \"origin-when-cross-origin\", \"strict-origin-when-cross-origin\", \"unsafe-url\",\n ]);\n // Comma-separated Referrer-Policy is a fallback list; the last\n // recognized policy wins, not the first or any weak token.\n const effectiveReferrer = referrer.split(\",\").map((item) => item.trim())\n .filter((item) => recognizedReferrers.has(item)).at(-1);\n const weakReferrer = effectiveReferrer === \"unsafe-url\" ||\n effectiveReferrer === \"no-referrer-when-downgrade\";\n const xframe = (record.x_frame_options ?? \"\").trim().toLowerCase();\n const evidence: SecurityPageEvidence = {\n page, scheme, status_code: record.status_code,\n https_redirect_declared: scheme === \"http\" && redirects && redirectTarget === \"https\",\n insecure_redirect_declared: scheme === \"http\" && redirects && redirectTarget === \"http\",\n unresolved_redirect: scheme === \"http\" && redirects && redirectTarget === \"unresolved\",\n hsts_state: hstsState,\n hsts_include_subdomains: Boolean(hsts && hstsState === \"enabled\" && hsts.includeSubdomains),\n hsts_preload_declared: Boolean(hsts && hstsState === \"enabled\" && hsts.preload),\n csp_state: cspState, csp_upgrade_insecure_requests: cspUpgrade,\n referrer_policy_observed: referrer.length > 0,\n weak_referrer_policy: weakReferrer,\n nosniff_observed: (record.x_content_type_options ?? \"\").trim().toLowerCase() === \"nosniff\",\n frame_protection_observed: frameAncestors || [\"deny\", \"sameorigin\"].includes(xframe),\n html_supplied: record.htmlContent !== undefined,\n mixed_blockable_declarations: staticHtml?.blockable ?? 0,\n mixed_upgradable_declarations: staticHtml?.upgradable ?? 0,\n insecure_form_actions: staticHtml?.forms ?? 0,\n mixed_ip_host_declarations: staticHtml?.ipHosts ?? 0,\n insecure_base_href: staticHtml?.insecureBase ?? false,\n declarations_truncated: staticHtml?.truncated ?? false,\n };\n review.pages.push(evidence);\n review.pages_sampled++;\n if (scheme === \"https\") review.https_observations++;\n else review.http_observations++;\n if (evidence.https_redirect_declared) review.https_redirect_declarations++;\n if (scheme === \"http\" && !evidence.https_redirect_declared) {\n review.http_without_secure_redirect++;\n if (redirects) finding(page, evidence.insecure_redirect_declared ? \"http_redirect_not_https\" : \"http_redirect_unresolved\",\n \"warning\", \"The supplied HTTP redirect did not declare an unambiguous HTTPS destination.\");\n else if (record.status_code >= 200 && record.status_code < 300) {\n finding(page, \"http_success_without_redirect\", \"warning\",\n \"The supplied HTTP observation returned a success response rather than an observed HTTPS redirect.\");\n }\n }\n if (hstsState === \"absent\" && scheme === \"https\") {\n review.https_without_hsts_observation++;\n finding(page, \"hsts_missing_observation\", \"info\",\n \"No HSTS header was supplied for this HTTPS response; existing browser HSTS state is unknown.\");\n } else if (hstsState === \"disabled\" || hstsState === \"invalid\" || hstsState === \"conflicting\") {\n review.hsts_disabled_or_invalid++;\n const code = hstsState === \"disabled\" ? \"hsts_disabled\" :\n hstsState === \"invalid\" ? \"hsts_invalid\" : \"hsts_conflicting\";\n finding(page, code, \"warning\",\n \"Supplied HTTPS HSTS directives do not establish one unambiguous enabled max-age policy.\");\n } else if (hstsState === \"http_ignored\") {\n finding(page, \"hsts_http_ignored\", \"info\",\n \"HSTS sent over plain HTTP is ignored by browsers; HTTPS observations are needed.\");\n }\n if (enforced.length || metaCsp.length) review.enforced_csp_observations++;\n if (reports.length && !enforced.length && !metaCsp.length) review.report_only_csp_observations++;\n if (scheme === \"https\" && cspState === \"report_only\") {\n finding(page, \"csp_report_only\", \"info\",\n \"Only CSP Report-Only headers were supplied; they do not enforce a protection policy.\");\n } else if (scheme === \"https\" && cspState === \"absent\") {\n finding(page, \"csp_unobserved\", \"info\",\n \"No enforced CSP header or meta declaration was supplied; this is a review lead, not a confirmed vulnerability.\");\n }\n if (weakReferrer) finding(page, \"weak_referrer_policy\", \"warning\",\n \"The observed Referrer-Policy may disclose more navigation context than intended.\");\n if (scheme === \"https\" && !evidence.nosniff_observed) {\n finding(page, \"nosniff_unobserved\", \"info\",\n \"X-Content-Type-Options: nosniff was not supplied; inspect effective response headers.\");\n }\n if (scheme === \"https\" && !evidence.frame_protection_observed) {\n finding(page, \"frame_protection_unobserved\", \"info\",\n \"No enforced CSP frame-ancestors or supported X-Frame-Options was supplied; determine intended framing.\");\n }\n if (evidence.mixed_blockable_declarations) {\n finding(page, \"mixed_blockable\", \"warning\",\n \"The supplied HTTPS HTML declares potentially blockable HTTP subresources; browser enforcement was not tested.\");\n }\n if (evidence.mixed_upgradable_declarations) {\n finding(page, \"mixed_upgradable_candidate\", \"info\",\n \"The supplied HTTPS HTML declares HTTP image/media resources that browsers may upgrade automatically.\");\n }\n if (evidence.insecure_form_actions) {\n finding(page, \"insecure_form_action\", \"warning\",\n \"The supplied HTTPS HTML declares form actions targeting HTTP; no form was submitted.\");\n }\n if (evidence.insecure_base_href) {\n finding(page, \"insecure_base_href\", \"warning\",\n \"An HTTP base href in supplied HTTPS HTML may change resolution of relative resource and form URLs.\");\n }\n if (evidence.declarations_truncated) {\n review.pages_with_truncated_html++;\n finding(page, \"html_sampling_limited\", \"info\",\n \"The static resource-declaration sampling budget was reached; additional markup was not evaluated.\");\n }\n if (record.status_code >= 400) finding(page, \"non_success_response\", \"info\",\n \"The supplied response was non-successful; header and markup observations may not represent the intended page.\");\n review.mixed_blockable_declarations += evidence.mixed_blockable_declarations;\n review.mixed_upgradable_declarations += evidence.mixed_upgradable_declarations;\n review.insecure_form_actions += evidence.insecure_form_actions;\n });\n all.sort((a, b) => (a.severity === b.severity ? 0 : a.severity === \"warning\" ? -1 : 1) ||\n a.page - b.page || a.code.localeCompare(b.code));\n review.total_findings = all.length;\n review.findings = all.slice(0, MAX_SECURITY_FINDINGS);\n review.findings_truncated = all.length > MAX_SECURITY_FINDINGS;\n return review;\n}\n"]}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * P1-11: bounded, offline review of caller-observed HTTP response metadata.
3
+ * Pure module: shared by local stdio and hosted Worker, no fetch or Node APIs.
4
+ */
5
+ export declare const MAX_HTTP_RESOURCES = 8;
6
+ export declare const MAX_HTTP_FINDINGS = 12;
7
+ export declare const MAX_HTTP_HEADER_VALUES = 8;
8
+ export declare const MAX_HTTP_HEADER_BYTES = 2048;
9
+ export declare const MAX_HTTP_TOTAL_BYTES = 30000;
10
+ export declare const HTTP_MIME_CATEGORIES: readonly ["html", "pdf", "image", "video", "audio", "text", "data", "binary", "unknown"];
11
+ export type HttpMimeCategory = typeof HTTP_MIME_CATEGORIES[number];
12
+ export declare const HTTP_CANONICAL_STATES: readonly ["absent", "one", "repeated", "conflicting", "unresolved"];
13
+ export type HttpCanonicalState = typeof HTTP_CANONICAL_STATES[number];
14
+ export declare const HTTP_FINDING_CODES: readonly ["explicit_noindex", "googlebot_noindex", "conflicting_robots", "explicit_noimageindex", "unresolved_canonical", "conflicting_canonical", "attachment_disposition", "non_success_response", "partial_http_response", "unknown_content_type", "html_in_non_html_review", "link_header_limited", "pdf_type_mismatch"];
15
+ export type HttpFindingCode = typeof HTTP_FINDING_CODES[number];
16
+ export interface HttpResourceObservation {
17
+ url: string;
18
+ status_code: number;
19
+ method?: "HEAD" | "GET";
20
+ content_type?: string;
21
+ content_disposition?: string;
22
+ x_robots_tag?: string[];
23
+ link?: string[];
24
+ }
25
+ export interface HttpDirectiveFinding {
26
+ code: HttpFindingCode;
27
+ severity: "warning" | "info";
28
+ resource: number;
29
+ message: string;
30
+ }
31
+ export interface HttpResourceEvidence {
32
+ resource: number;
33
+ status_code: number;
34
+ method: "HEAD" | "GET" | "unspecified";
35
+ mime_category: HttpMimeCategory;
36
+ non_html: boolean;
37
+ x_robots_observed: boolean;
38
+ explicit_noindex: boolean;
39
+ googlebot_noindex: boolean;
40
+ googlebot_noimageindex: boolean;
41
+ conflicting_robots: boolean;
42
+ canonical_declarations: number;
43
+ canonical_valid_targets: number;
44
+ canonical_state: HttpCanonicalState;
45
+ attachment_declared: boolean;
46
+ header_coverage_limited: boolean;
47
+ }
48
+ export interface HttpDirectiveReview {
49
+ scope: "caller_supplied_http_headers_only";
50
+ resources_sampled: number;
51
+ non_html_resources: number;
52
+ html_resources: number;
53
+ unknown_mime_resources: number;
54
+ non_success_resources: number;
55
+ explicit_noindex_resources: number;
56
+ googlebot_noindex_resources: number;
57
+ googlebot_noimageindex_resources: number;
58
+ conflicting_robots_resources: number;
59
+ canonical_header_resources: number;
60
+ conflicting_canonical_resources: number;
61
+ unresolved_canonical_references: number;
62
+ attachment_resources: number;
63
+ coverage_limited: true;
64
+ limitations: string[];
65
+ resources: HttpResourceEvidence[];
66
+ total_findings: number;
67
+ findings: HttpDirectiveFinding[];
68
+ findings_truncated: boolean;
69
+ error?: string;
70
+ }
71
+ export declare function emptyHttpDirectiveReview(): HttpDirectiveReview;
72
+ /** Safe *offline label*, not permission to issue a network request. */
73
+ export declare function safeHttpResourceUrl(value: string): string | null;
74
+ export declare function analyzeHttpDirectives(items: HttpResourceObservation[]): HttpDirectiveReview;