Skip to content

Profile endpoint rate limit - #20218

Merged
erikjohnston merged 13 commits into
element-hq:developfrom
barodeur:profile-endpoint-rate-limit
Sep 18, 2026
Merged

erikjohnston merged 13 commits into
element-hq:developfrom
barodeur:profile-endpoint-rate-limit

Conversation

@barodeur

@barodeur barodeur commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

This provides configurable (via rc_profile) rate limits for profile endpoints:

  • GET /profile/{username}
  • GET /profile/{username}/{keyName} including (displayname & avatar_url)

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)

@barodeur
barodeur marked this pull request as ready for review September 15, 2026 12:57
@barodeur
barodeur requested a review from a team as a code owner September 15, 2026 12:57
@barodeur
barodeur requested review from erikjohnston and removed request for a team September 15, 2026 12:57

@erikjohnston erikjohnston 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.

Broadly looks good, though I think we can maybe clean it up a tad.

Comment thread schema/synapse-config.schema.yaml Resolved
Comment thread synapse/rest/client/profile.py Resolved
Profile lookups only require authentication when
`require_auth_for_profile_requests` is set, which previously meant
checking that option in the helper and again in each servlet. Add a
generic `get_optional_user_by_req` to the auth classes, which returns
None when no access token is present, and use it so the option is
consulted once.
Use `get_user_by_req` when authentication is required and the optional
variant only otherwise, rather than always authenticating optionally and
raising on a missing token. Guests are then rejected when
`require_auth_for_profile_requests` is set, as before this branch, and
the option is still only consulted once.
Since we're using a `Protocol` to define the interface, declaring a
dummy `get_user_by_req` on `BaseAuth` may make it match the `Auth`
protcol when it shouldn't. It also makes it easy to forget to implement
`get_user_by_req` on new subclasses.

We use `abc` to ensure that a) `BaseAuth` can't be instansiated
directly, and b) any concrete subclasses does implement the
`get_user_by_req` method.
@erikjohnston

Copy link
Copy Markdown
Member

Thanks!

@erikjohnston
erikjohnston merged commit 15624be into element-hq:develop Sep 18, 2026
45 checks passed
@barodeur
barodeur deleted the profile-endpoint-rate-limit branch September 18, 2026 12:18
barodeur added a commit that referenced this pull request Sep 23, 2026
…uire_auth_for_profile_requests` (#20231)

As I was working on #20218, I
noticed what seemed to be an illegal configuration of synapse.

- `require_auth_for_profile_requests`: blocks profile requests unless
authenticated
- `limit_profile_requests_to_users_who_share_rooms`: blocks profile
requests unless authenticated user share a room with requested user

This, I think, should be an illegal config:

```
require_auth_for_profile_requests = false
limit_profile_requests_to_users_who_share_rooms = true
```

As of now, with such a config the shared-room check is never applied: a
profile can be requested anonymously, and also by an authenticated user
who doesn't share a room.


### Pull Request Checklist

<!-- Please read
https://element-hq.github.io/synapse/latest/development/contributing_guide.html
before submitting your pull request -->

* [x] Pull request is based on the develop branch
* [x] Pull request includes a [changelog
file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog).
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.
* [x] [Code
style](https://element-hq.github.io/synapse/latest/code_style.html) is
correct (run the
[linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))

---------

Co-authored-by: Olivier 'reivilibre' <oliverw@element.io>
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))
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Oct 25, 2026
Tested on NetBSD 10 amd64 with 2026Q3 environment.

Packaging changes:

  - drop mio patch because synapse uses newer mio with a fix

# Synapse 1.163.1 (2026-10-22)

## Internal Changes

- Update `certifi` to `2026.10.19` to address [GHSA-6q48-6c7w-9gw2](GHSA-6q48-6c7w-9gw2). This only affects TLS connections made by the Sentry SDK when `sentry` is configured, SAML, and a couple utility scripts; federation and Synapse's other outbound HTTP requests use the system trust store. ([\#20387](element-hq/synapse#20387))
- Bump `rustls-webpki` to `0.103.16` to actively distrust [compromised eMudhra intermediate CA certificates](https://emudhra.we-have-a-problem.com/). ([\#20392](element-hq/synapse#20392))

# Synapse 1.163.0 (2026-10-14)

## Features

- Advertise support for Matrix v1.14. Contributed by @famedly. ([\#20137](element-hq/synapse#20137))
- Advertise support for Matrix v1.15. ([\#20286](element-hq/synapse#20286))
- Catch up [MSC4354 Sticky Events](matrix-org/matrix-spec-proposals#4354) to remote homeservers that have missed them. ([\#20165](element-hq/synapse#20165))
- Add push rules for [MSC4075](matrix-org/matrix-spec-proposals#4075): MatrixRTC invites and notifications. ([\#20227](element-hq/synapse#20227))
- Make the task scheduler concurrency configurable via `task_scheduler.max_concurrent_tasks`, defaulting to 5. ([\#20230](element-hq/synapse#20230))
- Cancel a user's scheduled [MSC4140](matrix-org/matrix-spec-proposals#4140) delayed events when their account is deactivated. ([\#20247](element-hq/synapse#20247))

## Deprecations and Removals

- Remove the ability to send state events that are sticky, as this feature was removed from [MSC4354: Sticky Events](matrix-org/matrix-spec-proposals#4354). ([\#20256](element-hq/synapse#20256))

# 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants