How It Works
MekongTunnel uses standard SSH reverse port forwarding (-R) — no proprietary protocol, no agents, nothing exotic.
Architecture overview
Your Browser
│ HTTPS to happy-tiger-a1b2c3d4.proxy.mekongtunnel.dev
▼
┌──────────────────────────────────────────┐
│ MekongTunnel Server │
│ │
│ SSH :22 → HTTP :80 → HTTPS :443 │
│ │ │ │
│ ▼ ▼ │
│ Tunnel Registry ←─────────────────── │
│ map[subdomain]*Tunnel │
└────────────────┬─────────────────────────┘
│ forwarded-tcpip channel
▼
Your SSH client (mekong CLI)
│
▼
localhost:3000 (your app)Step by step
1. Client connects
When you run mekong 3000, the CLI establishes an SSH connection to the server and sends a tcpip-forward global request:
BindAddr: ""
BindPort: 802. Server assigns subdomain
The server generates a unique memorable subdomain (e.g. happy-tiger-a1b2c3d4) using a format of adjective-noun-hex. It then creates an internal TCP listener on a random loopback port (e.g. 127.0.0.1:54321).
3. Tunnel registered
The server stores the mapping:
subdomain → internal TCP listener address4. Browser request arrives
A browser hits https://happy-tiger-a1b2c3d4.proxy.mekongtunnel.dev. The server:
- Terminates TLS on port 443
- Extracts the subdomain from the
Hostheader - Looks up the tunnel in the registry
- Dials the internal listener (
127.0.0.1:54321)
5. SSH channel opened
The server opens a forwarded-tcpip SSH channel back through the SSH connection to the client:
channel open: forwarded-tcpip
DestAddr: "happy-tiger-a1b2c3d4.proxy.mekongtunnel.dev"
DestPort: 80
OriginAddr: <browser IP>
OriginPort: <browser port>6. Client proxies to local
The mekong CLI receives the forwarded-tcpip channel and dials localhost:3000, then copies data bidirectionally between the SSH channel and your local app.
7. Response flows back
The response from your app flows back through the SSH channel → server → HTTPS → browser.
WebSocket support
WebSocket connections are detected by inspecting the Upgrade: websocket header. The server hijacks the HTTP connection and sets up bidirectional byte copying with a 6-hour idle timeout per direction. There is no transfer cap by default (MAX_WEBSOCKET_TRANSFER_MB).
Security warning interstitial
For browser requests, MekongTunnel shows a one-time phishing warning page before forwarding to the tunnel. This protects users from malicious content shared via tunnel URLs.
- The warning sets a cookie (
mekong_warned_{subdomain}) valid for 24 hours - API clients (curl, etc.) are not affected — only browser User-Agents
- To skip it programmatically:
curl -H "mekongtunnel-skip-warning: 1" <url> - To skip it for every visitor, start the tunnel with
mekong <port> --skip-browser-warning(foreground only — not passed through in-dmode)
Rate limiting
Two layers of rate limiting are available. Both are off by default and are enabled with environment variables (see Configuration):
Connection rate (per IP): MAX_CONNECTIONS_PER_MINUTE new SSH connections per IP, using a 1-minute sliding window.
Request rate (per tunnel): Token bucket with REQUESTS_PER_SECOND and BURST_SIZE. Repeated violations only lead to an IP block when RATE_LIMIT_VIOLATIONS_MAX and BLOCK_DURATION are set.
Lifetime and idle timeout
A tunnel lives for 24 hours by default (7 days by default with --subdomain). Clients can request a different lifetime with --expire / MEKONG_EXPIRE, up to a maximum of 7 days. The idle timeout equals the lifetime, so a tunnel with no traffic closes after the same period.