Skip to content

Commit

Permalink
Do not create local world-readable files and directories per default
Browse files Browse the repository at this point in the history
Starting with e5dc1a8 ("Set umask before operations that create
local files") Nextcloud would create local files and directories with
their permission set to world readable. While you can protect access
to nextcloud's data/ directory by -x'ing it, when it comes to
permissions and security, a defensive approach is always
preferable. Hence this changes the used umask from 022 to 027.

This partly addresses #29041.

Signed-off-by: Florian Schmaus <flo@geekplace.eu>
  • Loading branch information
Flowdalic committed Dec 12, 2021
1 parent ce6dcbc commit 78edee3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function getId() {

public function mkdir($path) {
$sourcePath = $this->getSourcePath($path);
$oldMask = umask(022);
$result = @mkdir($sourcePath, 0777, true);
$oldMask = umask(027);
$result = @mkdir($sourcePath, 0770, true);
umask($oldMask);
return $result;
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public function touch($path, $mtime = null) {
if ($this->file_exists($path) and !$this->isUpdatable($path)) {
return false;
}
$oldMask = umask(022);
$oldMask = umask(027);
if (!is_null($mtime)) {
$result = @touch($this->getSourcePath($path), $mtime);
} else {
Expand All @@ -278,7 +278,7 @@ public function file_get_contents($path) {
}

public function file_put_contents($path, $data) {
$oldMask = umask(022);
$oldMask = umask(027);
$result = file_put_contents($this->getSourcePath($path), $data);
umask($oldMask);
return $result;
Expand Down Expand Up @@ -351,15 +351,15 @@ public function copy($path1, $path2) {
if ($this->is_dir($path1)) {
return parent::copy($path1, $path2);
} else {
$oldMask = umask(022);
$oldMask = umask(027);
$result = copy($this->getSourcePath($path1), $this->getSourcePath($path2));
umask($oldMask);
return $result;
}
}

public function fopen($path, $mode) {
$oldMask = umask(022);
$oldMask = umask(027);
$result = fopen($this->getSourcePath($path), $mode);
umask($oldMask);
return $result;
Expand Down

0 comments on commit 78edee3

Please sign in to comment.