|
| 1 | +# Security |
| 2 | + |
| 3 | +ProxyHub takes security seriously. This document describes the security features available, known issues that have been addressed, and how to configure security options. |
| 4 | + |
| 5 | +## Security Features |
| 6 | + |
| 7 | +### Socket.IO Authentication |
| 8 | + |
| 9 | +Restrict which clients can connect to your ProxyHub server by setting a shared authentication key. |
| 10 | + |
| 11 | +**Server:** |
| 12 | + |
| 13 | +```bash |
| 14 | +SOCKET_AUTH_KEY=your-secret-key node dist/index.js |
| 15 | +``` |
| 16 | + |
| 17 | +**Client:** |
| 18 | + |
| 19 | +```bash |
| 20 | +proxyhub -p 3000 --auth-key your-secret-key |
| 21 | + |
| 22 | +# Or via environment variable |
| 23 | +PROXYHUB_AUTH_KEY=your-secret-key proxyhub -p 3000 |
| 24 | +``` |
| 25 | + |
| 26 | +When `SOCKET_AUTH_KEY` is set on the server, only clients providing the matching key can establish a tunnel. When unset, any client can connect (backward compatible). |
| 27 | + |
| 28 | +Authentication uses `crypto.timingSafeEqual` to prevent timing attacks. |
| 29 | + |
| 30 | +### TLS Certificate Verification |
| 31 | + |
| 32 | +The client enforces TLS certificate verification by default. To allow self-signed certificates (e.g., in development), set: |
| 33 | + |
| 34 | +```bash |
| 35 | +PROXYHUB_ALLOW_INSECURE=1 proxyhub -p 3000 |
| 36 | +``` |
| 37 | + |
| 38 | +### CORS Restrictions |
| 39 | + |
| 40 | +**Server:** Restrict allowed origins for HTTP and WebSocket connections: |
| 41 | + |
| 42 | +```bash |
| 43 | +ALLOWED_ORIGINS=https://example.com,https://app.example.com node dist/index.js |
| 44 | +``` |
| 45 | + |
| 46 | +When unset, all origins are allowed (backward compatible). |
| 47 | + |
| 48 | +**Inspector:** The inspector UI only accepts CORS requests from `localhost` and `127.0.0.1`. |
| 49 | + |
| 50 | +### Token Protection |
| 51 | + |
| 52 | +Secure individual tunnels with per-tunnel tokens: |
| 53 | + |
| 54 | +```bash |
| 55 | +proxyhub -p 3000 --token mysecrettoken |
| 56 | +``` |
| 57 | + |
| 58 | +Requests must include the `X-Proxy-Token` header. See the main [README](README.md#token-protection) for details. |
| 59 | + |
| 60 | +### Rate Limiting |
| 61 | + |
| 62 | +**HTTP requests** are rate-limited by default (5000 requests per 10-minute window per IP). The `/status` and `/health` endpoints are excluded. |
| 63 | + |
| 64 | +**Socket.IO connections** are limited to 30 connections per minute per IP. |
| 65 | + |
| 66 | +Configure via environment variables: |
| 67 | + |
| 68 | +| Variable | Default | Description | |
| 69 | +|----------|---------|-------------| |
| 70 | +| `RATE_LIMIT_WINDOW_MS` | `600000` (10 min) | HTTP rate limit window in milliseconds | |
| 71 | +| `RATE_LIMIT_MAX_REQUESTS` | `100` | Max HTTP requests per window per IP | |
| 72 | +| `SOCKET_MAX_CONNECTIONS_PER_MINUTE` | `10` | Max socket connections per minute per IP | |
| 73 | + |
| 74 | +### Security Headers |
| 75 | + |
| 76 | +The server uses [helmet](https://helmetjs.github.io/) to set secure HTTP headers including Content-Security-Policy, X-Content-Type-Options, X-Frame-Options, and others. |
| 77 | + |
| 78 | +### Request Body Limits |
| 79 | + |
| 80 | +The server limits request bodies to 10 MB to prevent denial-of-service via oversized payloads. |
| 81 | + |
| 82 | +### Header Filtering |
| 83 | + |
| 84 | +Hop-by-hop headers (`Transfer-Encoding`, `Connection`, `Keep-Alive`, `Upgrade`, `TE`, `Trailer`, `Proxy-Authenticate`, `Proxy-Authorization`) are stripped from proxied requests to prevent header injection and protocol confusion attacks. |
| 85 | + |
| 86 | +### Unpredictable Tunnel IDs |
| 87 | + |
| 88 | +Tunnel IDs are generated using `crypto.randomBytes(16)` (32-character hex strings) instead of deterministic hashes. IDs are persisted in `~/.proxyhub/tunnel-ids.json` for stability across restarts while remaining unpredictable to attackers. |
| 89 | + |
| 90 | +## Fixed Security Issues |
| 91 | + |
| 92 | +| ID | Severity | Issue | Fix | |
| 93 | +|----|----------|-------|-----| |
| 94 | +| H8 | High | Vulnerable dependencies | Updated dependencies via `npm audit fix` | |
| 95 | +| H4 | High | Hop-by-hop headers forwarded to tunnels | Headers are now stripped before forwarding | |
| 96 | +| H3 | High | No request body size limit | Added 10 MB limit on JSON and URL-encoded bodies | |
| 97 | +| H1 | High | No rate limiting | Added HTTP and Socket.IO rate limiting | |
| 98 | +| C1 | Critical | No socket authentication | Added opt-in shared-key authentication with timing-safe comparison | |
| 99 | +| C2 | Critical | TLS certificate verification disabled | Enabled by default; opt-out via `PROXYHUB_ALLOW_INSECURE` | |
| 100 | +| C3 | Critical | Predictable tunnel IDs | Replaced MD5-based IDs with cryptographically random IDs | |
| 101 | +| C4 | Critical | Unrestricted CORS | Server respects `ALLOWED_ORIGINS`; inspector restricted to localhost | |
| 102 | +| M3 | Medium | Missing security headers | Added helmet middleware | |
| 103 | + |
| 104 | +## Environment Variables Reference |
| 105 | + |
| 106 | +### Server |
| 107 | + |
| 108 | +| Variable | Default | Description | |
| 109 | +|----------|---------|-------------| |
| 110 | +| `SOCKET_AUTH_KEY` | unset (no auth) | Shared key for socket authentication | |
| 111 | +| `ALLOWED_ORIGINS` | unset (allow all) | Comma-separated list of allowed CORS origins | |
| 112 | +| `RATE_LIMIT_WINDOW_MS` | `600000` | HTTP rate limit window (ms) | |
| 113 | +| `RATE_LIMIT_MAX_REQUESTS` | `5000` | Max HTTP requests per window | |
| 114 | +| `SOCKET_MAX_CONNECTIONS_PER_MINUTE` | `30` | Max socket connections per IP per minute | |
| 115 | + |
| 116 | +### Client |
| 117 | + |
| 118 | +| Variable | Default | Description | |
| 119 | +|----------|---------|-------------| |
| 120 | +| `PROXYHUB_AUTH_KEY` | unset (random) | Authentication key sent to the server | |
| 121 | +| `PROXYHUB_ALLOW_INSECURE` | unset (TLS on) | Set to allow self-signed TLS certificates | |
| 122 | + |
| 123 | +## Reporting Vulnerabilities |
| 124 | + |
| 125 | +If you discover a security vulnerability, please report it responsibly by opening a private issue on [GitHub](https://github.com/cube-root/proxyhub/issues) or contacting the maintainers directly. Do not disclose vulnerabilities publicly until a fix is available. |
0 commit comments