Skip to content

Commit 88150cb

Browse files
committed
fix(files): harden default permissions for uploaded files and directories
1 parent 59e5eea commit 88150cb

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
@@ -165,7 +165,7 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
165165
throw HTTPException::forMoveFailed(basename($this->path), $targetPath, $message);
166166
}
167167

168-
@chmod($destination, 0666 & ~umask());
168+
@chmod($destination, 0644 & ~umask());
169169

170170
// Success, so store our new information
171171
$this->path = $targetPath;
@@ -183,11 +183,13 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
183183
protected function setPath(string $path): string
184184
{
185185
if (! is_dir($path)) {
186-
mkdir($path, 0777, true);
186+
mkdir($path, 0755, true);
187187
// create the index.html file
188188
if (! is_file($path . 'index.html')) {
189189
$file = fopen($path . 'index.html', 'x+b');
190-
fclose($file);
190+
if (is_resource($file)) {
191+
fclose($file);
192+
}
191193
}
192194
}
193195

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

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

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

105105
public function testMoveSanitizesClientNameByDefault(): void

0 commit comments

Comments
 (0)