mirror of
https://github.com/coder/coder.git
synced 2026-10-16 14:48:56 +08:00
Malformed coordinate requests can panic per-connection coordinator goroutines and terminate coderd. Disconnect requests and nested cleanup of peers with full response buffers can also attempt to send on or close an already-closed channel. Validate request structure before authorization or state mutation in both tailnet coordinators, stop processing after disconnect, and avoid removing a peer twice during nested cleanup. Unexpected per-connection panics close the affected connection through the existing lost-peer cleanup. https://linear.app/codercom/issue/PLAT-595/security-nil-node-in-tailnet-updateself-crashes-entire-coderd-process
32 lines
786 B
Go
32 lines
786 B
Go
package tailnet
|
|
|
|
import (
|
|
"slices"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/tailnet/proto"
|
|
)
|
|
|
|
// ValidateCoordinateRequest checks the structural invariants required by the
|
|
// coordinator before authorization or state updates.
|
|
func ValidateCoordinateRequest(req *proto.CoordinateRequest) error {
|
|
if req == nil {
|
|
return xerrors.New("coordinate request is required")
|
|
}
|
|
if err := validateUpdateSelf(req); err != nil {
|
|
return err
|
|
}
|
|
if slices.Contains(req.ReadyForHandshake, nil) {
|
|
return xerrors.New("ready_for_handshake entries must not be nil")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func validateUpdateSelf(req *proto.CoordinateRequest) error {
|
|
if upd := req.GetUpdateSelf(); upd != nil && upd.GetNode() == nil {
|
|
return xerrors.New("update_self node is required")
|
|
}
|
|
return nil
|
|
}
|