Skip to content

Commit f333120

Browse files
committed
Do not send sent events to the server for multipart messages with invalid ID
1 parent b751051 commit f333120

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

api/pkg/handlers/message_handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ func (h *MessageHandler) PostEvent(c *fiber.Ctx) error {
296296
return h.responseUnprocessableEntity(c, errors, "validation errors while storing event")
297297
}
298298

299+
request.Sanitize()
299300
message, err := h.service.GetMessage(ctx, h.userIDFomContext(c), uuid.MustParse(request.MessageID))
300301
if err != nil && stacktrace.GetCode(err) == repositories.ErrCodeNotFound {
301302
return h.responseNotFound(c, fmt.Sprintf("cannot find message with ID [%s]", request.MessageID))

api/pkg/requests/message_event_request.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
// MessageEvent is the payload for sending and SMS message
1313
type MessageEvent struct {
14+
request
15+
1416
// Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible
1517
Timestamp time.Time `json:"timestamp" example:"2022-06-05T14:26:09.527976+03:00"`
1618

@@ -26,8 +28,14 @@ type MessageEvent struct {
2628
MessageID string `json:"messageID" swaggerignore:"true"` // used internally for validation
2729
}
2830

31+
// Sanitize the message event
32+
func (input *MessageEvent) Sanitize() *MessageEvent {
33+
input.MessageID = input.sanitizeMessageID(input.MessageID)
34+
return input
35+
}
36+
2937
// ToMessageStoreEventParams converts MessageEvent to services.MessageStoreEventParams
30-
func (input MessageEvent) ToMessageStoreEventParams(source string) services.MessageStoreEventParams {
38+
func (input *MessageEvent) ToMessageStoreEventParams(source string) services.MessageStoreEventParams {
3139
return services.MessageStoreEventParams{
3240
MessageID: uuid.MustParse(input.MessageID),
3341
Source: source,

api/pkg/requests/request.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ func (input *request) removeStringDuplicates(values []string) []string {
7777
return result
7878
}
7979

80+
func (input *request) sanitizeMessageID(value string) string {
81+
id := strings.Builder{}
82+
for _, char := range value {
83+
if char == '.' {
84+
return id.String()
85+
}
86+
id.WriteRune(char)
87+
}
88+
return id.String()
89+
}
90+
8091
// getLimit gets the take as a string
8192
func (input *request) getBool(value string) bool {
8293
if value == "true" {

0 commit comments

Comments
 (0)