☰
WEB SECURITY / PRACTICE

How to Protect Private WordPress Pages from Cache Leaks

How to Protect Private WordPress Pages from Cache Leaks

Caching makes WordPress faster, but incorrect rules can turn a private page into a publicly accessible one. If a page generated for an authenticated user is then stored in a shared cache, the next visitor may see someone else’s name, cart, personalized blocks, or Elementor content.

The problem is not limited to a caching plugin. Data may be stored at the WordPress, web server, CDN, or even browser-cache level. Protection must therefore be checked across the entire chain: from cookies and PHP sessions to HTTP headers and AJAX requests.

How Private Data Gets into a Shared Cache

A cache stores a ready-made server response so the same page does not have to be generated repeatedly. This is usually safe for a public article. However, an account page, cart, checkout, or other private screen depends on a specific user and cannot be served from one shared cached file.

The most dangerous scenario looks like this: a user logs in to the site, opens a private page, the server generates personalized HTML, and a plugin or CDN stores it without taking cookies into account. The next request to the same URL then receives the already prepared response containing someone else’s data.

A leak may involve more than the complete page. A separate AJAX request may return a user’s name, cart contents, subscription status, or personalized widgets. If that response has public or excessively long caching enabled, it may also be shown to other visitors.

  • a WordPress plugin cache or server-side page cache;
  • a CDN cache on edge servers;
  • a reverse proxy, for example in front of the web server;
  • a browser cache or intermediate proxies;
  • cached JSON responses from APIs and AJAX requests.

Which Pages and Requests Must Be Excluded from Caching

Start by listing URLs that contain or may contain personal data. The exact addresses depend on the theme, WooCommerce, membership system, and site structure, so focus not only on page names but also on how they behave.

The wp-admin area is generally not cached in full. The login, registration, password recovery, user account, cart, checkout, order, and other private post-login pages should likewise be excluded separately.

The rule must apply not only to HTML. If a private endpoint returns JSON or a page fragment, its response must also remain private or not be cached at all.

  • exclude account, cart, checkout, and order-page URLs;
  • do not cache login, registration, or password-recovery pages;
  • disable caching for requests containing WordPress authentication cookies or other session cookies;
  • check endpoints used by the cart, profile, membership features, and Elementor;
  • do not rely only on URL-based exclusions if the same page changes depending on the user.

How to Configure Cache Bypass Using Cookies and Headers

The most reliable general rule is this: if a request contains a cookie indicating authentication or an active user session, the page must not be served from a shared page cache. In WordPress, these are often login-related cookies, but the exact names may vary depending on the configuration and additional plugins.

It is important to distinguish between a cookie that merely exists in the browser and one that changes the response content. Disabling caching for every cookie without analysis can noticeably reduce performance. Ignoring a session cookie, however, can cause a data leak.

For private responses, the server must explicitly tell caches that the responses must not be stored or reused. Cache-Control: private, no-store is commonly used. For especially sensitive responses, this is safer than attempting to purge the cache after every request.

  • check whether the page cache bypasses caching for authenticated users;
  • configure bypass rules for relevant cookies, not just URLs;
  • do not use the Vary header as the only safeguard if the cache is not configured to process it correctly;
  • make sure the CDN does not overwrite private headers with its own rules;
  • for private HTML and JSON, verify the actual response headers rather than relying only on settings in the control panel.
Cache-Control: private, no-store
Pragma: no-cache

Example Web Server Logic

At the Nginx, Apache, reverse-proxy, or CDN level, the rules depend on the specific infrastructure. The general principle is that a request containing an authentication cookie must not read from the cache or write a new response to it. Do not copy a conditional example without adapting it: an error in the syntax or cookie name may either break caching or leave it unsafe.

  • identify which cookies are created after login on your site;
  • add them to the bypass and no-cache conditions;
  • check the CDN and origin-server rules separately;
  • after changing the configuration, restart or verify the service if your platform requires it.

Elementor, AJAX, and Dynamic Widgets

A page created in Elementor does not become public simply because a page builder is being used. The risk appears when a dynamic widget or AJAX handler returns personal data and the response is cached as if it were the same for everyone.

Pay particular attention to widgets that display a user’s name, personalized recommendations, login status, cart contents, group-specific prices, or restricted content. These elements may load after the page opens through a separate request, so checking the HTML alone is not enough.

If a personal block cannot be made fully public, it should be loaded through an uncached request or displayed only after the server verifies the session. Do not hide someone else’s data only with a CSS class: the information may still remain in the HTML or JSON.

  • check the browser’s Network panel while loading a private page;
  • find AJAX and Fetch requests that return personalized values;
  • make sure these responses do not have a public directive or a long max-age value;
  • do not cache JSON simply because the URL looks technical or contains the word ajax;
  • test the scenarios after login, logout, role changes, and cart clearing.

How to Test a Site for Cache Leaks

Testing must imitate a real situation involving two different users. Check not only the home page but also every URL where personalization is expected.

First, create or use two test accounts with different names, roles, or cart contents. Log in with the first account, open the private page several times, and record which data is displayed. Then log out, open the site in another browser or an incognito window, and check the same URL while logged out.

After that, log in with the second account. It must not see the first user’s data either in the HTML or in AJAX responses. Repeat the test after clearing the local cache and also after accessing the URL both with and without parameters.

  • check the site in an incognito window without authentication;
  • use two different accounts and different cart or profile data;
  • inspect response headers such as Age, X-Cache, HIT/MISS, Cache-Control, and similar service fields;
  • open the Network tab in DevTools and check HTML, Fetch, and XHR responses;
  • test mobile and desktop versions if the CDN or server caches them under different rules;
  • after making changes, clear the plugin, server, and CDN caches; otherwise, the test may show an old unsafe response.

Common Configuration Mistakes

The problem is often addressed only partially: a page is excluded from the plugin cache, but the CDN or server-side reverse proxy is forgotten. As a result, the origin already generates the correct response, while the CDN continues to deliver an old copy.

Another mistake is excluding only the account URL while leaving cached the AJAX requests that return its data. It is also dangerous to assume that restricted content is protected when it is merely hidden on the front end or loaded into the page code before access is verified.

Do not treat cache purging as a permanent solution. Purging is necessary after changing rules or updating public content, but it does not replace a correct bypass for private requests.

  • do not cache private pages even for a short period without a clear reason;
  • do not test the protection in only one browser;
  • do not rely on a MISS status without analyzing what will happen with the next request;
  • do not use identical rules for public pages and a personalized account area;
  • after updating the caching plugin, Elementor, or CDN, repeat tests of private scenarios.

Frequently asked questions

Do I need to disable caching completely on a WordPress site?

No. Public pages, images, CSS, and JavaScript can be cached. You only need to exclude private pages, authenticated requests, and responses that depend on the user.

Is excluding the account page from the cache enough?

Not always. Personal data may be loaded through AJAX requests or an API. Check all requests in DevTools and configure private headers or bypass rules for them.

Does incognito mode protect against a CDN leak?

Incognito mode helps check what an unauthenticated visitor sees without local cookies, but it does not provide protection by itself. If the CDN serves someone else’s cached page, incognito mode only helps detect the issue.

What should I do if users still see old data after changing the rules?

Clear the plugin, web server, reverse proxy, and CDN caches. Then check the response headers and repeat the test with two accounts. If the problem remains, look for another caching layer or an incorrect cookie-based bypass.

Can I use Cache-Control: no-cache instead of no-store?

These directives are not identical. no-cache allows a response to be stored but requires revalidation before it is used. For sensitive private data, private, no-store is generally safer when it is compatible with your site’s logic.

Conclusion

Protecting private pages from cache leaks requires coordinated rules at the WordPress, web server, CDN, and browser levels. Disable caching for the account area, login, cart, checkout, authenticated cookies, and personalized AJAX responses.

After every change, clear all cache layers and test the site while logged out and with two different accounts. Pay particular attention to Elementor and dynamic widgets: personal data must not enter a shared HTML or JSON cache.

← All web security materials