wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
701 stars 218 forks source link

[Clear Cache Dashboard button] - White screen after clicking clear cache button #5747

Open rosamillan opened 1 year ago

rosamillan commented 1 year ago

Before submitting an issue please check that you’ve completed the following steps:

Describe the bug white screen appears after clicking the "clear cache button"- in the dashboard. The error appears when the header is "Referrer-Policy: no-referrer"

To Reproduce Steps to reproduce the behavior: For the error to appear, the header "Referrer-Policy: no-referrer" must be present

  1. Go to 'wp-admin/options-general.php?page=wprocket#dashboard'
  2. Click on 'Clear and preload cache'
  3. See the error

Expected behavior

  1. Go to 'wp-admin/options-general.php?page=wprocket#dashboard'
  2. Click on 'Clear and preload cache'
  3. The cache is cleared and the dashboard is visible

Screenshots

  1. The Header is "Referrer-Policy: no-referrer" https://jmp.sh/1skSOtrG
  2. Click on 'Clear and preload cache' button: https://jmp.sh/FRoWYyFw
  3. White Screen appears: https://jmp.sh/mr6EL5Sl

Video provided by lucy (awesome debugging job): https://jumpshare.com/j/5QPVMsRAH2ChG0kT12dQ

Additional context This bug was tested in WPR version 3.12.4 and 3.12.5.1 The issue is resolved when you change the header to: Referrer-Policy: strict-origin-when-cross-origin

Alfonso noticed:

From the toolbar works ok.

Works ok: Clear cache from top menu https://www.domain.com/wp-admin/admin-post.php?action=purge_cache&type=all&_wp_http_referer=%2Fwp-admin%2Foptions-general.php%3Fpage%3Dwprocket&_wpnonce=d4eee5fa26

The only difference found it's the top menu link containing the _wp_http_referer and dashboard button no.

Backlog Grooming (for WP Media dev team use only)

CrochetFeve0251 commented 1 year ago

Scope a solution

A quick fix is to add the referrer to that action. For that we can add the following logic to the renderer:

if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
                $referer = filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL );
                $referer = '&_wp_http_referer=' . rawurlencode( remove_query_arg( 'fl_builder', $referer ) );
            } else {
                $referer = '';
            }

                $url = admin_url( 'admin-post.php?action=' . $action );

                $url .= $referer;

Estimate the effort

Effort XS

sandyfigueroa commented 9 months ago

I have a case in which the exact same issue is happening for the "Clear this cache" button in the page list: image

Adding the "&_wp_http_referer=%2Fwp-admin%2F" to the URL works fine for me.

Case related: https://secure.helpscout.net/conversation/2461303037/465232/ WP Rocket version: 3.15.7

joejoe04 commented 8 months ago

https://secure.helpscout.net/conversation/2523194404/477364 https://beddenspeciaalzaakhendriksen.nl

It looks like I have a case related to this issue but in reverse. In the initial case for this issue, cache clear attempts result in white page due to the "Referrer-Policy: no-referrer" header. In that case, the clear cache link did not include _wp_http_referer=%2Fwp-admin%2Foptions-general.php%3Fpage%3Dwprocket.

However, in my ticket above, the "Referrer-Policy: strict-origin-when-cross-origin" header is set, and the link also does contain the _wp_http_referer=%2Fwp-admin%2Fplugins.php param, but I get a white screen when clearing cache.

If I remove the _wp_http_referer param from the clear cache link, then clearing the cache does work: https://secure.helpscout.net/conversation/2523194404/477364/#thread-7575853068

jekayode commented 2 weeks ago

Related case: White screen when Clear Cache is clicked from Single Edit Post Sidebar:

https://secure.helpscout.net/conversation/2736897712/518288?folderId=8127831