diff options
author | Kegsay <kegan@matrix.org> | 2021-01-22 16:08:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-22 16:08:47 +0000 |
commit | 93942f8ab62ffdb55888d5d35adef6fe73e3ea59 (patch) | |
tree | e261374817728e22c5e4937975ea42cc71e54f9b /federationapi | |
parent | 0571d395b51d7788c692b916cd7ba9249a494ed1 (diff) |
Gate peeking behind msc flags (#1731)
Diffstat (limited to 'federationapi')
-rw-r--r-- | federationapi/federationapi.go | 3 | ||||
-rw-r--r-- | federationapi/federationapi_test.go | 2 | ||||
-rw-r--r-- | federationapi/routing/routing.go | 57 |
3 files changed, 33 insertions, 29 deletions
diff --git a/federationapi/federationapi.go b/federationapi/federationapi.go index 350d5853..6188b283 100644 --- a/federationapi/federationapi.go +++ b/federationapi/federationapi.go @@ -38,10 +38,11 @@ func AddPublicRoutes( federationSenderAPI federationSenderAPI.FederationSenderInternalAPI, eduAPI eduserverAPI.EDUServerInputAPI, keyAPI keyserverAPI.KeyInternalAPI, + mscCfg *config.MSCs, ) { routing.Setup( fedRouter, keyRouter, cfg, rsAPI, eduAPI, federationSenderAPI, keyRing, - federation, userAPI, keyAPI, + federation, userAPI, keyAPI, mscCfg, ) } diff --git a/federationapi/federationapi_test.go b/federationapi/federationapi_test.go index aed47a36..923cd0ec 100644 --- a/federationapi/federationapi_test.go +++ b/federationapi/federationapi_test.go @@ -31,7 +31,7 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) { fsAPI := base.FederationSenderHTTPClient() // 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. - 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) defer cancel() serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://")) diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go index 7e76a143..b579ae1f 100644 --- a/federationapi/routing/routing.go +++ b/federationapi/routing/routing.go @@ -48,6 +48,7 @@ func Setup( federation *gomatrixserverlib.FederationClient, userAPI userapi.UserInternalAPI, keyAPI keyserverAPI.KeyInternalAPI, + mscCfg *config.MSCs, ) { v2keysmux := keyMux.PathPrefix("/v2").Subrouter() v1fedmux := fedMux.PathPrefix("/v1").Subrouter() @@ -229,35 +230,37 @@ func Setup( }, )).Methods(http.MethodGet) - v1fedmux.Handle("/peek/{roomID}/{peekID}", httputil.MakeFedAPI( - "federation_peek", cfg.Matrix.ServerName, keys, wakeup, - func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse { - if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) { - return util.JSONResponse{ - Code: http.StatusForbidden, - JSON: jsonerror.Forbidden("Forbidden by server ACLs"), + if mscCfg.Enabled("msc2444") { + v1fedmux.Handle("/peek/{roomID}/{peekID}", httputil.MakeFedAPI( + "federation_peek", cfg.Matrix.ServerName, keys, wakeup, + func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse { + if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) { + return util.JSONResponse{ + Code: http.StatusForbidden, + JSON: jsonerror.Forbidden("Forbidden by server ACLs"), + } } - } - roomID := vars["roomID"] - peekID := vars["peekID"] - queryVars := httpReq.URL.Query() - remoteVersions := []gomatrixserverlib.RoomVersion{} - if vers, ok := queryVars["ver"]; ok { - // The remote side supplied a ?ver= so use that to build up the list - // of supported room versions - for _, v := range vers { - remoteVersions = append(remoteVersions, gomatrixserverlib.RoomVersion(v)) + roomID := vars["roomID"] + peekID := vars["peekID"] + queryVars := httpReq.URL.Query() + remoteVersions := []gomatrixserverlib.RoomVersion{} + if vers, ok := queryVars["ver"]; ok { + // The remote side supplied a ?ver= so use that to build up the list + // of supported room versions + for _, v := range vers { + 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 { - // The remote side didn't supply a ?ver= so just assume that they only - // support room version 1 - remoteVersions = append(remoteVersions, gomatrixserverlib.RoomVersionV1) - } - return Peek( - httpReq, request, cfg, rsAPI, roomID, peekID, remoteVersions, - ) - }, - )).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( "federation_make_join", cfg.Matrix.ServerName, keys, wakeup, |