aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-05 12:52:55 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-05 12:52:55 +0200
commit054a6d4268533ab3866ab9be48c6f499c29a6d02 (patch)
tree7a1255626aaebd383b356104847f8c0ecec69daf
parent4d909fffd88c2a66094cfec6f43ac932113906b9 (diff)
downloadeasybridge-054a6d4268533ab3866ab9be48c6f499c29a6d02.tar.gz
easybridge-054a6d4268533ab3866ab9be48c6f499c29a6d02.zip
Tolerate more invalid inputs from synapse
-rw-r--r--server.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/server.go b/server.go
index e87dad2..84a693e 100644
--- a/server.go
+++ b/server.go
@@ -117,7 +117,7 @@ func handleTxn(w http.ResponseWriter, r *http.Request) {
}
err = handleTxnEvent(ev)
if err != nil {
- ezbrSystemSend(ev.Sender, fmt.Sprintf("Could not process %s (%s): %s", ev.Type, ev.Sender, err))
+ ezbrSystemSend(ev.Sender, fmt.Sprintf("Could not process %s (from %s): %s", ev.Type, ev.Sender, err))
}
}
@@ -129,12 +129,21 @@ func handleTxn(w http.ResponseWriter, r *http.Request) {
func handleTxnEvent(e *mxlib.Event) error {
if e.Type == "m.room.message" {
+ e_body, ok := e.Content["body"].(string)
+ if !ok {
+ return fmt.Errorf("Invalid m.room.message event, body is not defined: %#v", e)
+ }
+ typ, ok := e.Content["msgtype"].(string)
+ if !ok {
+ return fmt.Errorf("Invalid m.room.message event, msgtype is not defined: %#v", e)
+ }
+
ev := &connector.Event{
Type: connector.EVENT_MESSAGE,
- Text: e.Content["body"].(string),
+ Text: e_body,
Id: e.EventId,
}
- typ := e.Content["msgtype"].(string)
+
if typ == "m.emote" {
ev.Type = connector.EVENT_MESSAGE
} else if typ == "m.file" || typ == "m.image" {
@@ -146,7 +155,7 @@ func handleTxnEvent(e *mxlib.Event) error {
if pm_room := dbIsPmRoom(e.RoomId); pm_room != nil {
if pm_room.Protocol == EASYBRIDGE_SYSTEM_PROTOCOL {
- handleSystemMessage(e.Sender, e.Content["body"].(string))
+ handleSystemMessage(e.Sender, e_body)
return nil
}
// If this is a private message room
@@ -185,7 +194,11 @@ func handleTxnEvent(e *mxlib.Event) error {
return fmt.Errorf("Room not bridged")
}
} else if e.Type == "m.room.member" {
- ms := e.Content["membership"].(string)
+ ms, ok := e.Content["membership"].(string)
+ if !ok {
+ return fmt.Errorf("Invalid m.room.member event, membership is not defined: %#v", e)
+ }
+
if ms == "leave" {
if pm_room := dbIsPmRoom(e.RoomId); pm_room != nil {
// If user leaves a PM room, we must drop it
@@ -209,11 +222,16 @@ func handleTxnEvent(e *mxlib.Event) error {
}
}
} else if e.Type == "m.room.topic" {
+ e_topic, ok := e.Content["topic"].(string)
+ if !ok {
+ return fmt.Errorf("Invalid m.room.topic event, topic is not defined: %#v", e)
+ }
+
if room := dbIsPublicRoom(e.RoomId); room != nil {
acct := FindJoinedAccount(e.Sender, room.Protocol, room.RoomID)
if acct != nil {
return acct.Conn.SetRoomInfo(room.RoomID, &connector.RoomInfo{
- Topic: e.Content["topic"].(string),
+ Topic: e_topic,
})
} else {
return fmt.Errorf("Could not find room account for %s %s %s", e.Sender, room.Protocol, room.RoomID)