Skip to content

fix(oauth): fail GitHub sign-in when the user payload is missing - #14093

Merged
ChiragAgg5k merged 1 commit into
mainfrom
cursor/github-oauth-null-user-306f
Oct 4, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
cursor/github-oauth-null-user-306f

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What does this PR do?

GitHub OAuth redirect (/v1/account/sessions/oauth2/:provider/redirect) returned a 500 on cloud release 1.50.126 when GitHub's user payload was missing. json_decode yielded null, and assigning that to Appwrite\Auth\OAuth2\Github::$user (array) threw a TypeError.

A missing or non-array user body is now an OAuth provider failure, the same way other adapters reject a user document the provider did not return (throw new Exception(..., 400)). The redirect handler loads the user id inside the existing OAuth2Exception catch, so that failure uses the existing failureRedirect(USER_OAUTH2_PROVIDER_FAILURE) path instead of a 500.

The $user property stays a typed array.

Fixes CLOUD-3QWQ

Test Plan

  • vendor/bin/phpunit tests/unit/Auth/OAuth2/GithubTest.php (12 tests, including testMissingUser for a JSON null user body)
  • vendor/bin/pint --test on the changed PHP files

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?
Open in Web Open in Cursor 

A null GitHub user body was assigned to a typed array and 500'd the
OAuth redirect. Treat that payload as an OAuth provider failure.

Fixes CLOUD-3QWQ

Co-authored-by: Chirag Aggarwal <[email protected]>
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/github-oauth-null-user-306f (after).

Metric Before After Change
🚀 Requests/sec 183.84 199.07 🟢 +8.3%
⏱️ Latency P50 93.4 ms 87.24 ms 🟢 -6.6%
⏱️ Latency P95 223.24 ms 204.51 ms 🟢 -8.4%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 87.24 204.51 12,540 199.07 -18.72
Account 163.85 310.51 660 11.2 -65.28
TablesDB 83.81 159 6,820 111.43 -15.89
Storage 81.33 176.98 3,300 55.43 -9.76
Functions 123.73 259.89 1,760 30.4 -11.95

Top API waits (after)

API request Max wait (ms)
account.name.update 513.16
functions.create 504.17
tablesdb.rows.delete 425.32
storage.buckets.create 425.18
account.prefs.update 417.59

@ChiragAgg5k
ChiragAgg5k marked this pull request as ready for review October 4, 2026 15:21
@ghost

ghost commented Oct 4, 2026

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The production fix looks sound, but the new regression test couples its assertion to internal request formatting contrary to the project's testing rules.

The change rejects missing or non-array GitHub user responses with an OAuth2 exception while retaining the typed array cache. It also moves user-ID retrieval into the redirect handler's provider-failure catch and adds a unit regression for a JSON null response.

Verdict New comments Fixed Still open
✅ Approved 1 0 0
Finding Where
🟡 Decouple the missing-user test from internal request formatting tests/unit/Auth/OAuth2/GithubTest.php:116
Fix with agent prompt
### Issue 1
tests/unit/Auth/OAuth2/GithubTest.php:116-124
**Decouple the missing-user test from internal request formatting**

The exact `request()` arguments and call count make this regression fail if authentication headers or fetching strategy change, even when a missing user still produces the correct exception. AGENTS.md requires named fakes and observable-behavior assertions rather than internal request details; use a fake that supplies the missing-user response and keep the exception assertions.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 3
File Change
app/controllers/api/account.php Catch OAuth2 failures raised while retrieving the provider user ID.
src/Appwrite/Auth/OAuth2/Github.php Validate the decoded user payload before assigning it to the array cache.
tests/unit/Auth/OAuth2/GithubTest.php Add a missing-user regression asserting the OAuth2 error type and message.

Reviewed 6d83cd1 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

Comment on lines +116 to +124
$github
->expects($this->once())
->method('request')
->with(
'GET',
'https://api.github.com/user',
['Authorization: token ' . \urlencode('access-token')],
)
->willReturn('null');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decouple the missing-user test from internal request formatting

The exact request() arguments and call count make this regression fail if authentication headers or fetching strategy change, even when a missing user still produces the correct exception. AGENTS.md requires named fakes and observable-behavior assertions rather than internal request details; use a fake that supplies the missing-user response and keep the exception assertions.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/Auth/OAuth2/GithubTest.php
Line: 116-124

Comment:
**Decouple the missing-user test from internal request formatting**

The exact `request()` arguments and call count make this regression fail if authentication headers or fetching strategy change, even when a missing user still produces the correct exception. AGENTS.md requires named fakes and observable-behavior assertions rather than internal request details; use a fake that supplies the missing-user response and keep the exception assertions.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@ChiragAgg5k
ChiragAgg5k merged commit b08ad97 into main Oct 4, 2026
51 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the cursor/github-oauth-null-user-306f branch October 4, 2026 15:36
abnegate added a commit that referenced this pull request Oct 5, 2026
cloud#5410 re-pins server-ce to this branch and needs main at or past
ee75768: the health tests that stop asserting wall-clock ping budgets
(#14069), Content-Length: 0 on empty client bodies for OAuth token
requests (#14072) and the SDK task no longer calling setters removed in
sdk-generator 5.3.4 (#14073). Also brings the GitHub OAuth missing-user
fix (#14093) and appwrite/geo 0.3.2 (#14100). The merge is clean and the
lock is untouched; both sides still resolve appwrite/sdk-generator 5.0.1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants