Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'root' => public_path(),
'serve' => false,
'throw' => true,
'directory_visibility' => 'public',
],

'local_secure_attachments' => [
Expand Down
3 changes: 2 additions & 1 deletion app/Uploads/ImageStorageDisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Log;
use League\Flysystem\UnableToSetVisibility;
use League\Flysystem\Visibility;
use Symfony\Component\HttpFoundation\StreamedResponse;

class ImageStorageDisk
Expand Down Expand Up @@ -85,7 +86,7 @@ public function put(string $path, string $data, bool $makePublic = false): void
// 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}");
}
Expand Down
30 changes: 30 additions & 0 deletions tests/Uploads/ImageStorageTest.php
Original file line number Diff line number Diff line change
@@ -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);
}
}