Summary
Gitea contains an improper access control issue where the repository context is not correctly verified when deleting attachments.
A user who once uploaded an attachment to a repository may still be able to delete that attachment after losing access to the original repository by issuing the delete request through a different repository they can still access.
Affected context
This vulnerability affects Gitea instances where users can upload attachments associated with repositories (for example, to issues, pull requests, or other repository-scoped objects).
The problem occurs when the attachment deletion logic authorizes the action based on the user's access to some repository rather than confirming that the user currently has permission on the specific repository that owns the attachment.
It is most relevant in multi-repository environments where user access to projects changes over time (e.g., revocation of collaborator or team membership).
Exploit preconditions
- Attack surface: HTTP/REST interface or web UI endpoints responsible for attachment deletion.
- Required access:
- The attacker must have previously uploaded an attachment to a repository.
- The attacker must currently have access to at least one other repository on the same Gitea instance.
- The attacker must no longer have access to the original repository that owns the attachment.
- Trigger point: A crafted attachment deletion request made via a repository where the attacker still has permissions, referencing an attachment belonging to a repository they no longer can access.
- Why exploitation is possible: The authorization logic fails to enforce a strict binding between an attachment and its owning repository, allowing attachment deletion to be authorized based on generic repository access rather than repository-specific ownership or access checks.
Why this happens
The core issue is an improper access control pattern where the system makes authorization decisions without validating all necessary context.
In this case, the deletion endpoint allows a user to delete an attachment if they can perform the operation in the context of any repository they can access, instead of checking:
- whether the user currently has access to the repository that owns the attachment, and
- whether their role permits deletion of that specific attachment.
This maps to CWE-284: Improper Access Control, where missing or incomplete authorization checks allow actions on resources that should be restricted based on the current user's relationship to the resource.
Potential impact
- Unauthorized deletion of attachments in repositories the user no longer has access to.
- Loss of issue or pull-request related evidence, such as logs, screenshots, or documents.
- Disruption of audit trails and historical context tied to project discussions.
- Potential weakening of compliance or review processes that rely on preserved attachments.
- Erosion of trust between project maintainers and contributors due to unexpected data loss.
General mitigation guidance
Effective mitigation focuses on enforcing resource-scoped authorization that considers the true ownership of each attachment:
- Ensure that every attachment is tightly bound to a specific repository (or owning entity) and that authorization checks always validate the user's current permissions on that exact repository before allowing deletion.
- Apply object-level access control rules so that operations on attachments reuse the same authorization logic used for other repository-scoped resources (e.g., issues, pull requests).
- Centralize permission checks for repository resources to reduce the chance of context mix-ups or duplicated, inconsistent authorization code.
- Design APIs so that attachment identifiers are not sufficient by themselves to perform operations; require explicit repository context that must match the attachment's owner.
- Adopt least-privilege defaults by limiting who can delete attachments and by tying deletion rights to specific roles or ownership where appropriate.
How teams detect issues like this
Detection typically involves examining how access control is implemented around repository-scoped resources:
- Static analysis and code review:
- Look for attachment deletion handlers that do not retrieve and verify the attachment's owning repository against the current user's permissions.
- Flag code paths where authorization is checked only at a high level (e.g., "user can delete attachments somewhere") instead of at the specific resource level ("user can delete this repository's attachments").
- Identify any endpoints where a resource ID (attachment ID) is accepted without cross-checking its parent repository or project.
- Policy and test-based detection:
- Add authorization-focused unit and integration tests that simulate users losing access to repositories and confirm that all associated resources (like attachments) become non-deletable for them.
- Use security testing tools or automated QA scripts to attempt cross-repository operations on attachments (e.g., delete from repo B an attachment owned by repo A).
- Operational monitoring:
- Monitor logs for attachment deletions where the user performing the action is not a current collaborator or member on the owning repository.
- Implement anomaly detection rules for high volumes of unexpected deletions or deletions performed by users with recent permission changes.

