Hardening ttyd: How a 6-Layer Test Net Let Us Audit All 66 Open PRs
Before touching a single upstream ttyd pull request, we built six automated verification layers: strict C warnings, 18 black-box protocol tests, Playwright visual baselines, sanitizers, fuzzers, and differential RED to GREEN proof.
If you ship a web terminal inside your developer tooling, ttyd is a gem: one tiny C binary, libuv, libwebsockets, and xterm.js compiled into a single header. If you just want verified drop-in binaries today, grab them with checksums and an SBOM from viaalink/ttyd-builds (v1.7.7-viaalink.3).
If you maintain open-source forks or want to see how we safely audited all 66 open upstream PRs on tsl0922/ttyd without breaking browsers, Windows builds, or multi-session load, here is the exact layered playbook we used.
Download static Linux and Windows builds from viaalink/ttyd-builds and check them with sha256sum -c.
Read the complete Upstream PR Ledger with verbatim multi-model review logs for every patch.
Use @viaalink/ttyd-client for the wire protocol and @viaalink/playwright-terminal-kit for browser tests.
Start a local browser terminal with via terminal start from the Viaalink CLI, which runs ttyd for you.
The problem with merging 66 open PRs blindly
The Viaalink CLI runs ttyd for its browser terminal (via terminal start) on Linux and Windows. Upstream tsl0922/ttyd had been sitting on 1.7.7 while 66 community pull requests piled up: pre-authentication WebSocket leaks, a Windows command-line buffer overflow, mobile iOS zoom bugs, PTY stalls under load, and conflicting patches solving the same crash two different ways.
Cherry-picking 30+ patches into a C server that spawns shells is asking for trouble. One careless merge can silently reopen an auth bypass, leak a DOM listener on every reconnect, or freeze terminals under heavy output.
So we flipped the usual order of work. Before touching the big backlog, we built a 6-layer safety net that runs fast, catches memory bugs automatically, and proves every fix against the unmodified upstream binary.
Architecture · The 6-layer verification pipeline behind viaalink/ttyd
Layer 1 & 2: Static hygiene and honest RED to GREEN proof
Turning on -Wall -Wextra -Werror under both GCC 13 and Clang 18 immediately caught 12 warnings, including three real bugs in C code: a missing NUL terminator after strncpy, a signed-versus-unsigned check that swallowed lws_write errors, and an unchecked chdir return value. Fixing those up front meant every new PR now has to compile with zero warnings.
Next, we wrote tests/battle_test.py using only the Python 3 standard library. Because it has zero external dependencies, the exact same 18-test script runs on native Linux, inside static musl containers, under qemu-user-static for ARM64, and under AddressSanitizer.
Passing tests on a patched binary only proves you did not break the happy path. To prove our fixes actually close real flaws, we added tests/red_green_diff.py to run the identical suite against both the stock 1.7.7 baseline and our candidate build.
Verification & Build Speed · Baseline stock 1.7.7 vs hardened release
Fourteen tests failed cleanly on stock 1.7.7 and turned green on our candidate build, with every failure trace and binary SHA-256 recorded in docs/RED_GREEN_PROOF.md. The suite also drives 75.6% line coverage and 93.2% function coverage across the C codebase, including 100 back-to-back sessions and a 50,000-line output flood with PAUSE and RESUME flow control.
We explicitly separate what Linux black-box tests can prove from what they cannot. Windows --url-arg overflow, mTLS client certificates, libwebsockets 5.1, macOS linking, and login(1) vhangup() are labeled honestly in docs/RED_GREEN_PROOF.md with their real verification methods.
Layer 3 & 4: Visual Playwright baselines, sanitizers, and fuzzing
Terminal bugs love hiding in browsers. A CSS tweak that fixes iOS safe-area padding can silently clip the bottom row on desktop Chromium, or break WebGL cell measurement on first load.
We added a standalone @playwright/test suite (tests/visual/) pinned to Microsoft’s official Playwright container so fonts and rendering stay deterministic. It runs 30 browser checks across Chromium, WebKit, iPhone 14, and Pixel 7 viewports: pixel baselines for DOM, Canvas, and WebGL renderers, CJK and emoji alignment, OSC 52 UTF-8 clipboard writes, Basic Auth shell spawning, URL security blocklists, backoff reconnect overlays, and --deny-framing iframe blocking.
On the C side, every commit runs the full 18-test suite compiled with AddressSanitizer and UndefinedBehaviorSanitizer, plus two libFuzzer targets (fuzz_protocol_ws and fuzz_origin_check) that ran millions of mutated frames with zero crashes.
Layer 5: Auditing all 66 PRs with three independent models
Once every PR had automated C, browser, sanitizer, and fuzzing gates, we audited all 66 open upstream PRs using three independent AI reviewers (Antigravity, Claude Code, and Mistral Vibe) alongside maintainer review. Every one of the 25 remaining post-baseline PRs has its verbatim review logs archived in docs/reviews/ and summarized in docs/UPSTREAM_PR_LEDGER.md.
Having three different models critique each original PR author’s approach paid off immediately. They caught real security and memory bugs inside community PRs that looked fine on a quick skim:
| Upstream PR(s) | What the original PR missed | How we hardened it before merging |
|---|---|---|
#1518 + #1549 + #1565 | Allowed remote OSC 52 clipboard reads | Made clipboard write-only and restored focus |
#1606 | ZMODEM cap trusted declared details.size | Enforced 256/512 MiB cap on streamed bytes |
#1597 + #1531 | Pinch-zoom triggered terminal reflow | Guarded syncViewport on scale === 1 |
#1536 | Auto-reconnected on clean exit (1000) | Skipped codes 1000, 1008, 1009 |
#1560 | Cast -1 pixel size to 65535 | Validated json_type_int within [0, 65535] |
#1529 + #1558 | out == NULL race; blind 50ms timer | Combined best parts; added UV_ENOTCONN guard |
#1520 | Dropped SGR releases; broke vim/htop | Kept leak-free contextmenu suppression only |
#1553 | Retired macos-13; unchecked curl \| tar | Pinned SHA-256, macos-15-intel, codesign |
Multi-model review also made declining dangerous PRs unambiguous. All three reviewers agreed to reject 8 PRs, including #1468 (a postMessage listener with zero event.origin check enabling cross-origin remote code execution), #1464 (Basic Auth credentials in URL query parameters), #1481 (unbounded HTTP POST realloc DoS that also broke Windows), #1493 (infinite keydown recursion on iOS), and #1448 (ftell() == -1 heap overflow on pipes plus a flag clash with -F/--deny-framing).
Six large or out-of-scope PRs (including #1504 mobile virtual keyboard, #1587 xterm 6.0.0, and #1591 libwebsockets 5.x) were cleanly deferred to dedicated future milestones, while 14 PRs were already superseded by stronger fixes or our zero-advisory webpack 5.113.0 frontend cleanup.
Layer 6: Fixing the 22-minute Windows build and shipping verifiable releases
Our first cross-build release hit an ugly surprise: Linux x86_64 and aarch64 finished in ~6 minutes each, while win32 dragged on for 22 minutes and 17 seconds.
Checking the job timestamps exposed the culprit in ten seconds: 19 minutes and 19 seconds went into openssl-3.6.1. The build script ran make all without no-shared no-tests no-apps no-docs, forcing MinGW’s PE linker to compile libcrypto/libssl DLLs, openssl.exe, and roughly 300 unused OpenSSL test .exe binaries, only to throw them away during install.
Switching OpenSSL to no-shared no-tests no-apps no-docs with make build_libs and make install_dev dropped the cold Windows build from 22m17s to 63 seconds. Adding CI stage caching brings warm runs down to roughly 30 seconds per target.
Every release on viaalink/ttyd-builds now verifies ttyd --version (ttyd version 1.7.7-viaalink.3) across x86_64, aarch64 via QEMU, and win32 via Wine, and publishes SHA256SUMS.txt plus a CycloneDX 1.5 SBOM (SBOM.cdx.json) with upstream 1.7.7 pedigree.
Giving back to upstream and companion open-source packages
We built this to give back cleanly, not to fragment the community. Our main branch stays identical to tsl0922/ttyd, every original author is credited in git history and release notes, and the work is offered back upstream as one rollup pull request, tsl0922/ttyd#1617, ready to split into four focused slices if @tsl0922 prefers.
Along the way, we also cleaned up and published two standalone TypeScript packages for anyone automating or testing ttyd:
@viaalink/ttyd-client: typed WebSocket client implementingttyd’s real binary message codes with a clean session API (type,resize,waitFor,exec).@viaalink/playwright-terminal-kit: Playwright harness for browser terminal E2E tests and pixel snapshots built on@viaalink/ttyd-client.
Build the test layers first, then touch the backlog. Six lightweight gates turned 66 tangled PRs into 38 verified merges, 14 proven RED to GREEN fixes, 8 prevented regressions, and a 63-second Windows static build.
Frequently asked questions
Why build a six-layer test suite before merging community pull requests?
Without automated regression checks, merging 38 community patches into a C and TypeScript terminal server is guesswork. Building the test net first let us prove 14 security and stability fixes RED to GREEN against stock 1.7.7 and catch subtle bugs hidden inside original PRs.
What does RED to GREEN differential proof mean in viaalink/ttyd?
We run the exact same 18-test black-box suite against both the unmodified stock 1.7.7 baseline and our patched binary. Fourteen tests fail on stock 1.7.7 (RED) and pass on our build (GREEN), with exact binary SHA-256 digests recorded in docs/RED_GREEN_PROOF.md.
Why did you decline 8 of the 66 open upstream PRs?
Independent review by three models plus maintainer inspection caught critical flaws in those patches, including an unvalidated cross-origin postMessage remote code execution bug, Basic Auth credentials passed in URL query strings, an unbounded HTTP POST memory exhaustion vector, and a heap overflow on pipes.
How do I verify and run the hardened ttyd binaries or automate browser terminals?
Download static Linux x86_64, Linux aarch64, or Windows x64 binaries with SHA256SUMS.txt and a CycloneDX SBOM from viaalink/ttyd-builds. For programmatic control and Playwright testing, use @viaalink/ttyd-client and @viaalink/playwright-terminal-kit on npm.