google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.25k stars 291 forks source link

Limit shared requests for AdSense reports to metrics and dimensions used by the Site Kit dashboard #5712

Closed felixarntz closed 2 years ago

felixarntz commented 2 years ago

Similar to #5711: As an additional security & privacy requirement, the report endpoints should only allow for specific metrics and dimensions to be requested when used by a user with shared access - namely those metrics and dimensions that are also used by Site Kit (so that users with shared access can't just craft any report request they like).

While this is still not 100% bullet proof, it is more compliant with really only sharing data that the Site Kit dashboard also shows anyway.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

In includes/Modules/AdSense.php:

Test Coverage

QA Brief

Be sure to test with a other real AdSense metrics and dimensions, see: https://developers.google.com/adsense/management/metrics-dimensions These should be requestable as the module owner but only the valid ones above should be requestable in a shared context.

Changelog entry

felixarntz commented 2 years ago

cc @ThierryA @marrrmarrr @aaemnnosttv

tofumatt commented 2 years ago

IB ✅

felixarntz commented 2 years ago

@techanvil @tofumatt Since the metrics and dimensions are not in the IB, please make sure to encompass in the code review or QA here to double-check the codebase for whether the implementation actually includes all the necessary metrics and dimensions (and not more).

wpdarren commented 2 years ago

QA Update: ⚠️

Make some requests with invalid AdSense report metrics and dimensions and verify that they return a 400 error with an error message in the format Unsupported (metric|dimension)/s requested: SOME_METRIC

@techanvil I do see the error message but it is returning a 500 error. From the QAB, it should be 400, so just checking.

image

Verified:

Checked that there are no errors for the AdSense report requests in the Network tab, i.e. requests with the path /wp-json/google-site-kit/v1/modules/adsense/data/report.

Screenshots ![image](https://user-images.githubusercontent.com/73545194/187207919-37f7c402-afb1-43b2-a020-ec81730e0670.png) ![image](https://user-images.githubusercontent.com/73545194/187207904-b6087f42-23d0-44a2-9c35-6ad5b12a0d78.png)
aaemnnosttv commented 2 years ago

@wpdarren the status code changed from what was in the IB and looks like the QAB wasn't updated, but it should be a 500 in this case.

I should note that requesting dummy metrics will error in a non-shared context as well with a slightly different message ("Unknown metric(s)" I believe), so it's important to test with real metrics which are outside of the allowed metrics for SK in both shared and non-shared contexts to see that it works for the module owner but not for a shared user.

You can see all the available metrics and dimensions for AdSense here: https://developers.google.com/adsense/management/metrics-dimensions

The QAB mentions which ones are allowed in a shared context, although again, they should still work outside of a shared context. Let me know if you have any questions about this.

wpdarren commented 2 years ago

QA Update: ⚠️

I am trying to find a site that I have access to live AdSense data. For some reason I am unable to see data from our usual testing site. Will pick this up on Monday and get moved forward.

wpdarren commented 2 years ago

QA Update: ✅

Verified:

Viewing the shared dashboard

Viewing as main admin

As main admin user when viewing the dashboard, the Performance over the last X days and Top Earning Pages widgets still work as expected within Monetization. There are no errors for the AdSense report requests in the Network tab

Screenshots ![image](https://user-images.githubusercontent.com/73545194/188440876-32600f6f-e425-44d5-abe9-44957930a66a.png) ![image](https://user-images.githubusercontent.com/73545194/188440901-636e27b4-d5b2-4a49-abf5-b3e638bf916c.png) ![image](https://user-images.githubusercontent.com/73545194/188440919-0102b9e8-0bf9-45da-981b-63fc8a01499e.png) ![image](https://user-images.githubusercontent.com/73545194/188440944-2a4be647-000f-4038-b0cf-c36b521a5f45.png) ![image](https://user-images.githubusercontent.com/73545194/188440971-99765a2a-58cc-4ad0-965e-a9c43505d23c.png) ![image](https://user-images.githubusercontent.com/73545194/188440987-5229b77b-efd9-4bce-85a8-c5a66b479062.png)
aaemnnosttv commented 2 years ago

Did a few extra checks in the context of the module owner and a view-only user. Confirmed non-allowlisted metrics and dimensions raised errors for the view-only user but not the owner, as expected 👍