-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix OAuth callback logic to not run before WordPress login redirect #2935
Comments
@eugene-manuilov (or who is taking over this one): Rather than implementing what WordPress already offers, it would be a cleaner solution to change the hook used to something more appropriate - like @ivankruchkoff Assigning to you for iteration, since you had already assigned to yourself (maybe accidentally?) - feel free to hand over to someone else if applicable. |
There are two things here to update:
|
To repro the second scenario as it currently works, reset your site |
@ivankruchkoff Great catch getting around the nonce problem, relying on a temporary user option sounds great. One point of feedback:
Maybe better to always delete the current user proxy nonce once they have received the access token? (i.e. before or during |
@felixarntz two changes,
First time: {
"action": "googlesitekit_proxy_setup",
"nonce": "d0f28c48a4"
} Second time: {
"action": "googlesitekit_proxy_setup",
"googlesitekit_code": "sitekit-<SNIP>",
"googlesitekit_site_code": "4/0AY<SNIP>",
"nonce": "d0f28c48a4"
} |
@ivankruchkoff The second change shouldn't be necessary, as that function already accounts for when one of the values is empty / not set. |
Updated |
After deleting the user meta proxy nonce, it's still recreated every time we view the dashboard due to https://github.com/google/site-kit-wp/blob/d63868a5a/includes/Core/Authentication/Authentication.php#L700 So in essence we always have a |
@ivankruchkoff Ah good catch! Maybe we don't actually need that anymore - @aaemnnosttv can you think of any reason why that's still there? I thought we now create the real proxy URLs on the server on demand, so I'd think the proxy nonce (and some of the other data) is no longer needed on the client and maybe shouldn't be there anymore. |
@felixarntz we do create real proxy URLs on demand now which we need to do to make the URL available via the datastore. This doesn't currently create a persistent nonce though, I think the problem is related to a change in the PR that perhaps should not have been made. @ivankruchkoff – you updated the More importantly though, I'm not really sure we need to introduce a persistent nonce again (we had something like this a long time ago as well). The ACs state that "when going through the Site Kit setup flow and logging yourself out of the site (e.g. in another tab), the flow should still work successfully (after having been prompted to re-login)." So if the nonce verification fails because the nonce was created for a different session, we could simply provide a retry link with a fresh nonce when it fails. WP does the same thing for some actions. E.g. logout: The result would be one more click in this edge case rather than adding a persistent nonce and then doing a less-secure simple string comparison on them. We would still check the user has permission to navigate to the proxy in |
@ivankruchkoff – after discussing with @felixarntz, we've decided to hold on the requirement to support the case where the request continues to work after logging in as part of this issue and I've removed that point from the ACs accordingly. For now, this only needs to be concerned with ensuring the plugin handlers for those are only executed for logged in users. We'll open a follow-up issue to see about improving the experience for the logged out case, but that's less important than the other requirements for now. |
To confirm @aaemnnosttv rather than create the persistent nonce approach, we can update the nonce validation https://github.com/google/site-kit-wp/blob/2bac88b/includes/Core/Authentication/Authentication.php#L1049 to create a new validation link for the user to follow. So they would:
|
Update following meeting, this IB only needs to cover the different action, no need for nonce changes or new links for validation. |
Updated the PR following the updated IB instructions. |
@felixarntz – in case you want to include this in the release – ✅ from me – it's a simple change. |
Makes sense to include, but GH actions is stuck again :/ We should make sure to work on #2969 in the coming sprint. |
QA ✅
|
Bug Description
It is currently possible to access the OAuth callback URL on any site to trigger Site Kit's logic to handle it. While this is not a real security flaw since the necessary permission checks are in place, it is still concerning, and more importantly, it can result in a user-facing problem in some certain circumstances, e.g. when for some reason being logged out while going through the Site Kit setup flow.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
{adminURL}/index.php?oauth2callback=1
URL on a site where you're not logged in, you should get redirected towp-login.php
, like it is expected to happen for admin URLs.googlesitekit_connect
,googlesitekit_disconnect
) should be run at a hook late enough so that it is only reached if the user is already logged in.Implementation Brief
Allow authentication urls for logged in users only
Change
handle_oauth
hook to run onadmin_init
inhttps://github.com/google/site-kit-wp/blob/2bac88b/includes/Core/Authentication/Authentication.php#L268
Remove the is_admin() call in
handle_oauth
https://github.com/google/site-kit-wp/blob/2bac88b/includes/Core/Authentication/Authentication.php#L633-L635
Allow logout after starting authentication
If we logout during authentication, when we first go to the google oauth screen, all of our WordPress nonce verification will fail due to https://core.trac.wordpress.org/browser/tags/5.7/src/wp-includes/pluggable.php#L2187. To get around this we can create a custom nonce verification approach:
Update nonce verification function
https://github.com/google/site-kit-wp/blob/2bac88b/includes/Core/Authentication/Authentication.php#L1040-L1051
Update the nonce from url:
https://github.com/google/site-kit-wp/blob/2bac88b/includes/Core/Authentication/Google_Proxy.php#L113
Delete the nonce option after we no longer need it:
prior to
$this->set_connected_proxy_url();
, delete the nonce option from there.https://github.com/google/site-kit-wp/blob/2bac88b/includes/Core/Authentication/Authentication.php#L311
Test Coverage
Visual Regression Changes
QA Brief
Ensure unit tests pass correctly.
Changelog entry
The text was updated successfully, but these errors were encountered: