Background

WeTTY is an open-source, browser-based terminal. A Node.js server shows a terminal in a web page and connects it, over HTTP and Socket.IO (a WebSocket-style real-time channel), to a local shell or to a remote machine over SSH. People use it to give access to servers from any browser.

A page that can open this channel can control the terminal, so WeTTY must make sure that only its own web page does so. Browsers enforce the same-origin policy, which stops one website’s scripts from reading another site’s responses, but WebSocket connections are not covered by it. Any page can try to open one, and the server has to inspect the Origin header the browser sends and refuse unfamiliar origins. Without this check, an attacker’s site could connect to a victim’s WeTTY and type into their terminal, which is called cross-site WebSocket hijacking.

Terms used below:

  • Origin is the combination of scheme, host and port of the page that started a request, for example https://wetty.example.com.
  • Host header is the name the client says it is connecting to.
  • Allowlist is a fixed list of values the administrator has said to trust.

Summary

The origin check builds its expected value from the request’s Host header. A request can satisfy it when Host and Origin agree, even if both name an attacker-controlled site. Neither value has to match independently trusted configuration.

DNS rebinding makes this relevant to browsers. An attacker-controlled hostname can first serve a page and later resolve to a WeTTY instance reachable by the victim. The browser continues to send that hostname in its requests. The check compares two matching values associated with the attacker’s origin and accepts a connection that the intended policy should reject.

How the Vulnerability Works

The origin check is correct in idea and wrong in implementation. A server defends itself by comparing the Origin header with a value it already trusts. WeTTY builds the “trusted” value from the request itself. It takes the Host header and the protocol, forms an expected origin, and accepts the request if Origin equals it.

Legitimate:   Host: wetty.example.com   Origin: https://wetty.example.com   -> accepted
Cross-site:   Host: wetty.example.com   Origin: https://evil.example         -> rejected
This bug:     Host: evil.example        Origin: https://evil.example         -> accepted

Both values come from the client’s side of the connection. Agreement between them proves nothing about whether the site is trusted. Normally an attacker cannot control the Host header that a victim’s browser sends to WeTTY, because it names WeTTY. DNS rebinding removes that obstacle.

In DNS rebinding the attacker owns a domain, evil.example, and its DNS server. The victim opens a page on that domain, which loads normally from the attacker’s server. The DNS answer is then changed so that evil.example points to an address on the victim’s network, such as the machine running WeTTY. The browser still believes it is talking to evil.example, so it sends Host: evil.example and Origin: https://evil.example. WeTTY compares the two, finds a match and accepts the connection.

What the attacker gets after that depends on authentication. If WeTTY signs in to SSH automatically, with server-configured credentials or passwordless SSH, the attacker’s script receives an open shell. If it prompts for a password, the attacker has the connection but not a session. The advisory also notes that binding WeTTY only to localhost does not stop this attack, because the victim’s own browser makes the request. An allowlist added next to this check does not repair 3.3.x versions, because the permissive comparison stays active, which is why the fix removes it and uses configuration instead. This is origin validation error (CWE-346).

Prerequisites

The attacker needs control of a hostname and its DNS resolution, a victim who visits that origin, and a WeTTY instance reachable from the victim’s browser. Browser networking restrictions and network controls can affect whether the rebinding path reaches the application.

Access after connection depends on SSH authentication. Automatic login with configured credentials can provide a shell after the origin bypass. A deployment requiring interactive credentials does not automatically supply an authenticated shell merely because Socket.IO accepts the connection.

Attack Path

Attack route
Attacker routeMitigationCtrl + scroll to zoom
  1. START
    Victim visits an attacker-controlled origin
  2. STEP 01
    Hostname resolves to a reachable WeTTY instance

    The browser retains the attacker hostname in its Host and Origin values.

    MITIGATION Reject request hosts outside trusted configuration

  3. STEP 02
    Socket.IO accepts matching untrusted headers

    MITIGATION Use an explicit trusted-origin allowlist

  4. STEP 03
    Terminal connection is established
  5. STEP 04
    Auto-login deployment exposes a shell

    MITIGATION Require independent terminal authentication

Root Cause

expectedOrigin() constructs an origin from the request’s Host header and protocol information. originAllowed() accepts an Origin matching that constructed value. This proves agreement within the request, not that either field represents a trusted deployment origin.

This origin check was introduced in 3.3.1, after an earlier cross-site WebSocket advisory. A foreign Origin was rejected when paired with the server’s real Host. Replacing Host with the same foreign hostname changed the result without trusted configuration authorizing it.

An allowlist added alongside this implicit acceptance cannot fully repair affected 3.3.x deployments. The permissive alternative remains active. The fixed implementation must remove that alternative and obtain trusted origins from configuration.

Validation

My own testing used WeTTY 3.3.5, a local SSH server and an auto-login setup. It compared handshakes and confirmed terminal output after the matching-header case. A headless Chromium test used controlled DNS-rebinding emulation, not exploitation against a public deployment.

RequestExpected boundaryRecorded result
Foreign Origin with the server’s real HostReject the foreign pageHandshake rejected
Same foreign Origin with matching attacker HostReject independently untrusted valuesConnection accepted
Accepted connection in the auto-login setupPreserve terminal access controlsMarker command output received

Upstream closed my separate submission as a duplicate and credits me as an additional Reporter. The advisory attributes the original report and proof of concept to sanidipeiris-alt and Finder credit to zaara2004. The observations above document my own testing, not ownership of the original team’s work.

Impact

The failed origin boundary permits terminal connections from an attacker-controlled page. In an auto-login configuration, this can expose command input and output with the configured SSH user’s permissions. Interactive authentication can limit what happens after connection.

Non-browser clients can set their own headers, but the browser chain crosses the boundary intended to isolate an unrelated website from a reachable terminal service. Binding to localhost alone does not independently validate that origin.

Remediation

Upgrade to 4.0.0 or later and configure an explicit trusted browser origin. PR #698 removes Host-derived trust. Missing-Origin browser requests must also satisfy checks tied to configured hosts.

Set --allowed-origin to the full browser-facing origin, including a nondefault port and excluding the base path. Avoid enabling the missing-Origin bypass on an unprotected deployment.

Before upgrading, use a proxy that rejects untrusted Host values on polling and WebSocket upgrades, with independent authentication or restricted client access. An extra allowlist entry on affected 3.3.x releases does not remove their implicit Host-based acceptance.

References