Skip to content

Add caching support to media endpoints#18235

Merged
erikjohnston merged 7 commits intodevelopfrom
erikj/auth_media_cache
Mar 13, 2025
Merged

Add caching support to media endpoints#18235
erikjohnston merged 7 commits intodevelopfrom
erikj/auth_media_cache

Conversation

@erikjohnston
Copy link
Copy Markdown
Member

We do a few things in this PR to better support caching:

  1. Change Cache-Control header to allow intermediary proxies to cache media only if they revalidate on every request. This means that the intermediary cache will still send the request to Synapse but with a If-None-Match header, at which point Synapse can check auth and respond with a 304 and empty content.
  2. Add ETag response header to all media responses. We hardcode this to 1 since all media is immutable (beyond being deleted).
  3. Check for If-None-Match header (after checking for auth), and if it matches then respond with a 304 and empty body.

And handle when clients revalidate their cache via `If-None-Match`
header and return 304 Not Modified.

This allows clients and intermediary proxies to cache media, while
allowing them to check auth.
@erikjohnston erikjohnston changed the title Add caching support to media Add caching support to media endpoints Mar 13, 2025
@erikjohnston erikjohnston marked this pull request as ready for review March 13, 2025 11:14
@erikjohnston erikjohnston requested a review from a team as a code owner March 13, 2025 11:14
Copy link
Copy Markdown
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

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

The logic looks sound, thanks for the tests!

Just some wording changes and a nit below.

Comment thread synapse/media/_base.py Outdated
Comment thread synapse/media/_base.py Outdated
Comment thread tests/rest/client/test_media.py Outdated
Comment thread synapse/media/_base.py Outdated
Comment thread synapse/media/_base.py Outdated
erikjohnston and others added 2 commits March 13, 2025 15:58
Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
@erikjohnston erikjohnston merged commit 59a15da into develop Mar 13, 2025
@erikjohnston erikjohnston deleted the erikj/auth_media_cache branch March 13, 2025 16:28
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Mar 27, 2025
Fixes high severity vulnerability *exploited in the wild*!


# Synapse 1.127.1 (2025-03-26)

## Security
- Fix [CVE-2025-30355](https://www.cve.org/CVERecord?id=CVE-2025-30355) / [GHSA-v56r-hwv5-mxg6](GHSA-v56r-hwv5-mxg6). **High severity vulnerability affecting federation. The vulnerability has been exploited in the wild.**



# Synapse 1.127.0 (2025-03-25)

No significant changes since 1.127.0rc1.




# Synapse 1.127.0rc1 (2025-03-18)

### Features

- Update [MSC4140](matrix-org/matrix-spec-proposals#4140) implementation to no longer cancel a user's own delayed state events with an event type & state key that match a more recent state event sent by that user. ([\#17810](element-hq/synapse#17810))

### Improved Documentation

- Fixed a minor typo in the Synapse documentation. Contributed by @karuto12. ([\#18224](element-hq/synapse#18224))

### Internal Changes

- Remove undocumented `SYNAPSE_USE_FROZEN_DICTS` environment variable. ([\#18123](element-hq/synapse#18123))
- Fix detection of workflow failures in the release script. ([\#18211](element-hq/synapse#18211))
- Add caching support to media endpoints. ([\#18235](element-hq/synapse#18235))



### Updates to locked dependencies

* Bump anyhow from 1.0.96 to 1.0.97. ([\#18201](element-hq/synapse#18201))
* Bump bcrypt from 4.2.1 to 4.3.0. ([\#18207](element-hq/synapse#18207))
* Bump bytes from 1.10.0 to 1.10.1. ([\#18227](element-hq/synapse#18227))
* Bump http from 1.2.0 to 1.3.1. ([\#18245](element-hq/synapse#18245))
* Bump sentry-sdk from 2.19.2 to 2.22.0. ([\#18205](element-hq/synapse#18205))
* Bump serde from 1.0.218 to 1.0.219. ([\#18228](element-hq/synapse#18228))
* Bump serde_json from 1.0.139 to 1.0.140. ([\#18202](element-hq/synapse#18202))
* Bump ulid from 1.2.0 to 1.2.1. ([\#18246](element-hq/synapse#18246))
yingziwu added a commit to yingziwu/synapse that referenced this pull request Apr 13, 2025
No significant changes since 1.127.0rc1.

- Update [MSC4140](matrix-org/matrix-spec-proposals#4140) implementation to no longer cancel a user's own delayed state events with an event type & state key that match a more recent state event sent by that user. ([\#17810](element-hq/synapse#17810))

- Fixed a minor typo in the Synapse documentation. Contributed by @karuto12. ([\#18224](element-hq/synapse#18224))

- Remove undocumented `SYNAPSE_USE_FROZEN_DICTS` environment variable. ([\#18123](element-hq/synapse#18123))
- Fix detection of workflow failures in the release script. ([\#18211](element-hq/synapse#18211))
- Add caching support to media endpoints. ([\#18235](element-hq/synapse#18235))

* Bump anyhow from 1.0.96 to 1.0.97. ([\#18201](element-hq/synapse#18201))
* Bump bcrypt from 4.2.1 to 4.3.0. ([\#18207](element-hq/synapse#18207))
* Bump bytes from 1.10.0 to 1.10.1. ([\#18227](element-hq/synapse#18227))
* Bump http from 1.2.0 to 1.3.1. ([\#18245](element-hq/synapse#18245))
* Bump sentry-sdk from 2.19.2 to 2.22.0. ([\#18205](element-hq/synapse#18205))
* Bump serde from 1.0.218 to 1.0.219. ([\#18228](element-hq/synapse#18228))
* Bump serde_json from 1.0.139 to 1.0.140. ([\#18202](element-hq/synapse#18202))
* Bump ulid from 1.2.0 to 1.2.1. ([\#18246](element-hq/synapse#18246))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants