Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Library/Homebrew/sandbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ def home_write_paths = []

sig { params(tmpdir: String).returns(T::Hash[String, String]) }
def sandbox_environment(tmpdir)
allow_read path: tmpdir, type: :subpath
allow_write_path(tmpdir)
allow_network path: tmpdir, type: :subpath
{ "HOMEBREW_TEMP" => tmpdir, "TMPDIR" => tmpdir, "TEMP" => tmpdir, "TMP" => tmpdir }
Expand Down
20 changes: 20 additions & 0 deletions Library/Homebrew/test/sandbox_shared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,26 @@
allow(described_class).to receive(:isolate_operation?).and_call_original
end

it "allows reading only its private temporary directory under a denied parent" do
temporary_directory = mktmpdir
outside = temporary_directory/"outside"
outside.write("secret")
sandbox.deny_read_path temporary_directory
result = sandbox.capture(RbConfig.ruby, temporary_directory:, args: ["-e", <<~RUBY, outside])
file = File.join(ENV.fetch("TMPDIR"), "archive")
File.write(file, "contents")
puts File.read(file)
begin
File.read(ARGV.fetch(0))
abort "Read escaped the sandbox"
rescue Errno::EPERM, Errno::EACCES
nil
end
RUBY

expect(result.stdout).to eq("contents\n")
end

it "allows its output directory and denies writes through an escaping symlink" do
directory = mktmpdir
output = directory/"output"
Expand Down
Loading