Sponsored Content
The Wayback Machine - https://web.archive.org/web/20210817024718/https://github.com/google/site-kit-wp/issues/1985
Skip to content
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

Update proxy permissions URL to pass through backend #1985

Closed
aaemnnosttv opened this issue Sep 3, 2020 · 4 comments
Closed

Update proxy permissions URL to pass through backend #1985

aaemnnosttv opened this issue Sep 3, 2020 · 4 comments

Comments

@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Sep 3, 2020 •

Feature Description

In #1857, we changed the way the proxy setup URL works to be similar to the connect and disconnect URLs by using a WP "admin action" URL. This allows us to do additional permission and capability checks before sending the user to the proxy. It also exposes less sensitive information to the client than is necessary.

Since the above issue is already very large, it makes sense to split out this portion to update the permissions URL to function in a similar way as this URL also contains some of the same information such as proxy credentials.


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

Acceptance criteria

  • There should be a new method Authentication::get_proxy_permissions_url() which returns a URL similar to Authentication::get_proxy_setup_url() but for a different action Google_Proxy::ACTION_PERMISSIONS (and corresponding nonce).
  • There should be a callback hooked into that new admin action which checks that the current user can authenticate, whether the proxy is in use, and only then it should redirect to the real proxy permissions URL (OAuth_Client::get_proxy_permissions_url()).
  • Any links in Site Kit UI should be updated to point to the new "proxied" proxy permissions URL, and the real proxy permissions URL should not be exposed in any client-side code.
  • There should be a new admin_action_googlesitekit_proxy_permissions action handler which when called, qualifies the current user before redirecting them to the OAuth_Client::get_proxy_permissions_url
  • The proxyPermissionsURL provided to the client should be in the form:
    {admin_url}?action=googlesitekit_proxy_permissions&nonce={nonce}

Implementation Brief

  • Define a new Google_Proxy::ACTION_PERMISSIONS class constant for the googlesitekit_proxy_permissions literal
  • Add a new Authentication::get_proxy_permissions_url method, essentially returning:
    return add_query_args(
        array(
            'action' => Google_Proxy::ACTION_PERMISSIONS,
            'nonce'  => wp_create_nonce( Google_Proxy::ACTION_PERMISSIONS )
        ),
        admin_url( 'index.php' )
    );
  • Update proxyPermissionsURL in Authentication::inline_js_base_data to use the new get_proxy_permissions_url instead so that the client always sends users through the WP backend to get there.
  • In Authentication::register, add a new action on 'admin_action_' . Google_Proxy::ACTION_PERMISSIONS which calls a new private method handle_proxy_permissions:
    • If not current_user_can( Permissions::AUTHENTICATE )
      wp_die with insufficient permissions message (use the same as core)
    • If not credentials->using_proxy()
      wp_die with insufficient permissions message (use the same as core)
    • Verify $_GET['nonce'] with Google_Proxy::ACTION_PERMISSIONS as the action or wp_die (use the same message as core for bad/expired nonce)
    • Redirect to OAuth_Client->get_proxy_permissions_url()

Tests

PHPUnit

  • Update AuthenticationTest to include coverage for the added 'admin_action_' . Google_Proxy::ACTION_PERMISSIONS action

QA Brief

  • Clicking the "Manage sites" link in the Site Kit user dropdown should still take you to the proxy Manage sites screen the same way it used to before.

Changelog entry

  • Improve authentication service permissions link to check Site Kit permissions first while not exposing the actual URL on the client.
@felixarntz
Copy link
Member

@felixarntz felixarntz commented Sep 8, 2020

IB ✅

@felixarntz
Copy link
Member

@felixarntz felixarntz commented Sep 23, 2020

@aaemnnosttv I've updated the ACs and IB to reflect the updated names from #2094 which I accidentally opened as a duplicate.

@aaemnnosttv
Copy link
Collaborator Author

@aaemnnosttv aaemnnosttv commented Oct 1, 2020

QA

  • Tested manage sites link redirects through WP
    image
    Complete token not shown
  • Checked that _googlesitekitBaseData.proxyPermissionsURL and getProxyPermissionsURL selector uses the new WP action URL
    .../wp-admin/index.php?action=googlesitekit_proxy_permissions&nonce=...
  • All client-facing uses of permissions URL use above URL
  • Authentication::handle_proxy_permissions checks nonce, user capability, and proxy authentication before redirecting to permissions management URL

⚠️ Added tests for test_handle_proxy_permissions do not cover any of the requirements of the guards to verify nonce, check permissions, or proxy use. I'll submit a quick follow up PR to address this.

@aaemnnosttv
Copy link
Collaborator Author

@aaemnnosttv aaemnnosttv commented Oct 2, 2020

QA ✅

@aaemnnosttv aaemnnosttv removed their assignment Oct 2, 2020
@felixarntz felixarntz closed this Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants