Tolerate more invalid inputs from synapse

This commit is contained in:
Alex 2020-04-05 12:52:55 +02:00
parent 4d909fffd8
commit 054a6d4268

View file

@ -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)