Repository navigation
fix(admin-edit-comms): run not-found guard before permission check (#1410) - #1415
Merged
Merged
Conversation
…1410) Closes #1410. The page handler at admin.edit.comms.php was checking `HasAccess(...)` (which dereferences `$res['aid']` / `$res['gid']`) BEFORE the `if (!$res)` not-found guard 130 lines further down. On a request for a non-existent cid, `$res` was false and `$res['aid']` evaluated to null under PHP 8.x (with an `E_WARNING: Trying to access array offset on value of type bool`; PHP 9 will turn the warning into a TypeError). The perm check then read "you can't edit a block owned by null" and surfaced the misleading "You don't have access to this!" toast instead of the correct "There was an error getting details. Maybe the block has been deleted?" toast. Moves the `if (!$res)` block + the `$pagelink` computation it depends on to immediately after the SELECT, before the perm check. Result is a 34-line relocation: same `Toast::emit` + `PageDie` shape, just earlier in the file so the bug condition can't fire. The comment above the moved block documents the new ordering rationale. Sister `admin.edit.ban.php` was already correctly ordered (its `if (!$res)` runs before `$canEditBan = HasAccess(...) || …`), so the bug was localised to admin.edit.comms.php. No leakage to non-Owner callers (the perm check still rejects real cids the caller doesn't own); the audit-log trail is unchanged (neither branch logs to `:prefix_log` — the issue body's "both branches call Log::add(LogType::Warning, ...)" claim was inaccurate, but the swap preserves whatever each branch did, which is nothing in this case). Regression guard: `AdminEditCommsCheckOrderTest.php` pins the order-of-guards contract directly against the file source. Static- shape tests are the right tool here because every code path that would exercise the bug runtime-wise calls `PageDie()` (`exit;`), which breaks PHPUnit's `RunInSeparateProcess` serializer — same constraint sister `ToastEmitRegressionTest.php` documents. Four tests pin: (1) the not-found guard runs before the perm check, (2) the not-found body stays correct, (3) the perm check is not weakened (both `EditOwnBans` + `EditGroupBans` arms preserved), and (4) the not-found branch still terminates via `PageDie()` after the toast emit so the buggy `$res['aid']` read never runs on bad-cid. Surfaced by the #1403 toast-lift adversarial review.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
Swaps the order of two guards in
web/pages/admin.edit.comms.php. The not-found check now runs before the permission check, so a request for a non-existent comm-block cid surfaces the correct "There was an error getting details. Maybe the block has been deleted?" toast instead of the misleading "You don't have access to this!" toast.Net change is a 34-line relocation of the existing
if (!$res) { Toast::emit(...); PageDie(); }block (plus the$pagelinkit depends on) from its previous spot ~130 lines below the SELECT to immediately after the SELECT, ahead of the perm check. Same shape, just earlier in the file. The comment above the moved block documents the new ordering rationale.Motivation and Context
Closes #1410. Pre-fix the perm check at line ~42 read
$res['aid']/$res['gid']BEFORE theif (!$res)not-found guard 130 lines down. On a bad cid,$reswasfalseand$res['aid']evaluated tonull(PHP 8.x emitsE_WARNING: Trying to access array offset on value of type bool; PHP 9 will turn the warning into aTypeError). Thenull != $userbank->GetAid()comparison then tripped the deny-access branch, so the user got the wrong toast AND the perm-flavored body worked as a side-channel for "does this cid exist?" enumeration.Surfaced by the #1403 toast-lift adversarial review.
Sister
admin.edit.ban.phpwas already correctly ordered (itsif (!$res)at line 82 runs before$canEditBan = HasAccess(...) || ...at line 87) — the bug was localised to admin.edit.comms.php. Neither branch of the comms file logged to:prefix_logbefore the swap; that contract is unchanged (the issue body's "both branches callLog::add(LogType::Warning, ...)" claim was inaccurate, but the swap preserves whatever each branch did, which is nothing in this case).How Has This Been Tested?
./sbpp.sh phpstan— clean./sbpp.sh test --filter=AdminEditCommsCheckOrder— 4 new tests, 18 assertions, all pass./sbpp.sh test— full suite green (693 tests, 2764 assertions)./sbpp.sh ts-check— clean./sbpp.sh composer api-contract— no diffThe new
AdminEditCommsCheckOrderTest.phppins four static-shape contracts against the source file:if (!$res)block must precede theHasAccess(WebPermission::mask(WebPermission::Owner, WebPermission::EditAllBans))check. Directly catches the admin.edit.comms.php runs the permission check before the not-found guard, surfacing the wrong error #1410 bug condition.HasAccess(WebPermission::EditOwnBans)/HasAccess(WebPermission::EditGroupBans)arms so a future cleanup can't accidentally drop the perm check entirely (the task description called this regression out explicitly).PageDie()runs after theToast::emitso the buggy$res['aid']deref in the perm check (and the inline<script>further down) never runs on the bad-cid path.Static-shape tests are the right tool here because every runtime path that exercises the bug calls
PageDie()(exit;), which breaks PHPUnit'sRunInSeparateProcessserializer — same constraint sisterToastEmitRegressionTest.phpdocuments at its file docblock. The runtime side is already covered by the existingweb/tests/e2e/specs/flows/admin-edit-comms-toast.spec.tsE2E spec, which doesn't have the serializer constraint.Screenshots (if appropriate):
User-visible behavior change only on the bad-cid path:
E_WARNINGin logsTypes of changes
Checklist:
Refs:
web/pages/admin.edit.comms.php— single-file fixweb/tests/integration/AdminEditCommsCheckOrderTest.php— regression guardI have read the CLA Document and I hereby sign the CLA