Skip to content

Commit 97ab093

Browse files
committed
fix(files): harden default permissions for uploaded files and directories
1 parent 3ad5144 commit 97ab093

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎system/HTTP/Files/UploadedFile.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
159159
throw HTTPException::forMoveFailed(basename($this->path), $targetPath, $message);
160160
}
161161

162-
@chmod($destination, 0666 & ~umask());
162+
@chmod($destination, 0644 & ~umask());
163163

164164
// Success, so store our new information
165165
$this->path = $targetPath;
@@ -177,11 +177,13 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
177177
protected function setPath(string $path): string
178178
{
179179
if (! is_dir($path)) {
180-
mkdir($path, 0777, true);
180+
mkdir($path, 0755, true);
181181
// create the index.html file
182182
if (! is_file($path . 'index.html')) {
183183
$file = fopen($path . 'index.html', 'x+b');
184-
fclose($file);
184+
if (is_resource($file)) {
185+
fclose($file);
186+
}
185187
}
186188
}
187189

‎tests/system/HTTP/Files/FileMovingTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function testMove(): void
9898

9999
$this->assertTrue($this->root->hasChild('destination/' . $finalFilename . '.txt'));
100100
$this->assertTrue($this->root->hasChild('destination/' . $finalFilename . '_1.txt'));
101-
$this->assertSame(0666 & ~umask(), $this->root->getChild('destination/' . $finalFilename . '.txt')->getPermissions());
101+
$this->assertSame(0644 & ~umask(), $this->root->getChild('destination/' . $finalFilename . '.txt')->getPermissions());
102102
}
103103

104104
public function testMoveSanitizesClientNameByDefault(): void

0 commit comments

Comments
 (0)