From 3e5737863198f49a43a1b67f2b7c369a953614ad Mon Sep 17 00:00:00 2001 From: Ibragim/Parviz Bekliev Date: Tue, 9 Feb 2021 12:08:40 +0300 Subject: [PATCH 1/4] fix / sso: after complete login via token make sure to delete only loginToken query-param from the window.location api. Related to https://github.com/vector-im/element-web/pull/16292 Signed-off-by: Bekliev Parviz --- src/vector/app.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/vector/app.tsx b/src/vector/app.tsx index 9df1d8c6c4..a8eb81a5a8 100644 --- a/src/vector/app.tsx +++ b/src/vector/app.tsx @@ -120,8 +120,11 @@ function onTokenLoginCompleted() { // if we did a token login, we're now left with the token, hs and is // url as query params in the url; a little nasty but let's redirect to // clear them. - const parsedUrl = url.parse(window.location.href); - parsedUrl.search = ""; + const parsedUrl = url.parse(window.location.href, true); + + parsedUrl.search = null; // to make `url.format` ignores `search` property and uses `query` instead + delete parsedUrl.query['loginToken']; + const formatted = url.format(parsedUrl); console.log(`Redirecting to ${formatted} to drop loginToken from queryparams`); window.history.replaceState(null, "", formatted); From 92a5787528c0eb1e37d05595362dfc80131d5843 Mon Sep 17 00:00:00 2001 From: Ibragim/Parviz Bekliev Date: Thu, 11 Feb 2021 17:47:50 +0300 Subject: [PATCH 2/4] Migrating from Node's deprecated `url` API to browser's `URL` Related to https://github.com/vector-im/element-web/pull/16292 Signed-off-by: Bekliev Parviz --- package.json | 3 +-- src/vector/app.tsx | 11 ++++------- src/vector/platform/WebPlatform.ts | 17 ++++++----------- yarn.lock | 11 +---------- 4 files changed, 12 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index ae27775025..a504a7f4f2 100644 --- a/package.json +++ b/package.json @@ -66,8 +66,7 @@ "react": "^16.14.0", "react-dom": "^16.14.0", "sanitize-html": "github:apostrophecms/sanitize-html#3c7f93f2058f696f5359e3e58d464161647226db", - "ua-parser-js": "^0.7.23", - "url": "^0.11.0" + "ua-parser-js": "^0.7.23" }, "devDependencies": { "@babel/core": "^7.12.10", diff --git a/src/vector/app.tsx b/src/vector/app.tsx index a8eb81a5a8..cc589f5835 100644 --- a/src/vector/app.tsx +++ b/src/vector/app.tsx @@ -23,7 +23,6 @@ import React from 'react'; // this incidentally means we can forget our React imports in JSX files without penalty. window.React = React; -import url from 'url'; import * as sdk from 'matrix-react-sdk'; import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg'; import {_td, newTranslatableError} from 'matrix-react-sdk/src/languageHandler'; @@ -120,14 +119,12 @@ function onTokenLoginCompleted() { // if we did a token login, we're now left with the token, hs and is // url as query params in the url; a little nasty but let's redirect to // clear them. - const parsedUrl = url.parse(window.location.href, true); + const url = new URL(window.location.href); - parsedUrl.search = null; // to make `url.format` ignores `search` property and uses `query` instead - delete parsedUrl.query['loginToken']; + url.searchParams.delete('loginToken'); - const formatted = url.format(parsedUrl); - console.log(`Redirecting to ${formatted} to drop loginToken from queryparams`); - window.history.replaceState(null, "", formatted); + console.log(`Redirecting to ${url.href} to drop loginToken from queryparams`); + window.history.replaceState(null, "", url.href); } export async function loadApp(fragParams: {}) { diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index 9f9f4a3995..019c60e90f 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -26,7 +26,6 @@ import {hideToast as hideUpdateToast, showToast as showUpdateToast} from "matrix import {Action} from "matrix-react-sdk/src/dispatcher/actions"; import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload'; -import url from 'url'; import UAParser from 'ua-parser-js'; const POKE_RATE_MS = 10 * 60 * 1000; // 10 min @@ -184,17 +183,13 @@ export default class WebPlatform extends VectorBasePlatform { getDefaultDeviceDisplayName(): string { // strip query-string and fragment from uri - const u = url.parse(window.location.href); - u.protocol = ""; - u.search = ""; - u.hash = ""; - // Remove trailing slash if present - u.pathname = u.pathname.replace(/\/$/, ""); + const url = new URL(window.location.href); - let appName = u.format(); - // Remove leading slashes if present - appName = appName.replace(/^\/\//, ""); - // `appName` is now in the format `develop.element.io`. + // `appName` in the format `develop.element.io/abc/xyz` + const appName = [ + url.host, + url.pathname.replace(/\/$/, ""), // Remove trailing slash if present + ].join(''); const ua = new UAParser(); const browserName = ua.getBrowser().name || "unknown browser"; diff --git a/yarn.lock b/yarn.lock index e78fafea4b..d5a0c84ecc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8890,16 +8890,7 @@ postcss-attribute-case-insensitive@^4.0.1: postcss "^7.0.2" postcss-selector-parser "^6.0.2" -postcss-calc@^7.0.1: - version "7.0.5" - resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-7.0.5.tgz#f8a6e99f12e619c2ebc23cf6c486fdc15860933e" - integrity sha512-1tKHutbGtLtEZF6PT4JSihCHfIVldU72mZ8SdZHIYriIZ9fh9k9aWSppaT8rHsyI3dX+KSR+W+Ix9BMY3AODrg== - dependencies: - postcss "^7.0.27" - postcss-selector-parser "^6.0.2" - postcss-value-parser "^4.0.2" - -postcss-calc@^7.0.5: +postcss-calc@^7.0.1, postcss-calc@^7.0.5: version "7.0.5" resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-7.0.5.tgz#f8a6e99f12e619c2ebc23cf6c486fdc15860933e" integrity sha512-1tKHutbGtLtEZF6PT4JSihCHfIVldU72mZ8SdZHIYriIZ9fh9k9aWSppaT8rHsyI3dX+KSR+W+Ix9BMY3AODrg== From e15d1c15018400b51ca21264439aa8d899dc0d5c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@googlemail.com> Date: Thu, 11 Feb 2021 16:27:30 +0000 Subject: [PATCH 3/4] Update src/vector/platform/WebPlatform.ts --- src/vector/platform/WebPlatform.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index 019c60e90f..6356e41bc3 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -189,7 +189,7 @@ export default class WebPlatform extends VectorBasePlatform { const appName = [ url.host, url.pathname.replace(/\/$/, ""), // Remove trailing slash if present - ].join(''); + ].join(""); const ua = new UAParser(); const browserName = ua.getBrowser().name || "unknown browser"; From 438eef0acdd537bf01c820e1f1ddd0279de9133e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@googlemail.com> Date: Thu, 11 Feb 2021 16:27:55 +0000 Subject: [PATCH 4/4] Update src/vector/app.tsx --- src/vector/app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/app.tsx b/src/vector/app.tsx index cc589f5835..a0e4ee50ca 100644 --- a/src/vector/app.tsx +++ b/src/vector/app.tsx @@ -121,7 +121,7 @@ function onTokenLoginCompleted() { // clear them. const url = new URL(window.location.href); - url.searchParams.delete('loginToken'); + url.searchParams.delete("loginToken"); console.log(`Redirecting to ${url.href} to drop loginToken from queryparams`); window.history.replaceState(null, "", url.href);