@benchcutlogic/edge-kit 0.0.0-stage → 0.2.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/dist/ssrf.d.ts ADDED
@@ -0,0 +1,165 @@
1
+ import * as Effect from 'effect/Effect';
2
+ import { BodyReadError, BodyTooLargeError } from './body.js';
3
+ export { BodyReadError, BodyTooLargeError };
4
+ declare const SsrfBlockedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
5
+ readonly _tag: "SsrfBlockedError";
6
+ } & Readonly<A>;
7
+ export declare class SsrfBlockedError extends SsrfBlockedError_base<{
8
+ readonly url: string;
9
+ readonly reason: string;
10
+ readonly address?: string;
11
+ }> {
12
+ get message(): string;
13
+ }
14
+ declare const InvalidUrlError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
15
+ readonly _tag: "InvalidUrlError";
16
+ } & Readonly<A>;
17
+ export declare class InvalidUrlError extends InvalidUrlError_base<{
18
+ readonly url: string;
19
+ readonly reason: string;
20
+ }> {
21
+ get message(): string;
22
+ }
23
+ declare const DeadlineExceededError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
24
+ readonly _tag: "DeadlineExceededError";
25
+ } & Readonly<A>;
26
+ export declare class DeadlineExceededError extends DeadlineExceededError_base<{
27
+ readonly url: string;
28
+ readonly timeoutMs: number;
29
+ }> {
30
+ get message(): string;
31
+ }
32
+ declare const NetworkError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
33
+ readonly _tag: "NetworkError";
34
+ } & Readonly<A>;
35
+ export declare class NetworkError extends NetworkError_base<{
36
+ readonly url: string;
37
+ readonly cause: unknown;
38
+ }> {
39
+ get message(): string;
40
+ }
41
+ export type DnsResolver = (hostname: string) => Promise<ReadonlyArray<string>> | Effect.Effect<ReadonlyArray<string>, unknown>;
42
+ export interface AssertPublicHttpUrlOptions {
43
+ readonly allowHttp?: boolean;
44
+ readonly allowedHosts?: ReadonlyArray<string>;
45
+ readonly dnsResolve?: DnsResolver;
46
+ }
47
+ export interface SsrfFetchRequestInit extends RequestInit {
48
+ readonly resolvedAddresses?: ReadonlyArray<string>;
49
+ }
50
+ export type SsrfFetchTransport = (input: string | URL, init?: SsrfFetchRequestInit) => Promise<Response>;
51
+ export interface SsrfFetchOptions extends AssertPublicHttpUrlOptions {
52
+ readonly totalTimeoutMs: number;
53
+ readonly maxResponseBytes?: number;
54
+ readonly maxRedirects?: number;
55
+ readonly method?: string;
56
+ readonly headers?: HeadersInit;
57
+ readonly body?: BodyInit | null;
58
+ readonly fetch?: SsrfFetchTransport;
59
+ }
60
+ export interface CappedResponse {
61
+ readonly url: string;
62
+ readonly status: number;
63
+ readonly statusText: string;
64
+ readonly headers: Headers;
65
+ readonly body: Uint8Array;
66
+ readonly redirectCount: number;
67
+ text(): string;
68
+ json(): unknown;
69
+ }
70
+ /**
71
+ * Returns `true` if `ip` is a private, loopback, link-local, unique-local,
72
+ * carrier-grade NAT, multicast, broadcast, unspecified, benchmark, documentation,
73
+ * reserved, or IPv4-mapped private IPv6 address.
74
+ *
75
+ * Uses `ipaddr.js` exclusively (no hand-rolled bitmasks).
76
+ */
77
+ export declare function isPrivateOrReservedIp(ip: string): boolean;
78
+ interface NodeDnsPromisesLike {
79
+ readonly lookup?: (hostname: string, options: {
80
+ readonly all: true;
81
+ readonly verbatim?: boolean;
82
+ }) => Promise<ReadonlyArray<{
83
+ readonly address: string;
84
+ }>>;
85
+ }
86
+ /**
87
+ * Builds a default DNS resolver backed by `node:dns/promises` (`lookup` with
88
+ * `all: true, verbatim: true`). Fails closed with an error when no DNS resolver
89
+ * is available in the current runtime (e.g. non-Node edge isolates).
90
+ */
91
+ export declare function createNodeDnsResolver(loadDns?: () => Promise<NodeDnsPromisesLike | null>): DnsResolver;
92
+ interface NodeReadableStreamLike {
93
+ on(event: 'data', listener: (chunk: Uint8Array) => void): void;
94
+ on(event: 'end', listener: () => void): void;
95
+ on(event: 'error', listener: (err: unknown) => void): void;
96
+ on(event: 'close', listener: () => void): void;
97
+ pipe<T extends NodeReadableStreamLike>(destination: T): T;
98
+ resume(): void;
99
+ destroy(error?: Error): void;
100
+ }
101
+ interface NodeHttpIncomingMessageLike extends NodeReadableStreamLike {
102
+ readonly statusCode?: number;
103
+ readonly statusMessage?: string;
104
+ readonly rawHeaders?: ReadonlyArray<string>;
105
+ }
106
+ interface NodeZlibModuleLike {
107
+ readonly createGunzip: () => NodeReadableStreamLike;
108
+ readonly createInflate: () => NodeReadableStreamLike;
109
+ readonly createBrotliDecompress: () => NodeReadableStreamLike;
110
+ readonly createZstdDecompress?: () => NodeReadableStreamLike;
111
+ }
112
+ interface NodeHttpClientRequestLike {
113
+ on(event: 'error', listener: (err: unknown) => void): void;
114
+ end(chunk?: Uint8Array): void;
115
+ destroy(error?: Error): void;
116
+ }
117
+ type NodeLookupCallback = (err: Error | null, address: string | ReadonlyArray<{
118
+ readonly address: string;
119
+ readonly family: number;
120
+ }>, family?: number) => void;
121
+ interface NodeRequestOptionsLike {
122
+ readonly method?: string;
123
+ readonly headers?: Record<string, string>;
124
+ readonly agent?: false;
125
+ readonly signal?: AbortSignal;
126
+ readonly servername?: string;
127
+ readonly lookup?: (hostname: string, options: {
128
+ readonly all?: boolean;
129
+ readonly family?: number;
130
+ } | number, callback: NodeLookupCallback) => void;
131
+ }
132
+ interface NodeHttpModuleLike {
133
+ readonly request: (url: URL, options: NodeRequestOptionsLike, callback: (res: NodeHttpIncomingMessageLike) => void) => NodeHttpClientRequestLike;
134
+ }
135
+ interface NodeHttpModules {
136
+ readonly http: NodeHttpModuleLike;
137
+ readonly https: NodeHttpModuleLike;
138
+ readonly zlib?: NodeZlibModuleLike;
139
+ }
140
+ /**
141
+ * Builds a Node `http`/`https` transport that pins TCP/TLS connections directly to
142
+ * `init.resolvedAddresses` while preserving the original `Host` header and TLS SNI
143
+ * (`servername`). Fails closed with `SsrfBlockedError` when no pinned transport is
144
+ * available in the current runtime for hostname destinations.
145
+ */
146
+ export declare function createPinnedNodeFetch(loadModules?: () => Promise<NodeHttpModules | null>): SsrfFetchTransport;
147
+ /**
148
+ * Validates that a URL is a public HTTP(S) target safe against SSRF.
149
+ *
150
+ * - Default HTTPS-only unless `allowHttp: true`.
151
+ * - Rejects embedded userinfo credentials.
152
+ * - Normalizes trailing dots on hostnames (`example.com.` -> `example.com`).
153
+ * - Blocks `localhost`, `*.localhost`, `*.local`, `*.internal`.
154
+ * - Enforces optional `allowedHosts` allowlist.
155
+ * - Blocks private/reserved IPv4, IPv6, and IPv4-mapped IPv6 literals and resolved IPs.
156
+ * - Resolves non-IP hostnames via `options.dnsResolve` or the default Node DNS resolver,
157
+ * failing closed with `SsrfBlockedError` if no resolver is available or resolution fails.
158
+ */
159
+ export declare function assertPublicHttpUrl(rawUrl: string | URL, options?: AssertPublicHttpUrlOptions): Effect.Effect<URL, InvalidUrlError | SsrfBlockedError>;
160
+ /**
161
+ * Fetches an external HTTP(S) URL with SSRF protection, DNS-pinned connections,
162
+ * manual redirect validation, cross-origin credential header stripping, a mandatory
163
+ * outer deadline across all hops + body read, and a streaming response body byte cap.
164
+ */
165
+ export declare function ssrfFetch(inputUrl: string | URL, options: SsrfFetchOptions): Effect.Effect<CappedResponse, InvalidUrlError | SsrfBlockedError | DeadlineExceededError | NetworkError | BodyTooLargeError | BodyReadError>;