mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-09 07:03:10 -06:00
Tweak soft-fail checking
This commit is contained in:
parent
c69c189a64
commit
175989e363
|
|
@ -30,6 +30,7 @@ import (
|
|||
// the soft-fail bool.
|
||||
func CheckForSoftFail(
|
||||
ctx context.Context,
|
||||
roomInfo *types.RoomInfo,
|
||||
db storage.Database,
|
||||
event *gomatrixserverlib.HeaderedEvent,
|
||||
stateEventIDs []string,
|
||||
|
|
@ -44,18 +45,11 @@ func CheckForSoftFail(
|
|||
return true, fmt.Errorf("StateEntriesForEventIDs failed: %w", err)
|
||||
}
|
||||
} else {
|
||||
// Work out if the room exists.
|
||||
var roomInfo *types.RoomInfo
|
||||
roomInfo, err = db.RoomInfo(ctx, event.RoomID())
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("db.RoomNID: %w", err)
|
||||
}
|
||||
// Then get the state entries for the current state snapshot.
|
||||
// We'll use this to check if the event is allowed right now.
|
||||
if roomInfo == nil || roomInfo.IsStub() {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// Then get the state entries for the current state snapshot.
|
||||
// We'll use this to check if the event is allowed right now.
|
||||
roomState := state.NewStateResolution(db, roomInfo)
|
||||
authStateEntries, err = roomState.LoadStateAtSnapshot(ctx, roomInfo.StateSnapshotNID())
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ func (r *Inputer) processRoomEvent(
|
|||
var rejectionErr error
|
||||
if rejectionErr = gomatrixserverlib.Allowed(event, &authEvents); rejectionErr != nil {
|
||||
isRejected = true
|
||||
logger.WithError(rejectionErr).Warnf("Event %s not allowed by auth events", event.EventID())
|
||||
logger.WithError(rejectionErr).Warnf("Event %s rejected by auth events", event.EventID())
|
||||
}
|
||||
|
||||
// Accumulate the auth event NIDs.
|
||||
|
|
@ -231,9 +231,10 @@ func (r *Inputer) processRoomEvent(
|
|||
// Check that the event passes authentication checks based on the
|
||||
// current room state.
|
||||
var err error
|
||||
softfail, err = helpers.CheckForSoftFail(ctx, r.DB, headered, input.StateEventIDs)
|
||||
softfail, err = helpers.CheckForSoftFail(ctx, roomInfo, r.DB, headered, input.StateEventIDs)
|
||||
if err != nil {
|
||||
logger.WithError(err).Warn("Error authing soft-failed event")
|
||||
logger.WithError(err).Warnf("Event %s rejected by current room state", event.EventID())
|
||||
rejectionErr = fmt.Errorf("rejected by current room state: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +308,7 @@ func (r *Inputer) processRoomEvent(
|
|||
return fmt.Errorf("r.processStateBefore: %w", err)
|
||||
}
|
||||
if rejectionErr != nil {
|
||||
rejectionErr = fmt.Errorf("rejected by state before event: %w", rejectionErr)
|
||||
logger.WithError(err).Warnf("Event %s rejected by state before event", event.EventID())
|
||||
isRejected = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue