@n8n/backend-network 1.0.0 → 1.1.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.
Files changed (57) hide show
  1. package/LICENSE_EE.md +27 -0
  2. package/dist/build.tsbuildinfo +1 -1
  3. package/dist/dns/dns-resolver.d.ts +13 -0
  4. package/dist/dns/dns-resolver.js +93 -0
  5. package/dist/dns/dns-resolver.js.map +1 -0
  6. package/dist/dns/in-memory-dns-cache.service.d.ts +21 -0
  7. package/dist/dns/in-memory-dns-cache.service.js +73 -0
  8. package/dist/dns/in-memory-dns-cache.service.js.map +1 -0
  9. package/dist/dns/index.d.ts +2 -0
  10. package/dist/dns/index.js +8 -0
  11. package/dist/dns/index.js.map +1 -0
  12. package/dist/http/axios-config.d.ts +1 -0
  13. package/dist/http/axios-config.js +42 -0
  14. package/dist/http/axios-config.js.map +1 -0
  15. package/dist/http/axios-utils.d.ts +24 -0
  16. package/dist/http/axios-utils.js +257 -0
  17. package/dist/http/axios-utils.js.map +1 -0
  18. package/dist/http/binary-buffer.d.ts +3 -0
  19. package/dist/http/binary-buffer.js +24 -0
  20. package/dist/http/binary-buffer.js.map +1 -0
  21. package/dist/http/binary-string.d.ts +2 -0
  22. package/dist/http/binary-string.js +16 -0
  23. package/dist/http/binary-string.js.map +1 -0
  24. package/dist/http/http-proxy.d.ts +7 -0
  25. package/dist/http/http-proxy.js +113 -0
  26. package/dist/http/http-proxy.js.map +1 -0
  27. package/dist/http/http-request.d.ts +7 -0
  28. package/dist/http/http-request.js +157 -0
  29. package/dist/http/http-request.js.map +1 -0
  30. package/dist/http/index.d.ts +8 -0
  31. package/dist/http/index.js +39 -0
  32. package/dist/http/index.js.map +1 -0
  33. package/dist/http/outbound-user-agent.d.ts +4 -0
  34. package/dist/http/outbound-user-agent.js +40 -0
  35. package/dist/http/outbound-user-agent.js.map +1 -0
  36. package/dist/http/parse-incoming-message.d.ts +16 -0
  37. package/dist/http/parse-incoming-message.js +75 -0
  38. package/dist/http/parse-incoming-message.js.map +1 -0
  39. package/dist/index.d.ts +3 -1
  40. package/dist/index.js +17 -0
  41. package/dist/index.js.map +1 -1
  42. package/dist/ssrf/hostname-matcher.d.ts +6 -0
  43. package/dist/ssrf/hostname-matcher.js +38 -0
  44. package/dist/ssrf/hostname-matcher.js.map +1 -0
  45. package/dist/ssrf/index.d.ts +3 -0
  46. package/dist/ssrf/index.js +8 -0
  47. package/dist/ssrf/index.js.map +1 -0
  48. package/dist/ssrf/ip-range-builder.d.ts +10 -0
  49. package/dist/ssrf/ip-range-builder.js +52 -0
  50. package/dist/ssrf/ip-range-builder.js.map +1 -0
  51. package/dist/ssrf/ssrf-blocked-ip.error.d.ts +6 -0
  52. package/dist/ssrf/ssrf-blocked-ip.error.js +21 -0
  53. package/dist/ssrf/ssrf-blocked-ip.error.js.map +1 -0
  54. package/dist/ssrf/ssrf-protection.service.d.ts +48 -0
  55. package/dist/ssrf/ssrf-protection.service.js +192 -0
  56. package/dist/ssrf/ssrf-protection.service.js.map +1 -0
  57. package/package.json +36 -8
@@ -0,0 +1,7 @@
1
+ import http from 'http';
2
+ import https from 'https';
3
+ export declare function resolveProxyUrl(targetUrl: string): string | undefined;
4
+ export declare function createHttpProxyAgent(customProxyUrl: string | null | undefined, targetUrl: string, options?: http.AgentOptions): http.Agent;
5
+ export declare function createHttpsProxyAgent(customProxyUrl: string | null | undefined, targetUrl: string, options?: https.AgentOptions): https.Agent;
6
+ export declare function installGlobalProxyAgent(): void;
7
+ export declare function uninstallGlobalProxyAgent(): void;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveProxyUrl = resolveProxyUrl;
7
+ exports.createHttpProxyAgent = createHttpProxyAgent;
8
+ exports.createHttpsProxyAgent = createHttpsProxyAgent;
9
+ exports.installGlobalProxyAgent = installGlobalProxyAgent;
10
+ exports.uninstallGlobalProxyAgent = uninstallGlobalProxyAgent;
11
+ const http_1 = __importDefault(require("http"));
12
+ const http_proxy_agent_1 = require("http-proxy-agent");
13
+ const https_1 = __importDefault(require("https"));
14
+ const https_proxy_agent_1 = require("https-proxy-agent");
15
+ const n8n_workflow_1 = require("n8n-workflow");
16
+ const proxy_from_env_1 = require("proxy-from-env");
17
+ function buildTargetUrl(hostname, port, protocol) {
18
+ const defaultPort = protocol === 'https' ? 443 : 80;
19
+ const portSuffix = port === defaultPort ? '' : `:${port}`;
20
+ return `${protocol}://${hostname}${portSuffix}`;
21
+ }
22
+ function extractHostInfo(options, defaultPort) {
23
+ const hostname = options.hostname ?? options.host ?? 'localhost';
24
+ const port = typeof options.port === 'string' ? parseInt(options.port, 10) : (options.port ?? defaultPort);
25
+ return { hostname: String(hostname), port: Number(port) };
26
+ }
27
+ function getOrCreateProxyAgent(cache, proxyUrl, createAgent) {
28
+ let proxyAgent = cache.get(proxyUrl);
29
+ if (!proxyAgent) {
30
+ proxyAgent = createAgent(proxyUrl);
31
+ cache.set(proxyUrl, proxyAgent);
32
+ }
33
+ return proxyAgent;
34
+ }
35
+ function createFallbackAgent(agentClass) {
36
+ return new agentClass();
37
+ }
38
+ class HttpProxyManager extends http_1.default.Agent {
39
+ constructor() {
40
+ super(...arguments);
41
+ this.proxyAgentCache = new Map();
42
+ this.fallbackAgent = createFallbackAgent(http_1.default.Agent);
43
+ }
44
+ addRequest(req, options) {
45
+ const { hostname, port } = extractHostInfo(options, 80);
46
+ const targetUrl = buildTargetUrl(hostname, port, 'http');
47
+ const proxyUrl = (0, proxy_from_env_1.getProxyForUrl)(targetUrl);
48
+ if (proxyUrl) {
49
+ const proxyAgent = getOrCreateProxyAgent(this.proxyAgentCache, proxyUrl, (url) => new http_proxy_agent_1.HttpProxyAgent(url));
50
+ return proxyAgent.addRequest(req, options);
51
+ }
52
+ return this.fallbackAgent.addRequest(req, options);
53
+ }
54
+ }
55
+ class HttpsProxyManager extends https_1.default.Agent {
56
+ constructor() {
57
+ super(...arguments);
58
+ this.proxyAgentCache = new Map();
59
+ this.fallbackAgent = createFallbackAgent(https_1.default.Agent);
60
+ }
61
+ addRequest(req, options) {
62
+ const { hostname, port } = extractHostInfo(options, 443);
63
+ const targetUrl = buildTargetUrl(hostname, port, 'https');
64
+ const proxyUrl = (0, proxy_from_env_1.getProxyForUrl)(targetUrl);
65
+ if (proxyUrl) {
66
+ const proxyAgent = getOrCreateProxyAgent(this.proxyAgentCache, proxyUrl, (url) => new https_proxy_agent_1.HttpsProxyAgent(url));
67
+ return proxyAgent.addRequest(req, options);
68
+ }
69
+ return this.fallbackAgent.addRequest(req, options);
70
+ }
71
+ }
72
+ function resolveProxyUrl(targetUrl) {
73
+ return (0, proxy_from_env_1.getProxyForUrl)(targetUrl) || undefined;
74
+ }
75
+ function createHttpProxyAgent(customProxyUrl = null, targetUrl, options) {
76
+ const proxyUrl = customProxyUrl ?? (0, proxy_from_env_1.getProxyForUrl)(targetUrl);
77
+ if (proxyUrl) {
78
+ return new http_proxy_agent_1.HttpProxyAgent(proxyUrl, options);
79
+ }
80
+ return new http_1.default.Agent(options);
81
+ }
82
+ function createHttpsProxyAgent(customProxyUrl = null, targetUrl, options) {
83
+ const proxyUrl = customProxyUrl ?? (0, proxy_from_env_1.getProxyForUrl)(targetUrl);
84
+ if (proxyUrl) {
85
+ return new https_proxy_agent_1.HttpsProxyAgent(proxyUrl, options);
86
+ }
87
+ return new https_1.default.Agent(options);
88
+ }
89
+ function hasProxyEnvironmentVariables() {
90
+ return Boolean(process.env.HTTP_PROXY ??
91
+ process.env.http_proxy ??
92
+ process.env.HTTPS_PROXY ??
93
+ process.env.https_proxy ??
94
+ process.env.ALL_PROXY ??
95
+ process.env.all_proxy);
96
+ }
97
+ function installGlobalProxyAgent() {
98
+ if (hasProxyEnvironmentVariables()) {
99
+ n8n_workflow_1.LoggerProxy.debug('Installing global HTTP proxy agents', {
100
+ HTTP_PROXY: process.env.HTTP_PROXY ?? process.env.http_proxy,
101
+ HTTPS_PROXY: process.env.HTTPS_PROXY ?? process.env.https_proxy,
102
+ NO_PROXY: process.env.NO_PROXY ?? process.env.no_proxy,
103
+ ALL_PROXY: process.env.ALL_PROXY ?? process.env.all_proxy,
104
+ });
105
+ http_1.default.globalAgent = new HttpProxyManager();
106
+ https_1.default.globalAgent = new HttpsProxyManager();
107
+ }
108
+ }
109
+ function uninstallGlobalProxyAgent() {
110
+ http_1.default.globalAgent = new http_1.default.Agent();
111
+ https_1.default.globalAgent = new https_1.default.Agent();
112
+ }
113
+ //# sourceMappingURL=http-proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-proxy.js","sourceRoot":"","sources":["../../src/http/http-proxy.ts"],"names":[],"mappings":";;;;;AAqGA,0CAEC;AAED,oDAYC;AAED,sDAYC;AAaD,0DAYC;AAED,8DAGC;AAjKD,gDAAwB;AACxB,uDAAkD;AAClD,kDAA0B;AAC1B,yDAAoD;AACpD,+CAA2C;AAC3C,mDAAgD;AAMhD,SAAS,cAAc,CAAC,QAAgB,EAAE,IAAY,EAAE,QAA0B;IACjF,MAAM,WAAW,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,MAAM,UAAU,GAAG,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;IAC1D,OAAO,GAAG,QAAQ,MAAM,QAAQ,GAAG,UAAU,EAAE,CAAC;AACjD,CAAC;AAED,SAAS,eAAe,CACvB,OAA4B,EAC5B,WAAmB;IAEnB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,IAAI,WAAW,CAAC;IACjE,MAAM,IAAI,GACT,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAA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ACzD,CAAC,CAAC;QAEH,cAAI,CAAC,WAAW,GAAG,IAAI,gBAAgB,EAAE,CAAC;QAC1C,eAAK,CAAC,WAAW,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC7C,CAAC;AACF,CAAC;AAED,SAAgB,yBAAyB;IACxC,cAAI,CAAC,WAAW,GAAG,IAAI,cAAI,CAAC,KAAK,EAAE,CAAC;IACpC,eAAK,CAAC,WAAW,GAAG,IAAI,eAAK,CAAC,KAAK,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ import type { IHttpRequestOptions, IN8nHttpFullResponse, IN8nHttpResponse, IRequestOptions } from 'n8n-workflow';
3
+ import type { SsrfBridge } from '../ssrf';
4
+ export declare function invokeAxios(axiosConfig: AxiosRequestConfig, authOptions?: IRequestOptions['auth']): Promise<import("axios").AxiosResponse<any, any, {}>>;
5
+ export declare function convertN8nRequestToAxios(n8nRequest: IHttpRequestOptions, ssrfBridge?: SsrfBridge): AxiosRequestConfig;
6
+ export declare function removeEmptyBody(requestOptions: IHttpRequestOptions | IRequestOptions): void;
7
+ export declare function httpRequest(requestOptions: IHttpRequestOptions, ssrfBridge?: SsrfBridge): Promise<IN8nHttpFullResponse | IN8nHttpResponse>;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.invokeAxios = invokeAxios;
7
+ exports.convertN8nRequestToAxios = convertN8nRequestToAxios;
8
+ exports.removeEmptyBody = removeEmptyBody;
9
+ exports.httpRequest = httpRequest;
10
+ const axios_1 = __importDefault(require("axios"));
11
+ const n8n_workflow_1 = require("n8n-workflow");
12
+ const qs_1 = require("qs");
13
+ const axios_utils_1 = require("./axios-utils");
14
+ const outbound_user_agent_1 = require("./outbound-user-agent");
15
+ async function invokeAxios(axiosConfig, authOptions = {}) {
16
+ try {
17
+ return await (0, axios_1.default)(axiosConfig);
18
+ }
19
+ catch (error) {
20
+ if (authOptions.sendImmediately !== false || !(error instanceof axios_1.default.AxiosError))
21
+ throw error;
22
+ const { response } = error;
23
+ if (response?.status !== 401 || !response.headers['www-authenticate']?.includes('nonce')) {
24
+ throw error;
25
+ }
26
+ const { auth } = axiosConfig;
27
+ delete axiosConfig.auth;
28
+ axiosConfig = (0, axios_utils_1.digestAuthAxiosConfig)(axiosConfig, response, auth);
29
+ return await (0, axios_1.default)(axiosConfig);
30
+ }
31
+ }
32
+ function convertN8nRequestToAxios(n8nRequest, ssrfBridge) {
33
+ const { headers, method, timeout, auth, proxy, url } = n8nRequest;
34
+ const axiosRequest = {
35
+ headers: headers ?? {},
36
+ method,
37
+ timeout,
38
+ auth,
39
+ url,
40
+ maxBodyLength: Infinity,
41
+ maxContentLength: Infinity,
42
+ };
43
+ axiosRequest.params = n8nRequest.qs;
44
+ if (n8nRequest.abortSignal) {
45
+ axiosRequest.signal = n8nRequest.abortSignal;
46
+ }
47
+ if (n8nRequest.baseURL !== undefined) {
48
+ axiosRequest.baseURL = n8nRequest.baseURL;
49
+ }
50
+ if (n8nRequest.disableFollowRedirect === true) {
51
+ axiosRequest.maxRedirects = 0;
52
+ }
53
+ if (n8nRequest.encoding !== undefined) {
54
+ axiosRequest.responseType = n8nRequest.encoding;
55
+ }
56
+ const host = (0, axios_utils_1.getHostFromRequestObject)(n8nRequest);
57
+ const agentOptions = { ...n8nRequest.agentOptions };
58
+ if (host) {
59
+ agentOptions.servername = host;
60
+ }
61
+ if (n8nRequest.skipSslCertificateValidation === true) {
62
+ agentOptions.rejectUnauthorized = false;
63
+ }
64
+ const secureLookup = ssrfBridge?.createSecureLookup();
65
+ (0, axios_utils_1.setAxiosAgents)(axiosRequest, agentOptions, proxy, secureLookup);
66
+ axiosRequest.beforeRedirect = (0, axios_utils_1.getBeforeRedirectFn)(agentOptions, axiosRequest, n8nRequest.proxy, n8nRequest.sendCredentialsOnCrossOriginRedirect ?? true, n8nRequest.allowedDomains, ssrfBridge);
67
+ if (n8nRequest.arrayFormat !== undefined) {
68
+ axiosRequest.paramsSerializer = (params) => {
69
+ return (0, qs_1.stringify)(params, { arrayFormat: n8nRequest.arrayFormat });
70
+ };
71
+ }
72
+ const { body } = n8nRequest;
73
+ if (body) {
74
+ const existingContentTypeHeaderKey = (0, axios_utils_1.searchForHeader)(axiosRequest, 'content-type');
75
+ if (existingContentTypeHeaderKey === undefined) {
76
+ axiosRequest.headers = axiosRequest.headers || {};
77
+ if ((0, axios_utils_1.isFormDataInstance)(body)) {
78
+ axiosRequest.headers = {
79
+ ...axiosRequest.headers,
80
+ ...body.getHeaders(),
81
+ };
82
+ }
83
+ else if (body instanceof URLSearchParams) {
84
+ axiosRequest.headers['Content-Type'] = 'application/x-www-form-urlencoded';
85
+ }
86
+ }
87
+ else if (axiosRequest.headers?.[existingContentTypeHeaderKey] === 'application/x-www-form-urlencoded') {
88
+ axiosRequest.data = new URLSearchParams(n8nRequest.body);
89
+ }
90
+ if (typeof body === 'string' || (typeof body === 'object' && !(0, n8n_workflow_1.isObjectEmpty)(body))) {
91
+ axiosRequest.data = body;
92
+ }
93
+ }
94
+ if (n8nRequest.json) {
95
+ const key = (0, axios_utils_1.searchForHeader)(axiosRequest, 'accept');
96
+ if (!key) {
97
+ axiosRequest.headers = {
98
+ ...axiosRequest.headers,
99
+ Accept: 'application/json',
100
+ };
101
+ }
102
+ }
103
+ (0, outbound_user_agent_1.applyDefaultOutboundUserAgent)(axiosRequest);
104
+ if (n8nRequest.ignoreHttpStatusErrors) {
105
+ const ignoreHttpStatusErrors = n8nRequest.ignoreHttpStatusErrors;
106
+ if ((0, axios_utils_1.isIgnoreStatusErrorConfig)(ignoreHttpStatusErrors)) {
107
+ axiosRequest.validateStatus = (status) => {
108
+ return !ignoreHttpStatusErrors.except.includes(status);
109
+ };
110
+ }
111
+ else {
112
+ axiosRequest.validateStatus = () => true;
113
+ }
114
+ }
115
+ return axiosRequest;
116
+ }
117
+ const NoBodyHttpMethods = ['GET', 'HEAD', 'OPTIONS'];
118
+ function isEmpty(value) {
119
+ if (value === null || value === undefined) {
120
+ return true;
121
+ }
122
+ if (typeof value === 'string' || Array.isArray(value) || Buffer.isBuffer(value)) {
123
+ return value.length === 0;
124
+ }
125
+ if (typeof value === 'object') {
126
+ return Object.keys(value).length === 0;
127
+ }
128
+ return false;
129
+ }
130
+ function removeEmptyBody(requestOptions) {
131
+ const method = requestOptions.method || 'GET';
132
+ if (NoBodyHttpMethods.includes(method) && isEmpty(requestOptions.body)) {
133
+ delete requestOptions.body;
134
+ }
135
+ }
136
+ async function httpRequest(requestOptions, ssrfBridge) {
137
+ removeEmptyBody(requestOptions);
138
+ const url = (0, axios_utils_1.buildTargetUrl)(requestOptions.url, requestOptions.baseURL) ?? requestOptions.url;
139
+ await (0, axios_utils_1.validateUrlSsrf)(url, ssrfBridge);
140
+ const axiosRequest = convertN8nRequestToAxios(requestOptions, ssrfBridge);
141
+ if (axiosRequest.data === undefined ||
142
+ (axiosRequest.method !== undefined && axiosRequest.method.toUpperCase() === 'GET')) {
143
+ delete axiosRequest.data;
144
+ }
145
+ (0, axios_utils_1.throwIfDomainNotAllowed)(axiosRequest, requestOptions.allowedDomains);
146
+ const result = await invokeAxios(axiosRequest, requestOptions.auth);
147
+ if (requestOptions.returnFullResponse) {
148
+ return {
149
+ body: result.data,
150
+ headers: result.headers,
151
+ statusCode: result.status,
152
+ statusMessage: result.statusText,
153
+ };
154
+ }
155
+ return result.data;
156
+ }
157
+ //# sourceMappingURL=http-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-request.js","sourceRoot":"","sources":["../../src/http/http-request.ts"],"names":[],"mappings":";;;;;AA6BA,kCAkBC;AAED,4DAoHC;AAqBD,0CAKC;AAED,kCAiCC;AA/ND,kDAA0B;AAQ1B,+CAA6C;AAC7C,2BAA+B;AAG/B,+CAWuB;AACvB,+DAAsE;AA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IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QACxE,OAAO,cAAc,CAAC,IAAI,CAAC;IAC5B,CAAC;AACF,CAAC;AAEM,KAAK,UAAU,WAAW,CAChC,cAAmC,EACnC,UAAuB;IAEvB,eAAe,CAAC,cAAc,CAAC,CAAC;IAEhC,MAAM,GAAG,GAAG,IAAA,4BAAc,EAAC,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC,GAAG,CAAC;IAC7F,MAAM,IAAA,6BAAe,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAEvC,MAAM,YAAY,GAAG,wBAAwB,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAC1E,IACC,YAAY,CAAC,IAAI,KAAK,SAAS;QAC/B,CAAC,YAAY,CAAC,MAAM,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,EACjF,CAAC;QACF,OAAO,YAAY,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,IAAA,qCAAuB,EAAC,YAAY,EAAE,cAAc,CAAC,cAAc,CAAC,CAAC;IAErE,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,YAAY,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IAEpE,IAAI,cAAc,CAAC,kBAAkB,EAAE,CAAC;QACvC,OAAO;YAEN,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,UAAU,EAAE,MAAM,CAAC,MAAM;YACzB,aAAa,EAAE,MAAM,CAAC,UAAU;SAChC,CAAC;IACH,CAAC;IAGD,OAAO,MAAM,CAAC,IAAI,CAAC;AACpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { createHttpProxyAgent, createHttpsProxyAgent, installGlobalProxyAgent, resolveProxyUrl, } from './http-proxy';
2
+ export { configureGlobalAxiosDefaults } from './axios-config';
3
+ export { createFormDataObject, generateContentLengthHeader, getBeforeRedirectFn, getHostFromRequestObject, isFormDataInstance, resolveLegacyRequestUrl, searchForHeader, setAxiosAgents, throwIfDomainNotAllowed, tryParseUrl, validateUrlSsrf, } from './axios-utils';
4
+ export { convertN8nRequestToAxios, httpRequest, invokeAxios, removeEmptyBody, } from './http-request';
5
+ export { applyDefaultOutboundUserAgent, buildRfcStyleUserAgent, getDefaultN8nOutboundUserAgent, } from './outbound-user-agent';
6
+ export { parseIncomingMessage } from './parse-incoming-message';
7
+ export { binaryToBuffer, streamToBuffer } from './binary-buffer';
8
+ export { binaryToString } from './binary-string';
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.binaryToString = exports.streamToBuffer = exports.binaryToBuffer = exports.parseIncomingMessage = exports.getDefaultN8nOutboundUserAgent = exports.buildRfcStyleUserAgent = exports.applyDefaultOutboundUserAgent = exports.removeEmptyBody = exports.invokeAxios = exports.httpRequest = exports.convertN8nRequestToAxios = exports.validateUrlSsrf = exports.tryParseUrl = exports.throwIfDomainNotAllowed = exports.setAxiosAgents = exports.searchForHeader = exports.resolveLegacyRequestUrl = exports.isFormDataInstance = exports.getHostFromRequestObject = exports.getBeforeRedirectFn = exports.generateContentLengthHeader = exports.createFormDataObject = exports.configureGlobalAxiosDefaults = exports.resolveProxyUrl = exports.installGlobalProxyAgent = exports.createHttpsProxyAgent = exports.createHttpProxyAgent = void 0;
4
+ var http_proxy_1 = require("./http-proxy");
5
+ Object.defineProperty(exports, "createHttpProxyAgent", { enumerable: true, get: function () { return http_proxy_1.createHttpProxyAgent; } });
6
+ Object.defineProperty(exports, "createHttpsProxyAgent", { enumerable: true, get: function () { return http_proxy_1.createHttpsProxyAgent; } });
7
+ Object.defineProperty(exports, "installGlobalProxyAgent", { enumerable: true, get: function () { return http_proxy_1.installGlobalProxyAgent; } });
8
+ Object.defineProperty(exports, "resolveProxyUrl", { enumerable: true, get: function () { return http_proxy_1.resolveProxyUrl; } });
9
+ var axios_config_1 = require("./axios-config");
10
+ Object.defineProperty(exports, "configureGlobalAxiosDefaults", { enumerable: true, get: function () { return axios_config_1.configureGlobalAxiosDefaults; } });
11
+ var axios_utils_1 = require("./axios-utils");
12
+ Object.defineProperty(exports, "createFormDataObject", { enumerable: true, get: function () { return axios_utils_1.createFormDataObject; } });
13
+ Object.defineProperty(exports, "generateContentLengthHeader", { enumerable: true, get: function () { return axios_utils_1.generateContentLengthHeader; } });
14
+ Object.defineProperty(exports, "getBeforeRedirectFn", { enumerable: true, get: function () { return axios_utils_1.getBeforeRedirectFn; } });
15
+ Object.defineProperty(exports, "getHostFromRequestObject", { enumerable: true, get: function () { return axios_utils_1.getHostFromRequestObject; } });
16
+ Object.defineProperty(exports, "isFormDataInstance", { enumerable: true, get: function () { return axios_utils_1.isFormDataInstance; } });
17
+ Object.defineProperty(exports, "resolveLegacyRequestUrl", { enumerable: true, get: function () { return axios_utils_1.resolveLegacyRequestUrl; } });
18
+ Object.defineProperty(exports, "searchForHeader", { enumerable: true, get: function () { return axios_utils_1.searchForHeader; } });
19
+ Object.defineProperty(exports, "setAxiosAgents", { enumerable: true, get: function () { return axios_utils_1.setAxiosAgents; } });
20
+ Object.defineProperty(exports, "throwIfDomainNotAllowed", { enumerable: true, get: function () { return axios_utils_1.throwIfDomainNotAllowed; } });
21
+ Object.defineProperty(exports, "tryParseUrl", { enumerable: true, get: function () { return axios_utils_1.tryParseUrl; } });
22
+ Object.defineProperty(exports, "validateUrlSsrf", { enumerable: true, get: function () { return axios_utils_1.validateUrlSsrf; } });
23
+ var http_request_1 = require("./http-request");
24
+ Object.defineProperty(exports, "convertN8nRequestToAxios", { enumerable: true, get: function () { return http_request_1.convertN8nRequestToAxios; } });
25
+ Object.defineProperty(exports, "httpRequest", { enumerable: true, get: function () { return http_request_1.httpRequest; } });
26
+ Object.defineProperty(exports, "invokeAxios", { enumerable: true, get: function () { return http_request_1.invokeAxios; } });
27
+ Object.defineProperty(exports, "removeEmptyBody", { enumerable: true, get: function () { return http_request_1.removeEmptyBody; } });
28
+ var outbound_user_agent_1 = require("./outbound-user-agent");
29
+ Object.defineProperty(exports, "applyDefaultOutboundUserAgent", { enumerable: true, get: function () { return outbound_user_agent_1.applyDefaultOutboundUserAgent; } });
30
+ Object.defineProperty(exports, "buildRfcStyleUserAgent", { enumerable: true, get: function () { return outbound_user_agent_1.buildRfcStyleUserAgent; } });
31
+ Object.defineProperty(exports, "getDefaultN8nOutboundUserAgent", { enumerable: true, get: function () { return outbound_user_agent_1.getDefaultN8nOutboundUserAgent; } });
32
+ var parse_incoming_message_1 = require("./parse-incoming-message");
33
+ Object.defineProperty(exports, "parseIncomingMessage", { enumerable: true, get: function () { return parse_incoming_message_1.parseIncomingMessage; } });
34
+ var binary_buffer_1 = require("./binary-buffer");
35
+ Object.defineProperty(exports, "binaryToBuffer", { enumerable: true, get: function () { return binary_buffer_1.binaryToBuffer; } });
36
+ Object.defineProperty(exports, "streamToBuffer", { enumerable: true, get: function () { return binary_buffer_1.streamToBuffer; } });
37
+ var binary_string_1 = require("./binary-string");
38
+ Object.defineProperty(exports, "binaryToString", { enumerable: true, get: function () { return binary_string_1.binaryToString; } });
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":";;;AAAA,2CAKsB;AAJrB,kHAAA,oBAAoB,OAAA;AACpB,mHAAA,qBAAqB,OAAA;AACrB,qHAAA,uBAAuB,OAAA;AACvB,6GAAA,eAAe,OAAA;AAEhB,+CAA8D;AAArD,4HAAA,4BAA4B,OAAA;AACrC,6CAYuB;AAXtB,mHAAA,oBAAoB,OAAA;AACpB,0HAAA,2BAA2B,OAAA;AAC3B,kHAAA,mBAAmB,OAAA;AACnB,uHAAA,wBAAwB,OAAA;AACxB,iHAAA,kBAAkB,OAAA;AAClB,sHAAA,uBAAuB,OAAA;AACvB,8GAAA,eAAe,OAAA;AACf,6GAAA,cAAc,OAAA;AACd,sHAAA,uBAAuB,OAAA;AACvB,0GAAA,WAAW,OAAA;AACX,8GAAA,eAAe,OAAA;AAEhB,+CAKwB;AAJvB,wHAAA,wBAAwB,OAAA;AACxB,2GAAA,WAAW,OAAA;AACX,2GAAA,WAAW,OAAA;AACX,+GAAA,eAAe,OAAA;AAEhB,6DAI+B;AAH9B,oIAAA,6BAA6B,OAAA;AAC7B,6HAAA,sBAAsB,OAAA;AACtB,qIAAA,8BAA8B,OAAA;AAE/B,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA;AAC7B,iDAAiE;AAAxD,+GAAA,cAAc,OAAA;AAAE,+GAAA,cAAc,OAAA;AACvC,iDAAiD;AAAxC,+GAAA,cAAc,OAAA"}
@@ -0,0 +1,4 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ export declare function buildRfcStyleUserAgent(version: string): string;
3
+ export declare function getDefaultN8nOutboundUserAgent(): string;
4
+ export declare function applyDefaultOutboundUserAgent(axiosConfig: AxiosRequestConfig): void;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRfcStyleUserAgent = buildRfcStyleUserAgent;
4
+ exports.getDefaultN8nOutboundUserAgent = getDefaultN8nOutboundUserAgent;
5
+ exports.applyDefaultOutboundUserAgent = applyDefaultOutboundUserAgent;
6
+ const config_1 = require("@n8n/config");
7
+ const di_1 = require("@n8n/di");
8
+ const node_path_1 = require("node:path");
9
+ const axios_utils_1 = require("./axios-utils");
10
+ const N8N_PRODUCT_URL = 'https://n8n.io/';
11
+ const LEGACY_USER_AGENT = 'n8n';
12
+ function readN8nVersion() {
13
+ try {
14
+ const pkg = require((0, node_path_1.join)(__dirname, '../../../../package.json'));
15
+ return pkg.version;
16
+ }
17
+ catch {
18
+ return '0.0.0';
19
+ }
20
+ }
21
+ function buildRfcStyleUserAgent(version) {
22
+ return `Mozilla/5.0 (compatible; n8n/${version}; +${N8N_PRODUCT_URL})`;
23
+ }
24
+ function getDefaultN8nOutboundUserAgent() {
25
+ const { enforceGlobalUserAgent, globalUserAgentValue } = di_1.Container.get(config_1.HttpRequestConfig);
26
+ if (!enforceGlobalUserAgent)
27
+ return LEGACY_USER_AGENT;
28
+ if (globalUserAgentValue.length > 0)
29
+ return globalUserAgentValue;
30
+ return buildRfcStyleUserAgent(readN8nVersion());
31
+ }
32
+ function applyDefaultOutboundUserAgent(axiosConfig) {
33
+ if ((0, axios_utils_1.searchForHeader)(axiosConfig, 'user-agent'))
34
+ return;
35
+ axiosConfig.headers = {
36
+ ...axiosConfig.headers,
37
+ 'User-Agent': getDefaultN8nOutboundUserAgent(),
38
+ };
39
+ }
40
+ //# sourceMappingURL=outbound-user-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbound-user-agent.js","sourceRoot":"","sources":["../../src/http/outbound-user-agent.ts"],"names":[],"mappings":";;AA2BA,wDAEC;AAUD,wEAQC;AAMD,sEAOC;AA5DD,wCAAgD;AAChD,gCAAoC;AAEpC,yCAAiC;AAEjC,+CAAgD;AAEhD,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAC1C,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC,SAAS,cAAc;IACtB,IAAI,CAAC;QAGJ,MAAM,GAAG,GAAG,OAAO,CAAC,IAAA,gBAAI,EAAC,SAAS,EAAE,0BAA0B,CAAC,CAAwB,CAAC;QACxF,OAAO,GAAG,CAAC,OAAO,CAAC;IACpB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,OAAO,CAAC;IAChB,CAAC;AACF,CAAC;AAQD,SAAgB,sBAAsB,CAAC,OAAe;IACrD,OAAO,gCAAgC,OAAO,MAAM,eAAe,GAAG,CAAC;AACxE,CAAC;AAUD,SAAgB,8BAA8B;IAC7C,MAAM,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,GAAG,cAAS,CAAC,GAAG,CAAC,0BAAiB,CAAC,CAAC;IAE1F,IAAI,CAAC,sBAAsB;QAAE,OAAO,iBAAiB,CAAC;IAEtD,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,oBAAoB,CAAC;IAEjE,OAAO,sBAAsB,CAAC,cAAc,EAAE,CAAC,CAAC;AACjD,CAAC;AAMD,SAAgB,6BAA6B,CAAC,WAA+B;IAC5E,IAAI,IAAA,6BAAe,EAAC,WAAW,EAAE,YAAY,CAAC;QAAE,OAAO;IAEvD,WAAW,CAAC,OAAO,GAAG;QACrB,GAAG,WAAW,CAAC,OAAO;QACtB,YAAY,EAAE,8BAA8B,EAAE;KAC9C,CAAC;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { IncomingMessage } from 'http';
2
+ interface IContentType {
3
+ type: string;
4
+ parameters: {
5
+ charset: string;
6
+ [key: string]: string;
7
+ };
8
+ }
9
+ export declare const parseContentType: (contentType?: string) => IContentType | null;
10
+ interface IContentDisposition {
11
+ type: string;
12
+ filename?: string;
13
+ }
14
+ export declare const parseContentDisposition: (contentDisposition?: string) => IContentDisposition | null;
15
+ export declare function parseIncomingMessage(message: IncomingMessage): void;
16
+ export {};
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseContentDisposition = exports.parseContentType = void 0;
4
+ exports.parseIncomingMessage = parseIncomingMessage;
5
+ function parseHeaderParameters(parameters) {
6
+ return parameters.reduce((acc, param) => {
7
+ const eqIdx = param.indexOf('=');
8
+ if (eqIdx === -1)
9
+ return acc;
10
+ const key = param.slice(0, eqIdx);
11
+ let processedValue = param.slice(eqIdx + 1).trim();
12
+ if (processedValue.startsWith('"') && processedValue.endsWith('"')) {
13
+ processedValue = processedValue.slice(1, -1);
14
+ try {
15
+ processedValue = decodeURIComponent(processedValue);
16
+ }
17
+ catch {
18
+ }
19
+ }
20
+ else {
21
+ try {
22
+ processedValue = decodeURIComponent(processedValue);
23
+ if (processedValue.startsWith('"') && processedValue.endsWith('"')) {
24
+ processedValue = processedValue.slice(1, -1);
25
+ }
26
+ }
27
+ catch {
28
+ }
29
+ }
30
+ acc[key.toLowerCase().trim()] = processedValue;
31
+ return acc;
32
+ }, {});
33
+ }
34
+ const parseContentType = (contentType) => {
35
+ if (!contentType) {
36
+ return null;
37
+ }
38
+ const [type, ...parameters] = contentType.split(';');
39
+ return {
40
+ type: type.toLowerCase(),
41
+ parameters: { charset: 'utf-8', ...parseHeaderParameters(parameters) },
42
+ };
43
+ };
44
+ exports.parseContentType = parseContentType;
45
+ const parseContentDisposition = (contentDisposition) => {
46
+ if (!contentDisposition) {
47
+ return null;
48
+ }
49
+ if (!contentDisposition.startsWith('attachment') && !contentDisposition.startsWith('inline')) {
50
+ contentDisposition = `attachment; ${contentDisposition}`;
51
+ }
52
+ const [type, ...parameters] = contentDisposition.split(';');
53
+ const parsedParameters = parseHeaderParameters(parameters);
54
+ let { filename } = parsedParameters;
55
+ const wildcard = parsedParameters['filename*'];
56
+ if (wildcard) {
57
+ const [_encoding, _locale, content] = wildcard?.split("'") ?? [];
58
+ filename = content;
59
+ }
60
+ return { type, filename };
61
+ };
62
+ exports.parseContentDisposition = parseContentDisposition;
63
+ function parseIncomingMessage(message) {
64
+ const contentType = (0, exports.parseContentType)(message.headers['content-type']);
65
+ if (contentType) {
66
+ const { type, parameters } = contentType;
67
+ message.contentType = type;
68
+ message.encoding = parameters.charset.toLowerCase();
69
+ }
70
+ const contentDisposition = (0, exports.parseContentDisposition)(message.headers['content-disposition']);
71
+ if (contentDisposition) {
72
+ message.contentDisposition = contentDisposition;
73
+ }
74
+ }
75
+ //# sourceMappingURL=parse-incoming-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-incoming-message.js","sourceRoot":"","sources":["../../src/http/parse-incoming-message.ts"],"names":[],"mappings":";;;AA2GA,oDAYC;AArHD,SAAS,qBAAqB,CAAC,UAAoB;IAClD,OAAO,UAAU,CAAC,MAAM,CACvB,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACd,MAA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AO,CAAC,cAAc,CAAC,CAAC,CAAC;IACtE,IAAI,WAAW,EAAE,CAAC;QACjB,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;QACzC,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;QAC3B,OAAO,CAAC,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,WAAW,EAAoB,CAAC;IACvE,CAAC;IAED,MAAM,kBAAkB,GAAG,IAAA,+BAAuB,EAAC,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAC3F,IAAI,kBAAkB,EAAE,CAAC;QACxB,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IACjD,CAAC;AACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1 +1,3 @@
1
- export {};
1
+ export * from './dns';
2
+ export * from './ssrf';
3
+ export * from './http';
package/dist/index.js CHANGED
@@ -1,3 +1,20 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./dns"), exports);
18
+ __exportStar(require("./ssrf"), exports);
19
+ __exportStar(require("./http"), exports);
3
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,yCAAuB;AACvB,yCAAuB"}
@@ -0,0 +1,6 @@
1
+ export declare class HostnameMatcher {
2
+ private readonly parsed;
3
+ constructor(patterns: readonly string[]);
4
+ matches(hostname: string): boolean;
5
+ private normalizeHostname;
6
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HostnameMatcher = void 0;
4
+ class HostnameMatcher {
5
+ constructor(patterns) {
6
+ this.parsed = patterns
7
+ .map((p) => this.normalizeHostname(p))
8
+ .filter(Boolean)
9
+ .map((value) => {
10
+ if (value.startsWith('*.')) {
11
+ const suffix = value.slice(1);
12
+ return { isWildcard: true, suffix };
13
+ }
14
+ return { isWildcard: false, value };
15
+ });
16
+ }
17
+ matches(hostname) {
18
+ const normalizedHostname = this.normalizeHostname(hostname);
19
+ for (const pattern of this.parsed) {
20
+ if (pattern.isWildcard) {
21
+ if (normalizedHostname.endsWith(pattern.suffix) &&
22
+ normalizedHostname.length > pattern.suffix.length) {
23
+ return true;
24
+ }
25
+ continue;
26
+ }
27
+ if (normalizedHostname === pattern.value) {
28
+ return true;
29
+ }
30
+ }
31
+ return false;
32
+ }
33
+ normalizeHostname(hostname) {
34
+ return hostname.trim().toLowerCase();
35
+ }
36
+ }
37
+ exports.HostnameMatcher = HostnameMatcher;
38
+ //# sourceMappingURL=hostname-matcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hostname-matcher.js","sourceRoot":"","sources":["../../src/ssrf/hostname-matcher.ts"],"names":[],"mappings":";;;AAiBA,MAAa,eAAe;IAG3B,YAAY,QAA2B;QACtC,IAAI,CAAC,MAAM,GAAG,QAAQ;aACpB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;aACrC,MAAM,CAAC,OAAO,CAAC;aACf,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACd,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC5B,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC9B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YACrC,CAAC;YACD,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC;IAKD,OAAO,CAAC,QAAgB;QACvB,MAAM,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAE5D,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACnC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBAGxB,IACC,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;oBAC3C,kBAAkB,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAChD,CAAC;oBACF,OAAO,IAAI,CAAC;gBACb,CAAC;gBACD,SAAS;YACV,CAAC;YAGD,IAAI,kBAAkB,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC1C,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC;IAEO,iBAAiB,CAAC,QAAgB;QACzC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACtC,CAAC;CACD;AA/CD,0CA+CC"}
@@ -0,0 +1,3 @@
1
+ export { SsrfProtectionService } from './ssrf-protection.service';
2
+ export type { SsrfBridge } from './ssrf-protection.service';
3
+ export { SsrfBlockedIpError } from './ssrf-blocked-ip.error';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SsrfBlockedIpError = exports.SsrfProtectionService = void 0;
4
+ var ssrf_protection_service_1 = require("./ssrf-protection.service");
5
+ Object.defineProperty(exports, "SsrfProtectionService", { enumerable: true, get: function () { return ssrf_protection_service_1.SsrfProtectionService; } });
6
+ var ssrf_blocked_ip_error_1 = require("./ssrf-blocked-ip.error");
7
+ Object.defineProperty(exports, "SsrfBlockedIpError", { enumerable: true, get: function () { return ssrf_blocked_ip_error_1.SsrfBlockedIpError; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ssrf/index.ts"],"names":[],"mappings":";;;AAAA,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAE9B,iEAA6D;AAApD,2HAAA,kBAAkB,OAAA"}
@@ -0,0 +1,10 @@
1
+ import { BlockList } from 'node:net';
2
+ export interface IpRangeIssue {
3
+ entry: string;
4
+ error: string;
5
+ }
6
+ export interface IpRangeBuildResult {
7
+ list: BlockList;
8
+ issues: IpRangeIssue[];
9
+ }
10
+ export declare function buildIpRangeList(cidrRanges: readonly string[]): IpRangeBuildResult;