diff --git a/src/utilities.ts b/src/utilities.ts index e279c05a..04c078c2 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -3,6 +3,7 @@ import os from 'os' import fs from 'fs' +import path from 'path' import util from 'util' import {getExecOutput, ExecOptions} from '@actions/exec' import * as toolCache from '@actions/tool-cache' @@ -39,7 +40,31 @@ export async function execCommand( args: string[], options: ExecOptions = {} as ExecOptions ): Promise { - const result = await getExecOutput(toolPath, args, options) + const allowedToolNames = new Set(['helm', 'kubectl', 'kompose']) + const resolvedToolPath = fs.realpathSync(toolPath) + const executableName = path.basename( + resolvedToolPath, + getExecutableExtension() + ) + + if (!path.isAbsolute(resolvedToolPath)) { + throw Error(util.format('Executable path must be absolute: %s', toolPath)) + } + + if (!allowedToolNames.has(executableName)) { + throw Error( + util.format('Unexpected executable selected: %s', resolvedToolPath) + ) + } + + const executableStat = fs.statSync(resolvedToolPath) + if (!executableStat.isFile()) { + throw Error( + util.format('Executable path is not a file: %s', resolvedToolPath) + ) + } + + const result = await getExecOutput(resolvedToolPath, args, options) if (result.exitCode != 0) { if (!!result.stderr) { throw Error(result.stderr) @@ -47,7 +72,7 @@ export async function execCommand( throw Error( util.format( '%s exited with result code %s', - toolPath, + resolvedToolPath, result.exitCode ) )