AdvancedCustomFields / AdvancedCustomFields/acf

ACF_Rest_Api::initialize() does not return $response on rest_pre_dispatch filter

Open Beginner friendly
#1,000 1 comment 0 reactions 0 assignees View on GitHub

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:

  1. Register a rest_pre_dispatch filter at priority ≤10 that returns a WP_Error to block unauthorized requests
  2. ACF's initialize() also runs at priority 10 via add_filter( 'rest_pre_dispatch', array( $this, 'initialize' ), 10, 3 )
  3. When ACF runs after the security plugin, it receives the WP_Error as $response but returns null (no return statement)
  4. WordPress checks ! empty( $result ) in WP_REST_Server::serve_request() — since null is empty, the request proceeds as if no error occurred
  5. 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.