Skip to content

Premium Analytics: Limit the subscribers proxy to subscriber counts - #55502

Merged
louwie17 merged 1 commit into
trunkfrom
fix/premium-analytics-subscribers-proxy-counts-only
Nov 27, 2026
Merged

louwie17 merged 1 commit into
trunkfrom
fix/premium-analytics-subscribers-proxy-counts-only

Conversation

@louwie17

@louwie17 louwie17 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes STATS-684

Proposed changes

  • Limit the Premium Analytics data proxy's subscribers group to subscribers/counts, the only subscriber endpoint the dashboard reads.
  • Before this change, the proxy forwarded every path under subscribers, signed as the site, to any user with view_stats. On a site that lets Editors or Authors view Stats, such a user could fetch the full subscriber list with every subscriber's email address. Classic Stats (stats-admin) only ever gave those users the counts.
  • The group now carries 'pattern' => 'counts', as posts already does. The pattern is anchored in the route and checked again in validate_data_endpoint(), so ?endpoint=subscribers on an allowed URL is rejected too.
  • Two rows in data_unsupported_paths cover the list and a single-subscriber path. Both fail without the fix.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No. It removes access to data the dashboard never used.

Testing instructions

You need a connected site with at least one email subscriber.

  1. As an admin, allow Editors to view Stats (Stats settings › "Allow stats reports to be viewed by").
  2. Log in as an Editor and open the Stats dashboard.
  3. In the browser console, run wp.apiFetch( { path: '/jetpack-premium-analytics/v1/proxy/v2/subscribers' } ).
    • On trunk, it resolves with the subscriber list, including email_address.
    • On this branch, it fails with rest_no_route (404).
  4. Run wp.apiFetch( { path: '/jetpack-premium-analytics/v1/proxy/v2/subscribers/counts' } ). It still returns the counts on both.
  5. Open the Subscribers tab. The subscriber totals still load.
  6. Remove Editors from the Stats roles again.

Admins keep their subscriber list. The dashboard never read it through this proxy, so only the proxy route closes for admins too:

  1. Log in as an admin and open the Stats dashboard's Subscribers tab.
    • Latest subscribers lists the subscribers. It reads stats/followers, not subscribers. A WordPress.com follower shows by name, and an email-only subscriber by email address.
    • The subscriber totals load.
  2. Click Manage subscribers on the Latest subscribers widget. Jetpack › Newsletter › Subscribers opens and lists every subscriber with their email address. It loads from wpcom/v2/subscribers/list, Jetpack's admin-only endpoint, not from this proxy.
  3. In the console, run wp.apiFetch( { path: '/jetpack-premium-analytics/v1/proxy/v2/subscribers' } ). As an admin it also fails with rest_no_route on this branch. That is expected, since nothing calls it.

I checked steps 3 and 4 on a local Docker site through the REST server (rest_do_request()), as an admin and as an Editor with Stats access. The proxy was forwarding to WordPress.com. On trunk, /v2/subscribers returned 200 with the email addresses. With the fix, it and /v2/subscribers/individual return 404, ?endpoint=subscribers returns 400, and /v2/subscribers/counts still returns 200. I did not repeat steps 3 and 4 in the browser.

For step 7, I loaded the Subscribers tab as an admin in the browser on trunk: Latest subscribers rendered from stats/followers and subscribers/counts. With the fix, both requests still returned 200 for an admin through the REST server. For step 8, I clicked through in the browser as an admin. Newsletter › Subscribers listed both subscribers with their email addresses, from wpcom/v2/subscribers/list, which this PR does not touch. The test site has only WordPress.com followers, so I could not see an email-only subscriber's row in Latest subscribers.

Unit tests: composer phpunit -- --filter Api_Proxy_Controller_Test in projects/packages/premium-analytics.

🤖 Generated with Claude Code

The proxy forwarded every path under `subscribers`, signed as the blog,
to anyone with `view_stats`. The dashboard reads only `subscribers/counts`,
but a Stats reader who is not an admin could also fetch the subscriber
list, with every subscriber's email address. Classic Stats exposes only
the counts to those users.

Constrain the group with `pattern => 'counts'`, as `posts` already is.

STATS-684

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@louwie17
louwie17 requested a review from a team as a code owner November 26, 2026 14:07
@louwie17 louwie17 self-assigned this Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/premium-analytics-subscribers-proxy-counts-only branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/premium-analytics-subscribers-proxy-counts-only

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Plugin] Stats Data [Tests] Includes Tests Docs labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: December 8, 2026
    • Code freeze: December 7, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Premium Analytics plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Stats Data plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@adamwoodnz adamwoodnz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for closing this off! @louwie17 I traced every caller of the subscribers prefix and subscribers/counts in the subscribers query is the only one, so nothing on the dashboard loses data. The anchored match in validate_endpoint() plus the existing .. and charset guards leave no way past it, and the two rejection cases you added cover both the bare prefix and a sub-path. I read this rather than running the PHP suite locally, so I'm leaning on CI for that. 🚢

@Nikschavan Nikschavan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix. I removed the counts pattern locally, and both new rows in data_unsupported_paths went red. I left one non-blocking note about stats/followers for a follow-up.

'subscribers' => array( 'capability' => 'view_stats' ),
'subscribers' => array(
'capability' => 'view_stats',
// Counts only: the subscriber list carries every subscriber's email address.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not from this PR, but stats/followers also returns subscriber email addresses to the same view_stats users. On a local site, an Editor with Stats access got every email-only subscriber's address in label from stats/followers?type=email&max=100&page=1, and page walks the rest of the list. Classic Stats allows the same through get_stats_resource(), so I am fine with this as a follow-up. Could you open an issue for it under STATS-684?

@louwie17
louwie17 merged commit 835466f into trunk Nov 27, 2026
106 of 107 checks passed
@louwie17
louwie17 deleted the fix/premium-analytics-subscribers-proxy-counts-only branch November 27, 2026 08:36
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Review This PR is ready for review. labels Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs [Package] Premium Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Plugin] Stats Data [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants