diff --git a/app/Livewire/Project/Service/FileStorage.php b/app/Livewire/Project/Service/FileStorage.php
index 9ad6e4d2f4..fcbc100a1a 100644
--- a/app/Livewire/Project/Service/FileStorage.php
+++ b/app/Livewire/Project/Service/FileStorage.php
@@ -137,7 +137,7 @@ class FileStorage extends Component
$this->fileStorage->save();
} else {
// Sync from model
- $this->content = $this->fileStorage->content;
+ $this->content = auth()->user()?->can('update', $this->resource) ? $this->fileStorage->content : null;
$this->isBasedOnGit = $this->fileStorage->is_based_on_git;
$this->isPreviewSuffixEnabled = $this->fileStorage->is_preview_suffix_enabled ?? true;
}
diff --git a/resources/views/livewire/project/service/file-storage.blade.php b/resources/views/livewire/project/service/file-storage.blade.php
index 377294ecfa..753b2f6555 100644
--- a/resources/views/livewire/project/service/file-storage.blade.php
+++ b/resources/views/livewire/project/service/file-storage.blade.php
@@ -119,10 +119,9 @@
id="isBasedOnGit">
@endif
-
+
+ The file content can contain secrets.
+
@endcan
@endif
@else
@@ -140,10 +139,16 @@
id="isBasedOnGit">
@endif
-
+ @can('update', $resource)
+
+ @else
+
+ The file content can contain secrets.
+
+ @endcan
@endif
@endif
diff --git a/tests/Feature/Authorization/FileMountContentVisibilityTest.php b/tests/Feature/Authorization/FileMountContentVisibilityTest.php
new file mode 100644
index 0000000000..149406183a
--- /dev/null
+++ b/tests/Feature/Authorization/FileMountContentVisibilityTest.php
@@ -0,0 +1,84 @@
+ 0]);
+
+ $this->team = Team::factory()->create();
+ $this->owner = User::factory()->create();
+ $this->member = User::factory()->create();
+ $this->team->members()->attach($this->owner, ['role' => 'owner']);
+ $this->team->members()->attach($this->member, ['role' => 'member']);
+
+ $server = Server::factory()->create(['team_id' => $this->team->id]);
+ $destination = $server->standaloneDockers()->firstOrFail();
+ $project = Project::factory()->create(['team_id' => $this->team->id]);
+ $environmentId = $project->environments()->firstOrFail()->id;
+
+ $application = Application::factory()->create([
+ 'environment_id' => $environmentId,
+ 'destination_id' => $destination->id,
+ 'destination_type' => $destination->getMorphClass(),
+ ]);
+ $service = Service::factory()->create([
+ 'server_id' => $server->id,
+ 'destination_id' => $destination->id,
+ 'destination_type' => $destination->getMorphClass(),
+ 'environment_id' => $environmentId,
+ ]);
+ $serviceApplication = ServiceApplication::create([
+ 'name' => 'app',
+ 'service_id' => $service->id,
+ ]);
+
+ $this->fileMounts = collect([$application, $serviceApplication])->map(fn ($resource) => LocalFileVolume::create([
+ 'fs_path' => '/data/app/.env',
+ 'mount_path' => '/app/.env',
+ 'content' => 'TOKEN=stored-file-mount-value',
+ 'is_directory' => false,
+ 'is_based_on_git' => false,
+ 'resource_id' => $resource->id,
+ 'resource_type' => $resource->getMorphClass(),
+ ]));
+});
+
+it('keeps file mount content out of member state', function () {
+ $this->actingAs($this->member);
+ session(['currentTeam' => $this->team]);
+
+ foreach ($this->fileMounts as $fileMount) {
+ $component = Livewire::test(FileStorage::class, ['fileStorage' => $fileMount])
+ ->assertSet('content', null)
+ ->assertSee('Hidden (only admins can view)');
+
+ expect(json_encode($component->snapshot).$component->html())->not->toContain('stored-file-mount-value');
+ }
+});
+
+it('keeps file mount content available to an owner', function () {
+ $this->actingAs($this->owner);
+ session(['currentTeam' => $this->team]);
+
+ foreach ($this->fileMounts as $fileMount) {
+ Livewire::test(FileStorage::class, ['fileStorage' => $fileMount])
+ ->assertSet('content', 'TOKEN=stored-file-mount-value');
+ }
+});