Repository navigation
Commit 3c7c3ff
fix: refuse an event-stream client, not just a WebSocket one
`allowedHosts` and the origin check were not being enforced on the `sse`
transport. The guard ran and decided to refuse, and then neither half of the
refusal landed: the message went through `sendMessage`, which tests
`readyState === 1` and calls `client.send` — a `ServerResponse` has neither,
so the loop skipped it — and `client.close()`, which a `ServerResponse` also
does not have, threw and was swallowed. The stream stayed open and kept
receiving builds.
The message goes through the middleware's `publishTo` now, which puts it on
the wire the client is actually on, and the connection is dropped the way that
client is dropped: a WebSocket closes, a response ends.
Verified on both transports: a disallowed origin is told
`Invalid Host/Origin header` and dropped, over a WebSocket and over a stream
alike — and a same-origin page, which `EventSource` gives no `Origin` at all,
is still let through.
Found via a CodeRabbit review of the middleware's README example, which had
the same two mistakes in it.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA1 parent 05f7f57 commit 3c7c3ff
1 file changed
Lines changed: 28 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
160 | 168 | | |
161 | 169 | | |
162 | 170 | | |
| |||
2472 | 2480 | | |
2473 | 2481 | | |
2474 | 2482 | | |
2475 | | - | |
| 2483 | + | |
2476 | 2484 | | |
2477 | 2485 | | |
2478 | 2486 | | |
| |||
2512 | 2520 | | |
2513 | 2521 | | |
2514 | 2522 | | |
2515 | | - | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
2516 | 2534 | | |
2517 | | - | |
2518 | | - | |
2519 | | - | |
2520 | | - | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
2521 | 2543 | | |
2522 | 2544 | | |
2523 | 2545 | | |
| |||
0 commit comments