Skip to content

MSC4140: authenticate the delayed event management endpoints and allow guests - #20257

Open
barodeur wants to merge 5 commits into
element-hq:developfrom
barodeur:msc4140-authenticated-management
Open

barodeur wants to merge 5 commits into
element-hq:developfrom
barodeur:msc4140-authenticated-management

Conversation

@barodeur

@barodeur barodeur commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Note

This depends on matrix-org/complement#924

In an earlier version of the MSC4140, the randomness of delay_id was the security against spoofing,  but since then the MSC has changed to:

A set of new authenticated Client-Server API endpoints at POST /_matrix/client/v1/delayed_events/{delay_id}/{action} [...]

If no delayed event for the requesting user with the specified delay_id can be found, the homeserver will respond with HTTP 404 and a standard error response with an errcode of M_NOT_FOUND.

All delayed event related endpoints are available to guest accounts.

What changes

  • cancel, restart and send require an access token and answer 404 for a delay_id that belongs to another user
  • The management ratelimiter is keyed on the user only
    • rc_delayed_event_mgmt documentation updated accordingly
  • GET /delayed_events/{delay_id} and GET /delayed_events allow guests
  • cancel, restart and send allow guests too

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

The `cancel`, `restart` and `send` delayed event endpoints accepted
unauthenticated requests and acted on any delayed event with a matching
`delay_id`. MSC4140 now specifies these as authenticated endpoints that
only act on the requesting user's own delayed events, returning 404
`M_NOT_FOUND` otherwise, and makes every delayed event endpoint
available to guests.

Authenticate the four management servlets (allowing guests), pass the
requester through to the handler, and scope the three store lookups to
the requester's localpart, as the single-event lookup already does. The
management ratelimiter is now always keyed on the requester, so the
source-IP fallback and its mention in the config docs are removed.

The two GET servlets also allow guests now.
…cated-management

# Conflicts:
#	tests/rest/client/test_delayed_events.py
…cated-management

# Conflicts:
#	synapse/handlers/delayed_events.py
#	tests/rest/client/test_delayed_events.py
@barodeur
barodeur marked this pull request as ready for review October 8, 2026 10:24
@barodeur
barodeur requested a review from a team as a code owner October 8, 2026 10:24
@barodeur
barodeur requested review from anoadragon453 and removed request for a team October 8, 2026 10:24
Comment thread changelog.d/20257.feature

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(pre-review note) heads up that Complement tests for delayed events appear to be failing due to 401 errors.

Looks like the tests will need to be updated to add authorisation to the requests.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I have a complement PR to make sure that delayed events are managed with authenticated requests: matrix-org/complement#924

The complement PR can be merged before and it would make the tests on this PR pass.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merged matrix-org/complement#924 and re-ran the Complement tests on this PR.

@anoadragon453
anoadragon453 self-requested a review October 9, 2026 10:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants