Repository navigation
fix: Use signed URLs for attachments on private disks (#126) - #127
Merged
Merged
Conversation
getUrl() always called Storage::url(), which returns an unsigned URL. On a private disk such as Laravel 11+'s `local` disk, the framework's storage route rejects unsigned requests, so every attachment link returned 403 (404 in production). Disks not configured with `'visibility' => 'public'` now get a temporaryUrl() that expires after `attachments.url_expiration` minutes (default 30). Disks that cannot sign URLs keep the plain URL. Fixes #126
testbench 9 (Laravel 11) ships a local disk without 'serve' => true, so the signed storage route was never registered and the private-disk attachment tests failed. Enable it to match the Laravel 11+ skeleton.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #126
Problem
CommentAttachment::getUrl()always calledStorage::disk($disk)->url($path), which returns an unsigned URL. Laravel 11+ serves the privatelocaldisk ('serve' => true) through its/storage/{path}route, which aborts unless the request has a valid signature or the disk's visibility ispublic. So withCOMMENTIONS_ATTACHMENTS_DISK=local, every attachment link returned 403, or 404 in production. A private S3 bucket fails the same way.Fix
'visibility' => 'public'now getstemporaryUrl(). A missing visibility counts as private, the same rule Laravel's own file serving uses.attachments.url_expirationconfig option, in minutes (COMMENTIONS_ATTACHMENTS_URL_EXPIRATION, default30).providesTemporaryUrls()is false, e.g. alocaldisk withoutserve) still get the plainurl(), so nothing throws.Behavior change
An S3 disk with no
visibilitykey now gets signed URLs. If that bucket is actually public through a bucket policy, the links still work, but they now expire. Setting'visibility' => 'public'on the disk brings back plain URLs.Not in scope
A signed URL isn't tied to a user, so anyone holding the link can open the file until it expires. Checking per user whether someone can see an attachment would need an authorized download route, which can come as a follow-up.
Tests
localdisk (real, not faked) produces a URL that the framework's storage route serves with 200. Before the fix this returned 403, the same as the issue.expirestimestamp followsurl_expiration../vendor/bin/pest: 186 passed.composer lint:checkpasses.composer static-analysisreports the same 7 errors asmain, all intests/Livewire/CommentReactionTest.php.