mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-29 08:18:27 +00:00
reject peeks for non-worldreadable rooms
This commit is contained in:
parent
8712ea337a
commit
eda84cd915
1 changed files with 26 additions and 0 deletions
|
@ -16,12 +16,14 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
|
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -144,6 +146,30 @@ func (r *RoomserverInternalAPI) performPeekRoomByID(
|
||||||
req.ServerNames = append(req.ServerNames, domain)
|
req.ServerNames = append(req.ServerNames, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this room isn't world_readable, we reject.
|
||||||
|
// XXX: would be nicer to call this with NIDs
|
||||||
|
// XXX: we should probably factor out history_visibility checks into a common utility method somewhere
|
||||||
|
// which handles the default value etc.
|
||||||
|
var worldReadable = false
|
||||||
|
ev, err := r.DB.GetStateEvent(ctx, roomID, "m.room.history_visibility", "")
|
||||||
|
if ev != nil {
|
||||||
|
content := map[string]string{}
|
||||||
|
if err = json.Unmarshal(ev.Content(), &content); err != nil {
|
||||||
|
util.GetLogger(ctx).WithError(err).Error("json.Unmarshal for history visibility failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if visibility, ok := content["history_visibility"]; ok {
|
||||||
|
worldReadable = visibility == "world_readable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !worldReadable {
|
||||||
|
return "", &api.PerformError{
|
||||||
|
Code: api.PerformErrorNotAllowed,
|
||||||
|
Msg: "Room is not world-readable",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: handle federated peeks
|
// TODO: handle federated peeks
|
||||||
|
|
||||||
err = r.WriteOutputEvents(roomID, []api.OutputEvent{
|
err = r.WriteOutputEvents(roomID, []api.OutputEvent{
|
||||||
|
|
Loading…
Reference in a new issue