Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audit: ignore group write bit #7073

Merged
merged 1 commit into from Mar 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions Library/Homebrew/dev-cmd/audit.rb
Expand Up @@ -242,15 +242,26 @@ def audit_style
end

def audit_file
# Under normal circumstances (umask 0022), we expect a file mode of 644. If
# the user's umask is more restrictive, respect that by masking out the
# corresponding bits. (The also included 0100000 flag means regular file.)
wanted_mode = 0100644 & ~File.umask
actual_mode = formula.path.stat.mode
unless actual_mode == wanted_mode
problem format("Incorrect file permissions (%03<actual>o): chmod %03<wanted>o %<path>s",
# Check that the file is world-readable.
if actual_mode & 0444 != 0444
problem format("Incorrect file permissions (%03<actual>o): chmod %<wanted>s %<path>s",
actual: actual_mode & 0777,
wanted: wanted_mode & 0777,
wanted: "+r",
path: formula.path)
end
# Check that the file is user-writeable.
if actual_mode & 0200 != 0200
problem format("Incorrect file permissions (%03<actual>o): chmod %<wanted>s %<path>s",
actual: actual_mode & 0777,
wanted: "u+w",
path: formula.path)
end
# Check that the file is *not* other-writeable.
if actual_mode & 0002 == 002
problem format("Incorrect file permissions (%03<actual>o): chmod %<wanted>s %<path>s",
actual: actual_mode & 0777,
wanted: "o-w",
path: formula.path)
end

Expand Down
33 changes: 31 additions & 2 deletions Library/Homebrew/test/dev-cmd/audit_spec.rb
Expand Up @@ -106,11 +106,40 @@ class Foo < Formula
RUBY

path = fa.formula.path
path.chmod 0400

path.chmod 0600
fa.audit_file
expect(fa.problems)
.to eq(["Incorrect file permissions (400): chmod 644 #{path}"])
.to eq([
"Incorrect file permissions (600): chmod +r #{path}",
])
fa.problems.clear

path.chmod 0444
fa.audit_file
expect(fa.problems)
.to eq([
"Incorrect file permissions (444): chmod u+w #{path}",
])
fa.problems.clear

path.chmod 0646
fa.audit_file
expect(fa.problems)
.to eq([
"Incorrect file permissions (646): chmod o-w #{path}",
])
fa.problems.clear

path.chmod 0002
fa.audit_file
expect(fa.problems)
.to eq([
"Incorrect file permissions (002): chmod +r #{path}",
"Incorrect file permissions (002): chmod u+w #{path}",
"Incorrect file permissions (002): chmod o-w #{path}",
])
fa.problems.clear
end

specify "DATA but no __END__" do
Expand Down