Skip to content

Reject OTK uploads if clients exceed 500 server-side keys - #20162

Merged
anoadragon453 merged 4 commits into
element-hq:developfrom
kaylendog:kaylendog/feat/reject-otks
Sep 14, 2026
Merged

anoadragon453 merged 4 commits into
element-hq:developfrom
kaylendog:kaylendog/feat/reject-otks

Conversation

@kaylendog

@kaylendog kaylendog commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

matrix-org/matrix-rust-sdk#6780 fixed a long-standing issue in the Rust SDK where OlmMachine::receive_sync_changes incorrectly treated a missing one_time_keys_counts as "no change", when (for sync v2) this means "no keys". This behaviour made it into the WASM SDK in release v18.5.0, which causes clients written using the JS SDK to endlessly upload OTKs on every sync.

This PR introduces a server-side check to see if a device has uploaded over 500 keys when it tries to upload more, errorring if this is the case. This should help inform client developers that something is wrong with their OTK implementation before it becomes a problem.

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)

@kaylendog
kaylendog force-pushed the kaylendog/feat/reject-otks branch 2 times, most recently from 9fe1486 to 9c82f30 Compare August 28, 2026 15:07
@kaylendog
kaylendog marked this pull request as ready for review August 28, 2026 15:15
@kaylendog
kaylendog requested a review from a team as a code owner August 28, 2026 15:15
@kaylendog
kaylendog requested review from anoadragon453 and removed request for a team August 28, 2026 15:15
Comment thread docs/usage/configuration/config_documentation.md Outdated
@richvdh

richvdh commented Sep 1, 2026

Copy link
Copy Markdown
Member

For links: the combination of matrix-org/matrix-rust-sdk#6780 and the js-sdk resulted in matrix-org/matrix-js-sdk#5501, which in turn led to people seeing decryption errors, which can't even be fixed by rolling back the client, since the incorrect OTKs have already been uploaded to the server.

The goal here is to provide a backstop against similar client breakage in future by refusing to cooperate with such broken clients. Hopefully this will result in a user-visible "it's all horribly broken" error, which is better than silent breakage that manifests through decryption errors some time later.

In any case, Synapse should have a guard against users uploading absurd numbers of OTKs.

Signed-off-by: Skye Elliot <actuallyori@gmail.com>
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
@anoadragon453
anoadragon453 force-pushed the kaylendog/feat/reject-otks branch from d663e95 to c38aca1 Compare September 14, 2026 12:03

@anoadragon453 anoadragon453 left a comment

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.

LGTM, other than one nit (which I can fix up). Thanks!

Comment thread synapse/handlers/e2e_keys.py Outdated
@anoadragon453
anoadragon453 merged commit 8c8138d into element-hq:develop Sep 14, 2026
42 checks passed
HarisDotParis pushed a commit to HarisDotParis/synapse that referenced this pull request Sep 16, 2026
…#20162)

Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Oct 13, 2026
Tested on NetBSD 10 amd64 with 2026Q3 environment.

Packaging changes:

  - use maturin's tool.mk, to get the part that respects MAKE_JOBS
  - patch mio, which had a pre-NetBSD10 type for kevent.udata, a
    latent bug apparently exposed by a new libc crate, but fixable on
    its own merits by code inspection.

# Synapse 1.162.0 (2026-09-29)

## Features

- Raise default room version to "12". Contributed by @jason-famedly @famedly. ([\#20130](element-hq/synapse#20130))
- Limit the number of end-to-end encryption one-time keys stored per device to 500 per algorithm, rejecting uploads which would exceed the limit with a `400 Bad Request`. ([\#20162](element-hq/synapse#20162))
- Add support for configuring a `username` for Redis connections, for Redis 6+ ACL authentication. ([\#20187](element-hq/synapse#20187))
- Add a rate limit on the client profile lookup endpoints, configurable via `rc_profile`. ([\#20218](element-hq/synapse#20218))
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Oct 21, 2026
Tested on NetBSD 10 amd64 with 2026Q3 environment.

Packaging changes:

  - use maturin's tool.mk, to get the part that respects MAKE_JOBS
  - patch mio, which had a pre-NetBSD10 type for kevent.udata, a
    latent bug apparently exposed by a new libc crate, but fixable on
    its own merits by code inspection.

# Synapse 1.162.0 (2026-09-29)

## Features

- Raise default room version to "12". Contributed by @jason-famedly @famedly. ([\#20130](element-hq/synapse#20130))
- Limit the number of end-to-end encryption one-time keys stored per device to 500 per algorithm, rejecting uploads which would exceed the limit with a `400 Bad Request`. ([\#20162](element-hq/synapse#20162))
- Add support for configuring a `username` for Redis connections, for Redis 6+ ACL authentication. ([\#20187](element-hq/synapse#20187))
- Add a rate limit on the client profile lookup endpoints, configurable via `rc_profile`. ([\#20218](element-hq/synapse#20218))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants