Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions apps/web/src/BasePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,9 @@
* The URL to return to after a successful OIDC authentication
*/
public getOidcCallbackUrl(): URL {
const url = new URL(window.location.href);
// The redirect URL has to exactly match that registered at the OIDC server, so
// ensure that the fragment part of the URL is empty.
url.hash = "";
// build it from scratch to avoid leaking ephemeral query params (e.g. `updated`).
const url = new URL(window.location.origin + window.location.pathname);

Check warning on line 471 in apps/web/src/BasePlatform.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=element-web&issues=AZ0MJTRoD-p0-at6FIS0&open=AZ0MJTRoD-p0-at6FIS0&pullRequest=32875

Check warning on line 471 in apps/web/src/BasePlatform.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=element-web&issues=AZ0MJTRoD-p0-at6FIS1&open=AZ0MJTRoD-p0-at6FIS1&pullRequest=32875
// Set no_universal_links=true to prevent the callback being handled by Element X installed on macOS Apple Silicon
url.searchParams.set("no_universal_links", "true");
return url;
Expand Down
18 changes: 18 additions & 0 deletions apps/web/test/unit-tests/vector/platform/WebPlatform-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,22 @@ describe("WebPlatform", () => {
platform.setErrorStatus(true);
expect(spy).toHaveBeenCalledWith(expect.anything(), { bgColor: "#f00" });
});

describe("getOidcCallbackUrl()", () => {
it("should not include the 'updated' query param in the redirect URI", () => {
Object.defineProperty(window, "location", {
value: {
href: "https://element.example.com/?updated=1.12.12",
origin: "https://element.example.com",
pathname: "/",
},
writable: true,
});
const platform = new WebPlatform();
const url = platform.getOidcCallbackUrl();

expect(url.searchParams.has("updated")).toBe(false);
expect(url.searchParams.get("no_universal_links")).toEqual("true");
});
});
});
Loading