@push.rocks/smartproxy 21.1.6 → 22.4.2
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 +89 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/core/utils/shared-security-manager.d.ts +17 -0
- package/dist_ts/core/utils/shared-security-manager.js +66 -1
- package/dist_ts/proxies/http-proxy/default-certificates.d.ts +54 -0
- package/dist_ts/proxies/http-proxy/default-certificates.js +127 -0
- package/dist_ts/proxies/http-proxy/http-proxy.d.ts +1 -1
- package/dist_ts/proxies/http-proxy/http-proxy.js +9 -14
- package/dist_ts/proxies/http-proxy/index.d.ts +5 -1
- package/dist_ts/proxies/http-proxy/index.js +6 -2
- package/dist_ts/proxies/http-proxy/security-manager.d.ts +4 -12
- package/dist_ts/proxies/http-proxy/security-manager.js +66 -99
- package/dist_ts/proxies/nftables-proxy/index.d.ts +1 -0
- package/dist_ts/proxies/nftables-proxy/index.js +2 -1
- package/dist_ts/proxies/nftables-proxy/nftables-proxy.d.ts +4 -26
- package/dist_ts/proxies/nftables-proxy/nftables-proxy.js +84 -236
- package/dist_ts/proxies/nftables-proxy/utils/index.d.ts +9 -0
- package/dist_ts/proxies/nftables-proxy/utils/index.js +12 -0
- package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.d.ts +66 -0
- package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.js +131 -0
- package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.d.ts +39 -0
- package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.js +112 -0
- package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.d.ts +59 -0
- package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.js +130 -0
- package/dist_ts/proxies/smart-proxy/certificate-manager.js +4 -3
- package/dist_ts/proxies/smart-proxy/connection-manager.d.ts +13 -2
- package/dist_ts/proxies/smart-proxy/connection-manager.js +16 -6
- package/dist_ts/proxies/smart-proxy/http-proxy-bridge.js +35 -10
- package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +0 -1
- package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +17 -0
- package/dist_ts/proxies/smart-proxy/route-connection-handler.js +72 -9
- package/dist_ts/proxies/smart-proxy/security-manager.d.ts +14 -12
- package/dist_ts/proxies/smart-proxy/security-manager.js +80 -74
- package/dist_ts/proxies/smart-proxy/smart-proxy.js +1 -2
- package/dist_ts/proxies/smart-proxy/tls-manager.d.ts +2 -9
- package/dist_ts/proxies/smart-proxy/tls-manager.js +3 -26
- package/dist_ts/proxies/smart-proxy/utils/index.d.ts +1 -1
- package/dist_ts/proxies/smart-proxy/utils/index.js +3 -4
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/api-helpers.d.ts +49 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/api-helpers.js +108 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.d.ts +57 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.js +89 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/http-helpers.d.ts +17 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/http-helpers.js +32 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/https-helpers.d.ts +68 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/https-helpers.js +117 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/index.d.ts +17 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/index.js +27 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.d.ts +63 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.js +105 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.d.ts +83 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.js +126 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/security-helpers.d.ts +47 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/security-helpers.js +66 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.d.ts +70 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.js +287 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.d.ts +46 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.js +67 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +4 -457
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +6 -950
- package/dist_ts/proxies/smart-proxy/utils/route-utils.js +2 -2
- package/dist_ts/proxies/smart-proxy/utils/route-validator.d.ts +67 -1
- package/dist_ts/proxies/smart-proxy/utils/route-validator.js +266 -6
- package/npmextra.json +12 -6
- package/package.json +34 -24
- package/readme.hints.md +184 -1
- package/readme.md +235 -172
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/core/utils/shared-security-manager.ts +98 -13
- package/ts/proxies/http-proxy/default-certificates.ts +150 -0
- package/ts/proxies/http-proxy/http-proxy.ts +9 -15
- package/ts/proxies/http-proxy/index.ts +6 -1
- package/ts/proxies/http-proxy/security-manager.ts +141 -161
- package/ts/proxies/nftables-proxy/index.ts +1 -0
- package/ts/proxies/nftables-proxy/nftables-proxy.ts +116 -290
- package/ts/proxies/nftables-proxy/utils/index.ts +38 -0
- package/ts/proxies/nftables-proxy/utils/nft-command-executor.ts +162 -0
- package/ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.ts +125 -0
- package/ts/proxies/nftables-proxy/utils/nft-rule-validator.ts +156 -0
- package/ts/proxies/smart-proxy/certificate-manager.ts +3 -2
- package/ts/proxies/smart-proxy/connection-manager.ts +21 -8
- package/ts/proxies/smart-proxy/http-proxy-bridge.ts +39 -13
- package/ts/proxies/smart-proxy/models/interfaces.ts +0 -1
- package/ts/proxies/smart-proxy/route-connection-handler.ts +88 -16
- package/ts/proxies/smart-proxy/security-manager.ts +98 -86
- package/ts/proxies/smart-proxy/smart-proxy.ts +0 -2
- package/ts/proxies/smart-proxy/tls-manager.ts +1 -37
- package/ts/proxies/smart-proxy/utils/index.ts +3 -5
- package/ts/proxies/smart-proxy/utils/route-helpers/api-helpers.ts +144 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.ts +124 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/http-helpers.ts +40 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/https-helpers.ts +163 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/index.ts +62 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.ts +154 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.ts +202 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/security-helpers.ts +96 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.ts +337 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.ts +98 -0
- package/ts/proxies/smart-proxy/utils/route-helpers.ts +5 -1302
- package/ts/proxies/smart-proxy/utils/route-utils.ts +1 -1
- package/ts/proxies/smart-proxy/utils/route-validator.ts +289 -7
- package/ts/proxies/http-proxy/certificate-manager.ts +0 -244
- package/ts/proxies/smart-proxy/utils/route-validators.ts +0 -283
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route Validators
|
|
3
|
-
*
|
|
4
|
-
* This file provides utility functions for validating route configurations.
|
|
5
|
-
* These validators help ensure that route configurations are valid and correctly structured.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { IRouteConfig, IRouteMatch, IRouteAction, TPortRange } from '../models/route-types.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Validates a port range or port number
|
|
12
|
-
* @param port Port number, port range, or port function
|
|
13
|
-
* @returns True if valid, false otherwise
|
|
14
|
-
*/
|
|
15
|
-
export function isValidPort(port: any): boolean {
|
|
16
|
-
if (typeof port === 'number') {
|
|
17
|
-
return port > 0 && port < 65536; // Valid port range is 1-65535
|
|
18
|
-
} else if (Array.isArray(port)) {
|
|
19
|
-
return port.every(p =>
|
|
20
|
-
(typeof p === 'number' && p > 0 && p < 65536) ||
|
|
21
|
-
(typeof p === 'object' && 'from' in p && 'to' in p &&
|
|
22
|
-
p.from > 0 && p.from < 65536 && p.to > 0 && p.to < 65536)
|
|
23
|
-
);
|
|
24
|
-
} else if (typeof port === 'function') {
|
|
25
|
-
// For function-based ports, we can't validate the result at config time
|
|
26
|
-
// so we just check that it's a function
|
|
27
|
-
return true;
|
|
28
|
-
} else if (typeof port === 'object' && 'from' in port && 'to' in port) {
|
|
29
|
-
return port.from > 0 && port.from < 65536 && port.to > 0 && port.to < 65536;
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Validates a domain string
|
|
36
|
-
* @param domain Domain string to validate
|
|
37
|
-
* @returns True if valid, false otherwise
|
|
38
|
-
*/
|
|
39
|
-
export function isValidDomain(domain: string): boolean {
|
|
40
|
-
// Basic domain validation regex - allows wildcards (*.example.com)
|
|
41
|
-
const domainRegex = /^(\*\.)?([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
|
|
42
|
-
return domainRegex.test(domain);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Validates a route match configuration
|
|
47
|
-
* @param match Route match configuration to validate
|
|
48
|
-
* @returns { valid: boolean, errors: string[] } Validation result
|
|
49
|
-
*/
|
|
50
|
-
export function validateRouteMatch(match: IRouteMatch): { valid: boolean; errors: string[] } {
|
|
51
|
-
const errors: string[] = [];
|
|
52
|
-
|
|
53
|
-
// Validate ports
|
|
54
|
-
if (match.ports !== undefined) {
|
|
55
|
-
if (!isValidPort(match.ports)) {
|
|
56
|
-
errors.push('Invalid port number or port range in match.ports');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Validate domains
|
|
61
|
-
if (match.domains !== undefined) {
|
|
62
|
-
if (typeof match.domains === 'string') {
|
|
63
|
-
if (!isValidDomain(match.domains)) {
|
|
64
|
-
errors.push(`Invalid domain format: ${match.domains}`);
|
|
65
|
-
}
|
|
66
|
-
} else if (Array.isArray(match.domains)) {
|
|
67
|
-
for (const domain of match.domains) {
|
|
68
|
-
if (!isValidDomain(domain)) {
|
|
69
|
-
errors.push(`Invalid domain format: ${domain}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
errors.push('Domains must be a string or an array of strings');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Validate path
|
|
78
|
-
if (match.path !== undefined) {
|
|
79
|
-
if (typeof match.path !== 'string' || !match.path.startsWith('/')) {
|
|
80
|
-
errors.push('Path must be a string starting with /');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
valid: errors.length === 0,
|
|
86
|
-
errors
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Validates a route action configuration
|
|
92
|
-
* @param action Route action configuration to validate
|
|
93
|
-
* @returns { valid: boolean, errors: string[] } Validation result
|
|
94
|
-
*/
|
|
95
|
-
export function validateRouteAction(action: IRouteAction): { valid: boolean; errors: string[] } {
|
|
96
|
-
const errors: string[] = [];
|
|
97
|
-
|
|
98
|
-
// Validate action type
|
|
99
|
-
if (!action.type) {
|
|
100
|
-
errors.push('Action type is required');
|
|
101
|
-
} else if (!['forward', 'socket-handler'].includes(action.type)) {
|
|
102
|
-
errors.push(`Invalid action type: ${action.type}`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Validate targets for 'forward' action
|
|
106
|
-
if (action.type === 'forward') {
|
|
107
|
-
if (!action.targets || !Array.isArray(action.targets) || action.targets.length === 0) {
|
|
108
|
-
errors.push('Targets array is required for forward action');
|
|
109
|
-
} else {
|
|
110
|
-
// Validate each target
|
|
111
|
-
action.targets.forEach((target, index) => {
|
|
112
|
-
// Validate target host
|
|
113
|
-
if (!target.host) {
|
|
114
|
-
errors.push(`Target[${index}] host is required`);
|
|
115
|
-
} else if (typeof target.host !== 'string' &&
|
|
116
|
-
!Array.isArray(target.host) &&
|
|
117
|
-
typeof target.host !== 'function') {
|
|
118
|
-
errors.push(`Target[${index}] host must be a string, array of strings, or function`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Validate target port
|
|
122
|
-
if (target.port === undefined) {
|
|
123
|
-
errors.push(`Target[${index}] port is required`);
|
|
124
|
-
} else if (typeof target.port !== 'number' &&
|
|
125
|
-
typeof target.port !== 'function' &&
|
|
126
|
-
target.port !== 'preserve') {
|
|
127
|
-
errors.push(`Target[${index}] port must be a number, 'preserve', or a function`);
|
|
128
|
-
} else if (typeof target.port === 'number' && !isValidPort(target.port)) {
|
|
129
|
-
errors.push(`Target[${index}] port must be between 1 and 65535`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Validate match criteria if present
|
|
133
|
-
if (target.match) {
|
|
134
|
-
if (target.match.ports && !Array.isArray(target.match.ports)) {
|
|
135
|
-
errors.push(`Target[${index}] match.ports must be an array`);
|
|
136
|
-
}
|
|
137
|
-
if (target.match.method && !Array.isArray(target.match.method)) {
|
|
138
|
-
errors.push(`Target[${index}] match.method must be an array`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Validate TLS options for forward actions
|
|
145
|
-
if (action.tls) {
|
|
146
|
-
if (!['passthrough', 'terminate', 'terminate-and-reencrypt'].includes(action.tls.mode)) {
|
|
147
|
-
errors.push(`Invalid TLS mode: ${action.tls.mode}`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// For termination modes, validate certificate
|
|
151
|
-
if (['terminate', 'terminate-and-reencrypt'].includes(action.tls.mode)) {
|
|
152
|
-
if (action.tls.certificate !== 'auto' &&
|
|
153
|
-
(!action.tls.certificate || !action.tls.certificate.key || !action.tls.certificate.cert)) {
|
|
154
|
-
errors.push('Certificate must be "auto" or an object with key and cert properties');
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Validate socket handler for 'socket-handler' action
|
|
161
|
-
if (action.type === 'socket-handler') {
|
|
162
|
-
if (!action.socketHandler) {
|
|
163
|
-
errors.push('Socket handler function is required for socket-handler action');
|
|
164
|
-
} else if (typeof action.socketHandler !== 'function') {
|
|
165
|
-
errors.push('Socket handler must be a function');
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return {
|
|
170
|
-
valid: errors.length === 0,
|
|
171
|
-
errors
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Validates a complete route configuration
|
|
177
|
-
* @param route Route configuration to validate
|
|
178
|
-
* @returns { valid: boolean, errors: string[] } Validation result
|
|
179
|
-
*/
|
|
180
|
-
export function validateRouteConfig(route: IRouteConfig): { valid: boolean; errors: string[] } {
|
|
181
|
-
const errors: string[] = [];
|
|
182
|
-
|
|
183
|
-
// Check for required properties
|
|
184
|
-
if (!route.match) {
|
|
185
|
-
errors.push('Route match configuration is required');
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (!route.action) {
|
|
189
|
-
errors.push('Route action configuration is required');
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Validate match configuration
|
|
193
|
-
if (route.match) {
|
|
194
|
-
const matchValidation = validateRouteMatch(route.match);
|
|
195
|
-
if (!matchValidation.valid) {
|
|
196
|
-
errors.push(...matchValidation.errors.map(err => `Match: ${err}`));
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Validate action configuration
|
|
201
|
-
if (route.action) {
|
|
202
|
-
const actionValidation = validateRouteAction(route.action);
|
|
203
|
-
if (!actionValidation.valid) {
|
|
204
|
-
errors.push(...actionValidation.errors.map(err => `Action: ${err}`));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Ensure the route has a unique identifier
|
|
209
|
-
if (!route.id && !route.name) {
|
|
210
|
-
errors.push('Route should have either an id or a name for identification');
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
valid: errors.length === 0,
|
|
215
|
-
errors
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Validate an array of route configurations
|
|
221
|
-
* @param routes Array of route configurations to validate
|
|
222
|
-
* @returns { valid: boolean, errors: { index: number, errors: string[] }[] } Validation result
|
|
223
|
-
*/
|
|
224
|
-
export function validateRoutes(routes: IRouteConfig[]): {
|
|
225
|
-
valid: boolean;
|
|
226
|
-
errors: { index: number; errors: string[] }[]
|
|
227
|
-
} {
|
|
228
|
-
const results: { index: number; errors: string[] }[] = [];
|
|
229
|
-
|
|
230
|
-
routes.forEach((route, index) => {
|
|
231
|
-
const validation = validateRouteConfig(route);
|
|
232
|
-
if (!validation.valid) {
|
|
233
|
-
results.push({
|
|
234
|
-
index,
|
|
235
|
-
errors: validation.errors
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
return {
|
|
241
|
-
valid: results.length === 0,
|
|
242
|
-
errors: results
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Check if a route configuration has the required properties for a specific action type
|
|
248
|
-
* @param route Route configuration to check
|
|
249
|
-
* @param actionType Expected action type
|
|
250
|
-
* @returns True if the route has the necessary properties, false otherwise
|
|
251
|
-
*/
|
|
252
|
-
export function hasRequiredPropertiesForAction(route: IRouteConfig, actionType: string): boolean {
|
|
253
|
-
if (!route.action || route.action.type !== actionType) {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
switch (actionType) {
|
|
258
|
-
case 'forward':
|
|
259
|
-
return !!route.action.targets &&
|
|
260
|
-
Array.isArray(route.action.targets) &&
|
|
261
|
-
route.action.targets.length > 0 &&
|
|
262
|
-
route.action.targets.every(t => t.host && t.port !== undefined);
|
|
263
|
-
case 'socket-handler':
|
|
264
|
-
return !!route.action.socketHandler && typeof route.action.socketHandler === 'function';
|
|
265
|
-
default:
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Throws an error if the route config is invalid, returns the config if valid
|
|
272
|
-
* Useful for immediate validation when creating routes
|
|
273
|
-
* @param route Route configuration to validate
|
|
274
|
-
* @returns The validated route configuration
|
|
275
|
-
* @throws Error if the route configuration is invalid
|
|
276
|
-
*/
|
|
277
|
-
export function assertValidRoute(route: IRouteConfig): IRouteConfig {
|
|
278
|
-
const validation = validateRouteConfig(route);
|
|
279
|
-
if (!validation.valid) {
|
|
280
|
-
throw new Error(`Invalid route configuration: ${validation.errors.join(', ')}`);
|
|
281
|
-
}
|
|
282
|
-
return route;
|
|
283
|
-
}
|