fix(auth): restore g_csrf_token CSRF validation in Sign In With Google#12797
fix(auth): restore g_csrf_token CSRF validation in Sign In With Google#12797adilburaksen wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
The CSRF token check was present in the original implementation but was inadvertently removed in commit 0803e42 (PR #9687, Nov 2024). Google's GIS (Google Identity Services) library sets an identical `g_csrf_token` value in both a cookie and the POST body; the server must compare them to prevent cross-site request forgery. Without this check, an attacker can craft a page that auto-submits a valid Google credential to the victim's WordPress login endpoint via CSRF, causing the plugin to authenticate the attacker's account on the victim's site. If the attacker's Google account email matches an existing WordPress account, this permanently links the attacker's credential to that account (account takeover). Restores the original validation using `hash_equals()` for constant-time comparison and re-adds the `ERROR_INVALID_CSRF_TOKEN` error code constant.
f9cb2e7 to
4b295fb
Compare
|
Re-opening this — the gap it addresses is still present on I see the linking flow has since been reworked (the new @eugene-manuilov could you point me at the right place to land this in the current structure? Happy to add tests and follow the GIS-documented cookie/body comparison. |
Summary
Restores the
g_csrf_tokenCSRF validation inAuthenticator::authenticate_user()that was inadvertently removed in commit0803e42d(PR #9687, November 2024).Background
Google's GIS (Google Identity Services) library sets an identical
g_csrf_tokenvalue in both a cookie and the POST body when the user clicks the Sign In With Google button. The server must compare these two values before processing the credential — this is the CSRF mitigation documented in the GIS server-side verification guide.The check existed in the original implementation (constant
ERROR_INVALID_CSRF_TOKENand the validation block inauthenticate_user), but was dropped without replacement.Impact Without the Check
An attacker can host a page that auto-submits a valid Google credential via CSRF POST to
wp-login.php?action=googlesitekit_auth:Because the plugin never validates
g_csrf_token, the server processes the credential. If the attacker's Google account email matches an existing WordPress account,find_user()permanently links the attacker's Google credential to that account — the attacker can then sign in as that user at any time.Fix
Restores the original two-line validation using
hash_equals()(constant-time comparison) and re-adds theERROR_INVALID_CSRF_TOKENerror code constant.Testing
g_csrf_tokenin both cookie and POST body automatically — valid requests pass unchanged.ERROR_INVALID_CSRF_TOKEN.PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist