diff --git a/app/index.ts b/app/index.ts index 84a804a4da14..e626d01ad923 100644 --- a/app/index.ts +++ b/app/index.ts @@ -32,6 +32,7 @@ import {gitDescribe} from 'git-describe'; import parseUrl from 'parse-url'; import * as AppMenu from './menus/menu'; +import notify from './notify'; import * as plugins from './plugins'; import {newWindow} from './ui/window'; import {installCLI} from './utils/cli-install'; @@ -238,6 +239,10 @@ app.on('open-file', (_event, path) => { app.on('open-url', (_event, sshUrl) => { GetWindow((win: BrowserWindow) => { - win.rpc.emit('open ssh', parseUrl(sshUrl)); + try { + win.rpc.emit('open ssh', parseUrl(sshUrl)); + } catch (e) { + notify('Invalid ssh url', 'Please check your ssh url and try again.', {error: e}); + } }); }); diff --git a/lib/actions/ui.ts b/lib/actions/ui.ts index 92da4ceea35d..48d152f6b227 100644 --- a/lib/actions/ui.ts +++ b/lib/actions/ui.ts @@ -300,6 +300,12 @@ export function openSSH(parsedUrl: ReturnType) { dispatch({ type: UI_OPEN_SSH_URL, effect() { + const resourseIsValid = /^[a-zA-Z0-9.-]+$/.test(parsedUrl.resource); + if (!resourseIsValid) { + notify('Invalid ssh url', 'Please check your ssh url and try again.'); + return; + } + let command = `${parsedUrl.protocol} ${parsedUrl.user ? `${parsedUrl.user}@` : ''}${parsedUrl.resource}`; if (parsedUrl.port) command += ` -p ${parsedUrl.port}`;