mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 04:52:46 +00:00
Encode URLs properly (#728)
We were escaping the URL before performing any pattern matching on it. This meant that if you sent data that URLdecoded to a "/", it would count as a "/" in the URL, potentially causing a 404. This was causing some flaky tests with some randomly-generated query parameters. Now, we keep URLs encoded while doing the pattern matching, and only afterwards do we URL decode each query parameter individually before passing them to their respective handler functions. github.com/gorilla/mux was also updated to v1.7.3 to fix a bug with URL encoding and subrouters.
This commit is contained in:
parent
1eb77b8161
commit
33a1392541
11 changed files with 236 additions and 45 deletions
|
@ -35,6 +35,10 @@ const (
|
|||
)
|
||||
|
||||
// Setup registers HTTP handlers with the given ServeMux.
|
||||
//
|
||||
// Due to Setup being used to call many other functions, a gocyclo nolint is
|
||||
// applied:
|
||||
// nolint: gocyclo
|
||||
func Setup(
|
||||
apiMux *mux.Router,
|
||||
cfg config.Dendrite,
|
||||
|
@ -64,7 +68,10 @@ func Setup(
|
|||
v1fedmux.Handle("/send/{txnID}/", common.MakeFedAPI(
|
||||
"federation_send", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return Send(
|
||||
httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]),
|
||||
cfg, query, producer, keys, federation,
|
||||
|
@ -75,7 +82,10 @@ func Setup(
|
|||
v1fedmux.Handle("/invite/{roomID}/{eventID}", common.MakeFedAPI(
|
||||
"federation_invite", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return Invite(
|
||||
httpReq, request, vars["roomID"], vars["eventID"],
|
||||
cfg, producer, keys,
|
||||
|
@ -92,7 +102,10 @@ func Setup(
|
|||
v1fedmux.Handle("/exchange_third_party_invite/{roomID}", common.MakeFedAPI(
|
||||
"exchange_third_party_invite", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return ExchangeThirdPartyInvite(
|
||||
httpReq, request, vars["roomID"], query, cfg, federation, producer,
|
||||
)
|
||||
|
@ -102,7 +115,10 @@ func Setup(
|
|||
v1fedmux.Handle("/event/{eventID}", common.MakeFedAPI(
|
||||
"federation_get_event", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return GetEvent(
|
||||
httpReq.Context(), request, query, vars["eventID"],
|
||||
)
|
||||
|
@ -112,7 +128,10 @@ func Setup(
|
|||
v1fedmux.Handle("/state/{roomID}", common.MakeFedAPI(
|
||||
"federation_get_event_auth", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return GetState(
|
||||
httpReq.Context(), request, query, vars["roomID"],
|
||||
)
|
||||
|
@ -122,7 +141,10 @@ func Setup(
|
|||
v1fedmux.Handle("/state_ids/{roomID}", common.MakeFedAPI(
|
||||
"federation_get_event_auth", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return GetStateIDs(
|
||||
httpReq.Context(), request, query, vars["roomID"],
|
||||
)
|
||||
|
@ -150,7 +172,10 @@ func Setup(
|
|||
v1fedmux.Handle("/user/devices/{userID}", common.MakeFedAPI(
|
||||
"federation_user_devices", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return GetUserDevices(
|
||||
httpReq, deviceDB, vars["userID"],
|
||||
)
|
||||
|
@ -160,7 +185,10 @@ func Setup(
|
|||
v1fedmux.Handle("/make_join/{roomID}/{userID}", common.MakeFedAPI(
|
||||
"federation_make_join", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
roomID := vars["roomID"]
|
||||
userID := vars["userID"]
|
||||
return MakeJoin(
|
||||
|
@ -172,7 +200,10 @@ func Setup(
|
|||
v1fedmux.Handle("/send_join/{roomID}/{userID}", common.MakeFedAPI(
|
||||
"federation_send_join", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
roomID := vars["roomID"]
|
||||
userID := vars["userID"]
|
||||
return SendJoin(
|
||||
|
@ -184,7 +215,10 @@ func Setup(
|
|||
v1fedmux.Handle("/make_leave/{roomID}/{userID}", common.MakeFedAPI(
|
||||
"federation_make_leave", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
roomID := vars["roomID"]
|
||||
userID := vars["userID"]
|
||||
return MakeLeave(
|
||||
|
@ -196,7 +230,10 @@ func Setup(
|
|||
v1fedmux.Handle("/send_leave/{roomID}/{userID}", common.MakeFedAPI(
|
||||
"federation_send_leave", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
roomID := vars["roomID"]
|
||||
userID := vars["userID"]
|
||||
return SendLeave(
|
||||
|
@ -215,7 +252,10 @@ func Setup(
|
|||
v1fedmux.Handle("/get_missing_events/{roomID}", common.MakeFedAPI(
|
||||
"federation_get_missing_events", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return GetMissingEvents(httpReq, request, query, vars["roomID"])
|
||||
},
|
||||
)).Methods(http.MethodPost)
|
||||
|
@ -223,7 +263,10 @@ func Setup(
|
|||
v1fedmux.Handle("/backfill/{roomID}/", common.MakeFedAPI(
|
||||
"federation_backfill", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
vars, err := common.URLDecodeMapValues(mux.Vars(httpReq))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return Backfill(httpReq, request, query, vars["roomID"], cfg)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue