Skip to content

Commit 33db2c6

Browse files
authored
fix: correct file permissions and chmod target in File and UploadedFile move() (#10519)
* fix: correct permissions and target in File and UploadedFile move() * docs: add changelog entry for File and UploadedFile move() permissions fix
1 parent 6dd1c5f commit 33db2c6

5 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎system/Files/File.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
170170
throw FileException::forUnableToMove($this->getBasename(), $targetPath, strip_tags($error['message']));
171171
}
172172

173-
@chmod($destination, 0777 & ~umask());
173+
@chmod($destination, 0666 & ~umask());
174174

175175
return new self($destination);
176176
}

‎system/HTTP/Files/UploadedFile.php‎

Lines changed: 1 addition & 1 deletion
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($targetPath, 0777 & ~umask());
162+
@chmod($destination, 0666 & ~umask());
163163

164164
// Success, so store our new information
165165
$this->path = $targetPath;

‎tests/system/Files/FileWithVfsTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,13 @@ public function testMoveReturnsNewInstance(): void
150150
$this->assertInstanceOf(File::class, $file);
151151
$this->assertSame($destination . '/apple.php', $file->getPathname());
152152
}
153+
154+
public function testMovePermissions(): void
155+
{
156+
$destination = $this->start . 'baker';
157+
$this->file->move($destination);
158+
159+
$expectedPerms = 0666 & ~umask();
160+
$this->assertSame($expectedPerms, $this->root->getChild('baker/apple.php')->getPermissions());
161+
}
153162
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +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());
101102
}
102103

103104
public function testMoveSanitizesClientNameByDefault(): void

‎user_guide_src/source/changelogs/v4.7.5.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Bugs Fixed
4242
- **CodeIgniter:** Fixed a bug where ``gatherOutput()`` could be called twice when ``startController()`` returned a ``ResponseInterface`` (e.g., from filter attributes or closure routes).
4343
- **Content Security Policy:** Fixed a bug where empty ``Content-Security-Policy``, ``Content-Security-Policy-Report-Only``, and ``Reporting-Endpoints`` response headers were generated when no corresponding values existed.
4444
- **Cookie:** Fixed a bug where ``Cookie`` instances created with ``raw: true`` allowed invalid characters in cookie values rejected by ``setrawcookie()``.
45+
- **Files:** Fixed a bug where ``File::move()`` and ``UploadedFile::move()`` set executable and overly permissive file permissions (``0777 & ~umask()`` instead of ``0666 & ~umask()``), and ``UploadedFile::move()`` targeted the parent directory instead of the destination file for ``chmod()``.
4546
- **Helpers:** Fixed a bug where ``get_dir_file_info()`` returned incomplete entries for subdirectories and missing files instead of omitting them.
4647
- **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden).
4748
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.

0 commit comments

Comments
 (0)