Summary
A broken access control flaw in Gitea lets one user change another user's primary email address without proper authorization checks.
When user identity is derived only from client-controlled parameters, attackers may hijack notification channels, disrupt account recovery, or facilitate further account compromise.
Affected context
This vulnerability occurs in Gitea's user management and account settings functionality, specifically in flows that update a user's primary email address.
It becomes relevant when the server trusts user identifiers supplied by the client (such as user IDs or usernames in requests) instead of verifying that the authenticated session belongs to the target account.
Deployments where users can manage their email addresses through web or API interfaces, and where email addresses are used for notifications or password reset, are particularly exposed.
Exploit preconditions
- Attack surface: Web UI or HTTP API endpoints responsible for updating user email addresses
- Required access: Authenticated or semi-authenticated user able to submit requests to the email change endpoint
- Trigger point: Sending a crafted request that references another user's identifier while updating the primary email address
- Why exploitation is possible: The application does not enforce a robust ownership check, allowing direct object references (user IDs / usernames) in the request to target accounts other than the one associated with the current session
Why this happens
The underlying bug class is broken access control due to insecure direct object references.
The server accepts client-supplied identifiers to select which user record to modify but fails to verify that the authenticated principal is authorized to change that specific record.
This maps to CWE-639: Authorization Bypass Through User-Controlled Key, where the application exposes internal objects (such as user accounts) through predictable identifiers without adequate ownership or permission enforcement.
Potential impact
- Attackers may change another user's primary email address, misdirecting notifications and alerts
- Account recovery and password reset workflows could be hijacked or disrupted
- Users can be effectively locked out of their accounts if recovery relies on the primary email
- Email-based verification and audit trails may be corrupted or sent to attacker-controlled addresses
- Trust in repository collaboration, issue tracking, and code review workflows can be undermined
General mitigation guidance
Mitigation typically centers on enforcing strict, server-side authorization checks for all state-changing operations on user resources.
Recommended patterns include:
- Binding email change operations to the authenticated user identity derived from the session or token, rather than trusting user IDs from request parameters
- Implementing ownership checks for any endpoint that references user accounts, ensuring only the account owner (or an explicitly privileged administrator) can modify primary email fields
- Normalizing access control logic through shared authorization middleware to avoid per-endpoint inconsistencies
- Treating email addresses as high-value identity attributes and requiring re-authentication or step-up verification for changes
- Designing APIs to operate on "current user" by default, minimizing the need for arbitrary user identifiers in sensitive operations
How teams detect issues like this
Detection often involves both automated and manual review of authorization flows:
- Static analysis or custom linting rules that flag patterns where user identifiers from request parameters are used directly to query or update account records
- Code review checklists emphasizing validation of ownership checks on endpoints that modify user profile, email, or authentication-related attributes
- Integration tests or security tests that attempt to perform actions on other users' accounts while authenticated as a different user, validating proper enforcement of access control
- Central policy enforcement for user management operations, ensuring all account modifications pass through a uniform authorization layer rather than ad hoc checks

