Skip to content

Commit 642ba66

Browse files
authored
Merge pull request #5601 from BookStackApp/file_permissions
Images: Changed how new image permissions are set
2 parents 4f36cdd + 1262083 commit 642ba66

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

app/Config/filesystems.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
'local' => [
3333
'driver' => 'local',
3434
'root' => public_path(),
35-
'visibility' => 'public',
3635
'serve' => false,
3736
'throw' => true,
3837
],
@@ -47,7 +46,6 @@
4746
'local_secure_images' => [
4847
'driver' => 'local',
4948
'root' => storage_path('uploads/images/'),
50-
'visibility' => 'public',
5149
'serve' => false,
5250
'throw' => true,
5351
],

app/Uploads/ImageStorageDisk.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use BookStack\Util\FilePathNormalizer;
66
use Illuminate\Contracts\Filesystem\Filesystem;
77
use Illuminate\Filesystem\FilesystemAdapter;
8+
use Illuminate\Support\Facades\Log;
9+
use League\Flysystem\UnableToSetVisibility;
810
use Symfony\Component\HttpFoundation\StreamedResponse;
911

1012
class ImageStorageDisk
@@ -74,12 +76,19 @@ public function put(string $path, string $data, bool $makePublic = false): void
7476
$path = $this->adjustPathForDisk($path);
7577
$this->filesystem->put($path, $data);
7678

77-
// Set visibility when a non-AWS-s3, s3-like storage option is in use.
78-
// Done since this call can break s3-like services but desired for other image stores.
79-
// Attempting to set ACL during above put request requires different permissions
80-
// hence would technically be a breaking change for actual s3 usage.
79+
// Set public visibility to ensure public access on S3, or that the file is accessible
80+
// to other processes (like web-servers) for local file storage options.
81+
// We avoid attempting this for (non-AWS) s3-like systems (even in a try-catch) as
82+
// we've always avoided setting permissions for s3-like due to potential issues,
83+
// with docs advising setting pre-configured permissions instead.
84+
// We also don't do this as the default filesystem/driver level as that can technically
85+
// require different ACLs for S3, and this provides us more logical control.
8186
if ($makePublic && !$this->isS3Like()) {
82-
$this->filesystem->setVisibility($path, 'public');
87+
try {
88+
$this->filesystem->setVisibility($path, 'public');
89+
} catch (UnableToSetVisibility $e) {
90+
Log::warning("Unable to set visibility for image upload with relative path: {$path}");
91+
}
8392
}
8493
}
8594

0 commit comments

Comments
 (0)