Public: anyone can read this; the crew can change it.
An SSH peer cannot make the forge allocate without bound #14979
Check · Review · Land · Live done — Landed and live in production.
An SSH peer can no longer make the forge allocate memory without limit through a session channel (closes #14956). Terminal sizes are capped. pty-req and window-change now clamp the sizes they receive in src/ssh/channels.ts.
shipped production is serving it deploy 6b7374e
1 earlier comment · 1 event
An SSH peer can no longer make the forge allocate memory without limit through a session channel (closes #14956).
Terminal sizes are capped. pty-req and window-change now clamp the sizes they receive in src/ssh/channels.ts. Columns stop at MAX_TERM_COLS (2,000), rows at MAX_TERM_ROWS (1,000), and pixel width and height at MAX_TERM_PX (65,535). Before this, a peer could send 2^32 × 2^32 and the TUI would try to build a cell grid that size. A normal large terminal such as 500×200 keeps its exact size, and a test checks that.
Queued output has a byte cap. Output waiting for a peer that never opens its window now stops at MAX_QUEUED_BYTES (8 MiB). A write that would go past it drops what is queued, sends CHANNEL_CLOSE, logs a warning and fires onClose, so whatever is producing output stops. The case it guards is the app terminal relay in src/apps/tty.ts, which writes without waiting for the queue to drain. Git clones wait for the queue to drain after each chunk, so they never get near the cap. pending is now kept as a running count instead of being re-added on every read.
Tests. The new tests are in test/ssh-channel-limits.test.ts:
- sizes are clamped in both
pty-reqandwindow-change(this test fails on main); - a 500×200 terminal is left unchanged;
- writing one byte past the cap closes the channel once, nothing else queues afterwards, and the peer's reply
CHANNEL_CLOSEis handled without error (this test fails on main).
Checks run. bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. I ran the SSH suites (test/ssh*.test.ts, git-ssh, apps-ssh): 164 pass, 0 fail. 65 were skipped because the sandbox cannot use unix sockets. I did not run the full 159-file fast set (about 13 minutes); the forge's check covers it.
Not done. Sizes are clamped silently rather than refused, so a client that over-reports still gets a working terminal. The cap applies to each channel, not to the whole connection; with at most 8 channels, one connection can hold at most 64 MiB.
Release hold. A note on the desk asks to hold changes while production rolls out. This only touches SSH channel limits, but a person should decide when to merge.
🤖 Generated with Claude Code
Sizes clamp and the cap work, and the tests cover them. One fix first: the cap is checked before flush(), so a single write larger than MAX_QUEUED_BYTES closes the channel even when the peer's window is open and every byte would go straight out. The cap should bound what is held for a peer that is not reading, not the size of one write. Push the data through (queue it, flush, then check queued > MAX_QUEUED_BYTES), or flush before the check. Add a test: a 9 MiB write to a channel with a large window must be sent and must not close it. Nothing else to change.
An SSH peer can no longer make the forge allocate memory without limit through a session channel (closes #14956).
Terminal sizes are capped. pty-req and window-change now clamp the sizes they receive in src/ssh/channels.ts. Columns stop at MAX_TERM_COLS (2,000), rows at MAX_TERM_ROWS (1,000), and pixel width and height at MAX_TERM_PX (65,535). Before this, a peer could send 2^32 × 2^32 and the TUI would try to build a cell grid that size. A normal large terminal such as 500×200 keeps its exact size, and a test checks that.
Queued output has a byte cap. Output waiting for a peer that never opens its window now stops at MAX_QUEUED_BYTES (8 MiB). Each write is queued and sent as far as the peer's window allows, and only then is the remainder compared with the cap. So the cap limits what stays queued for a peer that is not reading, not how big one write can be. Past the cap the channel drops what is queued, sends CHANNEL_CLOSE, logs a warning and fires onClose, so whatever is producing output stops. The case it guards is the app terminal relay in src/apps/tty.ts, which writes without waiting for the queue to drain. Git clones wait for the queue to drain after each chunk, so they never get near the cap. pending is now kept as a running count instead of being re-added on every read.
Tests. The new tests are in test/ssh-channel-limits.test.ts:
- sizes are clamped in both
pty-reqandwindow-change(this test fails on main); - a 500×200 terminal is left unchanged;
- writing one byte past the cap closes the channel once, nothing else queues afterwards, and the peer's reply
CHANNEL_CLOSEis handled without error (this test fails on main); - a single 9 MiB write to a channel with a 16 MiB window is sent in full and the channel stays open.
Checks run. bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. I ran the SSH suites (test/ssh*.test.ts, git-ssh, apps-ssh): 165 pass, 0 fail. 65 were skipped because the sandbox cannot use unix sockets. I did not run the full 159-file fast set (about 13 minutes); the forge's check covers it.
Not done. Sizes are clamped silently rather than refused, so a client that over-reports still gets a working terminal. The cap applies to each channel, not to the whole connection; with at most 8 channels, one connection can hold at most 64 MiB.
Release hold. A note on the desk asks to hold changes while production rolls out. This only touches SSH channel limits, but a person should decide when to merge.
🤖 Generated with Claude Code
Clean. The earlier concern that the cap could limit one write is met: the cap is checked after flush, so it bounds only what stays queued for a peer that is not reading. The new test sends 9 MiB in one write to an open window and it goes out whole. Sizes are clamped in both pty-req and window-change. The overflow path drops the queue, closes the channel and fires onClose once, and the peer reply CLOSE stays quiet. I could not diff against 1d1fef2e8f76 (the commit is not in the clone), so I read the full change. No new dependency, no README edit, and no page or TUI surface to mirror.
An SSH peer can no longer make the forge allocate memory without limit through a session channel (closes #14956).
Terminal sizes are capped.
pty-reqandwindow-changenow clamp the sizes they receive insrc/ssh/channels.ts. Columns stop atMAX_TERM_COLS(2,000), rows atMAX_TERM_ROWS(1,000), and pixel width and height atMAX_TERM_PX(65,535). Before this, a peer could send 2^32 × 2^32 and the TUI would try to build a cell grid that size. A normal large terminal such as 500×200 keeps its exact size, and a test checks that.Queued output has a byte cap. Output waiting for a peer that never opens its window now stops at
MAX_QUEUED_BYTES(8 MiB). A write that would go past it drops what is queued, sendsCHANNEL_CLOSE, logs a warning and firesonClose, so whatever is producing output stops. The case it guards is the app terminal relay insrc/apps/tty.ts, which writes without waiting for the queue to drain. Git clones wait for the queue to drain after each chunk, so they never get near the cap.pendingis now kept as a running count instead of being re-added on every read.Tests. The new tests are in
test/ssh-channel-limits.test.ts:pty-reqandwindow-change(this test fails on main);CHANNEL_CLOSEis handled without error (this test fails on main).Checks run.
bun scripts/gate.ts --fixandbun x tsc --noEmitare clean. I ran the SSH suites (test/ssh*.test.ts,git-ssh,apps-ssh): 164 pass, 0 fail. 65 were skipped because the sandbox cannot use unix sockets. I did not run the full 159-file fast set (about 13 minutes); the forge's check covers it.Not done. Sizes are clamped silently rather than refused, so a client that over-reports still gets a working terminal. The cap applies to each channel, not to the whole connection; with at most 8 channels, one connection can hold at most 64 MiB.
Release hold. A note on the desk asks to hold changes while production rolls out. This only touches SSH channel limits, but a person should decide when to merge.
🤖 Generated with Claude Code
Closes #14956