CVE-2020-15258 (TypeScript, published 2020-10-16T17:15Z)
Description: value: In Wire before 3.20.x, `shell.openExternal` was used without checking the URL. This vulnerability allows an attacker to execute code on the victims machine by sending messages containing links with arbitrary protocols. The victim has to interact with the link and sees the URL that is opened. The issue was patched by implementing a helper function which checks if the URL's protocol is common. If it is common, the URL will be opened externally. If not, the URL will not be opened and a warning appears for the user informing them that a probably insecure URL was blocked from being executed. The issue is patched in Wire 3.20.x. More technical details about exploitation are available in the linked advisory.
Severity: MEDIUM (CVSS v3 base score: 8)
Weakness: CWE-20 \u2014 Improper Input Validation
The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.
Repository: https://github.com/wireapp/wire-desktop
Files changed:
electron/html/about.html
electron/src/lib/showDialog.ts
electron/src/main.ts
electron/src/menu/system.ts
electron/src/window/AboutWindow.ts
electron/src/window/WindowUtil.test.ts
electron/src/window/WindowUtil.ts
yarn.lock
Commit message: Merge pull request from GHSA-5gpx-9976-ggpm


Vulnerable code:
        <a href="https://support.wire.com/hc/articles/115001919905"><span data-string="aboutUpdate"></span></a>
        <a href="https://medium.com/wire-news/webapp-updates/home"><span data-string="aboutReleases"></span></a>
  shell,
    await shell.openExternal(url);
      return shell.openExternal(url);
import {dialog, globalShortcut, ipcMain, Menu, MenuItemConstructorOptions, shell} from 'electron';
      click: () => shell.openExternal(config.legalUrl),
      click: () => shell.openExternal(config.privacyUrl),
      click: () => shell.openExternal(config.licensesUrl),
      click: () => shell.openExternal(config.supportUrl),
      click: () => shell.openExternal(EnvironmentUtil.web.getWebsiteUrl()),
import {app, BrowserWindow, ipcMain, session, shell} from 'electron';
      // Open HTTPS links in browser instead
      if (url.startsWith('https://')) {
        await shell.openExternal(url);
      } else {
        logger.info(`Attempt to open URL "${url}" in window prevented.`);
        callback({redirectURL: ABOUT_HTML});
import {BrowserWindow, screen} from 'electron';
fs-extra@9.0.0:
  version "9.0.0"
  resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.0.tgz#b6afc31036e247b2466dc99c29ae797d5d4580a3"
  integrity sha512-pmEYSk3vYsG/bF651KPUXZ+hvjpgWYw/Gc7W9NFUe3ZVLczKKWIij3IKpOrQcdw4TILtibFslZ0UmR8Vvzig4g==
  dependencies:
    at-least-node "^1.0.0"
    graceful-fs "^4.2.0"
    jsonfile "^6.0.1"
    universalify "^1.0.0"


Fixed code:
        <a href="https://support.wire.com/hc/articles/115001919905" target="_blank">
          <span data-string="aboutUpdate"></span>
        </a>
        <a href="https://medium.com/wire-news/webapp-updates/home" target="_blank">
          <span data-string="aboutReleases"></span>
        </a>
import * as locale from '../locale/locale';

export const showWarningDialog = (message: string): void => {
  const options: MessageBoxSyncOptions = {
    buttons: ['OK'],
    message,
    title: 'Warning',
    type: 'warning',
  };
  dialog.showMessageBoxSync(options);
};
    return WindowUtil.openExternal(url);
      return WindowUtil.openExternal(url);
import {dialog, globalShortcut, ipcMain, Menu, MenuItemConstructorOptions} from 'electron';
import * as WindowUtil from '../window/WindowUtil';
      click: () => WindowUtil.openExternal(config.legalUrl, true),
      click: () => WindowUtil.openExternal(config.privacyUrl, true),
      click: () => WindowUtil.openExternal(config.licensesUrl, true),
      click: () => WindowUtil.openExternal(config.supportUrl, true),
      click: () => WindowUtil.openExternal(EnvironmentUtil.web.getWebsiteUrl(), true),
import {app, BrowserWindow, ipcMain, session} from 'electron';
import * as WindowUtil from '../window/WindowUtil';
    });

    // Handle the new window event in the About Window
    aboutWindow.webContents.on('new-window', (event, url) => {
      event.preventDefault();
      // Ensure the link does not come from a webview
      if (typeof (event as any).sender.viewInstanceId !== 'undefined') {
        logger.log('New window was created from a webview, aborting.');
        return;

      return WindowUtil.openExternal(url, true);
/*
 * Wire
 * Copyright (C) 2020 Wire Swiss GmbH
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 *
 */

import {dialog, shell} from 'electron';
import * as assert from 'assert';
import * as sinon from 'sinon';

import * as WindowUtil from './WindowUtil';

describe('WindowUtil', () => {
  describe('openExternal', () => {
    let dialogStub: sinon.SinonStub;
    let shellStub: sinon.SinonStub;

    beforeEach(() => {
      shellStub = sinon.stub(shell, 'openExternal').returns(Promise.resolve());
      dialogStub = sinon.stub(dialog, 'showMessageBoxSync').returns(0);
    });

    afterEach(() => {
      dialogStub.restore();
      shellStub.restore();
    });

    it('opens secure URLs externally', async () => {
      const url = 'https://github.com/wireapp/wire-desktop';
      await WindowUtil.openExternal(url);

      assert.ok(shellStub.firstCall.calledWith(url));
      assert.ok(dialogStub.notCalled);
    });

    it('opens insecure URLs externally if allowed', async () => {
      const url = 'http://github.com/wireapp/wire-desktop';
      await WindowUtil.openExternal(url, false);

      assert.ok(shellStub.firstCall.calledWith(url));
      assert.ok(dialogStub.notCalled);
    });

    it(`doesn't open insecure URLs externally if not allowed`, async () => {
      const url = 'http://example.org';
      await WindowUtil.openExternal(url, true);

      assert.ok(shellStub.notCalled);
      assert.ok(dialogStub.called);
    });

    it(`doesn't open non-website URLs externally`, async () => {
      const url = 'smb://attacker.tld/public/pwn.desktop';
      await WindowUtil.openExternal(url);

      assert.ok(shellStub.notCalled);
      assert.ok(dialogStub.called);
    });
  });
});
import {BrowserWindow, screen, shell} from 'electron';
import * as path from 'path';
import * as URL from 'url';

import {getLogger} from '../logging/getLogger';
import {showWarningDialog} from '../lib/showDialog';

const logger = getLogger(path.basename(__filename));

export const openExternal = async (url: string, httpsOnly: boolean = false): Promise<void> => {
  try {
    const urlProtocol = URL.parse(url).protocol || '';
    const allowedProtocols = ['https:'];

    if (!httpsOnly) {
      allowedProtocols.push('ftp:', 'http:', 'mailto:');
    }

    if (!allowedProtocols.includes(urlProtocol)) {
      logger.warn(`Prevented opening external URL "${url}".`);
      showWarningDialog(`Prevented opening external URL "${url}".`);
      return;
    }

    await shell.openExternal(url);
  } catch (error) {
    logger.error(error);
  }
};