From 1aa626fcc7f04631b8720f7fe0e0681f5e48ec00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatsat=20=28Tats=29=20Mishra=20=F0=9F=90=89?= Date: Mon, 30 Nov 2026 12:41:48 +1300 Subject: [PATCH] Potential fix for code scanning alert no. 1: Shell command built from environment values Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- src/utilities.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) 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 ) )