Skip to content

Read the site token from X-Progress-Planner-Token instead of Authorization - #803

Open
ilicfilip wants to merge 2 commits into
codex/security-review-fixesfrom
filip/token-header
Open

ilicfilip wants to merge 2 commits into
codex/security-review-fixesfrom
filip/token-header

Conversation

@ilicfilip

@ilicfilip ilicfilip commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #802. Companion server change: ProgressPlanner/progress-planner-server#69.

The site token moves from Authorization: Bearer <token> to a dedicated X-Progress-Planner-Token header.

Why: bearer-auth plugins (for example JWT Authentication for WP REST API, about 50,000 installs) decode every Authorization: Bearer header on REST requests. When decoding fails they return their own error from rest_pre_dispatch, before our permission check runs, so stats and task sync would silently stop on those sites. Apache also doesn't strip a custom header, so the getallheaders() fallback from #802 is removed.

Changes

  • classes/rest/class-base.php: permissions_check() reads only X-Progress-Planner-Token. A Bearer header is ignored, and URL tokens are still rejected.
  • Tests and the e2e API client switch to the new header. A new test checks that a Bearer token alone does not authenticate.

Verified

  • Full PHPUnit suite passes (479 tests, including the integration tests); phpcs and PHPStan are clean.
  • Over HTTP on a local Valet site: the new header returns 200, while a Bearer header or a wrong token returns 401.

If this is rejected, close it together with the matching server PR; #802 stays as is.

…ation

Bearer-auth plugins such as JWT Authentication for WP REST API decode every
Authorization: Bearer header and reject the request before our permission
check runs, so stats and task sync would fail on those sites. A dedicated
header avoids that, and Apache does not strip it, so the getallheaders()
fallback is no longer needed.

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

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions

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-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.
📁 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-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.

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

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Code Coverage Report

Metric Value
Total Coverage 36.98% 📉
Base Coverage 36.95%
Difference 📈 0.03%

⚠️ 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 96.77% 94.59% -2.18%
ℹ️ 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 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 Author

Pushed ffda13a: keep /get-stats and /tasks responses out of caches. This is the same change as on #805 (see the comment there for the full reasoning), ported here so the strict branch doesn't lose it when the two are reconciled.

Why. With header-only authentication every caller requests the same /get-stats and /tasks URL. The plugin sent no cache headers, and WordPress sends no-cache headers only to logged-in users; the server is not logged in. A page cache could store an authenticated response and serve the site's stats or tasks to anyone, or return stale stats to the server. LiteSpeed Cache caches REST responses for guests by default, for 7 days.

What changed. Rest\Base::prevent_caching() on rest_post_dispatch sends Cache-Control: no-store, no-cache, must-revalidate, max-age=0, private plus an Expires in the past, and calls LiteSpeed Cache's litespeed_control_set_nocache hook, because its own cache header overrides the standard one. Each endpoint names its route through a ROUTE constant.

Cases covered (new Rest_Prevent_Caching_Test, 12 cases, real routing and authentication)

  • /get-stats and /tasks, each accepted (200), with a wrong token (401) and with no token (401): all get the headers and the LiteSpeed signal.
  • Not touched: core routes, other plugin routes, look-alike routes (/get-stats-extra, /tasks-extra), and one endpoint's filter on the other endpoint's route.
  • The filter is registered when the plugin boots.

Verified

  • PHPUnit (single site and multisite), composer check-cs and PHPStan pass locally, and all 22 GitHub checks pass on ffda13a.
  • curl against a local site on this branch: 200 and 401 on both endpoints and the removed legacy path (404) all carry Cache-Control: no-store, …, private; /wp/v2/posts is unchanged.
  • Not verified: LiteSpeed honouring the hook, which needs a LiteSpeed server.

Merge order is unchanged by this commit: #805 first, then server #68 and #69, then #802 and #803. ProgressPlanner/progress-planner-server#69 now also falls back to the legacy URL for sites on older plugins, so this strict branch no longer needs every site updated before the server switches.

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.

1 participant