diff --git a/warpgate-web/package.json b/warpgate-web/package.json index 0f2deeb..0dc649b 100644 --- a/warpgate-web/package.json +++ b/warpgate-web/package.json @@ -29,7 +29,7 @@ "@sveltejs/vite-plugin-svelte": "^1.4.0", "@tsconfig/svelte": "^3.0.0", "@types/qrcode": "^1.5.0", - "@types/shell-escape": "^0.2.1", + "@types/ua-parser-js": "^0.7.36", "@typescript-eslint/eslint-plugin": "^5.43.0", "@typescript-eslint/parser": "^5.58.0", "bootstrap": "^5.2.0-beta1", @@ -46,7 +46,6 @@ "otplib": "^12.0.1", "qrcode": "^1.5.1", "sass": "^1.61.0", - "shell-escape": "^0.2.0", "svelte": "^3.58.0", "svelte-check": "^2.9.2", "svelte-fa": "^3.0.1", @@ -58,6 +57,7 @@ "thenby": "^1.3.4", "tslib": "^2.5.0", "typescript": "^4.9.4", + "ua-parser-js": "^1.0.35", "vite": "^3.2.4", "vite-plugin-checker": "^0.5.3", "vite-tsconfig-paths": "^4.0.9", diff --git a/warpgate-web/src/common/protocols.ts b/warpgate-web/src/common/protocols.ts index 0822270..f2d3150 100644 --- a/warpgate-web/src/common/protocols.ts +++ b/warpgate-web/src/common/protocols.ts @@ -1,4 +1,4 @@ -import shellEscape from 'shell-escape' +import { shellEscape } from 'gateway/lib/shellEscape' import type { Info } from 'gateway/lib/api' export interface ConnectionOptions { diff --git a/warpgate-web/src/gateway/lib/shellEscape.ts b/warpgate-web/src/gateway/lib/shellEscape.ts new file mode 100644 index 0000000..5447e3e --- /dev/null +++ b/warpgate-web/src/gateway/lib/shellEscape.ts @@ -0,0 +1,32 @@ +import { UAParser } from 'ua-parser-js' + +function escapeUnix (arg: string): string { + if (!/^[A-Za-z0-9_\/-]+$/.test(arg)) { + return ('\'' + arg.replace(/'/g, '\'"\'"\'') + '\'').replace(/''/g, '') + } + return arg +} + +function escapeWin (arg: string): string { + if (!/^[A-Za-z0-9_\/-]+$/.test(arg)) { + return '"' + arg.replace(/"/g, '""') + '"' + } + return arg +} + +const isWin = new UAParser().getOS().name === 'Windows' + +export function shellEscape (stringOrArray: string[]|string): string { + const ret = [] + + const escapePath = isWin ? escapeWin : escapeUnix + + if (typeof stringOrArray == 'string') { + return escapePath(stringOrArray) + } else { + stringOrArray.forEach(function (member) { + ret.push(escapePath(member)) + }) + return ret.join(' ') + } +} diff --git a/warpgate-web/yarn.lock b/warpgate-web/yarn.lock index abeb0e5..60d4a98 100644 --- a/warpgate-web/yarn.lock +++ b/warpgate-web/yarn.lock @@ -340,10 +340,10 @@ resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91" integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw== -"@types/shell-escape@^0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@types/shell-escape/-/shell-escape-0.2.1.tgz#34631545340aa61bbabb672b906f1b910cd42757" - integrity sha512-95hZXmBvwtvsLMPefKT9xquUSAJXsVDUaipyUiYoYi3ZdLhZ3w30w230Ugs96IdoJQb5ECvj0D82Jj/op00qWQ== +"@types/ua-parser-js@^0.7.36": + version "0.7.36" + resolved "https://registry.yarnpkg.com/@types/ua-parser-js/-/ua-parser-js-0.7.36.tgz#9bd0b47f26b5a3151be21ba4ce9f5fa457c5f190" + integrity sha512-N1rW+njavs70y2cApeIw1vLMYXRwfBy+7trgavGuuTfOd7j1Yh7QTRc/yqsPl6ncokt72ZXuxEU0PiCp9bSwNQ== "@typescript-eslint/eslint-plugin@^5.43.0": version "5.43.0" @@ -2442,11 +2442,6 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== -shell-escape@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/shell-escape/-/shell-escape-0.2.0.tgz#68fd025eb0490b4f567a027f0bf22480b5f84133" - integrity sha512-uRRBT2MfEOyxuECseCZd28jC1AJ8hmqqneWQ4VWUTgCAFvb3wKU1jLqj6egC4Exrr88ogg3dp+zroH4wJuaXzw== - side-channel@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" @@ -2753,11 +2748,6 @@ tslib@^2.1.0, tslib@^2.4.0, tslib@^2.5.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== -tslib@^2.5.0: - version "2.5.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" - integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== - tsutils@^3.21.0: version "3.21.0" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623" @@ -2787,6 +2777,11 @@ typescript@*, typescript@^4.9.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78" integrity sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg== +ua-parser-js@^1.0.35: + version "1.0.35" + resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.35.tgz#c4ef44343bc3db0a3cbefdf21822f1b1fc1ab011" + integrity sha512-fKnGuqmTBnIE+/KXSzCn4db8RTigUzw1AN0DmdU6hJovUTbYJKyqj+8Mt1c4VfRDnOVJnENmfYkIPZ946UrSAA== + unbox-primitive@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471"