]> BookStack Code Mirror - bookstack/commitdiff
Images: Updated local disk to have open dir perms 5609/head
authorDan Brown <redacted>
Wed, 14 May 2025 17:15:20 +0000 (18:15 +0100)
committerDan Brown <redacted>
Wed, 14 May 2025 17:15:20 +0000 (18:15 +0100)
Closes #5605

app/Config/filesystems.php
app/Uploads/ImageStorageDisk.php
tests/Uploads/ImageStorageTest.php [new file with mode: 0644]

index ab507a2f8c6fae9f923d85624c6956dd589ffdef..ab73fec29682f070a3ae35a1a1ba7f4d844a9353 100644 (file)
@@ -34,6 +34,7 @@ return [
             'root'       => public_path(),
             'serve'      => false,
             'throw'      => true,
+            'directory_visibility' => 'public',
         ],
 
         'local_secure_attachments' => [
index 8e364831f75ede661cf7798f45c96f49a1b9ad57..f2667d993a8314e1a16982678fe9211408ea5e40 100644 (file)
@@ -7,6 +7,7 @@ use Illuminate\Contracts\Filesystem\Filesystem;
 use Illuminate\Filesystem\FilesystemAdapter;
 use Illuminate\Support\Facades\Log;
 use League\Flysystem\UnableToSetVisibility;
+use League\Flysystem\Visibility;
 use Symfony\Component\HttpFoundation\StreamedResponse;
 
 class ImageStorageDisk
@@ -85,7 +86,7 @@ class ImageStorageDisk
         // require different ACLs for S3, and this provides us more logical control.
         if ($makePublic && !$this->isS3Like()) {
             try {
-                $this->filesystem->setVisibility($path, 'public');
+                $this->filesystem->setVisibility($path, Visibility::PUBLIC);
             } catch (UnableToSetVisibility $e) {
                 Log::warning("Unable to set visibility for image upload with relative path: {$path}");
             }
diff --git a/tests/Uploads/ImageStorageTest.php b/tests/Uploads/ImageStorageTest.php
new file mode 100644 (file)
index 0000000..117da7f
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+namespace Tests\Uploads;
+
+use BookStack\Uploads\ImageStorage;
+use Tests\TestCase;
+
+class ImageStorageTest extends TestCase
+{
+    public function test_local_image_storage_sets_755_directory_permissions()
+    {
+        if (PHP_OS_FAMILY !== 'Linux') {
+            $this->markTestSkipped('Test only works on Linux');
+        }
+
+        config()->set('filesystems.default', 'local');
+        $storage = $this->app->make(ImageStorage::class);
+        $dirToCheck = 'test-dir-perms-' . substr(md5(random_bytes(16)), 0, 6);
+
+        $disk = $storage->getDisk('gallery');
+        $disk->put("{$dirToCheck}/image.png", 'abc', true);
+
+        $expectedPath = public_path("uploads/images/{$dirToCheck}");
+        $permissionsApplied = substr(sprintf('%o', fileperms($expectedPath)), -4);
+        $this->assertEquals('0755', $permissionsApplied);
+
+        @unlink("{$expectedPath}/image.png");
+        @rmdir($expectedPath);
+    }
+}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.