mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-25 05:01:41 +00:00
Gate peeking behind msc flags (#1731)
This commit is contained in:
parent
0571d395b5
commit
93942f8ab6
@ -46,6 +46,7 @@ func AddPublicRoutes(
|
|||||||
userAPI userapi.UserInternalAPI,
|
userAPI userapi.UserInternalAPI,
|
||||||
keyAPI keyserverAPI.KeyInternalAPI,
|
keyAPI keyserverAPI.KeyInternalAPI,
|
||||||
extRoomsProvider api.ExtraPublicRoomsProvider,
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
|
mscCfg *config.MSCs,
|
||||||
) {
|
) {
|
||||||
_, producer := kafka.SetupConsumerProducer(&cfg.Matrix.Kafka)
|
_, producer := kafka.SetupConsumerProducer(&cfg.Matrix.Kafka)
|
||||||
|
|
||||||
@ -57,6 +58,6 @@ func AddPublicRoutes(
|
|||||||
routing.Setup(
|
routing.Setup(
|
||||||
router, cfg, eduInputAPI, rsAPI, asAPI,
|
router, cfg, eduInputAPI, rsAPI, asAPI,
|
||||||
accountsDB, userAPI, federation,
|
accountsDB, userAPI, federation,
|
||||||
syncProducer, transactionsCache, fsAPI, keyAPI, extRoomsProvider,
|
syncProducer, transactionsCache, fsAPI, keyAPI, extRoomsProvider, mscCfg,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ func Setup(
|
|||||||
federationSender federationSenderAPI.FederationSenderInternalAPI,
|
federationSender federationSenderAPI.FederationSenderInternalAPI,
|
||||||
keyAPI keyserverAPI.KeyInternalAPI,
|
keyAPI keyserverAPI.KeyInternalAPI,
|
||||||
extRoomsProvider api.ExtraPublicRoomsProvider,
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
|
mscCfg *config.MSCs,
|
||||||
) {
|
) {
|
||||||
rateLimits := newRateLimits(&cfg.RateLimiting)
|
rateLimits := newRateLimits(&cfg.RateLimiting)
|
||||||
userInteractiveAuth := auth.NewUserInteractive(accountDB.GetAccountByPassword, cfg)
|
userInteractiveAuth := auth.NewUserInteractive(accountDB.GetAccountByPassword, cfg)
|
||||||
@ -110,20 +111,23 @@ func Setup(
|
|||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodPost, http.MethodOptions)
|
).Methods(http.MethodPost, http.MethodOptions)
|
||||||
r0mux.Handle("/peek/{roomIDOrAlias}",
|
|
||||||
httputil.MakeAuthAPI(gomatrixserverlib.Peek, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
if mscCfg.Enabled("msc2753") {
|
||||||
if r := rateLimits.rateLimit(req); r != nil {
|
r0mux.Handle("/peek/{roomIDOrAlias}",
|
||||||
return *r
|
httputil.MakeAuthAPI(gomatrixserverlib.Peek, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||||
}
|
if r := rateLimits.rateLimit(req); r != nil {
|
||||||
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
return *r
|
||||||
if err != nil {
|
}
|
||||||
return util.ErrorResponse(err)
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
||||||
}
|
if err != nil {
|
||||||
return PeekRoomByIDOrAlias(
|
return util.ErrorResponse(err)
|
||||||
req, device, rsAPI, accountDB, vars["roomIDOrAlias"],
|
}
|
||||||
)
|
return PeekRoomByIDOrAlias(
|
||||||
}),
|
req, device, rsAPI, accountDB, vars["roomIDOrAlias"],
|
||||||
).Methods(http.MethodPost, http.MethodOptions)
|
)
|
||||||
|
}),
|
||||||
|
).Methods(http.MethodPost, http.MethodOptions)
|
||||||
|
}
|
||||||
r0mux.Handle("/joined_rooms",
|
r0mux.Handle("/joined_rooms",
|
||||||
httputil.MakeAuthAPI("joined_rooms", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
httputil.MakeAuthAPI("joined_rooms", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||||
return GetJoinedRooms(req, device, rsAPI)
|
return GetJoinedRooms(req, device, rsAPI)
|
||||||
|
@ -35,6 +35,7 @@ func ClientAPI(base *setup.BaseDendrite, cfg *config.Dendrite) {
|
|||||||
clientapi.AddPublicRoutes(
|
clientapi.AddPublicRoutes(
|
||||||
base.PublicClientAPIMux, &base.Cfg.ClientAPI, accountDB, federation,
|
base.PublicClientAPIMux, &base.Cfg.ClientAPI, accountDB, federation,
|
||||||
rsAPI, eduInputAPI, asQuery, transactions.New(), fsAPI, userAPI, keyAPI, nil,
|
rsAPI, eduInputAPI, asQuery, transactions.New(), fsAPI, userAPI, keyAPI, nil,
|
||||||
|
&cfg.MSCs,
|
||||||
)
|
)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(
|
base.SetupAndServeHTTP(
|
||||||
|
@ -33,6 +33,7 @@ func FederationAPI(base *setup.BaseDendrite, cfg *config.Dendrite) {
|
|||||||
base.PublicFederationAPIMux, base.PublicKeyAPIMux,
|
base.PublicFederationAPIMux, base.PublicKeyAPIMux,
|
||||||
&base.Cfg.FederationAPI, userAPI, federation, keyRing,
|
&base.Cfg.FederationAPI, userAPI, federation, keyRing,
|
||||||
rsAPI, fsAPI, base.EDUServerClient(), keyAPI,
|
rsAPI, fsAPI, base.EDUServerClient(), keyAPI,
|
||||||
|
&base.Cfg.MSCs,
|
||||||
)
|
)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(
|
base.SetupAndServeHTTP(
|
||||||
|
@ -63,7 +63,7 @@ func main() {
|
|||||||
if *defaultsForCI {
|
if *defaultsForCI {
|
||||||
cfg.ClientAPI.RateLimiting.Enabled = false
|
cfg.ClientAPI.RateLimiting.Enabled = false
|
||||||
cfg.FederationSender.DisableTLSValidation = true
|
cfg.FederationSender.DisableTLSValidation = true
|
||||||
cfg.MSCs.MSCs = []string{"msc2836", "msc2946"}
|
cfg.MSCs.MSCs = []string{"msc2836", "msc2946", "msc2444", "msc2753"}
|
||||||
cfg.Logging[0].Level = "trace"
|
cfg.Logging[0].Level = "trace"
|
||||||
// don't hit matrix.org when running tests!!!
|
// don't hit matrix.org when running tests!!!
|
||||||
cfg.SigningKeyServer.KeyPerspectives = config.KeyPerspectives{}
|
cfg.SigningKeyServer.KeyPerspectives = config.KeyPerspectives{}
|
||||||
|
@ -38,10 +38,11 @@ func AddPublicRoutes(
|
|||||||
federationSenderAPI federationSenderAPI.FederationSenderInternalAPI,
|
federationSenderAPI federationSenderAPI.FederationSenderInternalAPI,
|
||||||
eduAPI eduserverAPI.EDUServerInputAPI,
|
eduAPI eduserverAPI.EDUServerInputAPI,
|
||||||
keyAPI keyserverAPI.KeyInternalAPI,
|
keyAPI keyserverAPI.KeyInternalAPI,
|
||||||
|
mscCfg *config.MSCs,
|
||||||
) {
|
) {
|
||||||
routing.Setup(
|
routing.Setup(
|
||||||
fedRouter, keyRouter, cfg, rsAPI,
|
fedRouter, keyRouter, cfg, rsAPI,
|
||||||
eduAPI, federationSenderAPI, keyRing,
|
eduAPI, federationSenderAPI, keyRing,
|
||||||
federation, userAPI, keyAPI,
|
federation, userAPI, keyAPI, mscCfg,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
|
|||||||
fsAPI := base.FederationSenderHTTPClient()
|
fsAPI := base.FederationSenderHTTPClient()
|
||||||
// TODO: This is pretty fragile, as if anything calls anything on these nils this test will break.
|
// TODO: This is pretty fragile, as if anything calls anything on these nils this test will break.
|
||||||
// Unfortunately, it makes little sense to instantiate these dependencies when we just want to test routing.
|
// Unfortunately, it makes little sense to instantiate these dependencies when we just want to test routing.
|
||||||
federationapi.AddPublicRoutes(base.PublicFederationAPIMux, base.PublicKeyAPIMux, &cfg.FederationAPI, nil, nil, keyRing, nil, fsAPI, nil, nil)
|
federationapi.AddPublicRoutes(base.PublicFederationAPIMux, base.PublicKeyAPIMux, &cfg.FederationAPI, nil, nil, keyRing, nil, fsAPI, nil, nil, &cfg.MSCs)
|
||||||
baseURL, cancel := test.ListenAndServe(t, base.PublicFederationAPIMux, true)
|
baseURL, cancel := test.ListenAndServe(t, base.PublicFederationAPIMux, true)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://"))
|
serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://"))
|
||||||
|
@ -48,6 +48,7 @@ func Setup(
|
|||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
userAPI userapi.UserInternalAPI,
|
userAPI userapi.UserInternalAPI,
|
||||||
keyAPI keyserverAPI.KeyInternalAPI,
|
keyAPI keyserverAPI.KeyInternalAPI,
|
||||||
|
mscCfg *config.MSCs,
|
||||||
) {
|
) {
|
||||||
v2keysmux := keyMux.PathPrefix("/v2").Subrouter()
|
v2keysmux := keyMux.PathPrefix("/v2").Subrouter()
|
||||||
v1fedmux := fedMux.PathPrefix("/v1").Subrouter()
|
v1fedmux := fedMux.PathPrefix("/v1").Subrouter()
|
||||||
@ -229,35 +230,37 @@ func Setup(
|
|||||||
},
|
},
|
||||||
)).Methods(http.MethodGet)
|
)).Methods(http.MethodGet)
|
||||||
|
|
||||||
v1fedmux.Handle("/peek/{roomID}/{peekID}", httputil.MakeFedAPI(
|
if mscCfg.Enabled("msc2444") {
|
||||||
"federation_peek", cfg.Matrix.ServerName, keys, wakeup,
|
v1fedmux.Handle("/peek/{roomID}/{peekID}", httputil.MakeFedAPI(
|
||||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
"federation_peek", cfg.Matrix.ServerName, keys, wakeup,
|
||||||
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
||||||
return util.JSONResponse{
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
||||||
Code: http.StatusForbidden,
|
return util.JSONResponse{
|
||||||
JSON: jsonerror.Forbidden("Forbidden by server ACLs"),
|
Code: http.StatusForbidden,
|
||||||
|
JSON: jsonerror.Forbidden("Forbidden by server ACLs"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
roomID := vars["roomID"]
|
||||||
roomID := vars["roomID"]
|
peekID := vars["peekID"]
|
||||||
peekID := vars["peekID"]
|
queryVars := httpReq.URL.Query()
|
||||||
queryVars := httpReq.URL.Query()
|
remoteVersions := []gomatrixserverlib.RoomVersion{}
|
||||||
remoteVersions := []gomatrixserverlib.RoomVersion{}
|
if vers, ok := queryVars["ver"]; ok {
|
||||||
if vers, ok := queryVars["ver"]; ok {
|
// The remote side supplied a ?ver= so use that to build up the list
|
||||||
// The remote side supplied a ?ver= so use that to build up the list
|
// of supported room versions
|
||||||
// of supported room versions
|
for _, v := range vers {
|
||||||
for _, v := range vers {
|
remoteVersions = append(remoteVersions, gomatrixserverlib.RoomVersion(v))
|
||||||
remoteVersions = append(remoteVersions, gomatrixserverlib.RoomVersion(v))
|
}
|
||||||
|
} else {
|
||||||
|
// The remote side didn't supply a ?ver= so just assume that they only
|
||||||
|
// support room version 1
|
||||||
|
remoteVersions = append(remoteVersions, gomatrixserverlib.RoomVersionV1)
|
||||||
}
|
}
|
||||||
} else {
|
return Peek(
|
||||||
// The remote side didn't supply a ?ver= so just assume that they only
|
httpReq, request, cfg, rsAPI, roomID, peekID, remoteVersions,
|
||||||
// support room version 1
|
)
|
||||||
remoteVersions = append(remoteVersions, gomatrixserverlib.RoomVersionV1)
|
},
|
||||||
}
|
)).Methods(http.MethodPut, http.MethodDelete)
|
||||||
return Peek(
|
}
|
||||||
httpReq, request, cfg, rsAPI, roomID, peekID, remoteVersions,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)).Methods(http.MethodPut, http.MethodDelete)
|
|
||||||
|
|
||||||
v1fedmux.Handle("/make_join/{roomID}/{userID}", httputil.MakeFedAPI(
|
v1fedmux.Handle("/make_join/{roomID}/{userID}", httputil.MakeFedAPI(
|
||||||
"federation_make_join", cfg.Matrix.ServerName, keys, wakeup,
|
"federation_make_join", cfg.Matrix.ServerName, keys, wakeup,
|
||||||
|
@ -3,7 +3,11 @@ package config
|
|||||||
type MSCs struct {
|
type MSCs struct {
|
||||||
Matrix *Global `yaml:"-"`
|
Matrix *Global `yaml:"-"`
|
||||||
|
|
||||||
// The MSCs to enable
|
// The MSCs to enable. Supported MSCs include:
|
||||||
|
// 'msc2444': Peeking over federation - https://github.com/matrix-org/matrix-doc/pull/2444
|
||||||
|
// 'msc2753': Peeking via /sync - https://github.com/matrix-org/matrix-doc/pull/2753
|
||||||
|
// 'msc2836': Threading - https://github.com/matrix-org/matrix-doc/pull/2836
|
||||||
|
// 'msc2946': Spaces Summary - https://github.com/matrix-org/matrix-doc/pull/2946
|
||||||
MSCs []string `yaml:"mscs"`
|
MSCs []string `yaml:"mscs"`
|
||||||
|
|
||||||
Database DatabaseOptions `yaml:"database"`
|
Database DatabaseOptions `yaml:"database"`
|
||||||
@ -14,6 +18,16 @@ func (c *MSCs) Defaults() {
|
|||||||
c.Database.ConnectionString = "file:mscs.db"
|
c.Database.ConnectionString = "file:mscs.db"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enabled returns true if the given msc is enabled. Should in the form 'msc12345'.
|
||||||
|
func (c *MSCs) Enabled(msc string) bool {
|
||||||
|
for _, m := range c.MSCs {
|
||||||
|
if m == msc {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (c *MSCs) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
func (c *MSCs) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
checkNotEmpty(configErrs, "mscs.database.connection_string", string(c.Database.ConnectionString))
|
checkNotEmpty(configErrs, "mscs.database.connection_string", string(c.Database.ConnectionString))
|
||||||
}
|
}
|
||||||
|
@ -62,11 +62,12 @@ func (m *Monolith) AddAllPublicRoutes(csMux, ssMux, keyMux, mediaMux *mux.Router
|
|||||||
m.FedClient, m.RoomserverAPI,
|
m.FedClient, m.RoomserverAPI,
|
||||||
m.EDUInternalAPI, m.AppserviceAPI, transactions.New(),
|
m.EDUInternalAPI, m.AppserviceAPI, transactions.New(),
|
||||||
m.FederationSenderAPI, m.UserAPI, m.KeyAPI, m.ExtPublicRoomsProvider,
|
m.FederationSenderAPI, m.UserAPI, m.KeyAPI, m.ExtPublicRoomsProvider,
|
||||||
|
&m.Config.MSCs,
|
||||||
)
|
)
|
||||||
federationapi.AddPublicRoutes(
|
federationapi.AddPublicRoutes(
|
||||||
ssMux, keyMux, &m.Config.FederationAPI, m.UserAPI, m.FedClient,
|
ssMux, keyMux, &m.Config.FederationAPI, m.UserAPI, m.FedClient,
|
||||||
m.KeyRing, m.RoomserverAPI, m.FederationSenderAPI,
|
m.KeyRing, m.RoomserverAPI, m.FederationSenderAPI,
|
||||||
m.EDUInternalAPI, m.KeyAPI,
|
m.EDUInternalAPI, m.KeyAPI, &m.Config.MSCs,
|
||||||
)
|
)
|
||||||
mediaapi.AddPublicRoutes(mediaMux, &m.Config.MediaAPI, m.UserAPI, m.Client)
|
mediaapi.AddPublicRoutes(mediaMux, &m.Config.MediaAPI, m.UserAPI, m.Client)
|
||||||
syncapi.AddPublicRoutes(
|
syncapi.AddPublicRoutes(
|
||||||
|
@ -42,7 +42,10 @@ func EnableMSC(base *setup.BaseDendrite, monolith *setup.Monolith, msc string) e
|
|||||||
return msc2836.Enable(base, monolith.RoomserverAPI, monolith.FederationSenderAPI, monolith.UserAPI, monolith.KeyRing)
|
return msc2836.Enable(base, monolith.RoomserverAPI, monolith.FederationSenderAPI, monolith.UserAPI, monolith.KeyRing)
|
||||||
case "msc2946":
|
case "msc2946":
|
||||||
return msc2946.Enable(base, monolith.RoomserverAPI, monolith.UserAPI, monolith.FederationSenderAPI, monolith.KeyRing)
|
return msc2946.Enable(base, monolith.RoomserverAPI, monolith.UserAPI, monolith.FederationSenderAPI, monolith.KeyRing)
|
||||||
|
case "msc2444": // enabled inside federationapi
|
||||||
|
case "msc2753": // enabled inside clientapi
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("EnableMSC: unknown msc '%s'", msc)
|
return fmt.Errorf("EnableMSC: unknown msc '%s'", msc)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user