Skip to content

Commit 11acada

Browse files
authored
Merge pull request #2524 from MikeMcQuaid/more-env-filtering-fixes
Hide sensitive tokens from install/test/post.
2 parents cb17a80 + d02b4f3 commit 11acada

File tree

9 files changed

+48
-14
lines changed

9 files changed

+48
-14
lines changed

Library/Homebrew/dev-cmd/mirror.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ module Homebrew
88
def mirror
99
odie "This command requires at least formula argument!" if ARGV.named.empty?
1010

11-
bintray_user = ENV["BINTRAY_USER"]
12-
bintray_key = ENV["BINTRAY_KEY"]
11+
bintray_user = ENV["HOMEBREW_BINTRAY_USER"]
12+
bintray_key = ENV["HOMEBREW_BINTRAY_KEY"]
1313
if !bintray_user || !bintray_key
14-
raise "Missing BINTRAY_USER or BINTRAY_KEY variables!"
14+
raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!"
1515
end
1616

1717
ARGV.formulae.each do |f|

Library/Homebrew/dev-cmd/pull.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def publish_changed_formula_bottles(_tap, changed_formulae_names)
263263
end
264264

265265
published = []
266-
bintray_creds = { user: ENV["BINTRAY_USER"], key: ENV["BINTRAY_KEY"] }
266+
bintray_creds = { user: ENV["HOMEBREW_BINTRAY_USER"], key: ENV["HOMEBREW_BINTRAY_KEY"] }
267267
if bintray_creds[:user] && bintray_creds[:key]
268268
changed_formulae_names.each do |name|
269269
f = Formula[name]
@@ -272,7 +272,7 @@ def publish_changed_formula_bottles(_tap, changed_formulae_names)
272272
published << f.full_name
273273
end
274274
else
275-
opoo "You must set BINTRAY_USER and BINTRAY_KEY to add or update bottles on Bintray!"
275+
opoo "You must set HOMEBREW_BINTRAY_USER and HOMEBREW_BINTRAY_KEY to add or update bottles on Bintray!"
276276
end
277277
published
278278
end

Library/Homebrew/diagnostic.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def check_user_path_1
439439

440440
message = ""
441441

442-
paths.each do |p|
442+
paths(ENV["HOMEBREW_PATH"]).each do |p|
443443
case p
444444
when "/usr/bin"
445445
unless $seen_prefix_bin
@@ -609,7 +609,7 @@ def check_for_config_scripts
609609
/Applications/Server.app/Contents/ServerRoot/usr/sbin
610610
].map(&:downcase)
611611

612-
paths.each do |p|
612+
paths(ENV["HOMEBREW_PATH"]).each do |p|
613613
next if whitelist.include?(p.downcase) || !File.directory?(p)
614614

615615
realpath = Pathname.new(p).realpath.to_s

Library/Homebrew/extend/ENV.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def with_build_environment
2626
ensure
2727
replace(old_env)
2828
end
29+
30+
def clear_sensitive_environment!
31+
ENV.keys.each do |key|
32+
next unless /(cookie|key|token)/i =~ key
33+
ENV.delete key
34+
end
35+
end
2936
end
3037

3138
ENV.extend(EnvActivation)

Library/Homebrew/formula.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
require "tap"
1414
require "keg"
1515
require "migrator"
16+
require "extend/ENV"
1617

1718
# A formula provides instructions and metadata for Homebrew to install a piece
1819
# of software. Every Homebrew formula is a {Formula}.
@@ -1013,10 +1014,17 @@ def run_post_install
10131014
@prefix_returns_versioned_prefix = true
10141015
build = self.build
10151016
self.build = Tab.for_formula(self)
1017+
10161018
old_tmpdir = ENV["TMPDIR"]
10171019
old_temp = ENV["TEMP"]
10181020
old_tmp = ENV["TMP"]
1021+
old_path = ENV["HOMEBREW_PATH"]
1022+
10191023
ENV["TMPDIR"] = ENV["TEMP"] = ENV["TMP"] = HOMEBREW_TEMP
1024+
ENV["HOMEBREW_PATH"] = nil
1025+
1026+
ENV.clear_sensitive_environment!
1027+
10201028
with_logging("post_install") do
10211029
post_install
10221030
end
@@ -1025,6 +1033,7 @@ def run_post_install
10251033
ENV["TMPDIR"] = old_tmpdir
10261034
ENV["TEMP"] = old_temp
10271035
ENV["TMP"] = old_tmp
1036+
ENV["HOMEBREW_PATH"] = old_path
10281037
@prefix_returns_versioned_prefix = false
10291038
end
10301039

@@ -1664,9 +1673,15 @@ def run_test
16641673
old_temp = ENV["TEMP"]
16651674
old_tmp = ENV["TMP"]
16661675
old_term = ENV["TERM"]
1676+
old_path = ENV["HOMEBREW_PATH"]
1677+
16671678
ENV["CURL_HOME"] = old_curl_home || old_home
16681679
ENV["TMPDIR"] = ENV["TEMP"] = ENV["TMP"] = HOMEBREW_TEMP
16691680
ENV["TERM"] = "dumb"
1681+
ENV["HOMEBREW_PATH"] = nil
1682+
1683+
ENV.clear_sensitive_environment!
1684+
16701685
mktemp("#{name}-test") do |staging|
16711686
staging.retain! if ARGV.keep_tmp?
16721687
@testpath = staging.tmpdir
@@ -1689,6 +1704,7 @@ def run_test
16891704
ENV["TEMP"] = old_temp
16901705
ENV["TMP"] = old_tmp
16911706
ENV["TERM"] = old_term
1707+
ENV["HOMEBREW_PATH"] = old_path
16921708
@prefix_returns_versioned_prefix = false
16931709
end
16941710

@@ -1925,17 +1941,24 @@ def stage
19251941
mkdir_p env_home
19261942

19271943
old_home = ENV["HOME"]
1928-
ENV["HOME"] = env_home
19291944
old_curl_home = ENV["CURL_HOME"]
1945+
old_path = ENV["HOMEBREW_PATH"]
1946+
1947+
ENV["HOME"] = env_home
19301948
ENV["CURL_HOME"] = old_curl_home || old_home
1949+
ENV["HOMEBREW_PATH"] = nil
1950+
19311951
setup_home env_home
19321952

1953+
ENV.clear_sensitive_environment!
1954+
19331955
begin
19341956
yield staging
19351957
ensure
19361958
@buildpath = nil
19371959
ENV["HOME"] = old_home
19381960
ENV["CURL_HOME"] = old_curl_home
1961+
ENV["HOMEBREW_PATH"] = old_path
19391962
end
19401963
end
19411964
end

Library/Homebrew/global.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def raise_deprecation_exceptions?
5353

5454
require "compat" unless ARGV.include?("--no-compat") || ENV["HOMEBREW_NO_COMPAT"]
5555

56-
ORIGINAL_PATHS = ENV["PATH"].split(File::PATH_SEPARATOR).map do |p|
56+
ORIGINAL_PATHS = ENV["HOMEBREW_PATH"].split(File::PATH_SEPARATOR).map do |p|
5757
begin
5858
Pathname.new(p).expand_path
5959
rescue

Library/Homebrew/test/diagnostic_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@
122122
specify "#check_user_path_3" do
123123
begin
124124
sbin = HOMEBREW_PREFIX/"sbin"
125-
ENV["PATH"] = "#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
126-
ENV["PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
125+
ENV["HOMEBREW_PATH"] =
126+
"#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
127+
ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
127128
(sbin/"something").mkpath
128129

129130
expect(subject.check_user_path_1).to be nil
@@ -149,7 +150,9 @@
149150
file = "#{path}/foo-config"
150151
FileUtils.touch file
151152
FileUtils.chmod 0755, file
152-
ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
153+
ENV["HOMEBREW_PATH"] =
154+
ENV["PATH"] =
155+
"#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
153156

154157
expect(subject.check_for_config_scripts)
155158
.to match('"config" scripts exist')

Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def brew(*args)
7272

7373
env.merge!(
7474
"PATH" => path,
75+
"HOMEBREW_PATH" => path,
7576
"HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew",
7677
"HOMEBREW_INTEGRATION_TEST" => command_id_from_args(args),
7778
"HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR,

Library/Homebrew/utils.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ def nostdout
406406
end
407407
end
408408

409-
def paths
410-
@paths ||= ENV["PATH"].split(File::PATH_SEPARATOR).collect do |p|
409+
def paths(env_path = ENV["PATH"])
410+
@paths ||= env_path.split(File::PATH_SEPARATOR).collect do |p|
411411
begin
412412
File.expand_path(p).chomp("/")
413413
rescue ArgumentError

0 commit comments

Comments
 (0)