mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Sanity-check room version on RS event input
This commit is contained in:
parent
60524f4b99
commit
1ed1d7ae03
28
roomserver/internal/helpers/sanity.go
Normal file
28
roomserver/internal/helpers/sanity.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package helpers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SanityCheckEvent looks for any obvious problems with the event before
|
||||||
|
// we bother to continue processing it any further.
|
||||||
|
func SanityCheckEvent(event *gomatrixserverlib.Event) error {
|
||||||
|
switch event.Type() {
|
||||||
|
case gomatrixserverlib.MRoomCreate:
|
||||||
|
var content gomatrixserverlib.CreateContent
|
||||||
|
if err := json.Unmarshal(event.Content(), &content); err != nil {
|
||||||
|
return fmt.Errorf("Failed to unmarshal content of create event %q", event.EventID())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that the room version is supported.
|
||||||
|
if content.RoomVersion != nil {
|
||||||
|
if _, err := content.RoomVersion.EventFormat(); err != nil {
|
||||||
|
return fmt.Errorf("Room version %q is unsupported in create event %q", *content.RoomVersion, event.EventID())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -44,6 +44,17 @@ func (r *Inputer) processRoomEvent(
|
||||||
headered := input.Event
|
headered := input.Event
|
||||||
event := headered.Unwrap()
|
event := headered.Unwrap()
|
||||||
|
|
||||||
|
// Run sanity checks against the event. This will catch any really
|
||||||
|
// obvious problems.
|
||||||
|
if err = helpers.SanityCheckEvent(&event); err != nil {
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"event_id": event.EventID(),
|
||||||
|
"type": event.Type(),
|
||||||
|
"room": event.RoomID(),
|
||||||
|
}).WithError(err).Info("Event failed sanity-checks")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Check that the event passes authentication checks and work out
|
// Check that the event passes authentication checks and work out
|
||||||
// the numeric IDs for the auth events.
|
// the numeric IDs for the auth events.
|
||||||
isRejected := false
|
isRejected := false
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue