Tolerate more invalid inputs from synapse
This commit is contained in:
parent
4d909fffd8
commit
054a6d4268
1 changed files with 24 additions and 6 deletions
30
server.go
30
server.go
|
@ -117,7 +117,7 @@ func handleTxn(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
err = handleTxnEvent(ev)
|
err = handleTxnEvent(ev)
|
||||||
if err != nil {
|
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 {
|
func handleTxnEvent(e *mxlib.Event) error {
|
||||||
if e.Type == "m.room.message" {
|
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{
|
ev := &connector.Event{
|
||||||
Type: connector.EVENT_MESSAGE,
|
Type: connector.EVENT_MESSAGE,
|
||||||
Text: e.Content["body"].(string),
|
Text: e_body,
|
||||||
Id: e.EventId,
|
Id: e.EventId,
|
||||||
}
|
}
|
||||||
typ := e.Content["msgtype"].(string)
|
|
||||||
if typ == "m.emote" {
|
if typ == "m.emote" {
|
||||||
ev.Type = connector.EVENT_MESSAGE
|
ev.Type = connector.EVENT_MESSAGE
|
||||||
} else if typ == "m.file" || typ == "m.image" {
|
} 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 := dbIsPmRoom(e.RoomId); pm_room != nil {
|
||||||
if pm_room.Protocol == EASYBRIDGE_SYSTEM_PROTOCOL {
|
if pm_room.Protocol == EASYBRIDGE_SYSTEM_PROTOCOL {
|
||||||
handleSystemMessage(e.Sender, e.Content["body"].(string))
|
handleSystemMessage(e.Sender, e_body)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// If this is a private message room
|
// If this is a private message room
|
||||||
|
@ -185,7 +194,11 @@ func handleTxnEvent(e *mxlib.Event) error {
|
||||||
return fmt.Errorf("Room not bridged")
|
return fmt.Errorf("Room not bridged")
|
||||||
}
|
}
|
||||||
} else if e.Type == "m.room.member" {
|
} 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 ms == "leave" {
|
||||||
if pm_room := dbIsPmRoom(e.RoomId); pm_room != nil {
|
if pm_room := dbIsPmRoom(e.RoomId); pm_room != nil {
|
||||||
// If user leaves a PM room, we must drop it
|
// 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" {
|
} 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 {
|
if room := dbIsPublicRoom(e.RoomId); room != nil {
|
||||||
acct := FindJoinedAccount(e.Sender, room.Protocol, room.RoomID)
|
acct := FindJoinedAccount(e.Sender, room.Protocol, room.RoomID)
|
||||||
if acct != nil {
|
if acct != nil {
|
||||||
return acct.Conn.SetRoomInfo(room.RoomID, &connector.RoomInfo{
|
return acct.Conn.SetRoomInfo(room.RoomID, &connector.RoomInfo{
|
||||||
Topic: e.Content["topic"].(string),
|
Topic: e_topic,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("Could not find room account for %s %s %s", e.Sender, room.Protocol, room.RoomID)
|
return fmt.Errorf("Could not find room account for %s %s %s", e.Sender, room.Protocol, room.RoomID)
|
||||||
|
|
Loading…
Reference in a new issue