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,58 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { observeProbe, readProbe } from "./probe.js";
|
|
2
|
+
const RATE_LIMIT_HEADERS = ["ratelimit", "ratelimit-policy", "ratelimit-limit", "x-ratelimit-limit", "x-rate-limit-limit",
|
|
3
|
+
"ratelimit-remaining", "ratelimit-reset", "x-ratelimit-remaining", "x-ratelimit-reset", "x-rate-limit-remaining", "x-rate-limit-reset"];
|
|
4
4
|
const RETRY_AFTER = "retry-after";
|
|
5
|
-
function findSimpleGetPath(spec) {
|
|
6
|
-
if (!spec)
|
|
7
|
-
return null;
|
|
8
|
-
const ops = collectOperations(spec);
|
|
9
|
-
for (const [path, method, op] of ops) {
|
|
10
|
-
if (method !== "get")
|
|
11
|
-
continue;
|
|
12
|
-
if (path.includes("{"))
|
|
13
|
-
continue;
|
|
14
|
-
if (op.parameters == null || (Array.isArray(op.parameters) && op.parameters.every((p) => p && !p.required)))
|
|
15
|
-
return path;
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
5
|
const id = "context_rate_limit_headers";
|
|
20
6
|
const label = "Rate Limit Headers";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
7
|
+
export async function checkRateLimitHeaders(ctx, cache) {
|
|
8
|
+
const probeResult = await readProbe(ctx, "rate", cache);
|
|
9
|
+
if (!probeResult) {
|
|
10
|
+
const check = { id, label, status: "error", detail: "OpenAPI inspection exceeded its work limit during probe selection",
|
|
11
|
+
data: { measurement: "unmeasured", measured: false } };
|
|
12
|
+
return { check, headers: {} };
|
|
28
13
|
}
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
ctx.shared.contextProbeHeaders = {};
|
|
44
|
-
return { id, label, status: "error", detail: "Rate-limit probe skipped: scan request budget exhausted", data: { probeUrl, headerFound: null } };
|
|
45
|
-
}
|
|
46
|
-
// Rate-limit headers commonly ride on error responses too (e.g. a 429 or
|
|
47
|
-
// an authenticated 401) — grade them rather than discarding the response.
|
|
48
|
-
if (result.response) {
|
|
49
|
-
ctx.shared.contextProbeHeaders = result.response.headers;
|
|
50
|
-
return gradeHeaders(result.response.headers, probeUrl);
|
|
14
|
+
const { selected, result } = probeResult;
|
|
15
|
+
const { data, response, attributable, html } = observeProbe(selected, result);
|
|
16
|
+
const { httpStatus } = data;
|
|
17
|
+
const eligible = result.ok || ((!result.ok && result.error.kind === "http_error") && (httpStatus === 401 || httpStatus === 403)) || httpStatus === 429;
|
|
18
|
+
let headers = {};
|
|
19
|
+
if (attributable && !html && eligible && response) {
|
|
20
|
+
headers = response.headers;
|
|
21
|
+
const limit = RATE_LIMIT_HEADERS.find(name => response.headers[name]?.trim());
|
|
22
|
+
const headerFound = limit ?? (response.headers[RETRY_AFTER]?.trim() ? RETRY_AFTER : null);
|
|
23
|
+
if (headerFound || (selected.probeSource === "operation" && httpStatus !== 401 && httpStatus !== 403)) {
|
|
24
|
+
return { headers, check: { id, label, status: limit ? "pass" : headerFound ? "partial" : "fail",
|
|
25
|
+
detail: headerFound ? `Rate-limit header observed: ${headerFound}` : "No rate-limit headers found in response",
|
|
26
|
+
data: { ...data, headerFound, measurement: "measured", measured: true },
|
|
27
|
+
} };
|
|
51
28
|
}
|
|
52
|
-
ctx.shared.contextProbeHeaders = {};
|
|
53
|
-
return { id, label, status: "fail", detail: `Could not reach ${probeUrl} to check rate-limit headers`, data: { probeUrl, headerFound: null } };
|
|
54
29
|
}
|
|
55
|
-
|
|
56
|
-
|
|
30
|
+
return { headers, check: { id, label, status: "error",
|
|
31
|
+
detail: `Rate-limit guidance could not be measured for the selected GET (${httpStatus === null ? "no HTTP response" : `HTTP ${httpStatus}`})`,
|
|
32
|
+
data: { ...data, headerFound: null, measurement: "unmeasured", measured: false, ...(!result.ok && { errorKind: result.error.kind }) },
|
|
33
|
+
} };
|
|
57
34
|
}
|
|
58
|
-
//# sourceMappingURL=rate-limits.js.map
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import type { DefaultTreeAdapterTypes } from "parse5";
|
|
1
2
|
import type { Check } from "../../core/types.js";
|
|
2
3
|
import type { ParsedOpenApiSpec } from "../schema/oas-types.js";
|
|
3
4
|
export declare function extractTosUrl(text: string): string | null;
|
|
4
|
-
export declare function extractTosUrlFromHtml(html: string
|
|
5
|
-
export declare function checkTosUrl(spec: ParsedOpenApiSpec | undefined, llmsTxtBody: string | null, pageBody: string | null, baseUrl: string
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export declare function extractTosUrlFromHtml(html: string | Iterable<DefaultTreeAdapterTypes.Element>, baseUrl: string): string | null;
|
|
6
|
+
export declare function checkTosUrl(spec: ParsedOpenApiSpec | undefined, llmsTxtBody: string | null, pageBody: string | null, baseUrl: string,
|
|
7
|
+
/** The link Standards read from the page. Given, the page is not parsed here. */
|
|
8
|
+
pageTermsUrl?: string | null): Check;
|
|
9
|
+
/**
|
|
10
|
+
* What the contact check reports of a security.txt: its first usable Contact URI. Standards reads this from the
|
|
11
|
+
* file, which can be megabytes, so that no later bridge holds the file for one line of it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function securityTxtContact(securityTxt: string): Pick<Check, "detail" | "data"> | null;
|
|
14
|
+
export declare function checkContactInfo(spec: ParsedOpenApiSpec | undefined,
|
|
15
|
+
/** The file's text, or what Standards read from it. */
|
|
16
|
+
securityTxt: string | Pick<Check, "detail" | "data"> | null): Check;
|
|
@@ -1,55 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (/\/(?:terms|tos)(?=[-/]|$)/i.test(url.pathname))
|
|
12
|
-
return url.href;
|
|
13
|
-
if (!legalUrl && /\/legal(?=[-/]|$)/i.test(url.pathname))
|
|
14
|
-
legalUrl = url.href;
|
|
15
|
-
}
|
|
16
|
-
return legalUrl;
|
|
1
|
+
import { htmlElements } from "../../utils/html.js";
|
|
2
|
+
import { documentBase, parseReference } from "../../utils/url.js";
|
|
3
|
+
import { securityContact } from "../standards/well-known.js";
|
|
4
|
+
const TERMS_PATH = /\/(?:terms|tos)(?=[-/.]|$)/i;
|
|
5
|
+
function webUrl(href, base) {
|
|
6
|
+
if (!href.trim() || href.startsWith("#"))
|
|
7
|
+
return;
|
|
8
|
+
const url = parseReference(href, base);
|
|
9
|
+
if (url?.protocol === "https:" || url?.protocol === "http:")
|
|
10
|
+
return url;
|
|
17
11
|
}
|
|
18
12
|
export function extractTosUrl(text) {
|
|
19
|
-
|
|
13
|
+
for (const [raw] of text.matchAll(/https?:\/\/[^\s<>"'()\]]+/gi)) {
|
|
14
|
+
// Starting only at the first character of a run keeps a long inner run of punctuation linear.
|
|
15
|
+
const url = webUrl(raw.replace(/(?<![.,;:!?)}\]])[.,;:!?)}\]]+$/, ""));
|
|
16
|
+
if (url && TERMS_PATH.test(url.pathname))
|
|
17
|
+
return url.href;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
20
|
}
|
|
21
21
|
export function extractTosUrlFromHtml(html, baseUrl) {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
// A link left open is rebuilt in every later paragraph: judge each reference once, not once per copy. Only whether
|
|
23
|
+
// it resolves is kept. Under a long base every resolved URL is as long, and a page of them outgrows the bridge's heap.
|
|
24
|
+
const resolves = new Map();
|
|
25
|
+
// The first <base> applies to the whole document, including anchors that precede it.
|
|
26
|
+
let base;
|
|
27
|
+
const anchors = [];
|
|
28
|
+
for (const element of typeof html === "string" ? htmlElements(html) : html) {
|
|
29
|
+
const href = element.attrs.find(a => a.name === "href")?.value;
|
|
30
|
+
if (element.tagName === "base" && href !== undefined && base === undefined)
|
|
31
|
+
base = documentBase(href, baseUrl);
|
|
32
|
+
if (element.tagName === "a")
|
|
33
|
+
anchors.push(element);
|
|
34
|
+
}
|
|
35
|
+
// Under a base the scan cannot use (null), only an absolute link resolves.
|
|
36
|
+
const resolve = (href) => webUrl(href, base === null ? undefined : base ?? baseUrl);
|
|
37
|
+
for (const element of anchors) {
|
|
38
|
+
const href = element.attrs.find(a => a.name === "href")?.value ?? "";
|
|
39
|
+
if (!resolves.has(href)) {
|
|
40
|
+
const url = resolve(href);
|
|
41
|
+
if (url && TERMS_PATH.test(url.pathname))
|
|
42
|
+
return url.href;
|
|
43
|
+
resolves.set(href, url !== undefined);
|
|
44
|
+
}
|
|
45
|
+
if (!resolves.get(href))
|
|
46
|
+
continue;
|
|
47
|
+
const stack = element.childNodes.slice().reverse();
|
|
48
|
+
const text = [];
|
|
49
|
+
while (stack.length) {
|
|
50
|
+
const node = stack.pop();
|
|
51
|
+
if ("value" in node)
|
|
52
|
+
text.push(node.value);
|
|
53
|
+
else if ("childNodes" in node) {
|
|
54
|
+
for (let i = node.childNodes.length - 1; i >= 0; i--)
|
|
55
|
+
stack.push(node.childNodes[i]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!/^terms(?: of (?:service|use)| (?:&|and) conditions)?$/i.test(text.join("").trim()))
|
|
59
|
+
continue;
|
|
60
|
+
const url = resolve(href);
|
|
61
|
+
if (url)
|
|
62
|
+
return url.href;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
24
65
|
}
|
|
25
|
-
export function checkTosUrl(spec, llmsTxtBody, pageBody, baseUrl
|
|
66
|
+
export function checkTosUrl(spec, llmsTxtBody, pageBody, baseUrl,
|
|
67
|
+
/** The link Standards read from the page. Given, the page is not parsed here. */
|
|
68
|
+
pageTermsUrl) {
|
|
26
69
|
const id = "context_tos_url";
|
|
27
70
|
const label = "Terms of Service URL";
|
|
28
71
|
const specTos = spec?.info?.termsOfService;
|
|
29
|
-
const url = typeof specTos === "string" ?
|
|
30
|
-
|
|
31
|
-
|
|
72
|
+
const url = typeof specTos === "string" ? parseReference(specTos) : null;
|
|
73
|
+
function found(link, source) {
|
|
74
|
+
const status = source === "spec" ? "pass" : "partial";
|
|
75
|
+
// A clipped URL could point to a different resource. Keep the finding and omit the value.
|
|
76
|
+
if (link.length > 2048)
|
|
77
|
+
return { id, label, status, detail: `Terms of Service URL found in ${source} (URL exceeds display limit)`,
|
|
78
|
+
data: { source, url: null, urlOmitted: true } };
|
|
79
|
+
return { id, label, status, detail: `Terms of Service URL found in ${source}: ${link}`, data: { source, url: link } };
|
|
32
80
|
}
|
|
81
|
+
if (typeof specTos === "string" && (url?.protocol === "https:" || url?.protocol === "http:"))
|
|
82
|
+
return found(specTos, "spec");
|
|
33
83
|
if (llmsTxtBody) {
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
if (pageBody) {
|
|
39
|
-
const url = extractTosUrlFromHtml(pageBody, baseUrl);
|
|
40
|
-
if (url)
|
|
41
|
-
return { id, label, status: "partial", detail: `Terms of Service URL found in page: ${url}`, data: { source: "page", url } };
|
|
84
|
+
const link = extractTosUrl(llmsTxtBody);
|
|
85
|
+
if (link)
|
|
86
|
+
return found(link, "llms.txt");
|
|
42
87
|
}
|
|
88
|
+
const pageLink = pageTermsUrl !== undefined ? pageTermsUrl : pageBody ? extractTosUrlFromHtml(pageBody, baseUrl) : null;
|
|
89
|
+
if (pageLink)
|
|
90
|
+
return found(pageLink, "page");
|
|
43
91
|
return { id, label, status: "fail", detail: "No Terms of Service URL found", data: { source: null, url: null } };
|
|
44
92
|
}
|
|
93
|
+
// As with the Terms URL, a clipped contact could name a different recipient. Keep the finding and omit the value.
|
|
94
|
+
const omit = (value) => value !== null && value.length > 2048;
|
|
45
95
|
/**
|
|
46
|
-
*
|
|
96
|
+
* What the contact check reports of a security.txt: its first usable Contact URI. Standards reads this from the
|
|
97
|
+
* file, which can be megabytes, so that no later bridge holds the file for one line of it.
|
|
47
98
|
*/
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
|
|
99
|
+
export function securityTxtContact(securityTxt) {
|
|
100
|
+
const contactValue = securityContact(securityTxt);
|
|
101
|
+
if (!contactValue)
|
|
102
|
+
return null;
|
|
103
|
+
const mailto = contactValue.protocol === "mailto:";
|
|
104
|
+
const stored = mailto ? contactValue.pathname : contactValue.href;
|
|
105
|
+
// An address is cut from its URI, and V8 keeps the whole of a string for a piece of it: megabytes, under a long
|
|
106
|
+
// query. The address kept is a copy.
|
|
107
|
+
const data = omit(stored) ? { email: null, url: null, ...(mailto ? { emailOmitted: true } : { urlOmitted: true }) }
|
|
108
|
+
: mailto ? { email: (" " + stored).slice(1), url: null } : { email: null, url: stored };
|
|
109
|
+
// The detail prints the whole URI, and a mailto query or fragment is no part of the stored address.
|
|
110
|
+
const detail = omit(contactValue.href) ? "Contact info found in security.txt (URI exceeds display limit)"
|
|
111
|
+
: `Contact info found in security.txt: ${contactValue}`;
|
|
112
|
+
return { detail, data };
|
|
51
113
|
}
|
|
52
|
-
export function checkContactInfo(spec,
|
|
114
|
+
export function checkContactInfo(spec,
|
|
115
|
+
/** The file's text, or what Standards read from it. */
|
|
116
|
+
securityTxt) {
|
|
53
117
|
const id = "context_contact_info";
|
|
54
118
|
const label = "Contact Info";
|
|
55
119
|
const contact = spec?.info?.contact;
|
|
@@ -58,17 +122,15 @@ export function checkContactInfo(spec, securityTxtBody) {
|
|
|
58
122
|
if (email || url) {
|
|
59
123
|
const parts = [];
|
|
60
124
|
if (email)
|
|
61
|
-
parts.push(`email: ${email}`);
|
|
125
|
+
parts.push(omit(email) ? "email (exceeds display limit)" : `email: ${email}`);
|
|
62
126
|
if (url)
|
|
63
|
-
parts.push(`url: ${url}`);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const contactValue = extractSecurityTxtContact(securityTxtBody);
|
|
68
|
-
if (contactValue) {
|
|
69
|
-
return { id, label, status: "partial", detail: `Contact info found in security.txt: ${contactValue}`, data: { email: null, url: contactValue } };
|
|
70
|
-
}
|
|
127
|
+
parts.push(omit(url) ? "url (exceeds display limit)" : `url: ${url}`);
|
|
128
|
+
const data = { email: omit(email) ? null : email, ...(omit(email) && { emailOmitted: true }),
|
|
129
|
+
url: omit(url) ? null : url, ...(omit(url) && { urlOmitted: true }) };
|
|
130
|
+
return { id, label, status: "pass", detail: `Contact info found in spec: ${parts.join(", ")}`, data };
|
|
71
131
|
}
|
|
132
|
+
const published = typeof securityTxt === "string" ? securityTxtContact(securityTxt) : securityTxt;
|
|
133
|
+
if (published)
|
|
134
|
+
return { id, label, status: "partial", ...published };
|
|
72
135
|
return { id, label, status: "fail", detail: "No contact info found", data: { email: null, url: null } };
|
|
73
136
|
}
|
|
74
|
-
//# sourceMappingURL=tos-contact.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { Check } from "../../core/types.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type ParsedOpenApiSpec } from "../schema/oas-types.js";
|
|
3
3
|
export declare function checkVersioningSignal(spec: ParsedOpenApiSpec | undefined, contextProbeHeaders: Record<string, string>): Check;
|
|
4
|
-
//# sourceMappingURL=versioning.d.ts.map
|
|
@@ -1,22 +1,57 @@
|
|
|
1
|
+
import { parseReference } from "../../utils/url.js";
|
|
2
|
+
import { openApiServerUrl } from "../schema/oas-types.js";
|
|
1
3
|
const VERSION_HEADERS = ["x-api-version", "api-version", "x-version"];
|
|
2
4
|
export function checkVersioningSignal(spec, contextProbeHeaders) {
|
|
3
5
|
const id = "context_versioning_signal";
|
|
4
6
|
const label = "Versioning Signal";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const paths = Object.keys(spec?.paths ?? {});
|
|
8
|
+
if (spec?.swagger === "2.0" && typeof spec.basePath === "string")
|
|
9
|
+
paths.unshift(spec.basePath);
|
|
10
|
+
if (Array.isArray(spec?.servers)) {
|
|
11
|
+
for (const server of spec.servers) {
|
|
12
|
+
const raw = openApiServerUrl(server);
|
|
13
|
+
if (!raw)
|
|
14
|
+
continue;
|
|
15
|
+
const url = parseReference(raw, "https://example.invalid/");
|
|
16
|
+
if (url)
|
|
17
|
+
paths.push(url.pathname);
|
|
9
18
|
}
|
|
10
19
|
}
|
|
20
|
+
// A clipped path or version is a different value. Keep the finding and omit an overlong value.
|
|
21
|
+
const omitted = (signal, status, source) => ({ id, label, status, detail: `${source} (value exceeds display limit)`, data: { signal, value: null, valueOmitted: true } });
|
|
22
|
+
let longPath = false;
|
|
23
|
+
for (const path of paths) {
|
|
24
|
+
if (path.startsWith("/") && !path.startsWith("//") && /\/v\d+(?:[.-]\d+)*(?:\/|$)/i.test(path)) {
|
|
25
|
+
// A shorter versioned path is reportable evidence for the same signal.
|
|
26
|
+
if (path.length > 2048) {
|
|
27
|
+
longPath = true;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
return { id, label, status: "pass", detail: `Path-based versioning detected: ${path}`, data: { signal: "path", value: path } };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (longPath)
|
|
34
|
+
return omitted("path", "pass", "Path-based versioning detected");
|
|
35
|
+
let longHeader = false;
|
|
11
36
|
for (const header of VERSION_HEADERS) {
|
|
12
37
|
const value = contextProbeHeaders[header];
|
|
13
|
-
if (value
|
|
14
|
-
|
|
38
|
+
if (!value?.trim())
|
|
39
|
+
continue;
|
|
40
|
+
const stored = `${header}: ${value}`;
|
|
41
|
+
// As for paths: a header that fits is reportable evidence for the same signal.
|
|
42
|
+
if (stored.length > 2048) {
|
|
43
|
+
longHeader = true;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
return { id, label, status: "pass", detail: `Version header found: ${stored}`, data: { signal: "header", value: stored } };
|
|
15
47
|
}
|
|
48
|
+
if (longHeader)
|
|
49
|
+
return omitted("header", "pass", "Version header found");
|
|
16
50
|
const specVersion = spec?.info?.version;
|
|
17
51
|
if (typeof specVersion === "string" && specVersion.trim() !== "") {
|
|
52
|
+
if (specVersion.length > 2048)
|
|
53
|
+
return omitted("spec_info", "partial", "Spec info.version found");
|
|
18
54
|
return { id, label, status: "partial", detail: `Spec info.version found: ${specVersion}`, data: { signal: "spec_info", value: specVersion } };
|
|
19
55
|
}
|
|
20
56
|
return { id, label, status: "fail", detail: "No versioning signal found", data: { signal: null, value: null } };
|
|
21
57
|
}
|
|
22
|
-
//# sourceMappingURL=versioning.js.map
|
package/dist/bridges/index.d.ts
CHANGED
package/dist/bridges/index.js
CHANGED
|
@@ -13,13 +13,13 @@ export declare const AI_CRAWLERS: readonly [{
|
|
|
13
13
|
readonly name: "CCBot";
|
|
14
14
|
readonly userAgent: "ccbot";
|
|
15
15
|
}, {
|
|
16
|
-
readonly id: "
|
|
17
|
-
readonly name: "
|
|
18
|
-
readonly userAgent: "
|
|
16
|
+
readonly id: "google_extended";
|
|
17
|
+
readonly name: "Google-Extended";
|
|
18
|
+
readonly userAgent: "google-extended";
|
|
19
19
|
}, {
|
|
20
|
-
readonly id: "
|
|
21
|
-
readonly name: "
|
|
22
|
-
readonly userAgent: "
|
|
20
|
+
readonly id: "applebot_extended";
|
|
21
|
+
readonly name: "Applebot-Extended";
|
|
22
|
+
readonly userAgent: "applebot-extended";
|
|
23
23
|
}, {
|
|
24
24
|
readonly id: "perplexitybot";
|
|
25
25
|
readonly name: "PerplexityBot";
|
|
@@ -28,9 +28,29 @@ export declare const AI_CRAWLERS: readonly [{
|
|
|
28
28
|
/**
|
|
29
29
|
* Evaluate per-AI-crawler policy from parsed robots.txt data.
|
|
30
30
|
*
|
|
31
|
-
* @param parsed - Parsed robots.txt result, or null if robots.txt was
|
|
32
|
-
* @param
|
|
31
|
+
* @param parsed - Parsed robots.txt result, or null if robots.txt was unavailable or absent
|
|
32
|
+
* @param coverage - whether a complete policy file was observed
|
|
33
33
|
* @returns Array of 6 Check objects, one per AI crawler
|
|
34
34
|
*/
|
|
35
|
-
export declare function evaluateCrawlerPolicies(parsed: RobotsTxtResult | null,
|
|
36
|
-
|
|
35
|
+
export declare function evaluateCrawlerPolicies(parsed: RobotsTxtResult | null, coverage?: DirectiveInventory["coverage"]): Check[];
|
|
36
|
+
/** Supplementary declarations, independent of the six scored crawler policies. */
|
|
37
|
+
declare const PURPOSE_TOKENS: readonly [readonly ["ChatGPT-User", "user-directed"], readonly ["Claude-User", "user-directed"], readonly ["OAI-SearchBot", "search"], readonly ["Claude-SearchBot", "search"], readonly ["GPTBot", "training"], readonly ["ClaudeBot", "training"]];
|
|
38
|
+
export type DirectiveInventory = {
|
|
39
|
+
coverage: "absent" | "unavailable" | "incomplete";
|
|
40
|
+
} | {
|
|
41
|
+
coverage: "parsed";
|
|
42
|
+
agents: ReturnType<typeof agentDeclarations>[];
|
|
43
|
+
};
|
|
44
|
+
declare function agentDeclarations(parsed: RobotsTxtResult, [token, purpose]: typeof PURPOSE_TOKENS[number]): {
|
|
45
|
+
token: "GPTBot" | "ClaudeBot" | "ChatGPT-User" | "Claude-User" | "OAI-SearchBot" | "Claude-SearchBot";
|
|
46
|
+
purpose: "search" | "user-directed" | "training";
|
|
47
|
+
matchedToken: string | null;
|
|
48
|
+
ruleCount: number;
|
|
49
|
+
rules: {
|
|
50
|
+
clipped?: boolean | undefined;
|
|
51
|
+
type: "allow" | "disallow";
|
|
52
|
+
path: string;
|
|
53
|
+
}[];
|
|
54
|
+
};
|
|
55
|
+
export declare function directiveInventory(parsed: RobotsTxtResult): DirectiveInventory;
|
|
56
|
+
export {};
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
// AI crawler policy evaluation from parsed robots.txt data
|
|
2
|
-
import {
|
|
2
|
+
import { isAllowed } from "./robots-parser.js";
|
|
3
|
+
// Product tokens checked December 2026. Google-Extended and Applebot-Extended govern use of crawled data.
|
|
4
|
+
// https://developers.google.com/crawling/docs/google-extended
|
|
5
|
+
// https://support.apple.com/en-ie/119829
|
|
3
6
|
export const AI_CRAWLERS = [
|
|
4
7
|
{ id: "gptbot", name: "GPTBot", userAgent: "gptbot" },
|
|
5
8
|
{ id: "claudebot", name: "ClaudeBot", userAgent: "claudebot" },
|
|
6
9
|
{ id: "ccbot", name: "CCBot", userAgent: "ccbot" },
|
|
7
|
-
{ id: "
|
|
8
|
-
{ id: "
|
|
10
|
+
{ id: "google_extended", name: "Google-Extended", userAgent: "google-extended" },
|
|
11
|
+
{ id: "applebot_extended", name: "Applebot-Extended", userAgent: "applebot-extended" },
|
|
9
12
|
{ id: "perplexitybot", name: "PerplexityBot", userAgent: "perplexitybot" },
|
|
10
13
|
];
|
|
11
14
|
/**
|
|
12
15
|
* Evaluate per-AI-crawler policy from parsed robots.txt data.
|
|
13
16
|
*
|
|
14
|
-
* @param parsed - Parsed robots.txt result, or null if robots.txt was
|
|
15
|
-
* @param
|
|
17
|
+
* @param parsed - Parsed robots.txt result, or null if robots.txt was unavailable or absent
|
|
18
|
+
* @param coverage - whether a complete policy file was observed
|
|
16
19
|
* @returns Array of 6 Check objects, one per AI crawler
|
|
17
20
|
*/
|
|
18
|
-
export function evaluateCrawlerPolicies(parsed,
|
|
21
|
+
export function evaluateCrawlerPolicies(parsed, coverage = parsed ? "parsed" : "absent") {
|
|
19
22
|
return AI_CRAWLERS.map((crawler) => {
|
|
20
23
|
const id = `crawler_policy_${crawler.id}`;
|
|
21
24
|
const label = `${crawler.name} Policy`;
|
|
22
|
-
if (unavailable)
|
|
23
|
-
return { id, label, status: "error", detail: "Could not evaluate crawler policy without robots.txt" };
|
|
24
|
-
// No
|
|
25
|
+
if (coverage === "unavailable" || coverage === "incomplete")
|
|
26
|
+
return { id, label, status: "error", detail: "Could not evaluate crawler policy without a complete robots.txt" };
|
|
27
|
+
// No published file: exclude this policy from scoring.
|
|
25
28
|
if (parsed === null) {
|
|
26
29
|
return {
|
|
27
30
|
id,
|
|
@@ -32,7 +35,7 @@ export function evaluateCrawlerPolicies(parsed, unavailable = false) {
|
|
|
32
35
|
};
|
|
33
36
|
}
|
|
34
37
|
// Find group matching this crawler
|
|
35
|
-
const rules =
|
|
38
|
+
const rules = matchingGroups(parsed, crawler.userAgent).flatMap(group => group.rules).filter(rule => rule.path !== "");
|
|
36
39
|
if (!rules.length) {
|
|
37
40
|
// No matching group at all -> allowed
|
|
38
41
|
return {
|
|
@@ -51,56 +54,38 @@ export function evaluateCrawlerPolicies(parsed, unavailable = false) {
|
|
|
51
54
|
* Find the most specific matching group for a crawler.
|
|
52
55
|
* Prefer crawler-specific group over * group (RFC 9309).
|
|
53
56
|
*/
|
|
54
|
-
function
|
|
57
|
+
function matchingGroups(parsed, userAgent) {
|
|
55
58
|
const specific = parsed.groups.filter((group) => group.userAgents.includes(userAgent));
|
|
56
|
-
|
|
57
|
-
return matching.flatMap((group) => group.rules).filter((rule) => rule.path !== "");
|
|
59
|
+
return specific.length ? specific : parsed.groups.filter(group => group.userAgents.includes("*"));
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
60
62
|
* Evaluate a crawler's policy from its matching group's rules.
|
|
61
63
|
*/
|
|
62
64
|
function evaluateGroupPolicy(rules, id, label) {
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
id,
|
|
91
|
-
label,
|
|
92
|
-
status: "fail",
|
|
93
|
-
detail: "Blocked",
|
|
94
|
-
data: { policy: "fail" },
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
// Non-root Disallow rules -> partial
|
|
98
|
-
return {
|
|
99
|
-
id,
|
|
100
|
-
label,
|
|
101
|
-
status: "partial",
|
|
102
|
-
detail: "Partially restricted",
|
|
103
|
-
data: { policy: "partial" },
|
|
104
|
-
};
|
|
65
|
+
// Equivalent rules resolve to Allow, independent of group and source order.
|
|
66
|
+
const allowedPatterns = new Set(rules.filter(r => r.type === "allow").map(r => r.path));
|
|
67
|
+
const restrictions = rules.filter(r => r.type === "disallow" && !allowedPatterns.has(r.path));
|
|
68
|
+
const blanketBlock = restrictions.some(r => /^\/\**$/.test(r.path) || r.path === "*");
|
|
69
|
+
const rootAllowed = isAllowed(rules, "/");
|
|
70
|
+
const status = !restrictions.length ? "pass" :
|
|
71
|
+
blanketBlock && !rootAllowed && !allowedPatterns.size ? "fail" : "partial";
|
|
72
|
+
const detail = { pass: "Allowed", partial: "Partially restricted", fail: "Blocked" }[status];
|
|
73
|
+
return { id, label, status, detail, data: { policy: status, rootAllowed } };
|
|
74
|
+
}
|
|
75
|
+
/** Supplementary declarations, independent of the six scored crawler policies. */
|
|
76
|
+
const PURPOSE_TOKENS = [
|
|
77
|
+
["ChatGPT-User", "user-directed"], ["Claude-User", "user-directed"],
|
|
78
|
+
["OAI-SearchBot", "search"], ["Claude-SearchBot", "search"],
|
|
79
|
+
["GPTBot", "training"], ["ClaudeBot", "training"],
|
|
80
|
+
];
|
|
81
|
+
function agentDeclarations(parsed, [token, purpose]) {
|
|
82
|
+
const key = token.toLowerCase();
|
|
83
|
+
const groups = matchingGroups(parsed, key);
|
|
84
|
+
const matchedToken = !groups.length ? null : groups[0].userAgents.includes(key) ? token : "*";
|
|
85
|
+
const declarations = groups.flatMap(group => group.rules).filter(rule => rule.path !== "");
|
|
86
|
+
const rules = declarations.slice(0, 8).map(({ type, path }) => ({ type, path: path.slice(0, 256), ...(path.length > 256 && { clipped: true }) }));
|
|
87
|
+
return { token, purpose, matchedToken, ruleCount: declarations.length, rules };
|
|
88
|
+
}
|
|
89
|
+
export function directiveInventory(parsed) {
|
|
90
|
+
return { coverage: "parsed", agents: PURPOSE_TOKENS.map(token => agentDeclarations(parsed, token)) };
|
|
105
91
|
}
|
|
106
|
-
//# sourceMappingURL=crawler-policy.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { Check, HttpResponse } from "../../core/types.js";
|
|
1
|
+
import type { Check, HttpErrorKind, HttpResponse } from "../../core/types.js";
|
|
2
|
+
/** Only the requested URL can establish its own unreachability. A redirect proves that it answered. */
|
|
3
|
+
export declare function transportFailureAt(response: HttpResponse, requestedUrl: string): HttpErrorKind | undefined;
|
|
2
4
|
/**
|
|
3
5
|
* Check HTTP status from a pre-fetched page response.
|
|
4
6
|
* Does NOT make any HTTP calls -- takes the already-fetched response.
|
|
5
7
|
*/
|
|
6
8
|
export declare function checkHttpStatus(pageResponse: HttpResponse): Check;
|
|
7
|
-
//# sourceMappingURL=http-status.d.ts.map
|