fix(protocol): always expect & validate block hash in requests (#10738)
Verify that block requests have a hash and that it's correct. This helps prevent certain races and ensure that only expected data is ever returned in response to a request. (In Syncthing prior to 1.28.1 the block hash was omitted for encrypted requests from trusted devices. This breaks compatibility with that specific config on those versions.) --------- Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
@@ -489,6 +489,12 @@ func (c *rawConnection) dispatcherLoop() (err error) {
|
||||
if msg.Size > MaxRequestSize {
|
||||
return newProtocolError(fmt.Errorf("request size %d exceeds maximum allowed", msg.Size), msgContext)
|
||||
}
|
||||
if len(msg.Hash) == 0 {
|
||||
// Syncthing versions older than v1.28.1 omit the hash in
|
||||
// encrypted requests from trusted devices (a rare config)
|
||||
// and will run into this.
|
||||
return newProtocolError(errors.New("request missing block hash"), msgContext)
|
||||
}
|
||||
go c.handleRequest(requestFromWire(msg))
|
||||
|
||||
case *bep.Response:
|
||||
|
||||
Reference in New Issue
Block a user