rpcserver: detect unexpected replies before websocket shutdown
What changed, and why it matters
This commit fixes a test helper in btcd's RPC websocket server. The helper now reads any leftover server response before waiting for the connection to close. Previously, waiting first could let an authentication timeout hide a reply that was queued for an unauthenticated, malformed request. The change makes the test correctly detect unexpected replies, but it is a test-only fix; the underlying server behavior is not changed.
Review the underlying websocket RPC server logic to confirm that unauthenticated clients cannot elicit replies or side effects from malformed/batch requests. Consider whether the pre-authentication guards removed elsewhere need compensating server-side controls, since this commit only strengthens the test.
Security signals we found
Test-only hardening against hidden/unexpected RPC replies
Unauthenticated malformed request handling in websocket RPC path
Authentication timeout may mask server replies
Evidence from the diff
The change is in rpcwebsocket_test.go’s requireClosed helper. It reorders operations: conn.ReadMessage() now happens before s.waitDone(). The commit message explains that with pre-authentication guards removed, the server could queue a reply for a malformed request sent before authentication; waiting for shutdown first allowed the auth timeout to close the unread pipe and conceal that reply. By reading first, the test catches unexpected replies for single and batch requests. No production code is modified.
Changed components
rpcwebsocket_test.gobtcd RPC websocket server test helpersInspect captured patch +4 / −2
### rpcwebsocket_test.go
@@ -321,10 +321,12 @@ func requireClosed(t *testing.T, s *testWebsocketServer,
t.Helper()
- s.waitDone()
-
+ // Read before waiting for shutdown so a queued reply cannot be hidden
+ // by the authentication timeout closing the connection.
_, msg, err := conn.ReadMessage()
require.Error(t, err, "unexpected message %q", msg)
+
+ s.waitDone()
}
// TestWebsocketUnauthenticatedReadLimit checks that a client that hasn'tWhy this scored 31/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.