mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 07:35:07 +02:00
watchtower/wtdb: only accept properly sized blobs
Modifies the bbolt and mock tower databases to only accept blobs that are the expected size of the session's blob type. This prevents resource exhaustion attacks where a client may provide disproportionately large encrypted blob, even though all supported blob types are of fixed-size.
This commit is contained in:
@@ -46,6 +46,10 @@ var (
|
||||
// ErrNoSessionHintIndex signals that an active session does not have an
|
||||
// initialized index for tracking its own state updates.
|
||||
ErrNoSessionHintIndex = errors.New("session hint index missing")
|
||||
|
||||
// ErrInvalidBlobSize indicates that the encrypted blob provided by the
|
||||
// client is not valid according to the blob type of the session.
|
||||
ErrInvalidBlobSize = errors.New("invalid blob size")
|
||||
)
|
||||
|
||||
// TowerDB is single database providing a persistent storage engine for the
|
||||
@@ -233,6 +237,13 @@ func (t *TowerDB) InsertStateUpdate(update *SessionStateUpdate) (uint16, error)
|
||||
return err
|
||||
}
|
||||
|
||||
// Assert that the blob is the correct size for the session's
|
||||
// blob type.
|
||||
expBlobSize := blob.Size(session.Policy.BlobType)
|
||||
if len(update.EncryptedBlob) != expBlobSize {
|
||||
return ErrInvalidBlobSize
|
||||
}
|
||||
|
||||
// Validate the update against the current state of the session.
|
||||
err = session.AcceptUpdateSequence(
|
||||
update.SeqNum, update.LastApplied,
|
||||
|
Reference in New Issue
Block a user