ssrf-safe 0.0.0-stage → 1.0.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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +379 -2
- package/dist/chunk-4CL2OZUY.cjs +521 -0
- package/dist/chunk-5WDHI7VU.js +521 -0
- package/dist/chunk-EDSDB6GK.cjs +163 -0
- package/dist/chunk-LI4OVIRR.js +163 -0
- package/dist/fetch.cjs +91 -0
- package/dist/fetch.d.cts +25 -0
- package/dist/fetch.d.ts +25 -0
- package/dist/fetch.js +91 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +113 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +20 -0
- package/dist/node.cjs +371 -0
- package/dist/node.d.cts +101 -0
- package/dist/node.d.ts +101 -0
- package/dist/node.js +371 -0
- package/dist/shared-BGmNa6ne.d.cts +17 -0
- package/dist/shared-BGmNa6ne.d.ts +17 -0
- package/package.json +95 -4
package/dist/node.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertSafeUrl,
|
|
3
|
+
buildResponse,
|
|
4
|
+
createDeadline,
|
|
5
|
+
isNullBodyStatus,
|
|
6
|
+
isReadableStream,
|
|
7
|
+
isRedirectStatus,
|
|
8
|
+
limitBody,
|
|
9
|
+
planRedirect,
|
|
10
|
+
resolveLimits,
|
|
11
|
+
tooLarge,
|
|
12
|
+
tooManyRedirects
|
|
13
|
+
} from "./chunk-LI4OVIRR.js";
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_BLOCKED_HOSTS,
|
|
16
|
+
FetchLimitError,
|
|
17
|
+
SsrfError,
|
|
18
|
+
checkAddress,
|
|
19
|
+
checkHostname,
|
|
20
|
+
checkUrl,
|
|
21
|
+
classifyIp,
|
|
22
|
+
formatIp,
|
|
23
|
+
isPrivateIp,
|
|
24
|
+
isSafeUrl,
|
|
25
|
+
normalizeIp,
|
|
26
|
+
parseHostIp,
|
|
27
|
+
parseIp
|
|
28
|
+
} from "./chunk-5WDHI7VU.js";
|
|
29
|
+
|
|
30
|
+
// src/node.ts
|
|
31
|
+
import * as dns from "node:dns";
|
|
32
|
+
import * as http from "node:http";
|
|
33
|
+
import * as https from "node:https";
|
|
34
|
+
import * as net from "node:net";
|
|
35
|
+
import * as zlib from "node:zlib";
|
|
36
|
+
var defaultResolver = async (hostname) => dns.promises.lookup(hostname, { all: true });
|
|
37
|
+
function toAddresses(list) {
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const item of list) {
|
|
40
|
+
const raw = typeof item === "string" ? item : item?.address;
|
|
41
|
+
const ip = typeof raw === "string" ? parseIp(raw) : void 0;
|
|
42
|
+
if (!ip) throw new SsrfError(`The resolver returned something that isn't an IP address: ${String(raw)}`, { rule: "dns" });
|
|
43
|
+
out.push({ address: formatIp(ip), family: ip.version });
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
async function resolveChecked(hostname, options) {
|
|
48
|
+
const verdict = checkHostname(hostname, options);
|
|
49
|
+
if (!verdict.safe) {
|
|
50
|
+
const details = { rule: verdict.rule, host: hostname };
|
|
51
|
+
if (verdict.ip !== void 0) details.ip = verdict.ip;
|
|
52
|
+
throw new SsrfError(`Blocked ${verdict.reason}`, details);
|
|
53
|
+
}
|
|
54
|
+
if (verdict.ip !== void 0) {
|
|
55
|
+
return [{ address: verdict.ip, family: verdict.ip.includes(":") ? 6 : 4 }];
|
|
56
|
+
}
|
|
57
|
+
let name = hostname;
|
|
58
|
+
while (name.endsWith(".") && name.length > 1) name = name.slice(0, -1);
|
|
59
|
+
const addresses = toAddresses(await (options.resolve ?? defaultResolver)(name));
|
|
60
|
+
if (addresses.length === 0) {
|
|
61
|
+
throw new SsrfError(`Blocked ${hostname}: it didn't resolve to any address`, { rule: "dns", host: hostname });
|
|
62
|
+
}
|
|
63
|
+
const addressOptions = verdict.trusted ? { ...options, allowPrivate: true } : options;
|
|
64
|
+
for (const a of addresses) {
|
|
65
|
+
const check = checkAddress(parseIp(a.address), addressOptions, hostname);
|
|
66
|
+
if (!check.safe) {
|
|
67
|
+
throw new SsrfError(`Blocked ${check.reason}`, { rule: check.rule, host: hostname, ip: a.address });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return addresses;
|
|
71
|
+
}
|
|
72
|
+
async function checkHost(hostname, options = {}) {
|
|
73
|
+
try {
|
|
74
|
+
const addresses = await resolveChecked(hostname, options);
|
|
75
|
+
return { safe: true, host: hostname, addresses: addresses.map((a) => a.address) };
|
|
76
|
+
} catch (err) {
|
|
77
|
+
if (err instanceof SsrfError) {
|
|
78
|
+
return { safe: false, rule: err.rule, reason: err.message, host: hostname, addresses: err.ip ? [err.ip] : [] };
|
|
79
|
+
}
|
|
80
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
81
|
+
return { safe: false, rule: "dns", reason: `DNS lookup failed: ${message}`, host: hostname, addresses: [] };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function createLookup(options) {
|
|
85
|
+
return (hostname, opts, cb) => {
|
|
86
|
+
const callback = typeof opts === "function" ? opts : cb;
|
|
87
|
+
const lookupOpts = typeof opts === "function" ? {} : opts ?? {};
|
|
88
|
+
resolveChecked(hostname, options).then(
|
|
89
|
+
(list) => {
|
|
90
|
+
const family = lookupOpts.family === "IPv4" ? 4 : lookupOpts.family === "IPv6" ? 6 : lookupOpts.family;
|
|
91
|
+
const addrs = family === 4 || family === 6 ? list.filter((a) => a.family === family) : list;
|
|
92
|
+
if (addrs.length === 0) {
|
|
93
|
+
const err = new Error(`getaddrinfo ENOTFOUND ${hostname}`);
|
|
94
|
+
err.code = "ENOTFOUND";
|
|
95
|
+
callback(err, "");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (lookupOpts.all) callback(null, addrs);
|
|
99
|
+
else callback(null, addrs[0].address, addrs[0].family);
|
|
100
|
+
},
|
|
101
|
+
(err) => callback(err, "")
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
var CHECK_KEYS = [
|
|
106
|
+
"resolve",
|
|
107
|
+
"allowHosts",
|
|
108
|
+
"blockHosts",
|
|
109
|
+
"allowPrivate",
|
|
110
|
+
"ports",
|
|
111
|
+
"blockPorts",
|
|
112
|
+
"protocols",
|
|
113
|
+
"allowCredentials",
|
|
114
|
+
"maxLength"
|
|
115
|
+
];
|
|
116
|
+
function splitOptions(options) {
|
|
117
|
+
const check = {};
|
|
118
|
+
const agent = { ...options };
|
|
119
|
+
for (const key of CHECK_KEYS) {
|
|
120
|
+
if (key in agent) {
|
|
121
|
+
check[key] = agent[key];
|
|
122
|
+
delete agent[key];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
delete agent.lookup;
|
|
126
|
+
return { check, agent };
|
|
127
|
+
}
|
|
128
|
+
function guardConnection(options, check) {
|
|
129
|
+
if (options.socketPath) {
|
|
130
|
+
return new SsrfError(`Blocked a connection to the Unix socket ${options.socketPath}`, { rule: "blocked-host" });
|
|
131
|
+
}
|
|
132
|
+
const host = String(options.host ?? options.hostname ?? "localhost");
|
|
133
|
+
const port = options.port === void 0 || options.port === null || options.port === "" ? void 0 : Number(options.port);
|
|
134
|
+
if (port !== void 0) {
|
|
135
|
+
if (check.ports && !check.ports.includes(port)) {
|
|
136
|
+
return new SsrfError(`Blocked port ${port}: not in the allowed ports`, { rule: "port", host });
|
|
137
|
+
}
|
|
138
|
+
if (check.blockPorts?.includes(port)) {
|
|
139
|
+
return new SsrfError(`Blocked port ${port}`, { rule: "port", host });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const ip = parseHostIp(host);
|
|
143
|
+
const verdict = ip ? checkAddress(ip, check) : checkHostname(host, check);
|
|
144
|
+
if (!verdict.safe) {
|
|
145
|
+
const details = { rule: verdict.rule, host };
|
|
146
|
+
if (verdict.ip !== void 0) details.ip = verdict.ip;
|
|
147
|
+
return new SsrfError(`Blocked ${verdict.reason}`, details);
|
|
148
|
+
}
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
function failConnection(err, callback) {
|
|
152
|
+
if (typeof callback === "function") {
|
|
153
|
+
process.nextTick(callback, err);
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
const socket = new net.Socket();
|
|
157
|
+
process.nextTick(() => socket.destroy(err));
|
|
158
|
+
return socket;
|
|
159
|
+
}
|
|
160
|
+
var kCheck = /* @__PURE__ */ Symbol("ssrf-safe.check");
|
|
161
|
+
var kLookup = /* @__PURE__ */ Symbol("ssrf-safe.lookup");
|
|
162
|
+
var SafeHttpAgent = class extends http.Agent {
|
|
163
|
+
[kCheck];
|
|
164
|
+
[kLookup];
|
|
165
|
+
constructor(options = {}) {
|
|
166
|
+
const { check, agent } = splitOptions(options);
|
|
167
|
+
super(agent);
|
|
168
|
+
this[kCheck] = check;
|
|
169
|
+
this[kLookup] = createLookup(check);
|
|
170
|
+
}
|
|
171
|
+
createConnection(options, callback) {
|
|
172
|
+
const err = guardConnection(options, this[kCheck]);
|
|
173
|
+
if (err) return failConnection(err, callback);
|
|
174
|
+
const proto = http.Agent.prototype;
|
|
175
|
+
return proto.createConnection.call(this, { ...options, lookup: this[kLookup] }, callback);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var SafeHttpsAgent = class extends https.Agent {
|
|
179
|
+
[kCheck];
|
|
180
|
+
[kLookup];
|
|
181
|
+
constructor(options = {}) {
|
|
182
|
+
const { check, agent } = splitOptions(options);
|
|
183
|
+
super(agent);
|
|
184
|
+
this[kCheck] = check;
|
|
185
|
+
this[kLookup] = createLookup(check);
|
|
186
|
+
}
|
|
187
|
+
createConnection(options, callback) {
|
|
188
|
+
const err = guardConnection(options, this[kCheck]);
|
|
189
|
+
if (err) return failConnection(err, callback);
|
|
190
|
+
const proto = https.Agent.prototype;
|
|
191
|
+
return proto.createConnection.call(this, { ...options, lookup: this[kLookup] }, callback);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
function createSafeAgent(options = {}) {
|
|
195
|
+
return { http: new SafeHttpAgent(options), https: new SafeHttpsAgent(options) };
|
|
196
|
+
}
|
|
197
|
+
var safeHttpAgent = new SafeHttpAgent();
|
|
198
|
+
var safeHttpsAgent = new SafeHttpsAgent();
|
|
199
|
+
async function prepareBody(body, headers) {
|
|
200
|
+
if (body === null || body === void 0) return null;
|
|
201
|
+
if (isReadableStream(body)) return body;
|
|
202
|
+
const serialised = new Response(body);
|
|
203
|
+
const type = serialised.headers.get("content-type");
|
|
204
|
+
if (type && !headers.has("content-type")) headers.set("content-type", type);
|
|
205
|
+
return new Uint8Array(await serialised.arrayBuffer());
|
|
206
|
+
}
|
|
207
|
+
function sendRequest(url, method, headers, body, agent, signal) {
|
|
208
|
+
return new Promise((resolve, reject) => {
|
|
209
|
+
if (signal.aborted) {
|
|
210
|
+
reject(signal.reason);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const outgoing = {};
|
|
214
|
+
headers.forEach((value, key) => {
|
|
215
|
+
outgoing[key] = value;
|
|
216
|
+
});
|
|
217
|
+
if (body instanceof Uint8Array) outgoing["content-length"] = String(body.byteLength);
|
|
218
|
+
const mod = url.protocol === "https:" ? https : http;
|
|
219
|
+
const req = mod.request(url, { method, headers: outgoing, agent });
|
|
220
|
+
const onAbort = () => req.destroy(signal.reason);
|
|
221
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
222
|
+
req.on("response", (res) => {
|
|
223
|
+
signal.removeEventListener("abort", onAbort);
|
|
224
|
+
resolve(res);
|
|
225
|
+
});
|
|
226
|
+
req.on("error", (err) => {
|
|
227
|
+
signal.removeEventListener("abort", onAbort);
|
|
228
|
+
reject(signal.aborted ? signal.reason : err);
|
|
229
|
+
});
|
|
230
|
+
if (body === null) {
|
|
231
|
+
req.end();
|
|
232
|
+
} else if (body instanceof Uint8Array) {
|
|
233
|
+
req.end(body);
|
|
234
|
+
} else {
|
|
235
|
+
const reader = body.getReader();
|
|
236
|
+
const pump = async () => {
|
|
237
|
+
for (; ; ) {
|
|
238
|
+
const { value, done } = await reader.read();
|
|
239
|
+
if (done) break;
|
|
240
|
+
if (!req.write(value)) await new Promise((r) => req.once("drain", r));
|
|
241
|
+
}
|
|
242
|
+
req.end();
|
|
243
|
+
};
|
|
244
|
+
pump().catch((err) => req.destroy(err));
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
function decode(res) {
|
|
249
|
+
const encoding = String(res.headers["content-encoding"] ?? "").trim().toLowerCase();
|
|
250
|
+
let decoder;
|
|
251
|
+
if (encoding === "gzip" || encoding === "x-gzip") decoder = zlib.createGunzip();
|
|
252
|
+
else if (encoding === "deflate") decoder = zlib.createInflate();
|
|
253
|
+
else if (encoding === "br") decoder = zlib.createBrotliDecompress();
|
|
254
|
+
if (!decoder) return res;
|
|
255
|
+
const d = decoder;
|
|
256
|
+
res.on("error", (err) => d.destroy(err));
|
|
257
|
+
d.on("close", () => res.destroy());
|
|
258
|
+
return res.pipe(d);
|
|
259
|
+
}
|
|
260
|
+
function toWebStream(readable) {
|
|
261
|
+
const iterator = readable[Symbol.asyncIterator]();
|
|
262
|
+
return new ReadableStream({
|
|
263
|
+
async pull(controller) {
|
|
264
|
+
const { value, done } = await iterator.next();
|
|
265
|
+
if (done) controller.close();
|
|
266
|
+
else controller.enqueue(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
267
|
+
},
|
|
268
|
+
cancel() {
|
|
269
|
+
readable.destroy();
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
async function safeFetch(input, init = {}, options = {}) {
|
|
274
|
+
const limits = resolveLimits(options);
|
|
275
|
+
const mode = init.redirect ?? "follow";
|
|
276
|
+
const headers = new Headers(init.headers);
|
|
277
|
+
if (!headers.has("accept")) headers.set("accept", "*/*");
|
|
278
|
+
if (!headers.has("accept-encoding")) headers.set("accept-encoding", "gzip, deflate, br");
|
|
279
|
+
let state = {
|
|
280
|
+
url: assertSafeUrl(input, options),
|
|
281
|
+
method: init.method ?? "GET",
|
|
282
|
+
headers,
|
|
283
|
+
body: null,
|
|
284
|
+
streamed: isReadableStream(init.body)
|
|
285
|
+
};
|
|
286
|
+
const upperMethod = state.method.toUpperCase();
|
|
287
|
+
if ((upperMethod === "GET" || upperMethod === "HEAD") && init.body !== null && init.body !== void 0) {
|
|
288
|
+
throw new TypeError("A GET or HEAD request can't have a body");
|
|
289
|
+
}
|
|
290
|
+
state.body = await prepareBody(init.body, headers);
|
|
291
|
+
const { agentOptions, ...rest } = options;
|
|
292
|
+
const agentConfig = { ...agentOptions, ...rest, keepAlive: false };
|
|
293
|
+
const agents = { http: new SafeHttpAgent(agentConfig), https: new SafeHttpsAgent(agentConfig) };
|
|
294
|
+
const deadline = createDeadline(limits.timeout, init.signal);
|
|
295
|
+
let redirects = 0;
|
|
296
|
+
try {
|
|
297
|
+
for (; ; ) {
|
|
298
|
+
if (state.url.protocol !== "http:" && state.url.protocol !== "https:") {
|
|
299
|
+
throw new SsrfError(`Blocked ${state.url.protocol} URL: ssrf-safe/node fetches http and https only`, {
|
|
300
|
+
rule: "protocol",
|
|
301
|
+
url: state.url.href
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
const agent = state.url.protocol === "https:" ? agents.https : agents.http;
|
|
305
|
+
const res = await sendRequest(state.url, state.method, state.headers, state.body, agent, deadline.signal);
|
|
306
|
+
const status = res.statusCode ?? 0;
|
|
307
|
+
const location = res.headers.location;
|
|
308
|
+
if (mode !== "manual" && isRedirectStatus(status) && typeof location === "string") {
|
|
309
|
+
res.destroy();
|
|
310
|
+
if (mode === "error") throw new TypeError(`Unexpected redirect to ${location} (redirect: "error")`);
|
|
311
|
+
if (redirects >= limits.maxRedirects) throw tooManyRedirects(limits.maxRedirects, state.url);
|
|
312
|
+
state = planRedirect(state, status, location, options);
|
|
313
|
+
redirects++;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (status < 200 || status > 599) {
|
|
317
|
+
res.destroy();
|
|
318
|
+
throw new TypeError(`Unsupported response status ${status}`);
|
|
319
|
+
}
|
|
320
|
+
const responseHeaders = new Headers();
|
|
321
|
+
const raw = res.rawHeaders;
|
|
322
|
+
for (let i = 0; i + 1 < raw.length; i += 2) {
|
|
323
|
+
try {
|
|
324
|
+
responseHeaders.append(raw[i], raw[i + 1]);
|
|
325
|
+
} catch {
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const length = Number(res.headers["content-length"]);
|
|
329
|
+
if (!res.headers["content-encoding"] && length > limits.maxBytes) {
|
|
330
|
+
res.destroy();
|
|
331
|
+
throw tooLarge(limits.maxBytes, state.url);
|
|
332
|
+
}
|
|
333
|
+
const hasBody = !isNullBodyStatus(status) && state.method.toUpperCase() !== "HEAD";
|
|
334
|
+
let body = null;
|
|
335
|
+
if (hasBody) {
|
|
336
|
+
const stream = decode(res);
|
|
337
|
+
const onAbort = () => stream.destroy(deadline.reason());
|
|
338
|
+
deadline.signal.addEventListener("abort", onAbort, { once: true });
|
|
339
|
+
const onEnd = () => {
|
|
340
|
+
deadline.signal.removeEventListener("abort", onAbort);
|
|
341
|
+
deadline.done();
|
|
342
|
+
};
|
|
343
|
+
body = limitBody(toWebStream(stream), limits.maxBytes, state.url, deadline, onEnd);
|
|
344
|
+
} else {
|
|
345
|
+
res.resume();
|
|
346
|
+
deadline.done();
|
|
347
|
+
}
|
|
348
|
+
return buildResponse(body, { status, statusText: res.statusMessage ?? "", headers: responseHeaders }, state.url, redirects > 0);
|
|
349
|
+
}
|
|
350
|
+
} catch (err) {
|
|
351
|
+
deadline.done();
|
|
352
|
+
throw deadline.signal.aborted ? deadline.reason() : err;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
export {
|
|
356
|
+
DEFAULT_BLOCKED_HOSTS,
|
|
357
|
+
FetchLimitError,
|
|
358
|
+
SafeHttpAgent,
|
|
359
|
+
SafeHttpsAgent,
|
|
360
|
+
SsrfError,
|
|
361
|
+
checkHost,
|
|
362
|
+
checkUrl,
|
|
363
|
+
classifyIp,
|
|
364
|
+
createSafeAgent,
|
|
365
|
+
isPrivateIp,
|
|
366
|
+
isSafeUrl,
|
|
367
|
+
normalizeIp,
|
|
368
|
+
safeFetch,
|
|
369
|
+
safeHttpAgent,
|
|
370
|
+
safeHttpsAgent
|
|
371
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redirect handling, limits and response building shared by
|
|
3
|
+
* `ssrf-safe/fetch` and `ssrf-safe/node`. No runtime-specific APIs.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
interface FetchLimits {
|
|
7
|
+
/** Most redirects to follow. Each one is checked like the first URL. Default 5. */
|
|
8
|
+
maxRedirects?: number;
|
|
9
|
+
/** Time limit in milliseconds for the whole request, including reading the body. Default 30000. `0` or `Infinity` turns it off. */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
/** Largest response body to read, in bytes (after decompression). Default 10 MiB. `Infinity` turns it off. */
|
|
12
|
+
maxBytes?: number;
|
|
13
|
+
/** Follow redirects from https to http. Default `false`. */
|
|
14
|
+
allowDowngrade?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { FetchLimits as F };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redirect handling, limits and response building shared by
|
|
3
|
+
* `ssrf-safe/fetch` and `ssrf-safe/node`. No runtime-specific APIs.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
interface FetchLimits {
|
|
7
|
+
/** Most redirects to follow. Each one is checked like the first URL. Default 5. */
|
|
8
|
+
maxRedirects?: number;
|
|
9
|
+
/** Time limit in milliseconds for the whole request, including reading the body. Default 30000. `0` or `Infinity` turns it off. */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
/** Largest response body to read, in bytes (after decompression). Default 10 MiB. `Infinity` turns it off. */
|
|
12
|
+
maxBytes?: number;
|
|
13
|
+
/** Follow redirects from https to http. Default `false`. */
|
|
14
|
+
allowDowngrade?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { FetchLimits as F };
|
package/package.json
CHANGED
|
@@ -1,6 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssrf-safe",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Fetch URLs safely from servers and AI agents: blocks private IPs, cloud metadata endpoints and redirects to internal hosts (SSRF protection).",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ssrf",
|
|
7
|
+
"fetch",
|
|
8
|
+
"security",
|
|
9
|
+
"url",
|
|
10
|
+
"private-ip",
|
|
11
|
+
"ip",
|
|
12
|
+
"dns-rebinding",
|
|
13
|
+
"cloud-metadata",
|
|
14
|
+
"redirect",
|
|
15
|
+
"agent",
|
|
16
|
+
"http-agent",
|
|
17
|
+
"axios",
|
|
18
|
+
"got",
|
|
19
|
+
"ai-agent",
|
|
20
|
+
"llm",
|
|
21
|
+
"mcp",
|
|
22
|
+
"webhook",
|
|
23
|
+
"proxy",
|
|
24
|
+
"validation",
|
|
25
|
+
"network"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"author": "CK Giri <ckgdev@gmail.com>",
|
|
29
|
+
"homepage": "https://github.com/ckgiri/ssrf-safe",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/ckgiri/ssrf-safe.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/ckgiri/ssrf-safe/issues"
|
|
36
|
+
},
|
|
37
|
+
"type": "module",
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"main": "./dist/index.cjs",
|
|
40
|
+
"module": "./dist/index.js",
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"default": "./dist/index.js"
|
|
47
|
+
},
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/index.d.cts",
|
|
50
|
+
"default": "./dist/index.cjs"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"./fetch": {
|
|
54
|
+
"import": {
|
|
55
|
+
"types": "./dist/fetch.d.ts",
|
|
56
|
+
"default": "./dist/fetch.js"
|
|
57
|
+
},
|
|
58
|
+
"require": {
|
|
59
|
+
"types": "./dist/fetch.d.cts",
|
|
60
|
+
"default": "./dist/fetch.cjs"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"./node": {
|
|
64
|
+
"import": {
|
|
65
|
+
"types": "./dist/node.d.ts",
|
|
66
|
+
"default": "./dist/node.js"
|
|
67
|
+
},
|
|
68
|
+
"require": {
|
|
69
|
+
"types": "./dist/node.d.cts",
|
|
70
|
+
"default": "./dist/node.cjs"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"./package.json": "./package.json"
|
|
74
|
+
},
|
|
75
|
+
"files": [
|
|
76
|
+
"dist",
|
|
77
|
+
"CHANGELOG.md"
|
|
78
|
+
],
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=18"
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"build": "tsup",
|
|
84
|
+
"test": "vitest run --no-file-parallelism",
|
|
85
|
+
"typecheck": "tsc -p .",
|
|
86
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build",
|
|
87
|
+
"release": "npm version patch && git push --follow-tags",
|
|
88
|
+
"release:minor": "npm version minor && git push --follow-tags",
|
|
89
|
+
"release:major": "npm version major && git push --follow-tags"
|
|
90
|
+
},
|
|
91
|
+
"devDependencies": {
|
|
92
|
+
"@types/node": "^20.14.0",
|
|
93
|
+
"tsup": "^8.3.0",
|
|
94
|
+
"typescript": "^5.6.0",
|
|
95
|
+
"vitest": "^2.1.0"
|
|
96
|
+
}
|
|
97
|
+
}
|