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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -9,6 +10,8 @@ import (
|
||||||
"github.com/status-im/status-go/protocol/v1"
|
"github.com/status-im/status-go/protocol/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const maxChatMessageTextLength = 4096
|
||||||
|
|
||||||
// maxWhisperDrift is how many milliseconds we allow the clock value to differ
|
// maxWhisperDrift is how many milliseconds we allow the clock value to differ
|
||||||
// from whisperTimestamp
|
// from whisperTimestamp
|
||||||
const maxWhisperFutureDriftMs uint64 = 120000
|
const maxWhisperFutureDriftMs uint64 = 120000
|
||||||
|
@ -163,6 +166,10 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp
|
||||||
return errors.New("text can't be empty")
|
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 {
|
if len(message.ChatId) == 0 {
|
||||||
return errors.New("chatId can't be empty")
|
return errors.New("chatId can't be empty")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
@ -193,6 +194,21 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
|
||||||
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
|
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",
|
Name: "Unknown MessageType",
|
||||||
WhisperTimestamp: 2,
|
WhisperTimestamp: 2,
|
||||||
|
|
Loading…
Reference in New Issue