Add config param to disable client wellknown fetch (#34084)
* Add enable_client_well_known_lookups config option Signed-off-by: David Langley <langley.dave@gmail.com> * Gate client .well-known poll on enable_client_well_known_lookups Signed-off-by: David Langley <langley.dave@gmail.com> * Gate MatrixRTC foci well-known fallback on enable_client_well_known_lookups Signed-off-by: David Langley <langley.dave@gmail.com> --------- Signed-off-by: David Langley <langley.dave@gmail.com> Co-authored-by: David Langley <langley.dave@gmail.com>
This commit is contained in:
co-authored by
David Langley
parent
c4606c19f8
commit
6aeb5f552b
@@ -15,6 +15,7 @@ import fetchMock from "@fetch-mock/vitest";
|
|||||||
import { advanceDateAndTime, stubClient, createTestClient } from "test-utils";
|
import { advanceDateAndTime, stubClient, createTestClient } from "test-utils";
|
||||||
|
|
||||||
import { type IMatrixClientPeg, MatrixClientPeg as peg } from "./MatrixClientPeg";
|
import { type IMatrixClientPeg, MatrixClientPeg as peg } from "./MatrixClientPeg";
|
||||||
|
import SdkConfig from "./SdkConfig";
|
||||||
|
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
|
|
||||||
@@ -116,5 +117,30 @@ describe("MatrixClientPeg", () => {
|
|||||||
await testPeg.start();
|
await testPeg.start();
|
||||||
expect(mockInitRustCrypto).toHaveBeenCalledTimes(1);
|
expect(mockInitRustCrypto).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should poll the client well-known by default", async () => {
|
||||||
|
vi.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined);
|
||||||
|
const startClient = vi.spyOn(testPeg.safeGet(), "startClient").mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await testPeg.start();
|
||||||
|
|
||||||
|
const opts = startClient.mock.calls[0][0];
|
||||||
|
expect(opts?.clientWellKnownPollPeriod).toBe(2 * 60 * 60);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not poll the client well-known when enable_client_well_known_lookups is false", async () => {
|
||||||
|
const sdkConfigGet = SdkConfig.get;
|
||||||
|
vi.spyOn(SdkConfig, "get").mockImplementation((key?: any, altCaseName?: string): any => {
|
||||||
|
if (key === "enable_client_well_known_lookups") return false;
|
||||||
|
return sdkConfigGet(key, altCaseName);
|
||||||
|
});
|
||||||
|
vi.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined);
|
||||||
|
const startClient = vi.spyOn(testPeg.safeGet(), "startClient").mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await testPeg.start();
|
||||||
|
|
||||||
|
const opts = startClient.mock.calls[0][0];
|
||||||
|
expect(opts?.clientWellKnownPollPeriod).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -263,7 +263,11 @@ class MatrixClientPegClass implements IMatrixClientPeg {
|
|||||||
// the react sdk doesn't work without this, so don't allow
|
// the react sdk doesn't work without this, so don't allow
|
||||||
opts.pendingEventOrdering = PendingEventOrdering.Detached;
|
opts.pendingEventOrdering = PendingEventOrdering.Detached;
|
||||||
opts.lazyLoadMembers = true;
|
opts.lazyLoadMembers = true;
|
||||||
opts.clientWellKnownPollPeriod = 2 * 60 * 60; // 2 hours
|
// Poll the user's `<server_name>/.well-known/matrix/client` for client config unless disabled by config.
|
||||||
|
// Leaving `clientWellKnownPollPeriod` unset stops the SDK fetching it.
|
||||||
|
if (SdkConfig.get("enable_client_well_known_lookups")) {
|
||||||
|
opts.clientWellKnownPollPeriod = 2 * 60 * 60; // 2 hours
|
||||||
|
}
|
||||||
opts.threadSupport = true;
|
opts.threadSupport = true;
|
||||||
if (SettingsStore.getValue("feature_user_status")) {
|
if (SettingsStore.getValue("feature_user_status")) {
|
||||||
opts.unstableMSC4429SyncUserProfileFields = ["org.matrix.msc4426.status"];
|
opts.unstableMSC4429SyncUserProfileFields = ["org.matrix.msc4426.status"];
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export const DEFAULTS = {
|
|||||||
integrations_rest_url: "https://scalar.vector.im/api",
|
integrations_rest_url: "https://scalar.vector.im/api",
|
||||||
show_labs_settings: false,
|
show_labs_settings: false,
|
||||||
force_verification: false,
|
force_verification: false,
|
||||||
|
enable_client_well_known_lookups: true,
|
||||||
|
|
||||||
jitsi: {
|
jitsi: {
|
||||||
preferred_domain: "meet.element.io",
|
preferred_domain: "meet.element.io",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
|
|||||||
import WidgetStore from "./WidgetStore";
|
import WidgetStore from "./WidgetStore";
|
||||||
import SettingsStore from "../settings/SettingsStore";
|
import SettingsStore from "../settings/SettingsStore";
|
||||||
import { SettingLevel } from "../settings/SettingLevel";
|
import { SettingLevel } from "../settings/SettingLevel";
|
||||||
|
import SdkConfig from "../SdkConfig";
|
||||||
import { Call, CallEvent, ConnectionState } from "../models/Call";
|
import { Call, CallEvent, ConnectionState } from "../models/Call";
|
||||||
|
|
||||||
export enum CallStoreEvent {
|
export enum CallStoreEvent {
|
||||||
@@ -71,10 +72,13 @@ export class CallStore extends AsyncStoreWithClient<EmptyObject> {
|
|||||||
}
|
}
|
||||||
// See https://github.com/matrix-org/matrix-spec-proposals/blob/d61969a9a3696b6c54d7987b1643b5bc03670927/proposals/4143-matrix-rtc.md#discovery-of-foci-using-well-knownmatrixclient
|
// See https://github.com/matrix-org/matrix-spec-proposals/blob/d61969a9a3696b6c54d7987b1643b5bc03670927/proposals/4143-matrix-rtc.md#discovery-of-foci-using-well-knownmatrixclient
|
||||||
// This well-known option has since been removed from the spec but is still widely deployed.
|
// This well-known option has since been removed from the spec but is still widely deployed.
|
||||||
await this.matrixClient.waitForClientWellKnown();
|
// Reading it can be disabled via config; the modern endpoint above is unaffected.
|
||||||
const foci = this.matrixClient.getClientWellKnown()?.["org.matrix.msc4143.rtc_foci"];
|
if (SdkConfig.get("enable_client_well_known_lookups")) {
|
||||||
if (Array.isArray(foci)) {
|
await this.matrixClient.waitForClientWellKnown();
|
||||||
foci.forEach((foci) => this.configuredMatrixRTCTransports.add(foci));
|
const foci = this.matrixClient.getClientWellKnown()?.["org.matrix.msc4143.rtc_foci"];
|
||||||
|
if (Array.isArray(foci)) {
|
||||||
|
foci.forEach((foci) => this.configuredMatrixRTCTransports.add(foci));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.emit(CallStoreEvent.TransportsUpdated);
|
this.emit(CallStoreEvent.TransportsUpdated);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { type MockedObject } from "jest-mock";
|
|||||||
|
|
||||||
import { ElementCall } from "../../../src/models/Call";
|
import { ElementCall } from "../../../src/models/Call";
|
||||||
import { CallStore } from "../../../src/stores/CallStore";
|
import { CallStore } from "../../../src/stores/CallStore";
|
||||||
|
import SdkConfig from "../../../src/SdkConfig";
|
||||||
import {
|
import {
|
||||||
setUpClientRoomAndStores,
|
setUpClientRoomAndStores,
|
||||||
cleanUpClientRoomAndStores,
|
cleanUpClientRoomAndStores,
|
||||||
@@ -66,4 +67,20 @@ describe("CallStore", () => {
|
|||||||
{ type: "type-d", other_data: "baz" },
|
{ type: "type-d", other_data: "baz" },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
it("does not fall back to client well-known when enable_client_well_known_lookups is false", async () => {
|
||||||
|
const sdkConfigGet = SdkConfig.get;
|
||||||
|
jest.spyOn(SdkConfig, "get").mockImplementation((key?: any, altCaseName?: string): any => {
|
||||||
|
if (key === "enable_client_well_known_lookups") return false;
|
||||||
|
return sdkConfigGet(key, altCaseName);
|
||||||
|
});
|
||||||
|
client._unstable_getRTCTransports.mockResolvedValue([{ type: "type-a", some_data: "value" }]);
|
||||||
|
client.getClientWellKnown.mockReturnValue({
|
||||||
|
"org.matrix.msc4143.rtc_foci": [{ type: "type-c", other_data: "bar" }],
|
||||||
|
});
|
||||||
|
await setupAsyncStoreWithClient(CallStore.instance, client);
|
||||||
|
// Only the modern endpoint contributes; the legacy well-known fallback is skipped entirely.
|
||||||
|
expect(CallStore.instance.getConfiguredRTCTransports()).toEqual([{ type: "type-a", some_data: "value" }]);
|
||||||
|
expect(client.waitForClientWellKnown).not.toHaveBeenCalled();
|
||||||
|
expect(client.getClientWellKnown).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ If both `default_server_config` and `default_server_name` are used, Element will
|
|||||||
information using `.well-known`, and if that fails, take `default_server_config` as the homeserver connection
|
information using `.well-known`, and if that fails, take `default_server_config` as the homeserver connection
|
||||||
information.
|
information.
|
||||||
|
|
||||||
|
1. `enable_client_well_known_lookups`: Controls whether Element makes runtime requests to the logged-in user's
|
||||||
|
[`<server_name>/.well-known/matrix/...`](https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixclient)
|
||||||
|
endpoints (for example, polling for client configuration after login). Set it to `false` to stop Element making these
|
||||||
|
requests, so it only contacts the homeserver base URL; the `well_known` object returned inline in the `/login` response
|
||||||
|
is unaffected. Defaults to `true`.
|
||||||
|
|
||||||
## Labs flags
|
## Labs flags
|
||||||
|
|
||||||
Labs flags are optional, typically beta or in-development, features that can be turned on or off. The full range of
|
Labs flags are optional, typically beta or in-development, features that can be turned on or off. The full range of
|
||||||
|
|||||||
+8
@@ -37,6 +37,14 @@ export interface WebConfigJson {
|
|||||||
disable_login_language_selector?: boolean;
|
disable_login_language_selector?: boolean;
|
||||||
disable_3pid_login?: boolean;
|
disable_3pid_login?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the app may make runtime requests to the user's `<server_name>/.well-known/matrix/...`
|
||||||
|
* endpoints (such as the post-login client well-known poll). Set to false to disable these, so the app
|
||||||
|
* only contacts the homeserver base URL. Does not affect the `well_known` returned inline in the
|
||||||
|
* `/login` response. Defaults to true.
|
||||||
|
*/
|
||||||
|
enable_client_well_known_lookups?: boolean;
|
||||||
|
|
||||||
brand?: string;
|
brand?: string;
|
||||||
branding?: {
|
branding?: {
|
||||||
welcome_background_url?: string | string[]; // chosen at random if array
|
welcome_background_url?: string | string[]; // chosen at random if array
|
||||||
|
|||||||
Reference in New Issue
Block a user