Summary
When Gitea's non-default automatic account-linking mode is enabled alongside registration, the linking flow can trust a name or email entered in the form instead of verifying it against the OAuth2 provider's identity. An attacker with an account at a configured provider could link their identity to another Gitea user and sign in as that user, potentially including an administrator.
Affected context
The issue applies when [oauth2_client].ACCOUNT_LINKING is set to auto and registration is enabled. During OAuth2 sign-up and account linking, the form could use user-submitted name or email details to select an existing Gitea account rather than requiring a match with the identity asserted by the provider. A successful link persists for later sign-ins.
Exploit preconditions
- Attack surface: Gitea's OAuth2 account-linking and registration flow
- Required access: An account with a configured OAuth2 provider; no victim password is required
- Configuration: Automatic account linking is enabled and registration is enabled
- Trigger point: The attacker submits the account-linking form with another user's name or email
- Why exploitation is possible: The existing account was selected using submitted form data rather than a verified provider identity
Why this happens
The linking flow treated user-controlled identity fields as authoritative when selecting an existing account. Because it did not require the selected account to match the email or provider-derived user name asserted by the OAuth2 provider, an attacker could associate their own external identity with another user's account. This is an authentication weakness (CWE-287) and can also involve authorization bypass through a user-controlled account identifier (CWE-639).
Potential impact
- An attacker could sign in as another Gitea user without knowing that user's password.
- A compromised account could expose private repositories or other account data.
- An attacker could gain administrator-level access if a privileged account is linked.
- The unauthorized link could enable continued access through later OAuth2 sign-ins.
General mitigation guidance
Defensive patterns include verifying account ownership using identity attributes asserted by the OAuth2 provider, rather than trusting names or email addresses submitted in a form. Automatic linking can be disabled by default or replaced with an explicit account-ownership check, such as requiring the existing account's password or an authenticated session. Validate provider identity claims, minimize trust in user-controlled linking inputs, and apply least privilege to accounts and OAuth2 integrations.
How teams detect issues like this
Review account-linking code for lookups that use form-supplied names, emails, or account identifiers without confirming them against trusted provider claims. Static analysis and code review can flag flows where user-controlled values determine an authenticated account. Monitor account-link events for mismatches between provider identity claims and the linked Gitea account, and enforce policies requiring verified identity matching or explicit proof of existing-account ownership.

