Skip to content

Close the holes a security review of main turned up - #2

Merged
tks98 merged 2 commits into
mainfrom
security-fixes
Nov 23, 2026
Merged

tks98 merged 2 commits into
mainfrom
security-fixes

Conversation

@tks98

@tks98 tks98 commented Nov 23, 2026

Copy link
Copy Markdown
Owner

I ran a security review of main (ed98ad1) and this fixes what it found. I'm keeping the step-by-step write-up and the proof scripts out of the repo for now, since opcode-dev.com stays as it is until this is merged and the preview Worker is redeployed.

The one that matters most is R. webR's eval_js() runs JavaScript on the page that started it, and any program in a sandbox can ask Opcode to run Rscript through ~/.opcode/host, so a bad pip or npm package could read and rewrite every project. Wasm modules loaded with dyn.load could do the same. scripts/copy-npm-toolchains.mjs now patches webR when it copies it (each patch has to match exactly or the build stops), and createR refuses a copy that still runs JavaScript. I tested the patched build in Node and the R e2e test still passes. webR's worker is still on the app's origin though, so I think the real fix is moving it to an origin of its own at some point.

The rest, roughly by file:

  • scripts/server.mjs: a path component over 255 characters made statSync throw and the process exit, folder redirects could point at another host (//x//evil.example/..%2fassets), and any client could switch sites with X-Forwarded-Host. Those are fixed, with OPCODE_TRUST_PROXY=on for proxies that set that header. The app now sends frame-ancestors 'none', and the preview host page is sandboxed, with OPCODE_APP_ORIGINS limiting who may embed it.
  • scripts/wisp-server.mjs: under --via-proxy, DNS names went into the CONNECT line unchecked (so a client could write its own request to the proxy), and one client could choose the name another client's connection was sent under. Also no server-side flow control, and reusing a stream id leaked sockets past --max-streams. All fixed. With --via-proxy the proxy still looks names up itself, so it needs its own rules against private addresses, which the docs now say.
  • Preview: a previewed page shares the host frame's origin and could script it, which let it navigate the Opcode tab and, with one preview origin, read the next project's preview traffic. Host frames are now sandboxed and each server gets its own frame, removed before the next one loads. Checked in Chrome with storage partitioning on. The Linux bridge's response parser also had a loop on a negative chunk size.
  • ?machine= links now ask before downloading, skip the toolchain cache, and machine files are size-checked and must unpack to a v86 snapshot before they are saved. The offline machine's fetch adapter could stay live if a relay was saved while it loaded, which is fixed too.
  • Smaller things: zip import enforces real sizes rather than declared ones, export leaves out names like ..\x.bat, the editor mirrors at most 5,000 files and 50 MB, a file name could hang the tab through new RegExp in #runJavac.
  • Build: cached inputs are hashed again before use, Actions are pinned to commit SHAs (I checked each against its tag), Docker publishing has its own job with packages: write, and base images and the Alpine build inputs are pinned.

Testing: npm test is 222 passing (155 before), svelte-check is clean, and 22 of 23 e2e tests pass in Chromium locally. The failing one is "makes a web page that updates as you type", which fails on macOS because the test sends Cmd+F, and passes with Control+F. I couldn't build the Docker image here and the workflow changes haven't run yet, so this PR's CI is the first real test of those.

After merging, the preview Worker needs a redeploy to pick up the per-server frames (the command is now in deploy/preview-host.wrangler.toml). Things people will notice: webr::eval_js() errors, ?machine= asks first, uploads stop at 2,000 files or 50 MB, and the first build re-downloads Rust once because the stamp format changed.

AI disclosure: Claude did the review and wrote most of these fixes, using several agents. I reproduced the main findings before fixing them, and I read the diffs and ran the tests above myself.

🤖 Generated with Claude Code

tks98 and others added 2 commits November 23, 2026 10:40
R could run JavaScript on the app's page through webR's eval_js and
through wasm modules loaded with dyn.load, so any program in any project
could read the user's other projects. webR is now patched when it is
copied in (the build stops if a patch no longer matches), and Opcode
refuses an unpatched copy.

The rest:
- server.mjs: a long path no longer crashes it, folder redirects stay on
  the site, X-Forwarded-Host only counts with OPCODE_TRUST_PROXY=on, the
  app can't be framed, and the preview host page is sandboxed
  (OPCODE_APP_ORIGINS limits who may embed it).
- wisp-server.mjs: only real host names reach a --via-proxy CONNECT
  line, a name learned from DNS is used only if the relay's own lookup
  agrees, the Wisp window is enforced and reading pauses when too much is
  waiting, and reused stream ids no longer leak sockets.
- Preview: host frames are sandboxed and there is one per server, so a
  previewed page can't navigate the Opcode tab or see the next project's
  requests. The Linux bridge's response parser has limits and no longer
  loops on a negative chunk size.
- ?machine= links ask first, aren't cached, and machine files are
  checked (header, unpacked size, v86 format) before they are saved. An
  offline machine's page-fetch adapter is turned off before it runs.
- Zip import enforces real sizes, export leaves out unsafe names, and
  the editor mirrors at most 5,000 files and 50 MB.
- Build: cached inputs are hashed again, Actions are pinned to commits,
  Docker publishing has its own job, base images and Alpine inputs are
  pinned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ubuntu-latest is now Ubuntu 26.04, where Playwright 1.56 can't install
Chromium ("Playwright does not support chromium on ubuntu26.04-x64"), so
the end-to-end job failed before running a test. Pin the runner like the
actions themselves; move it along with a Playwright update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tks98
tks98 merged commit 2e1f134 into main Nov 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant