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
@@ -26,6 +26,27 @@ func TestRouteWSBroadcastMode(t *testing.T) {
|
||||
if room["mode"] != "broadcast" {
|
||||
t.Fatalf("bag mode=%v", room["mode"])
|
||||
}
|
||||
if room["require_auth"] != true {
|
||||
t.Fatalf("broadcast must require authentication by default: %v", room)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRouteWSPublicBroadcastOptOut(t *testing.T) {
|
||||
a := app.New(nil)
|
||||
out, err := ws.RouteWS(a, "/live", map[string]any{
|
||||
"mode": "broadcast",
|
||||
"require_auth": false,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
spec, err := ws.RouteSpecOf(out, "/live")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if spec.RequireAuth {
|
||||
t.Fatalf("explicit public route unexpectedly requires authentication: %+v", spec)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRouteWSEchoDefault(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user