AdvancedCustomFields / AdvancedCustomFields/acf
ACF_Rest_Api::initialize() does not return $response on rest_pre_dispatch filter
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
ACF_Rest_Api::initialize() in includes/rest-api/class-acf-rest-api.php (lines 35-52) is registered as a rest_pre_dispatch filter callback but does not return the $response parameter. Both code paths return null implicitly, which overwrites any response (including WP_Error) set by other plugins earlier in the filter chain.
This is a security concern: any plugin using rest_pre_dispatch for authentication can have its error response silently discarded, allowing unauthorized API access.
To Reproduce
Steps to reproduce the behavior:
- Register a
rest_pre_dispatchfilter at priority ≤10 that returns aWP_Errorto block unauthorized requests - ACF's
initialize()also runs at priority 10 viaadd_filter( 'rest_pre_dispatch', array( $this, 'initialize' ), 10, 3 ) - When ACF runs after the security plugin, it receives the
WP_Erroras$responsebut returnsnull(no return statement) - WordPress checks
! empty( $result )inWP_REST_Server::serve_request()— sincenullis empty, the request proceeds as if no error occurred - The REST API responds with 200 instead of the expected 401
Expected behavior
initialize() should return $response to preserve the filter chain, as per WordPress filter contract:
public function initialize( $response, $handler, $request ) {
if ( ! acf_get_setting( 'rest_api_enabled' ) ) {
return $response; // currently: bare `return;`
}
$this->request = new ACF_Rest_Request();
$this->request->parse_request( $request );
$this->register_field();
if ( acf_get_setting( 'rest_api_embed_links' ) ) {
$this->embed_links = new ACF_Rest_Embed_Links();
$this->embed_links->initialize();
}
return $response; // currently: missing
}
Screenshots or Video
N/A — this is a code-level filter issue, not a UI bug.
Code
N/A — no field group export needed. The bug is in ACF core: includes/rest-api/class-acf-rest-api.php lines 35-52.
Version Information:
- WordPress Version: 6.8
- PHP Version: 8.2
- ACF Version: ACF PRO 6.7.0.2
- Browser: N/A (REST API / server-side)
Additional context
- This was previously reported on the ACF Support Forum in April 2024 but remains unresolved :https://support.advancedcustomfields.com/forums/topic/rest_pre_dispatch-not-return-response
- The fix is a 2-line change: replace return; with return $response; on line 37, and add return $response; after line 51
- I'm happy to submit a PR with the fix if the team confirms.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read includes/rest-api/class-acf-rest-api.php around lines 35-52 and the rest_pre_dispatch registration, then trace how WP_REST_Server::serve_request() handles the filter result. Ensure ACF_Rest_Api::initialize() preserves and returns $response on both paths, including WP_Error responses from earlier filters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- api, security
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 90/100