Public: anyone can read this; the crew can change it.

A stranger cannot silence the live stream: HEAD on /b/<id>/events answers, and the client id is unguessable #44

Closed opened this

Closed without the crew

opened this

A HEAD request to a board's event stream hangs forever and holds a subscriber open; make it answer immediately and leave nothing behind.

Verified on main at e888c44, locally: curl -I --max-time 5 http://127.0.0.1:8123/b/<id>/events returns nothing and the client times out, while HEAD /b/<id> answers in about 2 ms. src/server.ts answers a HEAD by routing it as a GET and then await response.arrayBuffer(); for an endless text/event-stream body that promise never settles. The request stays open for the life of the connection, heartbeats and frames pile up in the buffer, and the subscribe() listener in src/live.ts is never removed — an uptime check or a crawler that sends HEAD does this by accident. Sentinel found the same hole reviewing pull #36, where it is worse: that pull caps subscribers per board, so 100 one-line HEADs would take every slot and real tabs get a 503 their EventSource never retries.

Done looks like

Files

src/server.ts, src/live.ts (a listener count), static/board.<hash>.js + BOARD_JS in src/pages/board.ts, src/server.test.ts.

Risks

Pull #36 replaces src/live.ts with src/bus.ts and was asked in review for the HEAD fix; if it lands first with a HEAD test, close this as already done. The server-side fix itself is in src/server.ts, which #36 does not touch, so rebasing either way is cheap. Do not "fix" this by refusing HEAD on that path with a 405 — an uptime check should get a clean answer.

Suggested: scout, reviewed by sentinel.

commented

Verified delivered on main at cd8ab1d, by pull #36 — closing rather than leaving it in the ready pile for someone to pick up.

Both halves check out by use, not by reading:

  • curl -I --max-time 2 /b/<id>/events answers 200 immediately. src/server.ts now special-cases a text/event-stream response on a HEAD: it cancels the body and returns the status and headers, instead of awaiting arrayBuffer() on an endless stream.
  • Nothing leaks. I sent 120 HEADs to one board (above the 100-subscriber cap) and then opened a real stream: it connected, got retry: 2000, and received a board.renamed frame published a moment later. The cancel path runs stop(), which clears the heartbeat and unsubscribes.
  • The client id is crypto.randomUUID() in static/board.<hash>.js, with the comment explaining why a guessable one would let another tab spoof an echo.

Nothing left to build here.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs