From 3dfa6d0cc9f4020f065392b3f8eeaca9680b347e Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 3 Dec 2023 17:55:12 +0000 Subject: [PATCH] Validate public key lengths on `debug_` API endpoints (fixes #1113) --- src/core/proto.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/proto.go b/src/core/proto.go index d8cae73..bffc202 100644 --- a/src/core/proto.go +++ b/src/core/proto.go @@ -251,15 +251,16 @@ func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) { if kbs, err = hex.DecodeString(req.Key); err != nil { return nil, err } + if len(kbs) != ed25519.PublicKeySize { + return nil, fmt.Errorf("invalid public key length") + } copy(key[:], kbs) ch := make(chan []byte, 1) p.sendGetSelfRequest(key, func(info []byte) { ch <- info }) - timer := time.NewTimer(6 * time.Second) - defer timer.Stop() select { - case <-timer.C: + case <-time.After(6 * time.Second): return nil, errors.New("timeout") case info := <-ch: var msg json.RawMessage @@ -291,15 +292,16 @@ func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error) if kbs, err = hex.DecodeString(req.Key); err != nil { return nil, err } + if len(kbs) != ed25519.PublicKeySize { + return nil, fmt.Errorf("invalid public key length") + } copy(key[:], kbs) ch := make(chan []byte, 1) p.sendGetPeersRequest(key, func(info []byte) { ch <- info }) - timer := time.NewTimer(6 * time.Second) - defer timer.Stop() select { - case <-timer.C: + case <-time.After(6 * time.Second): return nil, errors.New("timeout") case info := <-ch: ks := make(map[string][]string) @@ -341,15 +343,16 @@ func (p *protoHandler) getTreeHandler(in json.RawMessage) (interface{}, error) { if kbs, err = hex.DecodeString(req.Key); err != nil { return nil, err } + if len(kbs) != ed25519.PublicKeySize { + return nil, fmt.Errorf("invalid public key length") + } copy(key[:], kbs) ch := make(chan []byte, 1) p.sendGetTreeRequest(key, func(info []byte) { ch <- info }) - timer := time.NewTimer(6 * time.Second) - defer timer.Stop() select { - case <-timer.C: + case <-time.After(6 * time.Second): return nil, errors.New("timeout") case info := <-ch: ks := make(map[string][]string)