@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
package/readme.hints.md
CHANGED
|
@@ -345,4 +345,187 @@ new SmartProxy({
|
|
|
345
345
|
1. Implement proper certificate expiry date extraction using X.509 parsing
|
|
346
346
|
2. Add support for returning expiry date with custom certificates
|
|
347
347
|
3. Consider adding validation for custom certificate format
|
|
348
|
-
4. Add events/hooks for certificate provisioning lifecycle
|
|
348
|
+
4. Add events/hooks for certificate provisioning lifecycle
|
|
349
|
+
|
|
350
|
+
## HTTPS/TLS Configuration Guide
|
|
351
|
+
|
|
352
|
+
SmartProxy supports three TLS modes for handling HTTPS traffic. Understanding when to use each mode is crucial for correct configuration.
|
|
353
|
+
|
|
354
|
+
### TLS Mode: Passthrough (SNI Routing)
|
|
355
|
+
|
|
356
|
+
**When to use**: Backend server handles its own TLS certificates.
|
|
357
|
+
|
|
358
|
+
**How it works**:
|
|
359
|
+
1. Client connects with TLS ClientHello containing SNI (Server Name Indication)
|
|
360
|
+
2. SmartProxy extracts the SNI hostname without decrypting
|
|
361
|
+
3. Connection is forwarded to backend as-is (still encrypted)
|
|
362
|
+
4. Backend server terminates TLS with its own certificate
|
|
363
|
+
|
|
364
|
+
**Configuration**:
|
|
365
|
+
```typescript
|
|
366
|
+
{
|
|
367
|
+
match: { ports: 443, domains: 'backend.example.com' },
|
|
368
|
+
action: {
|
|
369
|
+
type: 'forward',
|
|
370
|
+
targets: [{ host: 'backend-server', port: 443 }],
|
|
371
|
+
tls: { mode: 'passthrough' }
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Requirements**:
|
|
377
|
+
- Backend must have valid TLS certificate for the domain
|
|
378
|
+
- Client's SNI must be present (session tickets without SNI will be rejected)
|
|
379
|
+
- No HTTP-level inspection possible (encrypted end-to-end)
|
|
380
|
+
|
|
381
|
+
### TLS Mode: Terminate
|
|
382
|
+
|
|
383
|
+
**When to use**: SmartProxy handles TLS, backend receives plain HTTP.
|
|
384
|
+
|
|
385
|
+
**How it works**:
|
|
386
|
+
1. Client connects with TLS ClientHello
|
|
387
|
+
2. SmartProxy terminates TLS (decrypts traffic)
|
|
388
|
+
3. Decrypted HTTP is forwarded to backend on plain HTTP port
|
|
389
|
+
4. Backend receives unencrypted traffic
|
|
390
|
+
|
|
391
|
+
**Configuration**:
|
|
392
|
+
```typescript
|
|
393
|
+
{
|
|
394
|
+
match: { ports: 443, domains: 'api.example.com' },
|
|
395
|
+
action: {
|
|
396
|
+
type: 'forward',
|
|
397
|
+
targets: [{ host: 'localhost', port: 8080 }], // HTTP backend
|
|
398
|
+
tls: {
|
|
399
|
+
mode: 'terminate',
|
|
400
|
+
certificate: 'auto' // Let's Encrypt, or provide { key, cert }
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
**Requirements**:
|
|
407
|
+
- ACME email configured for auto certificates: `acme: { email: 'admin@example.com' }`
|
|
408
|
+
- Port 80 available for HTTP-01 challenges (or use DNS-01)
|
|
409
|
+
- Backend accessible on HTTP port
|
|
410
|
+
|
|
411
|
+
### TLS Mode: Terminate and Re-encrypt
|
|
412
|
+
|
|
413
|
+
**When to use**: SmartProxy handles client TLS, but backend also requires TLS.
|
|
414
|
+
|
|
415
|
+
**How it works**:
|
|
416
|
+
1. Client connects with TLS ClientHello
|
|
417
|
+
2. SmartProxy terminates client TLS (decrypts)
|
|
418
|
+
3. SmartProxy creates new TLS connection to backend
|
|
419
|
+
4. Traffic is re-encrypted for the backend connection
|
|
420
|
+
|
|
421
|
+
**Configuration**:
|
|
422
|
+
```typescript
|
|
423
|
+
{
|
|
424
|
+
match: { ports: 443, domains: 'secure.example.com' },
|
|
425
|
+
action: {
|
|
426
|
+
type: 'forward',
|
|
427
|
+
targets: [{ host: 'backend-tls', port: 443 }], // HTTPS backend
|
|
428
|
+
tls: {
|
|
429
|
+
mode: 'terminate-and-reencrypt',
|
|
430
|
+
certificate: 'auto'
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
**Requirements**:
|
|
437
|
+
- Same as 'terminate' mode
|
|
438
|
+
- Backend must have valid TLS (can be self-signed for internal use)
|
|
439
|
+
|
|
440
|
+
### HttpProxy Integration
|
|
441
|
+
|
|
442
|
+
For TLS termination modes (`terminate` and `terminate-and-reencrypt`), SmartProxy uses an internal HttpProxy component:
|
|
443
|
+
|
|
444
|
+
- HttpProxy listens on an internal port (default: 8443)
|
|
445
|
+
- SmartProxy forwards TLS connections to HttpProxy for termination
|
|
446
|
+
- Client IP is preserved via `CLIENT_IP:` header protocol
|
|
447
|
+
- HTTP/2 and WebSocket are supported after TLS termination
|
|
448
|
+
|
|
449
|
+
**Configuration**:
|
|
450
|
+
```typescript
|
|
451
|
+
{
|
|
452
|
+
useHttpProxy: [443], // Ports that use HttpProxy for TLS termination
|
|
453
|
+
httpProxyPort: 8443, // Internal HttpProxy port
|
|
454
|
+
acme: {
|
|
455
|
+
email: 'admin@example.com',
|
|
456
|
+
useProduction: true // false for Let's Encrypt staging
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Common Configuration Patterns
|
|
462
|
+
|
|
463
|
+
**HTTP to HTTPS Redirect**:
|
|
464
|
+
```typescript
|
|
465
|
+
import { createHttpToHttpsRedirect } from '@push.rocks/smartproxy';
|
|
466
|
+
|
|
467
|
+
const redirectRoute = createHttpToHttpsRedirect(['example.com', 'www.example.com']);
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
**Complete HTTPS Server (with redirect)**:
|
|
471
|
+
```typescript
|
|
472
|
+
import { createCompleteHttpsServer } from '@push.rocks/smartproxy';
|
|
473
|
+
|
|
474
|
+
const routes = createCompleteHttpsServer(
|
|
475
|
+
'example.com',
|
|
476
|
+
{ host: 'localhost', port: 8080 },
|
|
477
|
+
{ certificate: 'auto' }
|
|
478
|
+
);
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
**Load Balancer with Health Checks**:
|
|
482
|
+
```typescript
|
|
483
|
+
import { createLoadBalancerRoute } from '@push.rocks/smartproxy';
|
|
484
|
+
|
|
485
|
+
const lbRoute = createLoadBalancerRoute(
|
|
486
|
+
'api.example.com',
|
|
487
|
+
[
|
|
488
|
+
{ host: 'backend1', port: 8080 },
|
|
489
|
+
{ host: 'backend2', port: 8080 },
|
|
490
|
+
{ host: 'backend3', port: 8080 }
|
|
491
|
+
],
|
|
492
|
+
{ tls: { mode: 'terminate', certificate: 'auto' } }
|
|
493
|
+
);
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
### Smart SNI Requirement (v22.3+)
|
|
497
|
+
|
|
498
|
+
SmartProxy automatically determines when SNI is required for routing. Session tickets (TLS resumption without SNI) are now allowed in more scenarios:
|
|
499
|
+
|
|
500
|
+
**SNI NOT required (session tickets allowed):**
|
|
501
|
+
- Single passthrough route with static target(s) and no domain restriction
|
|
502
|
+
- Single passthrough route with wildcard-only domain (`*` or `['*']`)
|
|
503
|
+
- TLS termination routes (`terminate` or `terminate-and-reencrypt`)
|
|
504
|
+
- Mixed terminate + passthrough routes (termination takes precedence)
|
|
505
|
+
|
|
506
|
+
**SNI IS required (session tickets blocked):**
|
|
507
|
+
- Multiple passthrough routes on the same port (need SNI to pick correct route)
|
|
508
|
+
- Route has dynamic host function (e.g., `host: (ctx) => ctx.domain === 'api.example.com' ? 'api-backend' : 'web-backend'`)
|
|
509
|
+
- Route has specific domain restriction (e.g., `domains: 'api.example.com'` or `domains: '*.example.com'`)
|
|
510
|
+
|
|
511
|
+
This allows simple single-target passthrough setups to work with TLS session resumption, improving performance for clients that reuse connections.
|
|
512
|
+
|
|
513
|
+
### Troubleshooting
|
|
514
|
+
|
|
515
|
+
**"No SNI detected" errors**:
|
|
516
|
+
- Client is using TLS session resumption without SNI
|
|
517
|
+
- Solution: Configure route for TLS termination (allows session resumption), or ensure you have a single-target passthrough route with no domain restrictions
|
|
518
|
+
|
|
519
|
+
**"HttpProxy not available" errors**:
|
|
520
|
+
- `useHttpProxy` not configured for the port
|
|
521
|
+
- Solution: Add port to `useHttpProxy` array in settings
|
|
522
|
+
|
|
523
|
+
**Certificate provisioning failures**:
|
|
524
|
+
- Port 80 not accessible for HTTP-01 challenges
|
|
525
|
+
- ACME email not configured
|
|
526
|
+
- Solution: Ensure port 80 is available and `acme.email` is set
|
|
527
|
+
|
|
528
|
+
**Connection timeouts to HttpProxy**:
|
|
529
|
+
- CLIENT_IP header parsing timeout (default: 2000ms)
|
|
530
|
+
- Network congestion between SmartProxy and HttpProxy
|
|
531
|
+
- Solution: Check localhost connectivity, increase timeout if needed
|