Skip to content

Add compatibility release for the site token header rollout - #805

Open
jdevalk wants to merge 6 commits into
developfrom
codex/token-header-compatibility
Open

jdevalk wants to merge 6 commits into
developfrom
codex/token-header-compatibility

Conversation

@jdevalk

@jdevalk jdevalk commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

The server must be able to switch to X-Progress-Planner-Token while installed plugins still accept its existing URL-based requests. This is the temporary compatibility stage, based directly on develop, to ship before the strict security branches.

  • Accept the custom header on /get-stats and /tasks.
  • Preserve legacy statistics URLs and the token parameter.
  • Give the custom header precedence: an empty or wrong header cannot fall back to a valid URL token.
  • Compare credentials exactly; strip the legacy token/ prefix only in the URL fallback.
  • Add 29 REST authentication cases covering both transports, header precedence, malformed input and bearer-only rejection.
  • Document deployment order and rollback in README.

Rollout: distribute this plugin first and verify each site is ready; deploy ProgressPlanner/progress-planner-server#68 plus ProgressPlanner/progress-planner-server#69 together; then ship plugin #802 plus #803 to remove URL authentication. The strict branches overlap these REST changes and must be reconciled before their later release. Existing keys are unchanged.

Validation: all 22 GitHub checks pass on c83ea1ab, including the seven PHP/WordPress integration jobs, coverage, Plugin Check, both browser suites, and upgrade compatibility. PHPUnit passes with 501 tests / 1,460 assertions in single-site and multisite runs, including the 29 new authentication cases. Changed-file PHPCS and PHPStan also pass in an isolated, network-disabled local container. The branch is conflict-free against develop. No release has been published or deployed.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Test on Playground
Test this pull request on the Playground
or download the zip

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
10 0 10

⚠️ Warnings (10)

📁 classes/suggested-tasks/data-collector/class-unpublished-content.php (1 warning)
📍 Line 🔖 Check 💬 Message
103 WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information.
📁 classes/suggested-tasks/providers/class-content-review.php (4 warnings)
📍 Line 🔖 Check 💬 Message
232 WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information.
377 WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information.
381 WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information.
388 WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information.
📁 classes/activities/class-query.php (2 warnings)
📍 Line 🔖 Check 💬 Message
71 PluginCheck.Security.DirectDB.UnescapedDBParameter Unescaped parameter $table_name used in $wpdb->query()\n$table_name assigned unsafely at line 58.
163 PluginCheck.Security.DirectDB.UnescapedDBParameter Unescaped parameter $where_args used in $wpdb->get_results()\n$where_args assigned unsafely at line 153.
📁 classes/suggested-tasks/data-collector/class-terms-without-posts.php (1 warning)
📍 Line 🔖 Check 💬 Message
120 PluginCheck.Security.DirectDB.UnescapedDBParameter Unescaped parameter $query used in $wpdb->get_results()\n$query assigned unsafely at line 118.
📁 classes/suggested-tasks/data-collector/class-yoast-orphaned-content.php (1 warning)
📍 Line 🔖 Check 💬 Message
111 PluginCheck.Security.DirectDB.UnescapedDBParameter Unescaped parameter $query used in $wpdb->get_row()\n$query assigned unsafely at line 98.
📁 classes/suggested-tasks/data-collector/class-terms-without-description.php (1 warning)
📍 Line 🔖 Check 💬 Message
108 PluginCheck.Security.DirectDB.UnescapedDBParameter Unescaped parameter $query used in $wpdb->get_results()\n$query assigned unsafely at line 106.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

✅ Code Coverage Report

Metric Value
Total Coverage 35.14% 📉
Base Coverage 35.07%
Difference 📈 0.07%

⚠️ Coverage below recommended 40% threshold

🎉 Great job maintaining/improving code coverage!

📊 File-level Coverage Changes (1 files)

📉 Coverage Decreased

Class Before After Change
Progress_Planner\Rest\Base 100.00% 98.21% -1.79%
ℹ️ About this report
  • All tests run in a single job with Xdebug coverage
  • Security tests excluded from coverage to prevent output issues
  • Coverage calculated from line coverage percentages

With the X-Progress-Planner-Token header every caller requests the same
/get-stats and /tasks URL. WordPress sends no-cache headers only to logged-in
users, and the server is not logged in, so a page cache could store an
authenticated response and serve it to anyone, or hand the server stale data.
LiteSpeed Cache caches REST responses for guests by default for seven days.

Send Cache-Control: no-store, private on every response from these routes,
including rejected ones and the legacy URLs, and call LiteSpeed Cache's
litespeed_control_set_nocache hook because its own cache header overrides
the standard one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ilicfilip added a commit that referenced this pull request Nov 17, 2026
With the X-Progress-Planner-Token header every caller requests the same
/get-stats and /tasks URL. WordPress sends no-cache headers only to logged-in
users, and the server is not logged in, so a page cache could store an
authenticated response and serve it to anyone, or hand the server stale data.
LiteSpeed Cache caches REST responses for guests by default for seven days.

Send Cache-Control: no-store, private on every response from these routes,
including rejected ones, and call LiteSpeed Cache's
litespeed_control_set_nocache hook because its own cache header overrides
the standard one. Same change as on #805.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ilicfilip

Copy link
Copy Markdown
Collaborator

Pushed c1131d8: keep /get-stats and /tasks responses out of caches.

Why. Before this PR the token was part of the URL (/get-stats/token/<key>, /tasks?token=<key>), so a cached response could only be fetched again with the secret URL. With X-Progress-Planner-Token, every caller requests the same URL. The plugin sent no cache headers, and WordPress sends no-cache headers only to logged-in users; the server is not logged in. Checked on a local site with this branch: a header-authenticated GET /get-stats returned 200 with no Cache-Control at all. A page cache that stores it would:

  • serve the site's stats (pending updates, plugins, activity, badges) or task list to anyone who requests the URL;
  • return stale stats to the server. LiteSpeed Cache, for example, caches REST responses for guests by default (cache-rest: 1) for 7 days (cache-ttl_rest: 604800).

What changed. Rest\Base::prevent_caching() on rest_post_dispatch, for the endpoint's own route and the routes below it:

  • sends Cache-Control: no-store, no-cache, must-revalidate, max-age=0, private and an Expires in the past;
  • calls do_action( 'litespeed_control_set_nocache', … ). LiteSpeed Cache sends its own cache header, which overrides the standard one, and this is its public API to opt a response out.

Each endpoint sets its route through a ROUTE constant (/get-stats, /tasks).

Cases covered

  • Accepted requests and rejected ones (401 for a missing, empty or wrong token) both get the headers, so an error page can't be cached in place of the real answer either.
  • Legacy URLs (/get-stats/token/<key>, /get-stats/<key>, ?token=) and the ?rest_route= form the server uses.
  • Not touched: core routes (/wp/v2/posts), other plugin routes (/progress-planner/v1/recommendations), look-alike routes (/get-stats-extra, /tasks-extra), and one endpoint's filter on the other endpoint's route.

Verified

  • All 29 auth cases in Rest_Token_Compatibility_Test now also assert the headers and the LiteSpeed signal.
  • New tests check that the filter is registered and that other routes are left alone.
  • PHPUnit (single site and multisite), composer check-cs and PHPStan pass locally, and all 22 GitHub checks pass on c1131d8.
  • curl against a local site on this branch: 200 and 401 on both endpoints, the legacy path and the ?rest_route= form all carry Cache-Control: no-store, …, private; /wp/v2/posts is unchanged.
  • Not verified: LiteSpeed actually honouring the hook. That needs a LiteSpeed server, and the local sites run nginx.

The server side adds a second layer in ProgressPlanner/progress-planner-server#69: a random query argument on every stats request, for caches that ignore headers. The same plugin change is on #803, so it isn't lost when the strict branches replace these REST changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants