From 3ef29a72f9eabf121ce43cf90c75588db7db9499 Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Wed, 22 Nov 2023 23:12:10 +0530 Subject: [PATCH] check if ssh url is valid --- app/index.ts | 7 ++++++- lib/actions/ui.ts | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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}`;