Drop messages with text longer than 4096 characters (#2029)
This commit is contained in:
parent
b67ce580d0
commit
88a3022ea8
|
@ -2,6 +2,7 @@ package protocol
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -9,6 +10,8 @@ import (
|
|||
"github.com/status-im/status-go/protocol/v1"
|
||||
)
|
||||
|
||||
const maxChatMessageTextLength = 4096
|
||||
|
||||
// maxWhisperDrift is how many milliseconds we allow the clock value to differ
|
||||
// from whisperTimestamp
|
||||
const maxWhisperFutureDriftMs uint64 = 120000
|
||||
|
@ -163,6 +166,10 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp
|
|||
return errors.New("text can't be empty")
|
||||
}
|
||||
|
||||
if len(message.Text) > maxChatMessageTextLength {
|
||||
return fmt.Errorf("text shouldn't be longer than %d", maxChatMessageTextLength)
|
||||
}
|
||||
|
||||
if len(message.ChatId) == 0 {
|
||||
return errors.New("chatId can't be empty")
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package protocol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
@ -193,6 +194,21 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
|
|||
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Too long text",
|
||||
WhisperTimestamp: 2,
|
||||
Valid: false,
|
||||
Message: protobuf.ChatMessage{
|
||||
ChatId: "a",
|
||||
Clock: 1,
|
||||
Timestamp: 2,
|
||||
Text: fmt.Sprintf("%x", make([]byte, maxChatMessageTextLength/2+1)),
|
||||
ResponseTo: "",
|
||||
EnsName: "",
|
||||
MessageType: protobuf.MessageType_ONE_TO_ONE,
|
||||
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Unknown MessageType",
|
||||
WhisperTimestamp: 2,
|
||||
|
|
Loading…
Reference in New Issue