Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(etherpad) fix handling certain URL types

Saúl Ibarra Corretgé4c3512b37596
diff --git a/modules/UI/UI.js b/modules/UI/UI.js
index 7b7d2660b1..35d583524a 100644
--- a/modules/UI/UI.js
+++ b/modules/UI/UI.js
@@ -11,6 +11,7 @@ import {
} from '../../react/features/base/conference/actions';
import { isMobileBrowser } from '../../react/features/base/environment/utils';
import { setColorAlpha } from '../../react/features/base/util/helpers';
+import { sanitizeUrl } from '../../react/features/base/util/uri';
import { setDocumentUrl } from '../../react/features/etherpad/actions';
import { setFilmstripVisible } from '../../react/features/filmstrip/actions.any';
import {
@@ -135,14 +136,16 @@ UI.unbindEvents = () => {
* @param {string} name etherpad id
*/
UI.initEtherpad = name => {
- if (etherpadManager || !config.etherpad_base || !name) {
+ const etherpadBaseUrl = sanitizeUrl(config.etherpad_base);
+
+ if (etherpadManager || !etherpadBaseUrl || !name) {
return;
}
logger.log('Etherpad is enabled');
etherpadManager = new EtherpadManager(eventEmitter);
- const url = new URL(name, config.etherpad_base);
+ const url = new URL(name, etherpadBaseUrl);
APP.store.dispatch(setDocumentUrl(url.toString()));
diff --git a/package-lock.json b/package-lock.json
index 145ba4d5d4..f6caff75f0 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@amplitude/react-native": "2.7.0",
+ "@braintree/sanitize-url": "7.0.0",
"@emotion/react": "11.10.6",
"@emotion/styled": "11.10.6",
"@giphy/js-fetch-api": "4.7.1",
@@ -2595,6 +2596,11 @@
"node": ">=6.9.0"
}
},
+ "node_modules/@braintree/sanitize-url": {
+ "version": "7.0.0",
+ "resolved": "https://registry.npmjs.org/@braintree/sanitize-url/-/sanitize-url-7.0.0.tgz",
+ "integrity": "sha512-GMu2OJiTd1HSe74bbJYQnVvELANpYiGFZELyyTM1CR0sdv5ReQAcJ/c/8pIrPab3lO11+D+EpuGLUxqz+y832g=="
+ },
"node_modules/@callstack/react-theme-provider": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/@callstack/react-theme-provider/-/react-theme-provider-3.0.9.tgz",
@@ -21556,6 +21562,11 @@
"to-fast-properties": "^2.0.0"
}
},
+ "@braintree/sanitize-url": {
+ "version": "7.0.0",
+ "resolved": "https://registry.npmjs.org/@braintree/sanitize-url/-/sanitize-url-7.0.0.tgz",
+ "integrity": "sha512-GMu2OJiTd1HSe74bbJYQnVvELANpYiGFZELyyTM1CR0sdv5ReQAcJ/c/8pIrPab3lO11+D+EpuGLUxqz+y832g=="
+ },
"@callstack/react-theme-provider": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/@callstack/react-theme-provider/-/react-theme-provider-3.0.9.tgz",
diff --git a/package.json b/package.json
index 922bcd7500..f9b91fe752 100644
--- a/package.json
+++ b/package.json
@@ -17,6 +17,7 @@
"readmeFilename": "README.md",
"dependencies": {
"@amplitude/react-native": "2.7.0",
+ "@braintree/sanitize-url": "7.0.0",
"@emotion/react": "11.10.6",
"@emotion/styled": "11.10.6",
"@giphy/js-fetch-api": "4.7.1",
diff --git a/react/features/base/util/uri.ts b/react/features/base/util/uri.ts
index b0bcc01072..02a86a08ba 100644
--- a/react/features/base/util/uri.ts
+++ b/react/features/base/util/uri.ts
@@ -1,3 +1,5 @@
+import { sanitizeUrl as _sanitizeUrl } from '@braintree/sanitize-url';
+
import { parseURLParams } from './parseURLParams';
import { normalizeNFKC } from './strings';
@@ -657,3 +659,25 @@ export function appendURLHashParam(url: string, name: string, value: string) {
return newUrl.toString();
}
+
+/**
+ * Sanitizes the given URL so that it's safe to use. If it's unsafe, null is returned.
+ *
+ * @param {string|URL} url - The URL that needs to be sanitized.
+ *
+ * @returns {URL?} - The sanitized URL, or null otherwise.
+ */
+export function sanitizeUrl(url?: string | URL): URL | null {
+ if (!url) {
+ return null;
+ }
+
+ const urlStr = url.toString();
+ const result = _sanitizeUrl(urlStr);
+
+ if (result === 'about:blank') {
+ return null;
+ }
+
+ return new URL(result);
+}
diff --git a/react/features/etherpad/middleware.ts b/react/features/etherpad/middleware.ts
index b4d61721ce..8ed139e90f 100644
--- a/react/features/etherpad/middleware.ts
+++ b/react/features/etherpad/middleware.ts
@@ -4,6 +4,7 @@ import { CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes';
import { getCurrentConference } from '../base/conference/functions';
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
+import { sanitizeUrl } from '../base/util/uri';
import { TOGGLE_DOCUMENT_EDITING } from './actionTypes';
import { setDocumentUrl } from './actions';
@@ -27,9 +28,10 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
({ value }: { value: string; }) => {
let url;
const { etherpad_base: etherpadBase } = getState()['features/base/config'];
+ const etherpadBaseUrl = sanitizeUrl(etherpadBase);
- if (etherpadBase) {
- url = new URL(value, etherpadBase).toString();
+ if (etherpadBaseUrl) {
+ url = new URL(value, etherpadBaseUrl.toString()).toString();
}
dispatch(setDocumentUrl(url));