Repository navigation
Premium Analytics: Limit the subscribers proxy to subscriber counts - #55502
Conversation
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>
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
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:
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. |
Code Coverage SummaryThis 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. 🤷 |
adamwoodnz
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
Fixes STATS-684
Proposed changes
subscribersgroup tosubscribers/counts, the only subscriber endpoint the dashboard reads.subscribers, signed as the site, to any user withview_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.'pattern' => 'counts', aspostsalready does. The pattern is anchored in the route and checked again invalidate_data_endpoint(), so?endpoint=subscriberson an allowed URL is rejected too.data_unsupported_pathscover 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.
wp.apiFetch( { path: '/jetpack-premium-analytics/v1/proxy/v2/subscribers' } ).email_address.rest_no_route(404).wp.apiFetch( { path: '/jetpack-premium-analytics/v1/proxy/v2/subscribers/counts' } ). It still returns the counts on both.Admins keep their subscriber list. The dashboard never read it through this proxy, so only the proxy route closes for admins too:
stats/followers, notsubscribers. A WordPress.com follower shows by name, and an email-only subscriber by email address.wpcom/v2/subscribers/list, Jetpack's admin-only endpoint, not from this proxy.wp.apiFetch( { path: '/jetpack-premium-analytics/v1/proxy/v2/subscribers' } ). As an admin it also fails withrest_no_routeon 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/subscribersreturned 200 with the email addresses. With the fix, it and/v2/subscribers/individualreturn 404,?endpoint=subscribersreturns 400, and/v2/subscribers/countsstill 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/followersandsubscribers/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, fromwpcom/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_Testinprojects/packages/premium-analytics.🤖 Generated with Claude Code