Fix fatal in role_can_view() when cap check fires before init - #1963
Open
andreilupu wants to merge 1 commit into
Open
Fix fatal in role_can_view() when cap check fires before init#1963andreilupu wants to merge 1 commit into
andreilupu wants to merge 1 commit into
Conversation
The user_has_cap/role_has_cap filters are registered in the Admin constructor, but the Settings object they dereference is only constructed in Plugin::init() on init priority 9. Any capability check for view_stream between plugins_loaded and init 9 — security/firewall plugins evaluating rules on plugins_loaded do exactly this — reaches role_can_view() with a null options chain, and in_array() with a null haystack is an uncaught TypeError on PHP 8+, fataling wp-admin and admin-ajax for every logged-in user. Null-coalesce the options access and deny access during the pre-init window instead of fataling. Adds regression tests for both the early (denied, no fatal) and normal (granted) paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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 #1962.
The
user_has_cap/role_has_capfilters are registered in theAdminconstructor, but theSettingsobject they dereference is only constructed inPlugin::init()oninitpriority 9. Any capability check forview_streambetweenplugins_loadedandinit9 (e.g. a security plugin evaluating firewall rules onplugins_loaded) reachesrole_can_view()with a null options chain, andin_array()with anullhaystack fatals on PHP 8+ — taking downwp-adminandadmin-ajax.phpfor every logged-in user.This PR null-coalesces the options access in
role_can_view()and denies access during the pre-initwindow instead of fataling. Post-initbehavior is unchanged. Includes regression tests for both paths (early check denied without fatal, allowed role still granted the cap).Checklist
contributing.md).Release Changelog
TypeErrorinrole_can_view()when theview_streamcapability is checked beforeinitpriority 9 (e.g. by security/firewall plugins onplugins_loaded) on PHP 8+.