Mike McQuaid d02b4f321d Hide sensitive tokens from install/test/post.
Hide these tokens to avoid malicious subprocesses e.g. sending them
over the network. Also, support using these tokens with environment
filtering and clear `HOMEBREW_PATH` from subprocesses to stop them
sniffing it. Finally, use `HOMEBREW_PATH` to detect Homebrew’s user’s
PATH for e.g. `brew doctor` etc.
2017-04-22 16:31:19 +01:00

39 lines
703 B
Ruby

require "hardware"
require "extend/ENV/shared"
require "extend/ENV/std"
require "extend/ENV/super"
def superenv?
ARGV.env != "std" && Superenv.bin
end
module EnvActivation
def activate_extensions!
if superenv?
extend(Superenv)
else
extend(Stdenv)
end
end
def with_build_environment
old_env = to_hash.dup
tmp_env = to_hash.dup.extend(EnvActivation)
tmp_env.activate_extensions!
tmp_env.setup_build_environment
replace(tmp_env)
yield
ensure
replace(old_env)
end
def clear_sensitive_environment!
ENV.keys.each do |key|
next unless /(cookie|key|token)/i =~ key
ENV.delete key
end
end
end
ENV.extend(EnvActivation)