Fix AttachmentController checkPermission not aborting for guests - #3140
Merged
tabuna merged 1 commit intoSep 13, 2026
Conversation
checkPermission() only aborted for an authenticated user who lacked the permission; a guest slipped past the abort_if check and then hit an unguarded Auth::user()->hasAccess() call in the middleware closure, turning into an uncaught 500 instead of a 403. Fixes orchidsoftware#2861
wakqasahmed
force-pushed
the
fix/issue-2861-attachcontroller-guest-permission
branch
from
September 13, 2026 07:30
4b0a7eb to
339093a
Compare
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 #2861
Proposed Changes
checkPermission()inController.phphad two related bugs: the immediateabort_if(Auth::user() !== null && ...)check never fires for a guest, since the guest case short-circuits the&&to false, and the middleware closure itself calledAuth::user()->hasAccess($permission)with no null check, so a guest reaching this controller directly would hit an uncaught "Call to a member function hasAccess() on null" (a 500) instead of a clean 403.abort_unless(Auth::user()?->hasAccess($permission), 403), so both an unauthenticated guest and an authenticated user without the permission get a 403.AttachmentTest.phpcovering a guest upload attempt and an authenticated user without theorchid.attachmentpermission, both hitting the controller directly (bypassing the app's own auth middleware group) so the controller's own check is what's actually being exercised.I ran the new tests against the unfixed code first and got the exact 500 the issue describes (
Call to a member function hasAccess() on null), then confirmed both tests plus the full existing suite (612 tests) pass after the fix.