Skip to content

fix(oauth): verify only the GitLab primary email - #14010

Merged
TorstenDittmann merged 10 commits into
mainfrom
torsten/gitlab-primary-email-c90a
Sep 30, 2026
Merged

TorstenDittmann merged 10 commits into
mainfrom
torsten/gitlab-primary-email-c90a

Conversation

@TorstenDittmann

@TorstenDittmann TorstenDittmann commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

GitLab sign-in reads the primary address from OpenID userinfo (GET /oauth/userinfo) and trusts email_verified for that address only.

The login request uses the read_user, openid, and email scopes. A token issued before openid cannot call userinfo. Those grants, including an existing GitLab repository connection refreshing its token, fall back to GET /api/v4/user for the id and profile. That fallback does not treat confirmed_at as a verified email, so it cannot link onto an existing account.

Test Plan

No automated test. The change is the GitLab adapter reading /oauth/userinfo and using email plus email_verified for the primary address, with a profile fallback for older tokens.

Related PRs and Issues

  • Account takeover report: GitLab OAuth email collision on an existing Appwrite account

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 

cursoragent and others added 2 commits September 30, 2026 09:27
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]>
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → torsten/gitlab-primary-email-c90a (after).

Metric Before After Change
🚀 Requests/sec 207.24 207.22 ⚪ 0%
⏱️ Latency P50 83.54 ms 82.36 ms ⚪ -1.4%
⏱️ Latency P95 194.37 ms 194.94 ms ⚪ +0.3%
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 82.36 194.94 13,053 207.22 +0.57
Account 160.53 317.71 687 11.4 +16.79
TablesDB 79.06 145.43 7,099 115.17 -7.94
Storage 78.21 170.59 3,435 57.3 +4.82
Functions 122.94 239.56 1,832 31.29 +11.33

Top API waits (after)

API request Max wait (ms)
account.name.update 466.99
functions.variables.update 390.43
functions.delete 386.6
account.prefs.update 384
functions.create 381.55

cursoragent and others added 3 commits September 30, 2026 09:43
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]>
@TorstenDittmann
TorstenDittmann marked this pull request as ready for review September 30, 2026 09:57
@ghost

ghost commented Sep 30, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The functionality addresses the earlier findings, but the new fallback test unnecessarily couples its success to internal request counts.

GitLab OAuth now reads the primary email from OpenID userinfo and trusts only its email_verified claim. Authorization requests read_user, openid, and email; older grants fall back to the REST profile without verifying the email. The PR also documents the application-scope upgrade and adds verification and legacy-token regression tests.

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.

Verdict New comments Fixed Still open
✅ Approved 1 3 0
Finding Where
🟡 Assert fallback results without fixing the internal request count tests/unit/Auth/OAuth2/GitlabTest.php:57
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
File Change
app/config/variables.php Document required console and VCS GitLab scopes and the upgrade steps.
docs/references/vcs/create-gitlab-installation.md Explain application scopes and reauthorization for GitLab installations.
src/Appwrite/Auth/OAuth2/Gitlab.php Use OpenID primary-email verification and retain an unverified REST-profile fallback for legacy grants.
tests/unit/Auth/OAuth2/GitlabTest.php Cover true, false, and missing verification claims plus legacy-token profile fallback.
✅ Fixed since the last review · 3
  • Existing GitLab OAuth applications need the new scopes enabled · src/Appwrite/Auth/OAuth2/Gitlab.php:34
  • Previously issued VCS tokens cannot call userinfo · src/Appwrite/Auth/OAuth2/Gitlab.php:235
  • Cover verified and unverified GitLab userinfo responses · src/Appwrite/Auth/OAuth2/Gitlab.php:146

Reviewed the commits since 6523b08 · 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 B · 2 blocking findings to address. Summary

Comment thread src/Appwrite/Auth/OAuth2/Gitlab.php Resolved
Comment thread src/Appwrite/Auth/OAuth2/Gitlab.php Resolved
Comment thread src/Appwrite/Auth/OAuth2/Gitlab.php Resolved
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Critical risk] Changes how user identity is verified in GitLab OAuth.

The PR does not appear safe to merge while transient GitLab userinfo errors can block existing-account sign-in.

Fix All in Claude CodeFindings

  1. P1 Transient errors block sign-in ▶
Fix with agent prompt
### Issue 1
src/Appwrite/Auth/OAuth2/Gitlab.php:248-251
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.

Summary

The PR changes GitLab OAuth sign-in to use the primary email and verification claim from userinfo, with an unverified profile fallback for older grants.

  • Existing grants can still supply a GitLab user ID through the fallback.
  • A transient userinfo error still takes that fallback path, leaving the existing sign-in concern unresolved.

Reviews (7) · Last reviewed commit: "Merge branch 'main' into torsten/gitlab-..."

Comment thread src/Appwrite/Auth/OAuth2/Gitlab.php Resolved
Comment thread src/Appwrite/Auth/OAuth2/Gitlab.php Resolved
Comment thread src/Appwrite/Auth/OAuth2/Gitlab.php Resolved
@TorstenDittmann
TorstenDittmann marked this pull request as draft September 30, 2026 10:39
@TorstenDittmann
TorstenDittmann marked this pull request as ready for review September 30, 2026 10:39
cursoragent and others added 2 commits September 30, 2026 10:42
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]>

@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 thread tests/unit/Auth/OAuth2/GitlabTest.php Resolved
Comment on lines +248 to +251
} 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 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.

Fix in Claude Code Fix in Codex

Comment thread tests/unit/Auth/OAuth2/GitlabTest.php Resolved
cursoragent and others added 2 commits September 30, 2026 11:04
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]>
@TorstenDittmann
TorstenDittmann merged commit 711e32f into main Sep 30, 2026
50 checks passed
@TorstenDittmann
TorstenDittmann deleted the torsten/gitlab-primary-email-c90a branch September 30, 2026 12:27
abnegate added a commit that referenced this pull request Sep 30, 2026
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]>
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.

3 participants