Skip to content

Expose Retry-After to cross-origin browser clients - #20548

Open
AyeshaWaseemAhmad wants to merge 2 commits into
element-hq:developfrom
AyeshaWaseemAhmad:fix/cors-expose-retry-after
Open

AyeshaWaseemAhmad wants to merge 2 commits into
element-hq:developfrom
AyeshaWaseemAhmad:fix/cors-expose-retry-after

Conversation

@AyeshaWaseemAhmad

Copy link
Copy Markdown
Contributor

set_cors_headers only listed Synapse-Trace-Id, Server and, on the rendezvous endpoints, ETag in Access-Control-Expose-Headers. Synapse sends Retry-After on 429 M_LIMIT_EXCEEDED responses, so a browser client on another origin got null from response.headers.get("Retry-After").

This adds Retry-After to both branches. Since Matrix v1.10 homeservers SHOULD send the header, and the retry_after_ms body field is deprecated.

Tests: a 429 raised through JsonResource now has Retry-After in the expose list, the rendezvous branch gets its own OPTIONS test, and the existing OptionsResourceTests expectation is updated. Not covered: the appservice proxy, which copies an upstream's Access-Control-Expose-Headers over ours.

Fixes #20542

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)

`set_cors_headers` listed only `Synapse-Trace-Id`, `Server` and (on the
rendezvous endpoints) `ETag` in `Access-Control-Expose-Headers`. Synapse
sends `Retry-After` on 429 `M_LIMIT_EXCEEDED` responses, but a browser
client on another origin could not read it through
`response.headers.get("Retry-After")`.

Add `Retry-After` to both branches so such clients can honour the
delay. The Matrix spec says homeservers SHOULD send this header, and the
`retry_after_ms` body field is deprecated.

Fixes element-hq#20542
@AyeshaWaseemAhmad
AyeshaWaseemAhmad requested a review from a team as a code owner November 21, 2026 17:53
@AyeshaWaseemAhmad
AyeshaWaseemAhmad requested review from devonh and removed request for a team November 21, 2026 17:53

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.

Expose Retry-After to cross-origin browser clients on HTTP 429 responses

2 participants