milieu-cli 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +177 -76
- package/dist/bridges/context/agents-json.d.ts +0 -1
- package/dist/bridges/context/agents-json.js +21 -12
- package/dist/bridges/context/auth-clarity.d.ts +0 -1
- package/dist/bridges/context/auth-clarity.js +11 -9
- package/dist/bridges/context/auth-legibility.d.ts +2 -2
- package/dist/bridges/context/auth-legibility.js +67 -60
- package/dist/bridges/context/index.d.ts +1 -2
- package/dist/bridges/context/index.js +19 -40
- package/dist/bridges/context/oauth-metadata.d.ts +14 -0
- package/dist/bridges/context/oauth-metadata.js +127 -0
- package/dist/bridges/context/probe.d.ts +33 -0
- package/dist/bridges/context/probe.js +157 -0
- package/dist/bridges/context/rate-limits.d.ts +5 -2
- package/dist/bridges/context/rate-limits.js +27 -51
- package/dist/bridges/context/tos-contact.d.ts +13 -4
- package/dist/bridges/context/tos-contact.js +108 -46
- package/dist/bridges/context/versioning.d.ts +1 -2
- package/dist/bridges/context/versioning.js +42 -7
- package/dist/bridges/index.d.ts +0 -1
- package/dist/bridges/index.js +0 -1
- package/dist/bridges/reachability/crawler-policy.d.ts +30 -10
- package/dist/bridges/reachability/crawler-policy.js +41 -56
- package/dist/bridges/reachability/http-status.d.ts +3 -2
- package/dist/bridges/reachability/http-status.js +18 -3
- package/dist/bridges/reachability/https-check.d.ts +2 -2
- package/dist/bridges/reachability/https-check.js +6 -3
- package/dist/bridges/reachability/index.d.ts +1 -2
- package/dist/bridges/reachability/index.js +34 -43
- package/dist/bridges/reachability/meta-robots.d.ts +0 -13
- package/dist/bridges/reachability/meta-robots.js +89 -101
- package/dist/bridges/reachability/robots-parser.d.ts +7 -7
- package/dist/bridges/reachability/robots-parser.js +65 -15
- package/dist/bridges/reachability/robots-txt.d.ts +4 -2
- package/dist/bridges/reachability/robots-txt.js +33 -60
- package/dist/bridges/schema/descriptions.d.ts +2 -2
- package/dist/bridges/schema/descriptions.js +79 -44
- package/dist/bridges/schema/error-schemas.d.ts +2 -2
- package/dist/bridges/schema/error-schemas.js +31 -18
- package/dist/bridges/schema/index.d.ts +2 -2
- package/dist/bridges/schema/index.js +48 -30
- package/dist/bridges/schema/oas-types.d.ts +65 -26
- package/dist/bridges/schema/oas-types.js +37 -7
- package/dist/bridges/schema/operation-ids.d.ts +2 -2
- package/dist/bridges/schema/operation-ids.js +2 -3
- package/dist/bridges/schema/required-fields.d.ts +2 -2
- package/dist/bridges/schema/required-fields.js +12 -10
- package/dist/bridges/schema/schema-sources.d.ts +19 -0
- package/dist/bridges/schema/schema-sources.js +182 -0
- package/dist/bridges/schema/schema-types.d.ts +2 -2
- package/dist/bridges/schema/schema-types.js +20 -21
- package/dist/bridges/separation/api-presence.d.ts +3 -15
- package/dist/bridges/separation/api-presence.js +34 -85
- package/dist/bridges/separation/developer-docs.d.ts +6 -18
- package/dist/bridges/separation/developer-docs.js +100 -99
- package/dist/bridges/separation/docs-discovery.d.ts +28 -0
- package/dist/bridges/separation/docs-discovery.js +95 -0
- package/dist/bridges/separation/evidence-summary.d.ts +2 -0
- package/dist/bridges/separation/evidence-summary.js +67 -0
- package/dist/bridges/separation/index.d.ts +2 -19
- package/dist/bridges/separation/index.js +35 -39
- package/dist/bridges/separation/published-routes.d.ts +69 -0
- package/dist/bridges/separation/published-routes.js +271 -0
- package/dist/bridges/separation/sdk-references.d.ts +8 -3
- package/dist/bridges/separation/sdk-references.js +86 -61
- package/dist/bridges/separation/webhook-support.d.ts +3 -23
- package/dist/bridges/separation/webhook-support.js +61 -162
- package/dist/bridges/standards/a2a-agent-card.d.ts +0 -1
- package/dist/bridges/standards/a2a-agent-card.js +24 -9
- package/dist/bridges/standards/graphql.d.ts +3 -4
- package/dist/bridges/standards/graphql.js +70 -66
- package/dist/bridges/standards/index.d.ts +1 -2
- package/dist/bridges/standards/index.js +57 -47
- package/dist/bridges/standards/json-ld.d.ts +25 -11
- package/dist/bridges/standards/json-ld.js +114 -56
- package/dist/bridges/standards/llms-txt.d.ts +4 -2
- package/dist/bridges/standards/llms-txt.js +46 -32
- package/dist/bridges/standards/markdown-negotiation.d.ts +4 -1
- package/dist/bridges/standards/markdown-negotiation.js +16 -11
- package/dist/bridges/standards/mcp.d.ts +3 -12
- package/dist/bridges/standards/mcp.js +89 -132
- package/dist/bridges/standards/openapi.d.ts +7 -15
- package/dist/bridges/standards/openapi.js +657 -207
- package/dist/bridges/standards/probe-evidence.d.ts +30 -0
- package/dist/bridges/standards/probe-evidence.js +90 -0
- package/dist/bridges/standards/schema-org.d.ts +15 -9
- package/dist/bridges/standards/schema-org.js +38 -64
- package/dist/bridges/standards/sitemap.d.ts +2 -3
- package/dist/bridges/standards/sitemap.js +161 -169
- package/dist/bridges/standards/well-known.d.ts +3 -7
- package/dist/bridges/standards/well-known.js +28 -12
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +107 -22
- package/dist/cli/journey-commands.d.ts +3 -0
- package/dist/cli/journey-commands.js +35 -0
- package/dist/cli/read-report.d.ts +2 -0
- package/dist/cli/read-report.js +11 -0
- package/dist/core/bridge-output.d.ts +11 -0
- package/dist/core/bridge-output.js +86 -0
- package/dist/core/bridge-session.d.ts +28 -0
- package/dist/core/bridge-session.js +58 -0
- package/dist/core/bridge-worker.d.ts +1 -0
- package/dist/core/bridge-worker.js +66 -0
- package/dist/core/diff.d.ts +79 -0
- package/dist/core/diff.js +499 -0
- package/dist/core/explanations.d.ts +1 -3
- package/dist/core/explanations.js +36 -59
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +2 -3
- package/dist/core/scan-options.d.ts +0 -1
- package/dist/core/scan-options.js +14 -6
- package/dist/core/scan.d.ts +0 -1
- package/dist/core/scan.js +91 -41
- package/dist/core/scoring.d.ts +6 -0
- package/dist/core/scoring.js +27 -0
- package/dist/core/types.d.ts +97 -61
- package/dist/core/types.js +9 -3
- package/dist/core/validate-report.d.ts +5 -0
- package/dist/core/validate-report.js +95 -0
- package/dist/core/version.d.ts +0 -1
- package/dist/core/version.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/journey/body-worker.d.ts +27 -0
- package/dist/journey/body-worker.js +140 -0
- package/dist/journey/case.d.ts +74 -0
- package/dist/journey/case.js +187 -0
- package/dist/journey/cli.d.ts +14 -0
- package/dist/journey/cli.js +226 -0
- package/dist/journey/compare.d.ts +43 -0
- package/dist/journey/compare.js +83 -0
- package/dist/journey/contracts.d.ts +143 -0
- package/dist/journey/contracts.js +37 -0
- package/dist/journey/decision.d.ts +72 -0
- package/dist/journey/decision.js +121 -0
- package/dist/journey/demo.d.ts +36 -0
- package/dist/journey/demo.js +137 -0
- package/dist/journey/document.d.ts +8 -0
- package/dist/journey/document.js +113 -0
- package/dist/journey/excerpt.d.ts +6 -0
- package/dist/journey/excerpt.js +54 -0
- package/dist/journey/name-guidance.d.ts +2 -0
- package/dist/journey/name-guidance.js +41 -0
- package/dist/journey/providers.d.ts +34 -0
- package/dist/journey/providers.js +197 -0
- package/dist/journey/report-validation.d.ts +3 -0
- package/dist/journey/report-validation.js +457 -0
- package/dist/journey/runner.d.ts +12 -0
- package/dist/journey/runner.js +321 -0
- package/dist/journey/scope.d.ts +8 -0
- package/dist/journey/scope.js +50 -0
- package/dist/journey/transport.d.ts +3 -0
- package/dist/journey/transport.js +45 -0
- package/dist/journey/verify.d.ts +21 -0
- package/dist/journey/verify.js +213 -0
- package/dist/render/colors.d.ts +6 -7
- package/dist/render/colors.js +16 -25
- package/dist/render/discovery-guidance.d.ts +3 -0
- package/dist/render/discovery-guidance.js +66 -0
- package/dist/render/format-bridge.d.ts +1 -2
- package/dist/render/format-bridge.js +22 -17
- package/dist/render/format-diff.d.ts +2 -0
- package/dist/render/format-diff.js +169 -0
- package/dist/render/format-scan.d.ts +0 -1
- package/dist/render/format-scan.js +6 -4
- package/dist/render/format-verbose.d.ts +0 -1
- package/dist/render/format-verbose.js +7 -4
- package/dist/render/index.d.ts +0 -1
- package/dist/render/index.js +1 -2
- package/dist/render/oauth-observations.d.ts +4 -0
- package/dist/render/oauth-observations.js +27 -0
- package/dist/render/progress-bar.d.ts +1 -2
- package/dist/render/progress-bar.js +8 -6
- package/dist/render/robots-inventory.d.ts +3 -0
- package/dist/render/robots-inventory.js +38 -0
- package/dist/render/symbols.d.ts +4 -10
- package/dist/render/symbols.js +15 -17
- package/dist/render/terminal-text.d.ts +1 -3
- package/dist/render/terminal-text.js +1 -5
- package/dist/utils/analysis-worker-entry.d.ts +3 -0
- package/dist/utils/analysis-worker-entry.js +12 -0
- package/dist/utils/analysis-worker.d.ts +12 -0
- package/dist/utils/analysis-worker.js +54 -0
- package/dist/utils/html.d.ts +39 -0
- package/dist/utils/html.js +261 -0
- package/dist/utils/http-client.d.ts +24 -17
- package/dist/utils/http-client.js +166 -200
- package/dist/utils/http-types.d.ts +43 -0
- package/dist/utils/http-types.js +11 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/package-registry.d.ts +11 -0
- package/dist/utils/package-registry.js +69 -0
- package/dist/utils/read-json-file.d.ts +3 -0
- package/dist/utils/read-json-file.js +41 -0
- package/dist/utils/record.d.ts +1 -0
- package/dist/utils/record.js +3 -0
- package/dist/utils/response-body.d.ts +7 -0
- package/dist/utils/response-body.js +71 -0
- package/dist/utils/ssrf.d.ts +11 -15
- package/dist/utils/ssrf.js +80 -44
- package/dist/utils/terminal-text.d.ts +2 -0
- package/dist/utils/terminal-text.js +4 -0
- package/dist/utils/url.d.ts +29 -1
- package/dist/utils/url.js +147 -17
- package/docs/examples/onboarding/account-claim.json +25 -0
- package/docs/examples/onboarding/pages/account-claim.html +3 -0
- package/docs/examples/onboarding/pages/production-activation.html +3 -0
- package/docs/examples/onboarding/pages/test-credential.html +3 -0
- package/docs/examples/onboarding/production-activation.json +25 -0
- package/docs/examples/onboarding/test-credential.json +25 -0
- package/docs/journey-qualification.md +46 -0
- package/docs/journeys.md +83 -0
- package/package.json +28 -8
- package/dist/bridges/context/agents-json.d.ts.map +0 -1
- package/dist/bridges/context/agents-json.js.map +0 -1
- package/dist/bridges/context/auth-clarity.d.ts.map +0 -1
- package/dist/bridges/context/auth-clarity.js.map +0 -1
- package/dist/bridges/context/auth-legibility.d.ts.map +0 -1
- package/dist/bridges/context/auth-legibility.js.map +0 -1
- package/dist/bridges/context/index.d.ts.map +0 -1
- package/dist/bridges/context/index.js.map +0 -1
- package/dist/bridges/context/rate-limits.d.ts.map +0 -1
- package/dist/bridges/context/rate-limits.js.map +0 -1
- package/dist/bridges/context/tos-contact.d.ts.map +0 -1
- package/dist/bridges/context/tos-contact.js.map +0 -1
- package/dist/bridges/context/versioning.d.ts.map +0 -1
- package/dist/bridges/context/versioning.js.map +0 -1
- package/dist/bridges/index.d.ts.map +0 -1
- package/dist/bridges/index.js.map +0 -1
- package/dist/bridges/reachability/crawler-policy.d.ts.map +0 -1
- package/dist/bridges/reachability/crawler-policy.js.map +0 -1
- package/dist/bridges/reachability/http-status.d.ts.map +0 -1
- package/dist/bridges/reachability/http-status.js.map +0 -1
- package/dist/bridges/reachability/https-check.d.ts.map +0 -1
- package/dist/bridges/reachability/https-check.js.map +0 -1
- package/dist/bridges/reachability/index.d.ts.map +0 -1
- package/dist/bridges/reachability/index.js.map +0 -1
- package/dist/bridges/reachability/meta-robots.d.ts.map +0 -1
- package/dist/bridges/reachability/meta-robots.js.map +0 -1
- package/dist/bridges/reachability/robots-parser.d.ts.map +0 -1
- package/dist/bridges/reachability/robots-parser.js.map +0 -1
- package/dist/bridges/reachability/robots-txt.d.ts.map +0 -1
- package/dist/bridges/reachability/robots-txt.js.map +0 -1
- package/dist/bridges/schema/descriptions.d.ts.map +0 -1
- package/dist/bridges/schema/descriptions.js.map +0 -1
- package/dist/bridges/schema/error-schemas.d.ts.map +0 -1
- package/dist/bridges/schema/error-schemas.js.map +0 -1
- package/dist/bridges/schema/index.d.ts.map +0 -1
- package/dist/bridges/schema/index.js.map +0 -1
- package/dist/bridges/schema/oas-types.d.ts.map +0 -1
- package/dist/bridges/schema/oas-types.js.map +0 -1
- package/dist/bridges/schema/operation-ids.d.ts.map +0 -1
- package/dist/bridges/schema/operation-ids.js.map +0 -1
- package/dist/bridges/schema/required-fields.d.ts.map +0 -1
- package/dist/bridges/schema/required-fields.js.map +0 -1
- package/dist/bridges/schema/schema-types.d.ts.map +0 -1
- package/dist/bridges/schema/schema-types.js.map +0 -1
- package/dist/bridges/separation/api-presence.d.ts.map +0 -1
- package/dist/bridges/separation/api-presence.js.map +0 -1
- package/dist/bridges/separation/developer-docs.d.ts.map +0 -1
- package/dist/bridges/separation/developer-docs.js.map +0 -1
- package/dist/bridges/separation/index.d.ts.map +0 -1
- package/dist/bridges/separation/index.js.map +0 -1
- package/dist/bridges/separation/sdk-references.d.ts.map +0 -1
- package/dist/bridges/separation/sdk-references.js.map +0 -1
- package/dist/bridges/separation/webhook-support.d.ts.map +0 -1
- package/dist/bridges/separation/webhook-support.js.map +0 -1
- package/dist/bridges/standards/a2a-agent-card.d.ts.map +0 -1
- package/dist/bridges/standards/a2a-agent-card.js.map +0 -1
- package/dist/bridges/standards/graphql.d.ts.map +0 -1
- package/dist/bridges/standards/graphql.js.map +0 -1
- package/dist/bridges/standards/index.d.ts.map +0 -1
- package/dist/bridges/standards/index.js.map +0 -1
- package/dist/bridges/standards/json-ld.d.ts.map +0 -1
- package/dist/bridges/standards/json-ld.js.map +0 -1
- package/dist/bridges/standards/llms-txt.d.ts.map +0 -1
- package/dist/bridges/standards/llms-txt.js.map +0 -1
- package/dist/bridges/standards/markdown-negotiation.d.ts.map +0 -1
- package/dist/bridges/standards/markdown-negotiation.js.map +0 -1
- package/dist/bridges/standards/mcp.d.ts.map +0 -1
- package/dist/bridges/standards/mcp.js.map +0 -1
- package/dist/bridges/standards/openapi.d.ts.map +0 -1
- package/dist/bridges/standards/openapi.js.map +0 -1
- package/dist/bridges/standards/schema-org.d.ts.map +0 -1
- package/dist/bridges/standards/schema-org.js.map +0 -1
- package/dist/bridges/standards/sitemap.d.ts.map +0 -1
- package/dist/bridges/standards/sitemap.js.map +0 -1
- package/dist/bridges/standards/well-known.d.ts.map +0 -1
- package/dist/bridges/standards/well-known.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/core/explanations.d.ts.map +0 -1
- package/dist/core/explanations.js.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/scan-options.d.ts.map +0 -1
- package/dist/core/scan-options.js.map +0 -1
- package/dist/core/scan.d.ts.map +0 -1
- package/dist/core/scan.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/core/version.d.ts.map +0 -1
- package/dist/core/version.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/render/colors.d.ts.map +0 -1
- package/dist/render/colors.js.map +0 -1
- package/dist/render/format-bridge.d.ts.map +0 -1
- package/dist/render/format-bridge.js.map +0 -1
- package/dist/render/format-scan.d.ts.map +0 -1
- package/dist/render/format-scan.js.map +0 -1
- package/dist/render/format-verbose.d.ts.map +0 -1
- package/dist/render/format-verbose.js.map +0 -1
- package/dist/render/index.d.ts.map +0 -1
- package/dist/render/index.js.map +0 -1
- package/dist/render/progress-bar.d.ts.map +0 -1
- package/dist/render/progress-bar.js.map +0 -1
- package/dist/render/symbols.d.ts.map +0 -1
- package/dist/render/symbols.js.map +0 -1
- package/dist/render/terminal-text.d.ts.map +0 -1
- package/dist/render/terminal-text.js.map +0 -1
- package/dist/utils/http-client.d.ts.map +0 -1
- package/dist/utils/http-client.js.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/ssrf.d.ts.map +0 -1
- package/dist/utils/ssrf.js.map +0 -1
- package/dist/utils/url.d.ts.map +0 -1
- package/dist/utils/url.js.map +0 -1
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
const TRANSPORT_FAILURES = new Set(["timeout", "dns", "connection_refused", "network_error", "ssl_error", "ssrf_blocked"]);
|
|
2
|
+
/** Only the requested URL can establish its own unreachability. A redirect proves that it answered. */
|
|
3
|
+
export function transportFailureAt(response, requestedUrl) {
|
|
4
|
+
if (response.ok || response.response || response.error.statusCode !== undefined ||
|
|
5
|
+
!TRANSPORT_FAILURES.has(response.error.kind))
|
|
6
|
+
return undefined;
|
|
7
|
+
return URL.parse(response.error.url)?.href === new URL(requestedUrl).href ? response.error.kind : undefined;
|
|
8
|
+
}
|
|
1
9
|
/**
|
|
2
10
|
* Check HTTP status from a pre-fetched page response.
|
|
3
11
|
* Does NOT make any HTTP calls -- takes the already-fetched response.
|
|
@@ -8,8 +16,11 @@ export function checkHttpStatus(pageResponse) {
|
|
|
8
16
|
if (pageResponse.ok) {
|
|
9
17
|
const { status, redirects, url } = pageResponse;
|
|
10
18
|
const data = redirects.length > 0
|
|
11
|
-
? { redirects, finalUrl: url }
|
|
12
|
-
:
|
|
19
|
+
? { statusCode: status, redirects, finalUrl: url }
|
|
20
|
+
: { statusCode: status };
|
|
21
|
+
if (pageResponse.bodyIncomplete || status === 206 || pageResponse.headers["content-range"] !== undefined) {
|
|
22
|
+
return { id, label, status: "partial", detail: `HTTP ${status}, partial response body`, data };
|
|
23
|
+
}
|
|
13
24
|
if (status >= 200 && status < 300) {
|
|
14
25
|
return {
|
|
15
26
|
id,
|
|
@@ -41,12 +52,15 @@ export function checkHttpStatus(pageResponse) {
|
|
|
41
52
|
// Failure cases
|
|
42
53
|
const { kind, message, statusCode } = pageResponse.error;
|
|
43
54
|
switch (kind) {
|
|
55
|
+
case "body_too_large":
|
|
56
|
+
return { id, label, status: "partial", detail: "Response too large to inspect", data: { statusCode, errorKind: kind } };
|
|
44
57
|
case "bot_protected":
|
|
45
58
|
return {
|
|
46
59
|
id,
|
|
47
60
|
label,
|
|
48
61
|
status: "fail",
|
|
49
62
|
detail: "Bot protection detected",
|
|
63
|
+
data: { statusCode, errorKind: kind },
|
|
50
64
|
};
|
|
51
65
|
case "timeout":
|
|
52
66
|
return {
|
|
@@ -54,6 +68,7 @@ export function checkHttpStatus(pageResponse) {
|
|
|
54
68
|
label,
|
|
55
69
|
status: "fail",
|
|
56
70
|
detail: "Request timed out",
|
|
71
|
+
data: { errorKind: kind },
|
|
57
72
|
};
|
|
58
73
|
case "http_error":
|
|
59
74
|
return {
|
|
@@ -61,6 +76,7 @@ export function checkHttpStatus(pageResponse) {
|
|
|
61
76
|
label,
|
|
62
77
|
status: "fail",
|
|
63
78
|
detail: statusCode ? `HTTP ${statusCode}` : message,
|
|
79
|
+
data: { statusCode, errorKind: kind },
|
|
64
80
|
};
|
|
65
81
|
case "request_budget_exhausted":
|
|
66
82
|
return {
|
|
@@ -78,4 +94,3 @@ export function checkHttpStatus(pageResponse) {
|
|
|
78
94
|
};
|
|
79
95
|
}
|
|
80
96
|
}
|
|
81
|
-
//# sourceMappingURL=http-status.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { Check } from "../../core/types.js";
|
|
1
|
+
import type { Check, HttpErrorKind } from "../../core/types.js";
|
|
2
2
|
export interface HttpsCheckResult {
|
|
3
3
|
check: Check;
|
|
4
4
|
abort: boolean;
|
|
5
5
|
abortReason?: string;
|
|
6
|
+
transportFailure?: HttpErrorKind;
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* Check HTTPS availability via HEAD request to https://<domain>.
|
|
@@ -11,4 +12,3 @@ export interface HttpsCheckResult {
|
|
|
11
12
|
* Abort-worthy errors: dns, connection_refused, ssl_error.
|
|
12
13
|
*/
|
|
13
14
|
export declare function checkHttps(domain: string, timeout?: number): Promise<HttpsCheckResult>;
|
|
14
|
-
//# sourceMappingURL=https-check.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { transportFailureAt } from "./http-status.js";
|
|
1
2
|
import { httpGet } from "../../utils/http-client.js";
|
|
2
3
|
const ABORT_ERRORS = new Set(["dns", "connection_refused", "ssl_error", "ssrf_blocked"]);
|
|
3
4
|
/**
|
|
@@ -7,11 +8,13 @@ const ABORT_ERRORS = new Set(["dns", "connection_refused", "ssl_error", "ssrf_bl
|
|
|
7
8
|
* Abort-worthy errors: dns, connection_refused, ssl_error.
|
|
8
9
|
*/
|
|
9
10
|
export async function checkHttps(domain, timeout) {
|
|
10
|
-
const
|
|
11
|
+
const url = "https://" + domain;
|
|
12
|
+
const result = await httpGet(url, {
|
|
11
13
|
method: "HEAD",
|
|
14
|
+
maxRedirects: 0,
|
|
12
15
|
timeout,
|
|
13
16
|
});
|
|
14
|
-
if (result.ok || result.response) {
|
|
17
|
+
if (result.ok || result.response || result.error.kind === "http_error" || result.error.statusCode !== undefined) {
|
|
15
18
|
return {
|
|
16
19
|
check: {
|
|
17
20
|
id: "https_available",
|
|
@@ -45,6 +48,6 @@ export async function checkHttps(domain, timeout) {
|
|
|
45
48
|
},
|
|
46
49
|
abort,
|
|
47
50
|
abortReason: abort ? kind : undefined,
|
|
51
|
+
transportFailure: transportFailureAt(result, url),
|
|
48
52
|
};
|
|
49
53
|
}
|
|
50
|
-
//# sourceMappingURL=https-check.js.map
|
|
@@ -9,5 +9,4 @@ import type { BridgeResult, ScanContext } from "../../core/types.js";
|
|
|
9
9
|
*
|
|
10
10
|
* Aborts on dns/connection_refused/ssl_error from HTTPS check.
|
|
11
11
|
*/
|
|
12
|
-
export declare function runReachabilityBridge(ctx: ScanContext): Promise<BridgeResult
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
|
12
|
+
export declare function runReachabilityBridge(ctx: ScanContext): Promise<BridgeResult<1>>;
|
|
@@ -1,38 +1,11 @@
|
|
|
1
1
|
import { httpGet } from "../../utils/http-client.js";
|
|
2
2
|
import { checkHttps } from "./https-check.js";
|
|
3
|
-
import { checkHttpStatus } from "./http-status.js";
|
|
3
|
+
import { checkHttpStatus, transportFailureAt } from "./http-status.js";
|
|
4
4
|
import { checkRobotsTxt } from "./robots-txt.js";
|
|
5
5
|
import { evaluateCrawlerPolicies } from "./crawler-policy.js";
|
|
6
6
|
import { checkMetaRobots, checkXRobotsTag } from "./meta-robots.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* - Pass = 1 point, Partial = 0.5 points, Fail/Error = 0 points
|
|
10
|
-
* - Checks with data.policy === "skip" excluded from both numerator and denominator
|
|
11
|
-
*/
|
|
12
|
-
function calculateScore(checks) {
|
|
13
|
-
let points = 0;
|
|
14
|
-
let maxPoints = 0;
|
|
15
|
-
for (const check of checks) {
|
|
16
|
-
// Skip checks excluded from scoring (e.g., crawler policy with no robots.txt)
|
|
17
|
-
if (check.data &&
|
|
18
|
-
check.data.policy === "skip") {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
// Error = probe never ran (e.g. request budget exhausted): unmeasured,
|
|
22
|
-
// excluded from both numerator and denominator.
|
|
23
|
-
if (check.status === "error")
|
|
24
|
-
continue;
|
|
25
|
-
maxPoints += 1;
|
|
26
|
-
if (check.status === "pass")
|
|
27
|
-
points += 1;
|
|
28
|
-
else if (check.status === "partial")
|
|
29
|
-
points += 0.5;
|
|
30
|
-
// fail = 0 points
|
|
31
|
-
}
|
|
32
|
-
const score = maxPoints === 0 ? 0 : Math.round((points / maxPoints) * 100);
|
|
33
|
-
const scoreLabel = score >= 80 ? "pass" : score >= 40 ? "partial" : "fail";
|
|
34
|
-
return { score, scoreLabel };
|
|
35
|
-
}
|
|
7
|
+
import { HTML_LIMIT_DETAIL, inspectableHtml } from "../../utils/html.js";
|
|
8
|
+
import { checkCoverage, scoreChecks } from "../../core/scoring.js";
|
|
36
9
|
/**
|
|
37
10
|
* Run Bridge 1: Reachability.
|
|
38
11
|
*
|
|
@@ -65,27 +38,39 @@ export async function runReachabilityBridge(ctx) {
|
|
|
65
38
|
};
|
|
66
39
|
}
|
|
67
40
|
// 2. Page GET (uses normalized baseUrl)
|
|
68
|
-
const
|
|
69
|
-
timeout: ctx.options.timeout,
|
|
70
|
-
|
|
41
|
+
const [fetchedPage, robotsResult] = await Promise.all([
|
|
42
|
+
httpGet(ctx.baseUrl, { timeout: ctx.options.timeout }),
|
|
43
|
+
checkRobotsTxt(ctx.baseUrl, ctx.options.timeout),
|
|
44
|
+
]);
|
|
45
|
+
const pageResponse = inspectableHtml(fetchedPage);
|
|
46
|
+
const overLimit = pageResponse !== fetchedPage;
|
|
71
47
|
// Store page body for Bridge 2 (JSON-LD, Schema.org extraction)
|
|
72
48
|
if (pageResponse.ok) {
|
|
73
49
|
ctx.shared.pageBody = pageResponse.body;
|
|
50
|
+
ctx.shared.pageUrl = pageResponse.url;
|
|
51
|
+
ctx.shared.pageResponse = pageResponse;
|
|
74
52
|
ctx.shared.pageHeaders = pageResponse.headers;
|
|
53
|
+
if (overLimit)
|
|
54
|
+
ctx.shared.pageOverHtmlLimit = true;
|
|
75
55
|
}
|
|
76
|
-
// 3. HTTP status check (no HTTP call --
|
|
77
|
-
const httpStatusCheck = checkHttpStatus(
|
|
78
|
-
// 4. robots.txt fetch + parse
|
|
79
|
-
const robotsResult = await checkRobotsTxt(ctx.baseUrl, ctx.options.timeout);
|
|
56
|
+
// 3. HTTP status check (no HTTP call -- the transfer itself was complete even when inspection is withheld)
|
|
57
|
+
const httpStatusCheck = checkHttpStatus(fetchedPage);
|
|
80
58
|
// Store sitemap URLs for Bridge 2 consumption
|
|
81
59
|
ctx.shared.robotsSitemaps = robotsResult.parsed?.sitemaps ?? [];
|
|
60
|
+
// An unmeasured robots.txt was cut or never read, so it may declare a sitemap this list lacks.
|
|
61
|
+
if (robotsResult.parsed?.sitemapsCut || robotsResult.check.status === "error")
|
|
62
|
+
ctx.shared.robotsSitemapsCut = true;
|
|
82
63
|
// 5. Crawler policies (uses parsed robots.txt data)
|
|
83
|
-
const crawlerChecks = evaluateCrawlerPolicies(robotsResult.parsed,
|
|
64
|
+
const crawlerChecks = evaluateCrawlerPolicies(robotsResult.parsed, robotsResult.coverage);
|
|
84
65
|
// 6. Meta robots (uses page response)
|
|
85
66
|
let metaRobotsCheck;
|
|
86
67
|
let xRobotsCheck;
|
|
87
68
|
if (pageResponse.ok) {
|
|
88
|
-
|
|
69
|
+
const incomplete = pageResponse.bodyIncomplete || pageResponse.status === 206 || pageResponse.headers["content-range"] !== undefined;
|
|
70
|
+
metaRobotsCheck = incomplete
|
|
71
|
+
? { id: "meta_robots", label: "Meta Robots Tags", status: "error",
|
|
72
|
+
detail: overLimit ? "Homepage " + HTML_LIMIT_DETAIL : "Homepage body could not be fully inspected" }
|
|
73
|
+
: checkMetaRobots(pageResponse.body);
|
|
89
74
|
xRobotsCheck = checkXRobotsTag(pageResponse.headers);
|
|
90
75
|
}
|
|
91
76
|
else {
|
|
@@ -102,16 +87,22 @@ export async function runReachabilityBridge(ctx) {
|
|
|
102
87
|
metaRobotsCheck,
|
|
103
88
|
xRobotsCheck,
|
|
104
89
|
];
|
|
90
|
+
// On an HTTP scan the separate HTTPS probe cannot prove that the HTTP origin answered.
|
|
91
|
+
const pageFailure = transportFailureAt(pageResponse, ctx.baseUrl);
|
|
92
|
+
const unreachable = pageFailure && robotsResult.transportFailure &&
|
|
93
|
+
(origin.protocol === "http:" || httpsResult.transportFailure);
|
|
105
94
|
// 8. Calculate score
|
|
106
|
-
const { score, scoreLabel } =
|
|
95
|
+
const { score, scoreLabel } = scoreChecks(checks);
|
|
96
|
+
const { measured, eligible } = checkCoverage(checks);
|
|
107
97
|
return {
|
|
108
98
|
id: 1,
|
|
109
99
|
name: "Reachability",
|
|
110
100
|
status: "evaluated",
|
|
111
|
-
score,
|
|
112
|
-
scoreLabel,
|
|
101
|
+
score: unreachable ? 0 : score,
|
|
102
|
+
scoreLabel: unreachable ? "fail" : scoreLabel,
|
|
113
103
|
checks,
|
|
104
|
+
...(unreachable && { abort: true, abortReason: pageFailure }),
|
|
105
|
+
...(measured < eligible && { message: `${measured} of ${eligible} eligible checks measured` }),
|
|
114
106
|
durationMs: Math.round(performance.now() - start),
|
|
115
107
|
};
|
|
116
108
|
}
|
|
117
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,16 +1,3 @@
|
|
|
1
1
|
import type { Check } from "../../core/types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Check for restrictive meta robots tags in the HTML <head> section.
|
|
4
|
-
* Uses regex only -- no HTML parser dependency.
|
|
5
|
-
*
|
|
6
|
-
* Scans for: robots, googlebot, bingbot name attributes.
|
|
7
|
-
* Handles both attribute orders, single/double quotes, self-closing tags, case insensitivity.
|
|
8
|
-
*/
|
|
9
2
|
export declare function checkMetaRobots(html: string): Check;
|
|
10
|
-
/**
|
|
11
|
-
* Check for X-Robots-Tag HTTP header directives.
|
|
12
|
-
*
|
|
13
|
-
* Headers object is expected to have lowercase keys (from Phase 2 httpGet).
|
|
14
|
-
*/
|
|
15
3
|
export declare function checkXRobotsTag(headers: Record<string, string>): Check;
|
|
16
|
-
//# sourceMappingURL=meta-robots.d.ts.map
|
|
@@ -1,110 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
status: "pass",
|
|
18
|
-
detail: "No restrictive meta robots tags found",
|
|
19
|
-
data: { directives: [] },
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const headContent = headMatch[1];
|
|
23
|
-
const filtered = [];
|
|
24
|
-
for (const [tag] of headContent.matchAll(/<meta(?=\s)[^<>]*>/gi)) {
|
|
25
|
-
if (!/\sname\s*=\s*["'](?:robots|googlebot|bingbot)["']/i.test(tag))
|
|
1
|
+
import { htmlElements } from "../../utils/html.js";
|
|
2
|
+
import { AI_CRAWLERS } from "./crawler-policy.js";
|
|
3
|
+
const AGENTS = new Set(["*", "robots", "googlebot", "bingbot", ...AI_CRAWLERS.map(c => c.userAgent)]);
|
|
4
|
+
const PARTIAL = new Set(["nofollow", "noarchive", "nosnippet", "noai", "noimageai"]);
|
|
5
|
+
const PARAMETERIZED = new Set(["max-snippet", "max-image-preview", "max-video-preview", "unavailable_after"]);
|
|
6
|
+
function collect(groups, value, agent, header) {
|
|
7
|
+
let scope = agent;
|
|
8
|
+
// A weekday and calendar date in unavailable_after can be separated by a comma.
|
|
9
|
+
for (const part of value.toLowerCase().split(/,(?![ \t]*\d{1,2}[ \t]+[a-z]{3}\b)/i)) {
|
|
10
|
+
let directive = part.trim();
|
|
11
|
+
const prefix = /^([\w.*-]+)\s*:/.exec(directive);
|
|
12
|
+
if (header && prefix && !PARAMETERIZED.has(prefix[1])) {
|
|
13
|
+
scope = prefix[1];
|
|
14
|
+
directive = directive.slice(prefix[0].length).trim();
|
|
15
|
+
}
|
|
16
|
+
if (!directive || !AGENTS.has(scope))
|
|
26
17
|
continue;
|
|
27
|
-
const
|
|
28
|
-
|
|
18
|
+
const key = scope === "robots" ? "*" : scope;
|
|
19
|
+
const set = groups.get(key) ?? new Set();
|
|
20
|
+
groups.set(key, set);
|
|
21
|
+
if (PARAMETERIZED.has(directive.split(":", 1)[0].trim())) {
|
|
22
|
+
set.add(directive);
|
|
29
23
|
continue;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
24
|
+
}
|
|
25
|
+
for (const [token] of directive.matchAll(/\S+/g)) {
|
|
26
|
+
if (token === "none") {
|
|
27
|
+
set.add("noindex");
|
|
28
|
+
set.add("nofollow");
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
set.add(token);
|
|
32
|
+
}
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
status: "partial",
|
|
50
|
-
detail: `Restrictive meta robots directives found: ${filtered.join(", ")}`,
|
|
51
|
-
data: { directives: filtered },
|
|
52
|
-
};
|
|
35
|
+
}
|
|
36
|
+
function evaluate(groups) {
|
|
37
|
+
const global = groups.get("*");
|
|
38
|
+
let status = global?.has("noindex") ? "fail" : "pass";
|
|
39
|
+
const restrictions = [];
|
|
40
|
+
for (const [agent, values] of groups) {
|
|
41
|
+
for (const value of values) {
|
|
42
|
+
if (value !== "noindex" && !PARTIAL.has(value))
|
|
43
|
+
continue;
|
|
44
|
+
if (status === "pass")
|
|
45
|
+
status = "partial";
|
|
46
|
+
restrictions.push(agent === "*" ? value : agent + ": " + value);
|
|
47
|
+
}
|
|
53
48
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
// Status uses every token; the report keeps the first 32 of each scope, leaving out over-long tokens.
|
|
50
|
+
const sample = (values) => {
|
|
51
|
+
const kept = [];
|
|
52
|
+
for (const value of values) {
|
|
53
|
+
if (kept.length === 32)
|
|
54
|
+
break;
|
|
55
|
+
if (value.length <= 256)
|
|
56
|
+
kept.push(value);
|
|
57
|
+
}
|
|
58
|
+
return kept;
|
|
60
59
|
};
|
|
60
|
+
const directives = sample(global ?? new Set());
|
|
61
|
+
const scoped = [...groups].filter(([agent]) => agent !== "*").map(([agent, values]) => ({ agent, total: values.size, kept: sample(values) }));
|
|
62
|
+
return { status, restrictions, data: {
|
|
63
|
+
directives, directivesTotal: global?.size ?? 0,
|
|
64
|
+
...(directives.length < (global?.size ?? 0) && { directivesTruncated: true }),
|
|
65
|
+
...(scoped.length && {
|
|
66
|
+
scopedDirectives: Object.fromEntries(scoped.map(scope => [scope.agent, scope.kept])),
|
|
67
|
+
scopedDirectivesTotal: Object.fromEntries(scoped.map(scope => [scope.agent, scope.total])),
|
|
68
|
+
...(scoped.some(scope => scope.kept.length < scope.total) && { scopedDirectivesTruncated: true }),
|
|
69
|
+
}),
|
|
70
|
+
} };
|
|
61
71
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
id,
|
|
74
|
-
label,
|
|
75
|
-
status: "pass",
|
|
76
|
-
detail: "No X-Robots-Tag header",
|
|
77
|
-
data: { directives: [], raw: "" },
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
const directives = headerValue
|
|
81
|
-
.split(",")
|
|
82
|
-
.map((d) => d.trim().toLowerCase())
|
|
83
|
-
.filter((d) => d.length > 0);
|
|
84
|
-
if (directives.some((d) => d.includes("noindex"))) {
|
|
85
|
-
return {
|
|
86
|
-
id,
|
|
87
|
-
label,
|
|
88
|
-
status: "fail",
|
|
89
|
-
detail: `X-Robots-Tag contains restrictive directives: ${directives.join(", ")}`,
|
|
90
|
-
data: { directives, raw: headerValue },
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (directives.some((d) => d.includes("nofollow") || d.includes("noarchive") || d === "none")) {
|
|
94
|
-
return {
|
|
95
|
-
id,
|
|
96
|
-
label,
|
|
97
|
-
status: "partial",
|
|
98
|
-
detail: `X-Robots-Tag contains directives: ${directives.join(", ")}`,
|
|
99
|
-
data: { directives, raw: headerValue },
|
|
100
|
-
};
|
|
72
|
+
export function checkMetaRobots(html) {
|
|
73
|
+
const groups = new Map();
|
|
74
|
+
for (const element of htmlElements(html)) {
|
|
75
|
+
if (element.tagName === "body")
|
|
76
|
+
break;
|
|
77
|
+
if (element.tagName !== "meta")
|
|
78
|
+
continue;
|
|
79
|
+
const name = element.attrs.find(attr => attr.name === "name")?.value.toLowerCase().trim();
|
|
80
|
+
const content = element.attrs.find(attr => attr.name === "content")?.value;
|
|
81
|
+
if (content && name && AGENTS.has(name))
|
|
82
|
+
collect(groups, content, name, false);
|
|
101
83
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
84
|
+
const { status, restrictions, data } = evaluate(groups);
|
|
85
|
+
const detail = status === "pass" ? "No restrictive meta robots tags found" :
|
|
86
|
+
`Restrictive meta robots directives found: ${restrictions.join(", ")}`;
|
|
87
|
+
return { id: "meta_robots", label: "Meta Robots Tags", status, detail, data };
|
|
88
|
+
}
|
|
89
|
+
export function checkXRobotsTag(headers) {
|
|
90
|
+
const raw = headers["x-robots-tag"] ?? "";
|
|
91
|
+
const groups = new Map();
|
|
92
|
+
collect(groups, raw, "*", true);
|
|
93
|
+
const { status, restrictions, data } = evaluate(groups);
|
|
94
|
+
const detail = !raw ? "No X-Robots-Tag header" :
|
|
95
|
+
status === "pass" ? "X-Robots-Tag header present with no restrictive directives" :
|
|
96
|
+
`X-Robots-Tag contains restrictive directives: ${restrictions.join(", ")}`;
|
|
97
|
+
return { id: "x_robots_tag", label: "X-Robots-Tag Header", status, detail, data: { ...data, raw } };
|
|
109
98
|
}
|
|
110
|
-
//# sourceMappingURL=meta-robots.js.map
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export interface RobotsTxtResult {
|
|
2
|
-
parseable: boolean;
|
|
3
2
|
ruleCount: number;
|
|
4
3
|
groups: RobotsGroup[];
|
|
4
|
+
/** The Sitemap URLs from the start of the file, duplicates included, that fit SITEMAPS_LENGTH_BUDGET together. */
|
|
5
5
|
sitemaps: string[];
|
|
6
|
+
/** Every accepted Sitemap declaration, including those left out of sitemaps. */
|
|
7
|
+
sitemapsTotal: number;
|
|
8
|
+
/** Set when a declaration left out names a URL that sitemaps does not hold. Repeats of a kept URL lose nothing. */
|
|
9
|
+
sitemapsCut?: true;
|
|
6
10
|
}
|
|
7
11
|
export interface RobotsGroup {
|
|
8
12
|
userAgents: string[];
|
|
@@ -17,10 +21,6 @@ export interface RobotsRule {
|
|
|
17
21
|
* Handles RFC 9309 edge cases: BOM, CRLF/CR/LF, comments,
|
|
18
22
|
* case-insensitive directives, case-sensitive paths, group boundaries.
|
|
19
23
|
*/
|
|
20
|
-
export declare function parseRobotsTxt(content: string): RobotsTxtResult;
|
|
21
|
-
/**
|
|
22
|
-
* Check whether a robots.txt path pattern matches a given URL path.
|
|
23
|
-
* Supports * wildcards and $ end anchor per RFC 9309.
|
|
24
|
-
*/
|
|
24
|
+
export declare function parseRobotsTxt(content: string, documentUrl?: string): RobotsTxtResult;
|
|
25
25
|
export declare function matchesPath(pattern: string, path: string): boolean;
|
|
26
|
-
|
|
26
|
+
export declare function isAllowed(rules: RobotsRule[], path: string): boolean;
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
1
|
+
import { parseReference } from "../../utils/url.js";
|
|
2
|
+
// Relative Sitemap lines resolved against a long robots.txt URL each become that long, so the
|
|
3
|
+
// retained list is bounded by total length rather than count to keep worker memory in check.
|
|
4
|
+
const SITEMAPS_LENGTH_BUDGET = 1_048_576;
|
|
3
5
|
/**
|
|
4
6
|
* Parse raw robots.txt content into structured data.
|
|
5
7
|
* Handles RFC 9309 edge cases: BOM, CRLF/CR/LF, comments,
|
|
6
8
|
* case-insensitive directives, case-sensitive paths, group boundaries.
|
|
7
9
|
*/
|
|
8
|
-
export function parseRobotsTxt(content) {
|
|
10
|
+
export function parseRobotsTxt(content, documentUrl) {
|
|
9
11
|
const groups = [];
|
|
10
12
|
const sitemaps = [];
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
let sitemapsTotal = 0;
|
|
14
|
+
let sitemapsLength = 0;
|
|
15
|
+
let sitemapsFull = false;
|
|
16
|
+
let sitemapsCut = false;
|
|
17
|
+
let kept;
|
|
18
|
+
// A UTF-8 BOM decoded under a declared Latin-1/windows-1252 charset arrives as "\u00EF\u00BB\u00BF".
|
|
19
|
+
const text = content.replace(/^(?:\uFEFF|\u00EF\u00BB\u00BF)/, "");
|
|
16
20
|
// 2. Split on CRLF, CR, or LF
|
|
17
21
|
const lines = text.split(/\r\n|\r|\n/);
|
|
18
22
|
let currentGroup = null;
|
|
@@ -30,17 +34,20 @@ export function parseRobotsTxt(content) {
|
|
|
30
34
|
const value = line.substring(colonIdx + 1).trim();
|
|
31
35
|
switch (directive) {
|
|
32
36
|
case "user-agent": {
|
|
37
|
+
const token = value.split(/[\s/]/, 1)[0].toLowerCase();
|
|
38
|
+
const agents = /^(?:\*|[a-z_-]+)$/.test(token) ? [token] : [];
|
|
33
39
|
// 6. If currentGroup has rules, start a new group
|
|
34
40
|
if (currentGroup && currentGroup.rules.length > 0) {
|
|
35
41
|
groups.push(currentGroup);
|
|
36
|
-
currentGroup = { userAgents:
|
|
42
|
+
currentGroup = { userAgents: agents, rules: [] };
|
|
37
43
|
}
|
|
38
44
|
else if (currentGroup) {
|
|
39
45
|
// Consecutive User-agent lines = same group
|
|
40
|
-
|
|
46
|
+
if (agents.length)
|
|
47
|
+
currentGroup.userAgents.push(token);
|
|
41
48
|
}
|
|
42
49
|
else {
|
|
43
|
-
currentGroup = { userAgents:
|
|
50
|
+
currentGroup = { userAgents: agents, rules: [] };
|
|
44
51
|
}
|
|
45
52
|
break;
|
|
46
53
|
}
|
|
@@ -55,7 +62,20 @@ export function parseRobotsTxt(content) {
|
|
|
55
62
|
}
|
|
56
63
|
case "sitemap": {
|
|
57
64
|
// 8. Sitemaps are not tied to any group
|
|
58
|
-
|
|
65
|
+
if (!value || /[\s\\<>]/.test(value))
|
|
66
|
+
break;
|
|
67
|
+
const url = parseReference(value, documentUrl);
|
|
68
|
+
if (url && ["http:", "https:"].includes(url.protocol) && !url.username && !url.password) {
|
|
69
|
+
sitemapsTotal++;
|
|
70
|
+
// Past the first URL that does not fit, a shorter one would follow a gap the sitemap check cannot see.
|
|
71
|
+
sitemapsFull ||= sitemapsLength + url.href.length > SITEMAPS_LENGTH_BUDGET;
|
|
72
|
+
if (sitemapsFull) {
|
|
73
|
+
sitemapsCut ||= !(kept ??= new Set(sitemaps)).has(url.href);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
sitemapsLength += url.href.length;
|
|
77
|
+
sitemaps.push(url.href);
|
|
78
|
+
}
|
|
59
79
|
break;
|
|
60
80
|
}
|
|
61
81
|
default:
|
|
@@ -70,17 +90,48 @@ export function parseRobotsTxt(content) {
|
|
|
70
90
|
// 11. Calculate ruleCount
|
|
71
91
|
const ruleCount = groups.reduce((sum, g) => sum + g.rules.length, 0);
|
|
72
92
|
return {
|
|
73
|
-
parseable: true,
|
|
74
93
|
ruleCount,
|
|
75
94
|
groups,
|
|
76
95
|
sitemaps,
|
|
96
|
+
sitemapsTotal,
|
|
97
|
+
...(sitemapsCut && { sitemapsCut: true }),
|
|
77
98
|
};
|
|
78
99
|
}
|
|
100
|
+
// RFC 9309 compares paths by octet, with percent-encoded unreserved ASCII decoded.
|
|
101
|
+
function normalizePath(path) {
|
|
102
|
+
return path.replace(/%[a-fA-F0-9]{2}|[^\x00-\x7f]/gu, value => {
|
|
103
|
+
if (!value.startsWith("%"))
|
|
104
|
+
return encodeURIComponent(/[\uD800-\uDFFF]/u.test(value) ? "\uFFFD" : value);
|
|
105
|
+
const character = String.fromCharCode(Number.parseInt(value.slice(1), 16));
|
|
106
|
+
return /^[a-zA-Z0-9._~-]$/.test(character) ? character : value.toUpperCase();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
export function matchesPath(pattern, path) {
|
|
110
|
+
return matchesNormalizedPath(normalizePath(pattern), normalizePath(path.startsWith("/") ? path : "/" + path));
|
|
111
|
+
}
|
|
112
|
+
export function isAllowed(rules, path) {
|
|
113
|
+
const target = normalizePath(path.startsWith("/") ? path : "/" + path);
|
|
114
|
+
let longest = -1;
|
|
115
|
+
let allowed = true;
|
|
116
|
+
for (const rule of rules) {
|
|
117
|
+
if (!rule.path)
|
|
118
|
+
continue;
|
|
119
|
+
const pattern = normalizePath(rule.path);
|
|
120
|
+
if (!matchesNormalizedPath(pattern, target))
|
|
121
|
+
continue;
|
|
122
|
+
const length = pattern.replace(/%[A-F0-9]{2}/g, "x").length;
|
|
123
|
+
if (length > longest || (length === longest && rule.type === "allow")) {
|
|
124
|
+
longest = length;
|
|
125
|
+
allowed = rule.type === "allow";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return allowed;
|
|
129
|
+
}
|
|
79
130
|
/**
|
|
80
131
|
* Check whether a robots.txt path pattern matches a given URL path.
|
|
81
132
|
* Supports * wildcards and $ end anchor per RFC 9309.
|
|
82
133
|
*/
|
|
83
|
-
|
|
134
|
+
function matchesNormalizedPath(pattern, path) {
|
|
84
135
|
const anchored = pattern.endsWith("$");
|
|
85
136
|
const glob = anchored ? pattern.slice(0, -1) : pattern;
|
|
86
137
|
const [prefix, ...parts] = glob.split("*");
|
|
@@ -104,4 +155,3 @@ export function matchesPath(pattern, path) {
|
|
|
104
155
|
}
|
|
105
156
|
return true;
|
|
106
157
|
}
|
|
107
|
-
//# sourceMappingURL=robots-parser.js.map
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { Check } from "../../core/types.js";
|
|
1
|
+
import type { Check, HttpErrorKind } from "../../core/types.js";
|
|
2
|
+
import { type DirectiveInventory } from "./crawler-policy.js";
|
|
2
3
|
import { type RobotsTxtResult } from "./robots-parser.js";
|
|
3
4
|
export interface RobotsTxtCheckResult {
|
|
4
5
|
check: Check;
|
|
5
6
|
parsed: RobotsTxtResult | null;
|
|
7
|
+
coverage: DirectiveInventory["coverage"];
|
|
8
|
+
transportFailure?: HttpErrorKind;
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* Fetch and parse robots.txt for the given domain.
|
|
@@ -11,4 +14,3 @@ export interface RobotsTxtCheckResult {
|
|
|
11
14
|
* use by crawler policy evaluation.
|
|
12
15
|
*/
|
|
13
16
|
export declare function checkRobotsTxt(origin: string, timeout?: number): Promise<RobotsTxtCheckResult>;
|
|
14
|
-
//# sourceMappingURL=robots-txt.d.ts.map
|