Also restrict SUID/GSID writes in sandbox

This commit is contained in:
Rylan Polster 2024-07-13 16:28:17 -04:00
parent 74bb9fb193
commit e054a3ccf6
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
2 changed files with 17 additions and 2 deletions

View File

@ -290,6 +290,7 @@ class Sandbox
(regex #"^/dev/tty[a-z0-9]*$") (regex #"^/dev/tty[a-z0-9]*$")
) )
(deny file-write*) ; deny non-allowlist file write operations (deny file-write*) ; deny non-allowlist file write operations
(deny file-write-setugid) ; deny non-allowlist file write SUID/SGID operations
(deny file-write-mode) ; deny non-allowlist file write mode operations (deny file-write-mode) ; deny non-allowlist file write mode operations
(allow process-exec (allow process-exec
(literal "/bin/ps") (literal "/bin/ps")

View File

@ -60,14 +60,28 @@ RSpec.describe Sandbox, :needs_macos do
describe "#disallow chmod on some directory" do describe "#disallow chmod on some directory" do
it "formula does a chmod to opt" do it "formula does a chmod to opt" do
expect { sandbox.exec "chmod", "ug-w", HOMEBREW_PREFIX}.to raise_error(ErrorDuringExecution) expect { sandbox.exec "chmod", "ug-w", HOMEBREW_PREFIX }.to raise_error(ErrorDuringExecution)
end end
it "allows chmod on a path allowed to write" do it "allows chmod on a path allowed to write" do
mktmpdir do |path| mktmpdir do |path|
FileUtils.touch path/"foo" FileUtils.touch path/"foo"
sandbox.allow_write_path(path) sandbox.allow_write_path(path)
expect { sandbox.exec "chmod", "ug-w", path/"foo"}.not_to raise_error(ErrorDuringExecution) expect { sandbox.exec "chmod", "ug-w", path/"foo" }.not_to raise_error(ErrorDuringExecution)
end
end
end
describe "#disallow chmod SUID or SGID on some directory" do
it "formula does a chmod 4000 to opt" do
expect { sandbox.exec "chmod", "4000", HOMEBREW_PREFIX }.to raise_error(ErrorDuringExecution)
end
it "allows chmod 4000 on a path allowed to write" do
mktmpdir do |path|
FileUtils.touch path/"foo"
sandbox.allow_write_path(path)
expect { sandbox.exec "chmod", "4000", path/"foo" }.not_to raise_error(ErrorDuringExecution)
end end
end end
end end