Skip to content

Commit 1dd1024

Browse files
authored
Merge pull request #5609 from BookStackApp/5605-folder-permissions
Images: Updated local disk to have open dir perms
2 parents 752cfe2 + 5ab31a8 commit 1dd1024

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

app/Config/filesystems.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'root' => public_path(),
3535
'serve' => false,
3636
'throw' => true,
37+
'directory_visibility' => 'public',
3738
],
3839

3940
'local_secure_attachments' => [

app/Uploads/ImageStorageDisk.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Filesystem\FilesystemAdapter;
88
use Illuminate\Support\Facades\Log;
99
use League\Flysystem\UnableToSetVisibility;
10+
use League\Flysystem\Visibility;
1011
use Symfony\Component\HttpFoundation\StreamedResponse;
1112

1213
class ImageStorageDisk
@@ -85,7 +86,7 @@ public function put(string $path, string $data, bool $makePublic = false): void
8586
// require different ACLs for S3, and this provides us more logical control.
8687
if ($makePublic && !$this->isS3Like()) {
8788
try {
88-
$this->filesystem->setVisibility($path, 'public');
89+
$this->filesystem->setVisibility($path, Visibility::PUBLIC);
8990
} catch (UnableToSetVisibility $e) {
9091
Log::warning("Unable to set visibility for image upload with relative path: {$path}");
9192
}

tests/Uploads/ImageStorageTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Tests\Uploads;
4+
5+
use BookStack\Uploads\ImageStorage;
6+
use Tests\TestCase;
7+
8+
class ImageStorageTest extends TestCase
9+
{
10+
public function test_local_image_storage_sets_755_directory_permissions()
11+
{
12+
if (PHP_OS_FAMILY !== 'Linux') {
13+
$this->markTestSkipped('Test only works on Linux');
14+
}
15+
16+
config()->set('filesystems.default', 'local');
17+
$storage = $this->app->make(ImageStorage::class);
18+
$dirToCheck = 'test-dir-perms-' . substr(md5(random_bytes(16)), 0, 6);
19+
20+
$disk = $storage->getDisk('gallery');
21+
$disk->put("{$dirToCheck}/image.png", 'abc', true);
22+
23+
$expectedPath = public_path("uploads/images/{$dirToCheck}");
24+
$permissionsApplied = substr(sprintf('%o', fileperms($expectedPath)), -4);
25+
$this->assertEquals('0755', $permissionsApplied);
26+
27+
@unlink("{$expectedPath}/image.png");
28+
@rmdir($expectedPath);
29+
}
30+
}

0 commit comments

Comments
 (0)