Solve Outbound federation rejects invite response which include invalid

JSON for room version 6
This commit is contained in:
Till Faelligen 2020-11-15 12:25:00 +01:00
parent 8ce740d949
commit 50eed11a80
2 changed files with 14 additions and 0 deletions

View file

@ -56,6 +56,11 @@ func (p *PerformError) JSONResponse() util.JSONResponse {
// TODO: Should we assert this is in fact JSON? E.g gjson parse? // TODO: Should we assert this is in fact JSON? E.g gjson parse?
JSON: json.RawMessage(p.Msg), JSON: json.RawMessage(p.Msg),
} }
case PerformErrCanonicalJSON:
return util.JSONResponse{
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON(p.Msg),
}
default: default:
return util.ErrorResponse(p) return util.ErrorResponse(p)
} }
@ -72,6 +77,8 @@ const (
PerformErrorNoOperation PerformErrorCode = 4 PerformErrorNoOperation PerformErrorCode = 4
// PerformErrRemote means that the request failed and the PerformError.Msg is the raw remote JSON error response // PerformErrRemote means that the request failed and the PerformError.Msg is the raw remote JSON error response
PerformErrRemote PerformErrorCode = 5 PerformErrRemote PerformErrorCode = 5
// PerformErrCanonicalJSON means that the request failed due to invalid json
PerformErrCanonicalJSON PerformErrorCode = 6
) )
type PerformJoinRequest struct { type PerformJoinRequest struct {

View file

@ -17,6 +17,7 @@ package perform
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/internal/config"
@ -158,6 +159,12 @@ func (r *Inviter) PerformInvite(
Msg: err.Error(), Msg: err.Error(),
Code: api.PerformErrorNotAllowed, Code: api.PerformErrorNotAllowed,
} }
if strings.Contains(err.Error(), "value is outside of safe range") {
log.Debug("setting error to PerformErrCanonicalJSON")
res.Error.Code = api.PerformErrCanonicalJSON
}
log.WithError(err).WithField("event_id", event.EventID()).Error("r.FSAPI.PerformInvite failed") log.WithError(err).WithField("event_id", event.EventID()).Error("r.FSAPI.PerformInvite failed")
return nil, nil return nil, nil
} }