diff --git a/VERSION b/VERSION index a60476bfe..cb6b534ab 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.58.0 +0.59.0 diff --git a/protocol/message_validator.go b/protocol/message_validator.go index 06ed8fa4b..9ec0bb253 100644 --- a/protocol/message_validator.go +++ b/protocol/message_validator.go @@ -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") } diff --git a/protocol/message_validator_test.go b/protocol/message_validator_test.go index ad5dadba1..592e6e7b6 100644 --- a/protocol/message_validator_test.go +++ b/protocol/message_validator_test.go @@ -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,