← Back to section · Digital Security
The Risk Surface of Port Forwarding: How Tunnels Bypass the Network Boundaries You Drew
SSH forwarding is an operations power tool — and the most easily overlooked boundary-penetration tool. This article dissects the mechanics of local, remote, and dynamic forwarding, the specific risks of agent and X11 forwarding, and how server-side controls such as PermitOpen put forwarding back in a cage.
First, Separate the Three Forwarding Types
SSH forwarding is the ability to reuse channels inside an established SSH connection to carry arbitrary TCP traffic. By direction there are three kinds, with completely different risk profiles:
- Local forwarding (-L): the client opens a listening port locally; traffic entering it travels through the SSH tunnel to a target the server can reach. The typical use is reaching an internal database. It extends “the network the server can reach” in front of the client — what you can reach is no longer just that server, but a whole segment behind it.
- Remote forwarding (-R): the reverse direction — a listening port opens on the server, and traffic flows back through the tunnel to the client side. The typical use is temporarily exposing an internal service. It gives a machine with no inbound channel a path to be reached, in exactly the opposite direction from most firewalls’ assumptions.
- Dynamic forwarding (-D): the client opens a SOCKS proxy port, with the target address specified per connection. This is the strongest and most dangerous kind: it is a general-purpose egress located at the SSH server’s network position — every address the server can reach becomes reachable.
Then there are two special forwards often switched on in passing: agent forwarding (-A) maps the local ssh-agent’s socket to the remote side, where processes can ask your agent to sign with your private key — the key never leaves your device, but its “right of use” does, and if the remote side is compromised, an attacker can impersonate you for further hops for as long as the session lives; the OpenSSH client offers the ssh-add -c confirmation option for this, making the agent ask the local user to approve each signature, turning “borrowing” into “borrowing with per-use consent” — the most effective mitigation when agent forwarding cannot be avoided. X11 forwarding pulls the graphics protocol into the channel and has a history of client-side security issues; it should normally be switched off entirely.
Why Boundaries Fail in Front of Tunnels
Network boundaries are designed on the assumption that traffic is classified by protocol and port, and that allowing SSH means “allowing administrative traffic.” Tunnels break exactly that assumption — once an SSH connection is established, what runs inside it is decided by the two endpoints: it can be an interactive shell, or it can be forwarding flows to arbitrary internal addresses. To a firewall that only sees the five-tuple, the two are indistinguishable.
Hence the classic failure scenario: an administrator grants a developer SSH access to a jump host, intending login-based operations; the developer uses dynamic forwarding to turn the jump host into a proxy and in effect obtains access paths to the entire internal network. Nobody “broke” anything; every action stayed within the capabilities of an authorised connection — the problem is that the authoriser believed they were granting A, while the protocol actually granted A plus the full forwarding capability. The gap between capability and intent is the core of forwarding risk.
Server-Side Governance: From Master Switch to Allowlist
OpenSSH leaves a graduated set of governance handles on the server side, in increasing strength:
- The
AllowTcpForwardingmaster switch:noturns everything off,local/remoteopen one direction only,allopens everything. For most servers other than bastions, the correct value isno— forwarding is not a default accessory of login. - The
PermitOpen host:portallowlist: with local forwarding permitted, converge reachable targets to an enumerated list — for example, forwarding only to the database’s port 5432, with every other internal address refused.PermitListenapplies the symmetric constraint to remote forwarding. DisableForwarding yesswitches off all forwarding including agent and X11 in one stroke, suited to accounts that should only ever get a shell.- Certificate-based SSH refines authorisation one more layer: the certificate’s
permit-port-forwardingand sibling extensions are off by default, opened per person at issuance, and reclaimed automatically when the certificate expires — forwarding permission gains an expiry date for the first time.
Client-side discipline matters too: the listening address of -L/-R binds to loopback by default; writing 0.0.0.0 instead opens the tunnel entrance to the whole LAN, and anyone who can reach your machine can ride through. Governance checklists should include one item: audit long-lived forwarding processes and autostart configurations — a temporary tunnel never closed after use is the most common “shadow entrance” inside real networks.
Forwarding, in essence, turns network position into a transferable resource. The way to manage it is not blanket prohibition (legitimate operations and development scenarios genuinely need it) but making every act of forwarding an enumerated, authorised, audited exception — not a free gift bundled with an authenticated connection.
Visibility: Tunnels Are Not Invisible
A common misconception is that once a tunnel is established, administrators are blind. In fact the server is not ignorant at the channel layer: every forwarding request is an explicit channel-open action in the SSH connection protocol, with the target address and port written into the request. sshd can record these events in its logs (at higher log verbosity, forwarding targets appear in the authentication log), and collecting those logs centrally on a bastion answers the question “whose connections opened tunnels to which internal addresses.”
The network side offers corroboration: a long-lived SSH connection that continuously moves large volumes of traffic, in a pattern completely unlike the sporadic small packets of an interactive session, is itself a signal worth a look. A simple detection rule — “long connection + high volume + outside office hours” — will not catch a carefully disguised adversary, but it is enough to expose the vast majority of “temporary tunnels forgotten and left open” and casual misuse — which is exactly the main composition of forwarding risk in real environments.
Detection must be positioned correctly: it does not replace the server-side PermitOpen allowlist (that is prior convergence); it adds after-the-fact visibility to “forwarding that has been allowed.” Prior enumeration governs the capability boundary, after-the-fact logging governs actual use — together, the two turn forwarding from a blind spot into a controlled feature.
References
- ssh_config manual page (LocalForward, RemoteForward, DynamicForward, ForwardAgent) — https://man.openbsd.org/ssh_config
- sshd_config manual page (AllowTcpForwarding, PermitOpen, PermitListen, DisableForwarding) — https://man.openbsd.org/sshd_config
- RFC 4254: The SSH Connection Protocol (channels and forwarding requests) — https://www.rfc-editor.org/rfc/rfc4254
Tags: SSHPort ForwardingTunnelsNetwork Boundaries