fix(web): harden WebSocket and net host boundaries
- WS handshake: same-origin CheckOrigin instead of allow-all
- route_ws require_auth/需要登录: broadcast/room need a session by default,
explicit opt-out for public feeds; unauthenticated handshakes get 401
- WS limits: 1 MiB per message, 256 replies per connect; transport errors
return {ok:false, error} instead of an empty success; empty rooms GC'd
- net host: enforce the 8 MiB response cap while reading (incl. error and
SSE error paths) so a peer cannot exhaust memory
- url_encode: %20 for space (URL segment semantics, not form +)
- docs: sync 网页 (route_ws 需要登录, connect caps) and CHANGELOG
- tests: gold expectations, live fixture opt-out, hub GC, ws auth gate
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8e23a5395a
commit
86b183e2d7
15 files changed
+233
-28
No files matched your search
@@ -35,6 +35,38 @@ func TestBroadcastFanout(t *testing.T) {
|
||||
unsubscribe(path, ch2)
|
||||
}
|
||||
|
||||
func TestUnsubscribeRemovesEmptyRoom(t *testing.T) {
|
||||
path := "/t-empty-room-gc"
|
||||
ch := subscribe(path)
|
||||
unsubscribe(path, ch)
|
||||
globalHub.mu.Lock()
|
||||
_, ok := globalHub.room[path]
|
||||
globalHub.mu.Unlock()
|
||||
if ok {
|
||||
t.Fatalf("empty room %q was not garbage-collected", path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResubscribeDuringCleanupKeepsRoom(t *testing.T) {
|
||||
path := "/t-room-rejoin"
|
||||
ch := subscribe(path)
|
||||
ch2 := subscribe(path)
|
||||
unsubscribe(path, ch)
|
||||
unsubscribe(path, ch2)
|
||||
ch3 := subscribe(path)
|
||||
Publish(path, "still-alive")
|
||||
if got := readOne(ch3); got != "still-alive" {
|
||||
t.Fatalf("re-subscribed chan got %q", got)
|
||||
}
|
||||
unsubscribe(path, ch3)
|
||||
globalHub.mu.Lock()
|
||||
_, ok := globalHub.room[path]
|
||||
globalHub.mu.Unlock()
|
||||
if ok {
|
||||
t.Fatalf("empty room %q was not garbage-collected after rejoin", path)
|
||||
}
|
||||
}
|
||||
|
||||
func readOne(ch chan string) string {
|
||||
select {
|
||||
case s := <-ch:
|
||||
|
||||
Reference in new issue
Block a user