Repository navigation
fix(oauth): verify only the GitLab primary email - #14010
Conversation
Sign-in uses the profile email from GET /user and treats it as verified only when that address is present and confirmed_at is set. Other addresses on the GitLab account are not consulted. Co-authored-by: Torsten Dittmann <[email protected]>
Request the openid and email scopes and read email plus email_verified from /oauth/userinfo. That claim is the primary address confirmation. The profile confirmed_at flag is no longer used. Co-authored-by: Torsten Dittmann <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Sign-in reads id, name, username, avatar, and the primary email from /oauth/userinfo. GET /api/v4/user remains only for tokens issued before the openid scope, and that response is never treated as a verified email. Co-authored-by: Torsten Dittmann <[email protected]>
Drop the REST profile call and the fallback around it. One OpenID userinfo request supplies the id, name, avatar, primary email, and email_verified. Co-authored-by: Torsten Dittmann <[email protected]>
The test only restated the userinfo response fields. Co-authored-by: Torsten Dittmann <[email protected]>
🔵 Tier A · Mergeable after minor fixes
GitLab OAuth now reads the primary email from OpenID userinfo and trusts only its Latest changes: The latest commits add an unverified REST-profile fallback for older grants, document required GitLab application scopes, and add unit coverage for email verification and legacy tokens.
Fix with agent prompt### Issue 1
tests/unit/Auth/OAuth2/GitlabTest.php:57
**Assert fallback results without fixing the internal request count**
The `exactly(2)` expectation makes this test fail if profile caching changes, even when all six public getters still return the correct values and the email remains unverified. Please keep the result assertions and allow the fake to serve repeated requests; AGENTS.md requires tests to assert observable behavior rather than internal call details.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 4
✅ Fixed since the last review · 3
Reviewed the commits since |
|
Sign-in still requests read_user along with openid and email, so existing GitLab applications that already allow read_user keep that scope. Co-authored-by: Torsten Dittmann <[email protected]>
When userinfo rejects a token issued before the openid scope, read the profile from the user API and leave the email unverified. Document that existing GitLab applications must allow openid and email. Co-authored-by: Torsten Dittmann <[email protected]>
| } catch (\Throwable) { | ||
| // A grant from before the openid scope cannot call userinfo. | ||
| // The profile still identifies the user. It does not verify the email. | ||
| $this->user = $this->profile($accessToken); |
There was a problem hiding this comment.
Transient errors block sign-in
If /oauth/userinfo returns a temporary HTTP error for a valid token, this catch also takes the legacy-profile path and marks the email unverified. When that email matches an existing account, the account callback rejects sign-in or linking instead of treating the response as a provider error.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Auth/OAuth2/Gitlab.php
Line: 248-251
Comment:
**Transient errors block sign-in**
If `/oauth/userinfo` returns a temporary HTTP error for a valid token, this catch also takes the legacy-profile path and marks the email unverified. When that email matches an existing account, the account callback rejects sign-in or linking instead of treating the response as a provider error.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Keep the userinfo fallback for older grants. The env descriptions, the installation reference, and the userinfo unit test are unchanged. Co-authored-by: Torsten Dittmann <[email protected]>
Brings in main's OAuth2 state and nonce validation (#14012), which cloud needs, along with the realtime origin alignment (#14020), subscriber target ownership (#14019), GitLab primary email (#14010), impersonation MFA (#14017), write-only webhook passwords (#14016), chunked-upload resume ownership (#14014), preview authorize validation (#14013), nightly forcing (#14015) and scheduled-function enqueue checks (#14011). The merge had no textual conflicts, and main left composer.json and composer.lock unchanged. So the lock keeps the branch's database and async pins. Main's assertResumeAllowed() in Storage Buckets/Files/Create checks Input(Database::PERMISSION_UPDATE, ...). utopia-php/database 8 has no PERMISSION_* constants, so every chunked resume would fail with an undefined-constant error. It now passes PermissionType::Update, as the rest of that action already does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
GitLab sign-in reads the primary address from OpenID userinfo (
GET /oauth/userinfo) and trustsemail_verifiedfor that address only.The login request uses the
read_user,openid, andemailscopes. A token issued beforeopenidcannot call userinfo. Those grants, including an existing GitLab repository connection refreshing its token, fall back toGET /api/v4/userfor the id and profile. That fallback does not treatconfirmed_atas a verified email, so it cannot link onto an existing account.Test Plan
No automated test. The change is the GitLab adapter reading
/oauth/userinfoand usingemailplusemail_verifiedfor the primary address, with a profile fallback for older tokens.Related PRs and Issues
Checklist