@jini-ai/http-kit 0.7.2 → 0.7.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -10
- package/README.md +6 -6
- package/dist/adapter.d.ts +7 -50
- package/dist/adapter.js +12 -54
- package/dist/api-security-middleware.d.ts +0 -16
- package/dist/api-security-middleware.js +2 -18
- package/dist/index.d.ts +10 -15
- package/dist/index.js +7 -10
- package/dist/internal-error.d.ts +42 -0
- package/dist/internal-error.js +48 -0
- package/dist/local-daemon-request.d.ts +11 -4
- package/dist/local-daemon-request.js +1 -28
- package/dist/middleware.d.ts +1 -0
- package/dist/middleware.js +1 -0
- package/dist/node-bridge.d.ts +108 -0
- package/dist/node-bridge.js +356 -0
- package/dist/observability.d.ts +3 -14
- package/dist/origin.d.ts +13 -30
- package/dist/origin.js +13 -13
- package/dist/range.d.ts +53 -0
- package/dist/range.js +93 -0
- package/dist/rate-limit.d.ts +1 -13
- package/dist/rate-limit.js +5 -2
- package/dist/request.d.ts +2 -13
- package/dist/request.js +0 -13
- package/dist/response.d.ts +8 -7
- package/dist/response.js +0 -36
- package/dist/route-registration-guard.d.ts +14 -0
- package/dist/route-registration-guard.js +17 -0
- package/dist/run-credentials.d.ts +73 -0
- package/dist/run-credentials.js +71 -0
- package/dist/settings/contracts.d.ts +49 -0
- package/dist/settings/contracts.js +2 -0
- package/dist/settings/http-request.d.ts +36 -0
- package/dist/settings/http-request.js +50 -0
- package/dist/settings/http.d.ts +10 -0
- package/dist/settings/http.js +216 -0
- package/dist/settings/index.d.ts +4 -0
- package/dist/settings/index.js +3 -0
- package/dist/settings/shared.d.ts +16 -0
- package/dist/settings/shared.js +16 -0
- package/dist/settings/stream.d.ts +25 -0
- package/dist/settings/stream.js +180 -0
- package/dist/sse.d.ts +1 -15
- package/dist/sse.js +77 -72
- package/dist/trust-proxy.d.ts +36 -0
- package/dist/trust-proxy.js +45 -0
- package/dist/types.d.ts +4 -52
- package/dist/types.js +1 -4
- package/package.json +24 -14
- package/dist/active-context.d.ts +0 -99
- package/dist/active-context.js +0 -77
- package/dist/agents.d.ts +0 -64
- package/dist/agents.js +0 -23
- package/dist/attachments.d.ts +0 -534
- package/dist/attachments.js +0 -1032
- package/dist/cancel-owned-runs.d.ts +0 -44
- package/dist/cancel-owned-runs.js +0 -35
- package/dist/component-catalog.d.ts +0 -74
- package/dist/component-catalog.js +0 -74
- package/dist/connectors.d.ts +0 -165
- package/dist/connectors.js +0 -474
- package/dist/daemon-status.d.ts +0 -72
- package/dist/daemon-status.js +0 -60
- package/dist/db-ops.d.ts +0 -116
- package/dist/db-ops.js +0 -191
- package/dist/delegated-tools.d.ts +0 -146
- package/dist/delegated-tools.js +0 -286
- package/dist/frontend-control.d.ts +0 -131
- package/dist/frontend-control.js +0 -77
- package/dist/frontend-sessions.d.ts +0 -100
- package/dist/frontend-sessions.js +0 -180
- package/dist/health.d.ts +0 -91
- package/dist/health.js +0 -53
- package/dist/host-tools.d.ts +0 -174
- package/dist/host-tools.js +0 -338
- package/dist/media.d.ts +0 -131
- package/dist/media.js +0 -352
- package/dist/memory.d.ts +0 -230
- package/dist/memory.js +0 -331
- package/dist/model-proxy.d.ts +0 -45
- package/dist/model-proxy.js +0 -619
- package/dist/origin-validation.d.ts +0 -64
- package/dist/origin-validation.js +0 -226
- package/dist/raw-sse.d.ts +0 -49
- package/dist/raw-sse.js +0 -92
- package/dist/read-only-tools.d.ts +0 -67
- package/dist/read-only-tools.js +0 -59
- package/dist/remote-run-events.d.ts +0 -66
- package/dist/remote-run-events.js +0 -230
- package/dist/research.d.ts +0 -42
- package/dist/research.js +0 -316
- package/dist/route-manifest.d.ts +0 -31
- package/dist/route-manifest.js +0 -103
- package/dist/routines.d.ts +0 -114
- package/dist/routines.js +0 -320
- package/dist/runs.d.ts +0 -79
- package/dist/runs.js +0 -232
- package/dist/terminals.d.ts +0 -125
- package/dist/terminals.js +0 -349
- package/dist/tool-catalog.d.ts +0 -68
- package/dist/tool-catalog.js +0 -68
- package/dist/verified-origin/configured-origin.d.ts +0 -37
- package/dist/verified-origin/configured-origin.js +0 -99
- package/dist/verified-origin/index.d.ts +0 -7
- package/dist/verified-origin/index.js +0 -6
- package/dist/verified-origin/loopback-host.d.ts +0 -9
- package/dist/verified-origin/loopback-host.js +0 -17
- package/dist/verified-origin/origin.d.ts +0 -64
- package/dist/verified-origin/origin.js +0 -162
- package/dist/verified-origin/ports.d.ts +0 -38
- package/dist/verified-origin/ports.js +0 -2
- package/dist/verified-origin/repo.memory.d.ts +0 -32
- package/dist/verified-origin/repo.memory.js +0 -34
- package/dist/verified-origin/site-path.d.ts +0 -113
- package/dist/verified-origin/site-path.js +0 -188
- package/dist/verified-origin/types.d.ts +0 -33
- package/dist/verified-origin/types.js +0 -30
- package/dist/verified-origin.d.ts +0 -2
- package/dist/verified-origin.js +0 -2
- package/dist/workspace-root.d.ts +0 -69
- package/dist/workspace-root.js +0 -63
- package/dist/xai.d.ts +0 -86
- package/dist/xai.js +0 -668
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** Public identity must not name a development listener. Normalize URL spellings first so
|
|
2
|
-
* shortened IPv4 and IPv4-mapped IPv6 cannot bypass the same rule used for localhost.
|
|
3
|
-
* Private intranet hosts remain valid. Invalid hosts are left to the caller's URL validation.
|
|
4
|
-
* @complexity O(host bytes), pure; parse failures return false.
|
|
5
|
-
*/
|
|
6
|
-
export function isLoopbackHost({ host }, _options = {}) {
|
|
7
|
-
let hostname;
|
|
8
|
-
const authority = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
9
|
-
try {
|
|
10
|
-
hostname = new URL(`http://${authority}`).hostname.toLowerCase().replace(/\.$/, "");
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return /^(?:localhost|.*\.localhost|127\.\d+\.\d+\.\d+|0\.0\.0\.0|\[(?:::1|::|::ffff:7f[\da-f]{2}:[\da-f]+)\])$/.test(hostname);
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=loopback-host.js.map
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { VerifiedOriginRequestContext, OriginRegistryPort, OriginSettingRepoPort, RedirectTargetContext, EgressTargetContext } from "./ports.js";
|
|
2
|
-
import { type VerifiedOrigin } from "./types.js";
|
|
3
|
-
export interface NormalizedTarget {
|
|
4
|
-
scheme: "https" | "http";
|
|
5
|
-
host: string;
|
|
6
|
-
port: number;
|
|
7
|
-
}
|
|
8
|
-
/** Reject parser-ambiguous backslashes, whitespace and controls before URL normalization.
|
|
9
|
-
* @complexity O(raw.length) time, O(1) space; pure.
|
|
10
|
-
* @example hasForbiddenRawUrlCharacter({ raw: "/a b" }); // true
|
|
11
|
-
*/
|
|
12
|
-
export declare function hasForbiddenRawUrlCharacter({ raw }: {
|
|
13
|
-
raw: string;
|
|
14
|
-
}): boolean;
|
|
15
|
-
/** Normalize absolute HTTP(S) candidates, refusing ambiguous input and userinfo with null.
|
|
16
|
-
* HTTP normalization enables development same-origin checks; cross-origin decisions require HTTPS.
|
|
17
|
-
* @complexity O(rawUrl.length) time; parser-bound space. Pure; parse errors return null.
|
|
18
|
-
* @example normalizeOriginCandidate({ rawUrl: "https://Example.com./path" });
|
|
19
|
-
*/
|
|
20
|
-
export declare function normalizeOriginCandidate({ rawUrl }: {
|
|
21
|
-
rawUrl: string;
|
|
22
|
-
}): NormalizedTarget | null;
|
|
23
|
-
/** Compare scheme, normalized host and effective port against trusted evidence.
|
|
24
|
-
* The target must already be normalized by normalizeOriginCandidate; basePath is not an origin boundary.
|
|
25
|
-
* @complexity O(canonical.host.length) time and space; pure.
|
|
26
|
-
* @example isSameOrigin({ target, canonical });
|
|
27
|
-
*/
|
|
28
|
-
export declare function isSameOrigin({ target, canonical }: {
|
|
29
|
-
target: NormalizedTarget;
|
|
30
|
-
canonical: VerifiedOrigin;
|
|
31
|
-
}): boolean;
|
|
32
|
-
export interface OriginRegistryDeps {
|
|
33
|
-
repo: OriginSettingRepoPort;
|
|
34
|
-
}
|
|
35
|
-
/** Canonical-origin and independent redirect/egress decisions over caller-owned storage.
|
|
36
|
-
* @example new OriginRegistry({ repo });
|
|
37
|
-
*/
|
|
38
|
-
export declare class OriginRegistry implements OriginRegistryPort {
|
|
39
|
-
private readonly repo;
|
|
40
|
-
constructor(deps: OriginRegistryDeps);
|
|
41
|
-
/** Resolve stored evidence or throw OriginNotVerifiedError; never derive trust from request headers.
|
|
42
|
-
* One repository lookup; O(1) additional time/space excluding the adapter.
|
|
43
|
-
*/
|
|
44
|
-
canonicalOrigin(ctx: VerifiedOriginRequestContext): Promise<VerifiedOrigin>;
|
|
45
|
-
/** Allow the canonical origin or an exact redirect-allowlist HTTPS host; errors return false.
|
|
46
|
-
* @complexity O(URL length + allowlist host bytes) time/space; at most two repository reads.
|
|
47
|
-
*/
|
|
48
|
-
isAllowedRedirectTarget({ context: ctx, url }: {
|
|
49
|
-
context: RedirectTargetContext;
|
|
50
|
-
url: string;
|
|
51
|
-
}): Promise<boolean>;
|
|
52
|
-
/** Apply the same fail-closed rule using the separate egress destination allowlist.
|
|
53
|
-
* @complexity O(URL length + allowlist host bytes) time/space; at most two repository reads.
|
|
54
|
-
*/
|
|
55
|
-
isAllowedEgressTarget({ context: ctx, url }: {
|
|
56
|
-
context: EgressTargetContext;
|
|
57
|
-
url: string;
|
|
58
|
-
}): Promise<boolean>;
|
|
59
|
-
/** Normalize before looking up trust, then check same origin before the HTTPS-only host allowlist.
|
|
60
|
-
* Storage/parse errors return false; O(URL length + allowlist host bytes) time/space.
|
|
61
|
-
*/
|
|
62
|
-
private isAllowedTarget;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=origin.d.ts.map
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { OriginNotVerifiedError, createVerifiedOrigin } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Check the original string before the WHATWG parser strips whitespace/controls or converts a
|
|
4
|
-
* backslash to a slash. A stored backslash plus a request tail can become a browser-followed
|
|
5
|
-
* cross-host Location even when a parsed-path check sees only slashes. Storage validation and
|
|
6
|
-
* redirect reads must use this same raw predicate; checking a reserialized url.href checks too late.
|
|
7
|
-
*/
|
|
8
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex: control chars are the POINT — F3 requires rejecting C0/DEL and backslash in a raw candidate URL before the WHATWG parser silently strips them. See this constant's own doc comment. See docs/decisions/DR-001-redirect-normalization.md.
|
|
9
|
-
const FORBIDDEN_RAW_CHARS = /[\\\s\x00-\x08\x0E-\x1F\x7F]/;
|
|
10
|
-
/** Reject parser-ambiguous backslashes, whitespace and controls before URL normalization.
|
|
11
|
-
* @complexity O(raw.length) time, O(1) space; pure.
|
|
12
|
-
* @example hasForbiddenRawUrlCharacter({ raw: "/a b" }); // true
|
|
13
|
-
*/
|
|
14
|
-
export function hasForbiddenRawUrlCharacter({ raw }) {
|
|
15
|
-
return FORBIDDEN_RAW_CHARS.test(raw);
|
|
16
|
-
}
|
|
17
|
-
function parseCandidateUrl(rawUrl) {
|
|
18
|
-
if (typeof rawUrl !== "string" || rawUrl.length === 0)
|
|
19
|
-
return null;
|
|
20
|
-
if (hasForbiddenRawUrlCharacter({ raw: rawUrl }))
|
|
21
|
-
return null;
|
|
22
|
-
try {
|
|
23
|
-
return new URL(rawUrl);
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function schemeOf(parsed) {
|
|
30
|
-
if (parsed.protocol === "https:")
|
|
31
|
-
return "https";
|
|
32
|
-
if (parsed.protocol === "http:")
|
|
33
|
-
return "http";
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
function defaultPortFor(scheme) {
|
|
37
|
-
return scheme === "https" ? 443 : 80;
|
|
38
|
-
}
|
|
39
|
-
// Explicit ports and scheme defaults (443 for HTTPS, 80 for HTTP) must compare identically.
|
|
40
|
-
function resolvePort(parsed, scheme) {
|
|
41
|
-
const port = parsed.port ? Number(parsed.port) : defaultPortFor(scheme);
|
|
42
|
-
if (!Number.isInteger(port) || port <= 0)
|
|
43
|
-
return null;
|
|
44
|
-
return port;
|
|
45
|
-
}
|
|
46
|
-
// WHATWG parsing performs IDNA/case normalization; the remaining single trailing DNS dot must
|
|
47
|
-
// be removed consistently from candidates, trusted origins and allowlists.
|
|
48
|
-
/** Normalize absolute HTTP(S) candidates, refusing ambiguous input and userinfo with null.
|
|
49
|
-
* HTTP normalization enables development same-origin checks; cross-origin decisions require HTTPS.
|
|
50
|
-
* @complexity O(rawUrl.length) time; parser-bound space. Pure; parse errors return null.
|
|
51
|
-
* @example normalizeOriginCandidate({ rawUrl: "https://Example.com./path" });
|
|
52
|
-
*/
|
|
53
|
-
export function normalizeOriginCandidate({ rawUrl }) {
|
|
54
|
-
const parsed = parseCandidateUrl(rawUrl);
|
|
55
|
-
if (!parsed)
|
|
56
|
-
return null;
|
|
57
|
-
const scheme = schemeOf(parsed);
|
|
58
|
-
if (!scheme)
|
|
59
|
-
return null;
|
|
60
|
-
if (parsed.username !== "" || parsed.password !== "")
|
|
61
|
-
return null;
|
|
62
|
-
const host = stripTrailingDot(parsed.hostname.toLowerCase());
|
|
63
|
-
if (!host)
|
|
64
|
-
return null;
|
|
65
|
-
const port = resolvePort(parsed, scheme);
|
|
66
|
-
if (port === null)
|
|
67
|
-
return null;
|
|
68
|
-
return { scheme, host, port };
|
|
69
|
-
}
|
|
70
|
-
function stripTrailingDot(host) {
|
|
71
|
-
return host.endsWith(".") ? host.slice(0, -1) : host;
|
|
72
|
-
}
|
|
73
|
-
/** Normalize a bare allowlisted host through the candidate's WHATWG/IDNA policy.
|
|
74
|
-
* URL delimiters and ports are not host entries; colons are valid only inside bracketed IPv6.
|
|
75
|
-
* Returns null for invalid entries; pure, O(host.length) time and space.
|
|
76
|
-
*/
|
|
77
|
-
function normalizeAllowlistedHost({ host }, _optional = {}) {
|
|
78
|
-
const value = host.trim();
|
|
79
|
-
if (/[/\\?#@%]/u.test(value))
|
|
80
|
-
return null;
|
|
81
|
-
if (value.includes(":") && !value.endsWith("]"))
|
|
82
|
-
return null;
|
|
83
|
-
return normalizeOriginCandidate({ rawUrl: `https://${value}` })?.host ?? null;
|
|
84
|
-
}
|
|
85
|
-
function effectivePort(origin) {
|
|
86
|
-
return origin.port ?? (origin.scheme === "https" ? 443 : 80);
|
|
87
|
-
}
|
|
88
|
-
// URL.origin strings preserve a trailing dot: https://site. and https://site reach the same
|
|
89
|
-
// server even though browsers keep their cookie/script origins separate. This destination rule
|
|
90
|
-
// compares normalized hosts so redirect validation and reserved-destination checks cannot disagree.
|
|
91
|
-
/** Compare scheme, normalized host and effective port against trusted evidence.
|
|
92
|
-
* The target must already be normalized by normalizeOriginCandidate; basePath is not an origin boundary.
|
|
93
|
-
* @complexity O(canonical.host.length) time and space; pure.
|
|
94
|
-
* @example isSameOrigin({ target, canonical });
|
|
95
|
-
*/
|
|
96
|
-
export function isSameOrigin({ target, canonical }) {
|
|
97
|
-
if (canonical.scheme !== target.scheme)
|
|
98
|
-
return false;
|
|
99
|
-
if (stripTrailingDot(canonical.host.toLowerCase()) !== target.host)
|
|
100
|
-
return false;
|
|
101
|
-
return effectivePort(canonical) === target.port;
|
|
102
|
-
}
|
|
103
|
-
/** Canonical-origin and independent redirect/egress decisions over caller-owned storage.
|
|
104
|
-
* @example new OriginRegistry({ repo });
|
|
105
|
-
*/
|
|
106
|
-
export class OriginRegistry {
|
|
107
|
-
repo;
|
|
108
|
-
constructor(deps) {
|
|
109
|
-
this.repo = deps.repo;
|
|
110
|
-
}
|
|
111
|
-
// This repository selects one origin per workspace; optional site/locale/origin keys do not
|
|
112
|
-
// currently select a different origin. Missing evidence must not trigger request-host guessing.
|
|
113
|
-
/** Resolve stored evidence or throw OriginNotVerifiedError; never derive trust from request headers.
|
|
114
|
-
* One repository lookup; O(1) additional time/space excluding the adapter.
|
|
115
|
-
*/
|
|
116
|
-
async canonicalOrigin(ctx) {
|
|
117
|
-
const origin = await this.repo.findByWorkspaceId({ workspaceId: ctx.workspaceId });
|
|
118
|
-
if (!origin) {
|
|
119
|
-
throw new OriginNotVerifiedError({ message: `no verified origin registered for workspace '${ctx.workspaceId}'` });
|
|
120
|
-
}
|
|
121
|
-
return createVerifiedOrigin(origin);
|
|
122
|
-
}
|
|
123
|
-
/** Allow the canonical origin or an exact redirect-allowlist HTTPS host; errors return false.
|
|
124
|
-
* @complexity O(URL length + allowlist host bytes) time/space; at most two repository reads.
|
|
125
|
-
*/
|
|
126
|
-
async isAllowedRedirectTarget({ context: ctx, url }) {
|
|
127
|
-
return this.isAllowedTarget(ctx, url, (workspaceId) => this.repo.findRedirectAllowlist({ workspaceId }));
|
|
128
|
-
}
|
|
129
|
-
/** Apply the same fail-closed rule using the separate egress destination allowlist.
|
|
130
|
-
* @complexity O(URL length + allowlist host bytes) time/space; at most two repository reads.
|
|
131
|
-
*/
|
|
132
|
-
async isAllowedEgressTarget({ context: ctx, url }) {
|
|
133
|
-
return this.isAllowedTarget(ctx, url, (workspaceId) => this.repo.findEgressAllowlist({ workspaceId }));
|
|
134
|
-
}
|
|
135
|
-
/** Normalize before looking up trust, then check same origin before the HTTPS-only host allowlist.
|
|
136
|
-
* Storage/parse errors return false; O(URL length + allowlist host bytes) time/space.
|
|
137
|
-
*/
|
|
138
|
-
async isAllowedTarget(ctx, rawUrl, loadAllowlist) {
|
|
139
|
-
try {
|
|
140
|
-
const target = normalizeOriginCandidate({ rawUrl });
|
|
141
|
-
if (!target)
|
|
142
|
-
return false;
|
|
143
|
-
const canonical = await this.canonicalOrigin({ workspaceId: ctx.workspaceId, ...(ctx.siteId === undefined ? {} : { siteId: ctx.siteId }) });
|
|
144
|
-
if (isSameOrigin({ target, canonical }))
|
|
145
|
-
return true;
|
|
146
|
-
// Cross-origin allowlist path is https-only, unconditionally — the. See docs/decisions/DR-001-redirect-normalization.md.
|
|
147
|
-
// dev-capability http exception above applies ONLY to the same-origin comparison, never
|
|
148
|
-
// to a cross-origin allowlisted target. See docs/decisions/DR-001-redirect-normalization.md.
|
|
149
|
-
if (target.scheme !== "https")
|
|
150
|
-
return false;
|
|
151
|
-
const allowlist = await loadAllowlist(ctx.workspaceId);
|
|
152
|
-
const allowSet = new Set(allowlist.map((host) => normalizeAllowlistedHost({ host })));
|
|
153
|
-
return allowSet.has(target.host);
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
// Fail closed: an unverified origin, a repo error, or any unexpected
|
|
157
|
-
// exception must never be treated as "allowed".
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
//# sourceMappingURL=origin.js.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { VerifiedOrigin } from "./types.js";
|
|
2
|
-
export interface VerifiedOriginRequestContext {
|
|
3
|
-
workspaceId: string;
|
|
4
|
-
siteId?: string;
|
|
5
|
-
locale?: string;
|
|
6
|
-
}
|
|
7
|
-
export interface RedirectTargetContext {
|
|
8
|
-
workspaceId: string;
|
|
9
|
-
siteId?: string;
|
|
10
|
-
originKey?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface EgressTargetContext {
|
|
13
|
-
workspaceId: string;
|
|
14
|
-
siteId?: string;
|
|
15
|
-
}
|
|
16
|
-
export interface OriginRegistryPort {
|
|
17
|
-
canonicalOrigin(ctx: VerifiedOriginRequestContext): Promise<VerifiedOrigin>;
|
|
18
|
-
isAllowedRedirectTarget(required: {
|
|
19
|
-
context: RedirectTargetContext;
|
|
20
|
-
url: string;
|
|
21
|
-
}): Promise<boolean>;
|
|
22
|
-
isAllowedEgressTarget(required: {
|
|
23
|
-
context: EgressTargetContext;
|
|
24
|
-
url: string;
|
|
25
|
-
}): Promise<boolean>;
|
|
26
|
-
}
|
|
27
|
-
export interface OriginSettingRepoPort {
|
|
28
|
-
findByWorkspaceId(required: {
|
|
29
|
-
workspaceId: string;
|
|
30
|
-
}): Promise<VerifiedOrigin | null>;
|
|
31
|
-
findRedirectAllowlist(required: {
|
|
32
|
-
workspaceId: string;
|
|
33
|
-
}): Promise<string[]>;
|
|
34
|
-
findEgressAllowlist(required: {
|
|
35
|
-
workspaceId: string;
|
|
36
|
-
}): Promise<string[]>;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { OriginSettingRepoPort } from "./ports.js";
|
|
2
|
-
import { type VerifiedOrigin } from "./types.js";
|
|
3
|
-
export interface OriginSettingSeed {
|
|
4
|
-
workspaceId: string;
|
|
5
|
-
origin: VerifiedOrigin;
|
|
6
|
-
/** Exact-match hosts trusted for cross-origin redirects; independent of third-party egress. */
|
|
7
|
-
redirectAllowlist?: string[];
|
|
8
|
-
/** Exact-match hosts trusted for third-party egress; redirect permission alone does not grant it. */
|
|
9
|
-
egressAllowlist?: string[];
|
|
10
|
-
}
|
|
11
|
-
/** Seeded read adapter that returns copies of origins and lists to protect stored trust.
|
|
12
|
-
* Reads are O(1) for an origin, O(k) for an allowlist; construction is O(total seed host bytes).
|
|
13
|
-
* @example new InMemoryOriginSettingRepo({ seeds: [{ workspaceId, origin }] });
|
|
14
|
-
*/
|
|
15
|
-
export declare class InMemoryOriginSettingRepo implements OriginSettingRepoPort {
|
|
16
|
-
private readonly origins;
|
|
17
|
-
private readonly redirectAllowlists;
|
|
18
|
-
private readonly egressAllowlists;
|
|
19
|
-
constructor({ seeds }: {
|
|
20
|
-
seeds: readonly OriginSettingSeed[];
|
|
21
|
-
});
|
|
22
|
-
findByWorkspaceId({ workspaceId }: {
|
|
23
|
-
workspaceId: string;
|
|
24
|
-
}): Promise<VerifiedOrigin | null>;
|
|
25
|
-
findRedirectAllowlist({ workspaceId }: {
|
|
26
|
-
workspaceId: string;
|
|
27
|
-
}): Promise<string[]>;
|
|
28
|
-
findEgressAllowlist({ workspaceId }: {
|
|
29
|
-
workspaceId: string;
|
|
30
|
-
}): Promise<string[]>;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=repo.memory.d.ts.map
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { createVerifiedOrigin } from "./types.js";
|
|
2
|
-
/** Seeded read adapter that returns copies of origins and lists to protect stored trust.
|
|
3
|
-
* Reads are O(1) for an origin, O(k) for an allowlist; construction is O(total seed host bytes).
|
|
4
|
-
* @example new InMemoryOriginSettingRepo({ seeds: [{ workspaceId, origin }] });
|
|
5
|
-
*/
|
|
6
|
-
export class InMemoryOriginSettingRepo {
|
|
7
|
-
origins;
|
|
8
|
-
redirectAllowlists;
|
|
9
|
-
egressAllowlists;
|
|
10
|
-
constructor({ seeds }) {
|
|
11
|
-
this.origins = new Map();
|
|
12
|
-
this.redirectAllowlists = new Map();
|
|
13
|
-
this.egressAllowlists = new Map();
|
|
14
|
-
for (const seed of seeds) {
|
|
15
|
-
this.origins.set(seed.workspaceId, createVerifiedOrigin(seed.origin));
|
|
16
|
-
this.redirectAllowlists.set(seed.workspaceId, normalizeHostList(seed.redirectAllowlist));
|
|
17
|
-
this.egressAllowlists.set(seed.workspaceId, normalizeHostList(seed.egressAllowlist));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async findByWorkspaceId({ workspaceId }) {
|
|
21
|
-
const origin = this.origins.get(workspaceId);
|
|
22
|
-
return origin ? { ...origin } : null;
|
|
23
|
-
}
|
|
24
|
-
async findRedirectAllowlist({ workspaceId }) {
|
|
25
|
-
return [...(this.redirectAllowlists.get(workspaceId) ?? [])];
|
|
26
|
-
}
|
|
27
|
-
async findEgressAllowlist({ workspaceId }) {
|
|
28
|
-
return [...(this.egressAllowlists.get(workspaceId) ?? [])];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function normalizeHostList(hosts) {
|
|
32
|
-
return (hosts ?? []).map((host) => host.trim().toLowerCase());
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=repo.memory.js.map
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Shared site-path checks: decoded, dot-resolved segments and origin tracking.
|
|
3
|
-
*
|
|
4
|
-
* Why the rule is not `path.startsWith("/admin")`:
|
|
5
|
-
* - `/administer-survey` is ordinary site content and must keep working, so the comparison is per
|
|
6
|
-
* SEGMENT, not per prefix.
|
|
7
|
-
* - `/%61dmin` is compared AFTER one percent-decode, not on the raw bytes. Express (which routes on
|
|
8
|
-
* the raw path) and browsers (which do not decode `%61` in a path) do NOT treat it as `/admin`; a
|
|
9
|
-
* proxy or server that decodes before routing does. Refusing it is deliberate over-refusal — the
|
|
10
|
-
* safe direction for a rule whose job is to keep public redirects and fetches off the admin
|
|
11
|
-
* surface.
|
|
12
|
-
* - `/ADMIN` reaches the same Express mount (Express matches paths case-insensitively by default),
|
|
13
|
-
* so the comparison is case-folded.
|
|
14
|
-
* - `/blog/../admin` is `/admin` by the time a browser issues the request, so dot segments are
|
|
15
|
-
* resolved first.
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
/** {@link checkSitePathname}'s verdict. Every arm is a refusal except `ok`. */
|
|
19
|
-
export type SitePathCheck = {
|
|
20
|
-
kind: "ok";
|
|
21
|
-
}
|
|
22
|
-
/** `decodeURIComponent` threw — a stray or truncated `%` sequence. */
|
|
23
|
-
| {
|
|
24
|
-
kind: "malformed-encoding";
|
|
25
|
-
}
|
|
26
|
-
/** Decodes to a backslash (a `/` to URL parsers) or a C0/C1 control character (CR/LF splitting). */
|
|
27
|
-
| {
|
|
28
|
-
kind: "disallowed-character";
|
|
29
|
-
} | {
|
|
30
|
-
kind: "reserved";
|
|
31
|
-
surface: string;
|
|
32
|
-
};
|
|
33
|
-
/** {@link checkSiteRelativeTarget}'s verdict — {@link SitePathCheck} plus the two structural arms
|
|
34
|
-
* that only apply when the input is still a raw, unparsed reference. */
|
|
35
|
-
export type SiteRelativeTargetCheck = SitePathCheck
|
|
36
|
-
/** `new URL()` could not parse it at all. */
|
|
37
|
-
| {
|
|
38
|
-
kind: "unparseable";
|
|
39
|
-
}
|
|
40
|
-
/** Parses, but resolves to a DIFFERENT host — e.g. `/\evil.example`, which starts with a single
|
|
41
|
-
* slash yet is `//evil.example` to a URL parser, so a `startsWith("//")` test never sees it. */
|
|
42
|
-
| {
|
|
43
|
-
kind: "off-origin";
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Whether `value` contains a C0 or C1 control character.
|
|
47
|
-
*
|
|
48
|
-
* CR/LF in a request target is HTTP request splitting and in a `Location` header is response
|
|
49
|
-
* splitting; NUL and friends are path-truncation tricks.
|
|
50
|
-
*
|
|
51
|
-
* @param required.value - Any string, already decoded or not.
|
|
52
|
-
* @returns `true` if any code unit is in `U+0000`–`U+001F` or `U+007F`–`U+009F`.
|
|
53
|
-
* @complexity O(n) in the string length.
|
|
54
|
-
* @example hasControlCharacter({ value: "/ok" }, {}); // => false
|
|
55
|
-
*/
|
|
56
|
-
export declare function hasControlCharacter({ value }: {
|
|
57
|
-
value: string;
|
|
58
|
-
}, _optional?: Record<string, never>): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Classify an already-parsed URL's pathname against the admin application's URL space.
|
|
61
|
-
*
|
|
62
|
-
* Takes the {@link URL} itself, not a bare pathname string, so this cannot be handed a raw,
|
|
63
|
-
* unparsed reference by accident: a string has no way to prove it went through `new URL()` first,
|
|
64
|
-
* and this rule's whole design (see the module doc) depends on comparing the DECODED, dot-resolved
|
|
65
|
-
* form a URL parser would actually produce. A caller that only has a raw string — a stored redirect
|
|
66
|
-
* target, anything from user input — must go through {@link checkSiteRelativeTarget} instead, which
|
|
67
|
-
* parses it (and rejects what doesn't parse) before this check ever runs.
|
|
68
|
-
*
|
|
69
|
-
* PRECONDITION: the caller has already established that `url` is on the site's own origin. This
|
|
70
|
-
* function reads only `pathname`, so `new URL("//admin", base)` (host `admin`, pathname `/`)
|
|
71
|
-
* returns `ok`. It deliberately does not compare origins itself: `platform/routing` cannot use
|
|
72
|
-
* `features/origin`'s normalizer, and a string `URL.origin` comparison is wrong for redirect
|
|
73
|
-
* candidates (`https://site./admin`). Callers: `checkSiteRelativeTarget` (probe-origin check),
|
|
74
|
-
* `site-inspection`'s `resolveWithinOrigin`, and `features/redirects/reserved-destination.ts` (the
|
|
75
|
-
* origin oracle's `isSameOrigin`).
|
|
76
|
-
*
|
|
77
|
-
* @param required.url - An already-parsed `URL`; only `url.pathname` is read.
|
|
78
|
-
* @param required.reservedSegments - First segments reserved by the host, stored case-folded.
|
|
79
|
-
* @returns `{ kind: "ok" }` when it is ordinary site content; otherwise the arm naming the refusal.
|
|
80
|
-
* @complexity O(n) in the pathname length.
|
|
81
|
-
* @example checkSitePathname({ url: new URL("/administer-survey", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
|
|
82
|
-
* @example checkSitePathname({ url: new URL("/%61dmin/settings", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "reserved", surface: "admin" }
|
|
83
|
-
*/
|
|
84
|
-
export declare function checkSitePathname({ url, reservedSegments }: {
|
|
85
|
-
url: URL;
|
|
86
|
-
reservedSegments: ReadonlySet<string>;
|
|
87
|
-
}, _optional?: Record<string, never>): SitePathCheck;
|
|
88
|
-
/**
|
|
89
|
-
* Classify a raw, site-relative reference (a stored redirect target, a caller-supplied path)
|
|
90
|
-
* against the admin application's URL space, including the structural check that it is site-
|
|
91
|
-
* relative at all.
|
|
92
|
-
*
|
|
93
|
-
* The structural pass runs FIRST and matters on its own: `/\evil.example` begins with exactly one
|
|
94
|
-
* slash, so a `startsWith("//")` or scheme test calls it site-relative, while `new URL()` — and
|
|
95
|
-
* every browser following a `Location` — reads the backslash as a separator and lands on
|
|
96
|
-
* `evil.example`. Resolving against a probe origin and asserting the origin TRACKED that base is a
|
|
97
|
-
* structural answer to that instead of a pattern someone has to keep correct — done against two
|
|
98
|
-
* different bases so the probe origin itself is not a nameable way to pass (see
|
|
99
|
-
* {@link PROBE_ORIGIN}).
|
|
100
|
-
*
|
|
101
|
-
* @param required.raw - The untrusted reference, expected to be site-relative.
|
|
102
|
-
* @param required.reservedSegments - First segments reserved by the host, stored case-folded.
|
|
103
|
-
* @returns `{ kind: "ok" }` when it stays on this site and names ordinary content; otherwise the
|
|
104
|
-
* arm naming the refusal.
|
|
105
|
-
* @complexity O(n) in the reference length.
|
|
106
|
-
* @example checkSiteRelativeTarget({ raw: "/new", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
|
|
107
|
-
* @example checkSiteRelativeTarget({ raw: "/\\evil.example", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "off-origin" }
|
|
108
|
-
*/
|
|
109
|
-
export declare function checkSiteRelativeTarget({ raw, reservedSegments }: {
|
|
110
|
-
raw: string;
|
|
111
|
-
reservedSegments: ReadonlySet<string>;
|
|
112
|
-
}, _optional?: Record<string, never>): SiteRelativeTargetCheck;
|
|
113
|
-
//# sourceMappingURL=site-path.d.ts.map
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Shared site-path checks: decoded, dot-resolved segments and origin tracking.
|
|
3
|
-
*
|
|
4
|
-
* Why the rule is not `path.startsWith("/admin")`:
|
|
5
|
-
* - `/administer-survey` is ordinary site content and must keep working, so the comparison is per
|
|
6
|
-
* SEGMENT, not per prefix.
|
|
7
|
-
* - `/%61dmin` is compared AFTER one percent-decode, not on the raw bytes. Express (which routes on
|
|
8
|
-
* the raw path) and browsers (which do not decode `%61` in a path) do NOT treat it as `/admin`; a
|
|
9
|
-
* proxy or server that decodes before routing does. Refusing it is deliberate over-refusal — the
|
|
10
|
-
* safe direction for a rule whose job is to keep public redirects and fetches off the admin
|
|
11
|
-
* surface.
|
|
12
|
-
* - `/ADMIN` reaches the same Express mount (Express matches paths case-insensitively by default),
|
|
13
|
-
* so the comparison is case-folded.
|
|
14
|
-
* - `/blog/../admin` is `/admin` by the time a browser issues the request, so dot segments are
|
|
15
|
-
* resolved first.
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Two hosts this deployment can never actually reach, used only so `new URL()` has a base to
|
|
20
|
-
* resolve a site-relative reference against. `.invalid` is reserved by RFC 2606 precisely for this.
|
|
21
|
-
*
|
|
22
|
-
* There are TWO because one base is NAMEABLE (t85 independent review, 2026-09-16). With a single
|
|
23
|
-
* base, `//reserved-path-probe.invalid/x` resolves to that very origin, so "did the origin survive"
|
|
24
|
-
* answered yes for a reference that leaves the site — reachable as `/store/buy`'s `returnTo`, which
|
|
25
|
-
* sent `Location: //reserved-path-probe.invalid/x`. Requiring the resolved origin to TRACK whichever
|
|
26
|
-
* base it was given leaves no origin an input can name, which is a structural answer rather than a
|
|
27
|
-
* denylist of the sentinel's spellings (the same reasoning as the probe itself — see
|
|
28
|
-
* {@link checkSiteRelativeTarget}). Both are bare origins, so a reference resolves to the same
|
|
29
|
-
* pathname against either.
|
|
30
|
-
*/
|
|
31
|
-
// eslint-disable-next-line sonarjs/no-clear-text-protocols -- Reserved .invalid probe origin used only for URL parsing; no network transport is invoked.
|
|
32
|
-
const PROBE_ORIGIN = "http://reserved-path-probe.invalid";
|
|
33
|
-
// eslint-disable-next-line sonarjs/no-clear-text-protocols -- Reserved .invalid probe origin used only for URL parsing; no network transport is invoked.
|
|
34
|
-
const SECOND_PROBE_ORIGIN = "http://reserved-path-probe-2.invalid";
|
|
35
|
-
/**
|
|
36
|
-
* Whether `value` contains a C0 or C1 control character.
|
|
37
|
-
*
|
|
38
|
-
* CR/LF in a request target is HTTP request splitting and in a `Location` header is response
|
|
39
|
-
* splitting; NUL and friends are path-truncation tricks.
|
|
40
|
-
*
|
|
41
|
-
* @param required.value - Any string, already decoded or not.
|
|
42
|
-
* @returns `true` if any code unit is in `U+0000`–`U+001F` or `U+007F`–`U+009F`.
|
|
43
|
-
* @complexity O(n) in the string length.
|
|
44
|
-
* @example hasControlCharacter({ value: "/ok" }, {}); // => false
|
|
45
|
-
*/
|
|
46
|
-
export function hasControlCharacter({ value }, _optional = {}) {
|
|
47
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
48
|
-
const code = value.charCodeAt(index);
|
|
49
|
-
if (code <= 0x1f || (code >= 0x7f && code <= 0x9f))
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Resolve `.` and `..` segments, RFC 3986 §5.2.4 style, on an already-decoded path.
|
|
56
|
-
*
|
|
57
|
-
* Done by hand rather than with a second `new URL()` pass because a decoded path can contain a
|
|
58
|
-
* literal `?` or `#` (from `%3F`/`%23`), and the URL parser would treat those as a query/fragment
|
|
59
|
-
* delimiter and TRUNCATE the path — turning `/x#/../admin` into `/x` and losing the very segment
|
|
60
|
-
* this check exists to find. A browser does no such thing: it never decodes `%23` before splitting
|
|
61
|
-
* the path, so the truncation would be a false negative, not a match for real behavior.
|
|
62
|
-
*
|
|
63
|
-
* Empty segments are dropped, so `//admin` collapses to `/admin`. That is deliberately stricter
|
|
64
|
-
* than a URL parser (which preserves `//`); over-matching here only ever refuses more.
|
|
65
|
-
*
|
|
66
|
-
* @param path - A decoded path, expected to start with `/`.
|
|
67
|
-
* @returns The path with dot segments removed, always starting with `/`.
|
|
68
|
-
* @complexity O(n) in the path length.
|
|
69
|
-
* @example resolveDotSegments("/blog/../admin"); // => "/admin"
|
|
70
|
-
*/
|
|
71
|
-
function resolveDotSegments(path) {
|
|
72
|
-
const out = [];
|
|
73
|
-
for (const segment of path.split("/")) {
|
|
74
|
-
if (segment === "" || segment === ".")
|
|
75
|
-
continue;
|
|
76
|
-
if (segment === "..")
|
|
77
|
-
out.pop();
|
|
78
|
-
else
|
|
79
|
-
out.push(segment);
|
|
80
|
-
}
|
|
81
|
-
return `/${out.join("/")}`;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The actual per-segment rule, on a pathname string that is guaranteed to have come from a real
|
|
85
|
-
* `URL` (see {@link checkSitePathname}, this function's only caller). Kept private: a bare
|
|
86
|
-
* string carries no proof it was ever parsed — the query/fragment stripping, dot-segment removal
|
|
87
|
-
* relative to a real origin, etc. are exactly what `new URL()` already did before that caller
|
|
88
|
-
* reaches this. Do not export this directly.
|
|
89
|
-
*
|
|
90
|
-
* Check the undecoded first segment too: Express mounts `/admin/..%2fpublic` under `/admin`,
|
|
91
|
-
* even though decoding and resolving dot segments produces `/public`.
|
|
92
|
-
* Order is load-bearing for the decoded check: decode ONCE, then resolve dot segments, then compare
|
|
93
|
-
* the first segment case-folded. Decoding first is what catches `/%61dmin` (over-refusal for Express
|
|
94
|
-
* and browsers, a real match for a decoding proxy — see the module doc); resolving dot segments after the decode is
|
|
95
|
-
* what catches `/blog/%2e%2e/admin`. Exactly one decode pass models one decoding intermediary:
|
|
96
|
-
* `/%2561dmin` would need two, so it stays allowed.
|
|
97
|
-
*
|
|
98
|
-
* @param required.pathname - An already-parsed `URL`'s `.pathname` (no query, no fragment).
|
|
99
|
-
* @param required.reservedSegments - First segments reserved by the host, stored case-folded.
|
|
100
|
-
* @returns `{ kind: "ok" }` when it is ordinary site content; otherwise the arm naming the refusal.
|
|
101
|
-
* @complexity O(n) in the pathname length.
|
|
102
|
-
*/
|
|
103
|
-
function checkDecodedSitePathname({ pathname, reservedSegments }, _optional = {}) {
|
|
104
|
-
let decoded;
|
|
105
|
-
try {
|
|
106
|
-
decoded = decodeURIComponent(pathname);
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
return { kind: "malformed-encoding" };
|
|
110
|
-
}
|
|
111
|
-
if (decoded.includes("\\") || hasControlCharacter({ value: decoded }, {}))
|
|
112
|
-
return { kind: "disallowed-character" };
|
|
113
|
-
const rawFirst = pathname.slice(1).split("/", 1).join("").toLowerCase();
|
|
114
|
-
if (reservedSegments.has(rawFirst))
|
|
115
|
-
return { kind: "reserved", surface: rawFirst };
|
|
116
|
-
// `resolveDotSegments` always returns a path with a leading "/", so the first segment is
|
|
117
|
-
// everything after it up to the next "/" — `split(..., 1)` yields exactly that one element.
|
|
118
|
-
const first = resolveDotSegments(decoded).slice(1).split("/", 1).join("").toLowerCase();
|
|
119
|
-
if (reservedSegments.has(first))
|
|
120
|
-
return { kind: "reserved", surface: first };
|
|
121
|
-
return { kind: "ok" };
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Classify an already-parsed URL's pathname against the admin application's URL space.
|
|
125
|
-
*
|
|
126
|
-
* Takes the {@link URL} itself, not a bare pathname string, so this cannot be handed a raw,
|
|
127
|
-
* unparsed reference by accident: a string has no way to prove it went through `new URL()` first,
|
|
128
|
-
* and this rule's whole design (see the module doc) depends on comparing the DECODED, dot-resolved
|
|
129
|
-
* form a URL parser would actually produce. A caller that only has a raw string — a stored redirect
|
|
130
|
-
* target, anything from user input — must go through {@link checkSiteRelativeTarget} instead, which
|
|
131
|
-
* parses it (and rejects what doesn't parse) before this check ever runs.
|
|
132
|
-
*
|
|
133
|
-
* PRECONDITION: the caller has already established that `url` is on the site's own origin. This
|
|
134
|
-
* function reads only `pathname`, so `new URL("//admin", base)` (host `admin`, pathname `/`)
|
|
135
|
-
* returns `ok`. It deliberately does not compare origins itself: `platform/routing` cannot use
|
|
136
|
-
* `features/origin`'s normalizer, and a string `URL.origin` comparison is wrong for redirect
|
|
137
|
-
* candidates (`https://site./admin`). Callers: `checkSiteRelativeTarget` (probe-origin check),
|
|
138
|
-
* `site-inspection`'s `resolveWithinOrigin`, and `features/redirects/reserved-destination.ts` (the
|
|
139
|
-
* origin oracle's `isSameOrigin`).
|
|
140
|
-
*
|
|
141
|
-
* @param required.url - An already-parsed `URL`; only `url.pathname` is read.
|
|
142
|
-
* @param required.reservedSegments - First segments reserved by the host, stored case-folded.
|
|
143
|
-
* @returns `{ kind: "ok" }` when it is ordinary site content; otherwise the arm naming the refusal.
|
|
144
|
-
* @complexity O(n) in the pathname length.
|
|
145
|
-
* @example checkSitePathname({ url: new URL("/administer-survey", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
|
|
146
|
-
* @example checkSitePathname({ url: new URL("/%61dmin/settings", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "reserved", surface: "admin" }
|
|
147
|
-
*/
|
|
148
|
-
export function checkSitePathname({ url, reservedSegments }, _optional = {}) {
|
|
149
|
-
return checkDecodedSitePathname({ pathname: url.pathname, reservedSegments }, {});
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Classify a raw, site-relative reference (a stored redirect target, a caller-supplied path)
|
|
153
|
-
* against the admin application's URL space, including the structural check that it is site-
|
|
154
|
-
* relative at all.
|
|
155
|
-
*
|
|
156
|
-
* The structural pass runs FIRST and matters on its own: `/\evil.example` begins with exactly one
|
|
157
|
-
* slash, so a `startsWith("//")` or scheme test calls it site-relative, while `new URL()` — and
|
|
158
|
-
* every browser following a `Location` — reads the backslash as a separator and lands on
|
|
159
|
-
* `evil.example`. Resolving against a probe origin and asserting the origin TRACKED that base is a
|
|
160
|
-
* structural answer to that instead of a pattern someone has to keep correct — done against two
|
|
161
|
-
* different bases so the probe origin itself is not a nameable way to pass (see
|
|
162
|
-
* {@link PROBE_ORIGIN}).
|
|
163
|
-
*
|
|
164
|
-
* @param required.raw - The untrusted reference, expected to be site-relative.
|
|
165
|
-
* @param required.reservedSegments - First segments reserved by the host, stored case-folded.
|
|
166
|
-
* @returns `{ kind: "ok" }` when it stays on this site and names ordinary content; otherwise the
|
|
167
|
-
* arm naming the refusal.
|
|
168
|
-
* @complexity O(n) in the reference length.
|
|
169
|
-
* @example checkSiteRelativeTarget({ raw: "/new", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
|
|
170
|
-
* @example checkSiteRelativeTarget({ raw: "/\\evil.example", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "off-origin" }
|
|
171
|
-
*/
|
|
172
|
-
export function checkSiteRelativeTarget({ raw, reservedSegments }, _optional = {}) {
|
|
173
|
-
if (hasControlCharacter({ value: raw }, {}))
|
|
174
|
-
return { kind: "disallowed-character" };
|
|
175
|
-
let parsed;
|
|
176
|
-
let reparsed;
|
|
177
|
-
try {
|
|
178
|
-
parsed = new URL(raw, PROBE_ORIGIN);
|
|
179
|
-
reparsed = new URL(raw, SECOND_PROBE_ORIGIN);
|
|
180
|
-
}
|
|
181
|
-
catch {
|
|
182
|
-
return { kind: "unparseable" };
|
|
183
|
-
}
|
|
184
|
-
if (parsed.origin !== PROBE_ORIGIN || reparsed.origin !== SECOND_PROBE_ORIGIN)
|
|
185
|
-
return { kind: "off-origin" };
|
|
186
|
-
return checkSitePathname({ url: parsed, reservedSegments }, {});
|
|
187
|
-
}
|
|
188
|
-
//# sourceMappingURL=site-path.js.map
|