Use OPTIONS for sliding sync detection poke (#12492)

* Use OPTIONS for sliding sync detection poke

This avoids unintended consequences, including high resource usage, which would accompany a "full" sync request. Instead, we just grab headers and enough information for CORS to pass, revealing likely support.

Fixes https://github.com/element-hq/element-web/issues/27426

* Appease the linter

* Reset for each test
This commit is contained in:
Travis Ralston 2024-05-03 00:31:34 -06:00 committed by GitHub
parent d25d529e86
commit 3059b5b1e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 2 deletions

View file

@ -378,7 +378,11 @@ export class SlidingSyncManager {
*/
public async nativeSlidingSyncSupport(client: MatrixClient): Promise<boolean> {
try {
await client.http.authedRequest<void>(Method.Post, "/sync", undefined, undefined, {
// We use OPTIONS to avoid causing a real sync to happen, as that may be intensive or encourage
// middleware software to start polling as our access token (thus stealing our to-device messages).
// See https://github.com/element-hq/element-web/issues/27426
// XXX: Using client.http is a bad thing - it's meant to be private access. See `client.http` for details.
await client.http.authedRequest<void>(Method.Options, "/sync", undefined, undefined, {
localTimeoutMs: 10 * 1000, // 10s
prefix: "/_matrix/client/unstable/org.matrix.msc3575",
});