Strip INPUT_* env variables from subprocesses

This commit is contained in:
Luke Tomlinson
2021-05-05 16:32:13 -04:00
parent 3491e2eeea
commit fad1bf5141
3 changed files with 21 additions and 2 deletions

View File

@@ -6,7 +6,7 @@ export interface ExecOptions {
/** optional working directory. defaults to current */
cwd?: string
/** optional envvar dictionary. defaults to current process's env */
/** optional envvar dictionary. defaults to current process's env with `INPUT_*` variables removed */
env?: {[key: string]: string}
/** optional. defaults to false */

View File

@@ -377,7 +377,7 @@ export class ToolRunner extends events.EventEmitter {
options = options || <im.ExecOptions>{}
const result = <child.SpawnOptions>{}
result.cwd = options.cwd
result.env = options.env
result.env = options.env || stripInputEnvironmentVariables(process.env)
result['windowsVerbatimArguments'] =
options.windowsVerbatimArguments || this._isCmdFile()
if (options.windowsVerbatimArguments) {
@@ -600,6 +600,16 @@ export function argStringToArray(argString: string): string[] {
return args
}
// Strips INPUT_ environment variables to prevent them leaking to child processes
export function stripInputEnvironmentVariables(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
return Object.entries(env).filter(([key, value]) => {
return !key.startsWith('INPUT_')
}).reduce((obj: NodeJS.ProcessEnv, [key, value]) => {
obj[key] = value
return obj
}, {})
}
class ExecState extends events.EventEmitter {
constructor(options: im.ExecOptions, toolPath: string) {
super()