Skip to content

Fix AttachmentController checkPermission not aborting for guests - #3140

Merged
tabuna merged 1 commit into
orchidsoftware:masterfrom
wakqasahmed:fix/issue-2861-attachcontroller-guest-permission
Sep 13, 2026
Merged

tabuna merged 1 commit into
orchidsoftware:masterfrom
wakqasahmed:fix/issue-2861-attachcontroller-guest-permission

Conversation

@wakqasahmed

Copy link
Copy Markdown
Contributor

Fixes #2861

Proposed Changes

  • checkPermission() in Controller.php had two related bugs: the immediate abort_if(Auth::user() !== null && ...) check never fires for a guest, since the guest case short-circuits the && to false, and the middleware closure itself called Auth::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.
  • Collapsed both into a single null-safe check inside the middleware closure using abort_unless(Auth::user()?->hasAccess($permission), 403), so both an unauthenticated guest and an authenticated user without the permission get a 403.
  • Added two feature tests to AttachmentTest.php covering a guest upload attempt and an authenticated user without the orchid.attachment permission, 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.

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
wakqasahmed force-pushed the fix/issue-2861-attachcontroller-guest-permission branch from 4b0a7eb to 339093a Compare September 13, 2026 07:30
@tabuna
tabuna merged commit faf4bb0 into orchidsoftware:master Sep 13, 2026
29 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

AttachmentController checkPermission issue

2 participants