Repository navigation
(fix): handle non-JSON Google OAuth2 responses - #13968
Conversation
…ON response A failed or empty userinfo/token response makes json_decode return null, which cannot be assigned to the typed array properties and crashes the OAuth2 redirect with a TypeError. Falling back to [] lets the controller reach its existing USER_MISSING_ID failure redirect.
🔵 Tier A · Mergeable after minor fixes
This PR makes Google OAuth2 user-info decoding fall back to an empty array when the response is not JSON. The latest commit also validates token-exchange and refresh responses, raising a provider exception rather than accepting a missing access token. Latest changes: The newest commit adds a shared token-response parser and uses it for both Google token exchange and refresh.
📂 Walkthrough · 1
⏳ Still open from earlier reviews · 1
✅ Fixed since the last review · 1
Reviewed the commits since |
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Defaulting a malformed token response to [] let a failed refresh overwrite the session's stored provider credentials with an empty access token, and let a failed code exchange continue to the userinfo call outside the controller's OAuth2 catch. Throwing the provider exception instead keeps the session untouched on refresh and routes the redirect to its provider-failure path.
Fixes Sentry CLOUD-3QWQ (https://appwrite.sentry.io/issues/7713484379/):
TypeError: Cannot assign null to property Appwrite\Auth\OAuth2\Google::$user of type arrayon/v1/account/sessions/oauth2/:provider/redirect(162 events).Cause
OAuth2::request()returns an empty string when curl fails (HTTP code 0), and Google can also return a non-JSON body.json_decode()then returnsnull, which cannot be assigned to the typedarray $user/array $tokensproperties.Fix
getUser()falls back to[], sogetUserID()returns''and the redirect takes its existingUSER_MISSING_IDfailure redirect instead of a 500.getTokens()andrefreshTokens()throw the OAuth2 provider exception when the response isn't JSON or has noaccess_token. The redirect's existing catch turns that into the provider-failure redirect, and a failed session refresh no longer overwrites the stored provider credentials with an empty access token.Many other providers use the same
$this->user = json_decode(...)pattern and can hit this too; this PR only fixes Google, the one reported.