GHSA-6c6r-5xr4-cr5m CVE-2026-57886 GO-2026-6035
Gitea: Cross-repository issue/comment attachment re-linking can expose private attachment content
- Severity
- 5.9 / 10
- Medium · CVSS 3.1
- Exploit chance (EPSS)
- 0.31%
- Chance of exploitation in the next 30 days. Higher than 24.14% of scored vulnerabilities.
- Known exploited
- No
- Not in CISA's catalog
- Fix
- Available
- 2 packages have a fixed version
Description
Summary
Gitea's issue and comment attachment update paths accept attachment UUIDs without verifying that each attachment belongs to the target issue/comment repository. If an authenticated attacker knows a victim attachment UUID, they can re-link that attachment to an attacker-controlled issue or comment, causing later attachment access checks to use the attacker's repository authorization context.
Affected
- Component: web issue/comment attachment handling.
- Confirmed version:
maincommita39b2775edcb3ba53def96794491b91335117d81(v1.27.0-dev-352-ga39b2775ed). - Fixed in: not fixed at the time of validation.
- Other versions: not exhaustively tested. The affected code path appears structurally similar to versions that contain the current issue/comment attachment update logic.
Description / Root Cause
files[] values from issue/comment edit flows are passed to updateAttachments in routers/web/repo/issue.go:589-629. That helper calls:
models/issues/issue_update.go:267-278(UpdateIssueAttachments)models/issues/comment.go:623-642(UpdateCommentAttachments)
Both functions load attachments by UUID and update the attachment linkage, but neither validates that the attachment row's RepoID matches the repository of the target issue/comment. They also do not reject attachments already linked to a different issue/comment.
Attachment reads then use the linked issue/release repository to decide access:
services/repository/repository.go:185-207returns the repository ID fromIssueIDorReleaseID.routers/web/repo/attachment.go:153-184checks read permission on that linked repository.routers/web/repo/attachment.go:216-224opens and serves the file from the attachment's storage path after the linked-repository permission check succeeds.
For the global /attachments/{uuid} route in routers/web/web.go:872-876, there is no current repository context, so the early attach.RepoID mismatch check in ServeAttachment does not protect against this re-linking case.
A patched sibling path already demonstrates the intended invariant: models/repo/release.go:179-215 rejects release attachments whose RepoID differs from the release repository. That guard was introduced for CVE-2026-20736, but the issue/comment paths still lack an equivalent check.
Impact
An attacker who can edit an issue/comment in a repository they can read can move a known victim attachment UUID into that repository's authorization context. After the re-link, the attachment download path resolves access against the attacker-controlled repository while serving the original attachment file.
This can disclose private issue/comment attachments if the attacker has obtained the UUID through prior legitimate access, copied links, notification content, logs, browser history, or another exposure. The attack does not require write access to the victim repository.
Reproduction Summary
Full HTTP/E2E observation:
- A local Gitea server was started with an isolated SQLite database.
- A victim user created private repositories, private issues, and issue attachments containing unique marker strings.
- An attacker user first attempted to download each victim attachment through
/attachments/{uuid}and received404. - The attacker then submitted the victim UUID through the real issue edit route in an attacker-controlled public repository.
- The same attacker could then download the victim issue attachment through
/attachments/{uuid}and received200; the response body contained the unique issue marker. - The attacker repeated the flow through the real comment edit route and could download the second victim attachment with
200; the response body contained the unique comment marker.
Model-level issue-path behavior:
- A fixture attachment with
RepoID = 2andIssueID = 4was passed toUpdateIssueAttachmentsfor attacker issueID = 1, whoseRepoID = 1. - The call succeeded.
- The attachment row still had
RepoID = 2, but itsIssueIDwas changed to the attacker issue. GetAttachmentLinkedTypeAndRepoIDthen resolved the attachment to attacker repositoryRepoID = 1.
Model-level comment-path behavior:
- The same cross-repository attachment UUID was passed to
UpdateCommentAttachmentsfor attacker commentID = 1. - The call succeeded.
- The attachment row still had
RepoID = 2, but itsIssueIDandCommentIDwere changed to the attacker's issue/comment. - The linked repository used for access checks became attacker repository
RepoID = 1.
Negative control:
- Existing release test
TestAddReleaseAttachmentsRejectsDifferentRepopasses and confirms the release path rejects the same class of cross-repository attachment linkage.
Detailed verifier and step-by-step runbook are available on request.
Suggested Fix
Add repository and linkage validation before updating issue/comment attachments.
Recommended checks:
- Load the target issue for
UpdateIssueAttachmentsand derive itsRepoID. - Load the target comment's issue for
UpdateCommentAttachmentsand derive itsRepoID. - Reject any attachment whose
RepoIDdiffers from the target issue repository. - Reject attachments already linked to a different issue/comment/release, except for attachments already linked to the same object being updated.
- If caller context is available at the web/service layer, also require new unlinked attachments to belong to the current actor or to have been uploaded in the current edit session.
- Preserve any legacy
RepoID = 0migration behavior only when it can be proven safe for the target repository.
Also consider a cleanup/audit query for existing inconsistent rows where attachment.issue_id != 0 and attachment.repo_id differs from the linked issue repository.
Regression Tests
Add tests that fail before the fix and pass after it:
UpdateIssueAttachmentsrejects an attachment whoseRepoIDdiffers from the target issue'sRepoID.UpdateCommentAttachmentsrejects an attachment whoseRepoIDdiffers from the target comment issue'sRepoID.- Same-repository unlinked attachment linking still works for normal issue/comment editing.
- Attachments already linked to a different issue/comment cannot be moved by passing their UUID in
files[]. - Existing release guard test remains passing.
Affected versions
Go
| Package | Vulnerable | Fixed in |
|---|---|---|
| code.gitea.io/gitea | < 1.27.0 |
1.27.0 |
| gitea.dev | < 1.27.0 |
1.27.0 |
How to fix
Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.
code.gitea.io/gitea Go → 1.27.0
- go
go get code.gitea.io/gitea@v1.27.0 && go mod tidy
gitea.dev Go → 1.27.0
- go
go get gitea.dev@v1.27.0 && go mod tidy
Severity breakdown
CVSS 3.1 5.9
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:N
- Attack vector
- Network
- Attack complexity
- High
- Privileges required
- Low
- User interaction
- None
- Scope
- Unchanged
- Confidentiality
- High
- Integrity
- Low
- Availability
- None
Weakness
CWE-639: Authorization Bypass Through User-Controlled Key
The system's authorization functionality does not prevent one user from gaining access to another user's data or record by modifying the key value identifying the data.
How to prevent it
- Architecture and Design: For each and every data access, ensure that the user has sufficient privilege to access the record that is being requested.
- Architecture and Design, Implementation: Make sure that the key that is used in the lookup of a specific user's record is not controllable externally by the user or that any tampering can be detected.
- Architecture and Design: Use encryption in order to make it more difficult to guess other legitimate values of the key or associate a digital signature with the key so that the server can verify that there has been no tampering.
CWE-862: Missing Authorization
The product does not perform an authorization check when an actor attempts to access a resource or perform an action.
How to prevent it
- Architecture and Design: Divide the product into anonymous, normal, privileged, and administrative areas. Reduce the attack surface by carefully mapping roles with data and functionality. Use role-based access control (RBAC) [REF-229] to enforce the roles at the appropriate boundaries. Note that this approach may not protect against horizontal authorization, i.e., it will not protect a user from attacking others with the same role.
- Architecture and Design: Ensure that access control checks are performed related to the business logic. These checks may be different than the access control checks that are applied to more generic resources such as files, connections, processes, memory, and database records. For example, a database may restrict access for medical records to a specific database user, but each record might only be intended to be accessible to the patient and the patient's doctor [REF-7].
- Architecture and Design: Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, consider using authorization frameworks such as the JAAS Authorization Framework [REF-233] and the OWASP ESAPI Access Control feature [REF-45].
- Architecture and Design: For web applications, make sure that the access control mechanism is enforced correctly at the server side on every page. Users should not be able to access any unauthorized functionality or information by simply requesting direct access to that page. One way to do this is to ensure that all pages containing sensitive information are not cached, and that all such pages restrict access to requests that are accompanied by an active and authenticated session token associated with a user who has the required permissions to access that page.
- System Configuration, Installation: Use the access control capabilities of your operating system and server environment and define your access control lists accordingly. Use a "default deny" policy when defining these ACLs.
References
Packages
Other links
- github.com/go-gitea/gitea/security/advisories/GHSA-6c6r-5xr4-cr5m
- github.com/go-gitea/gitea/pull/38406
- github.com/go-gitea/gitea/pull/38426
- github.com/go-gitea/gitea/commit/de4b8277e9cb576f2315fb03b5ab6478b42a1d31
- github.com/go-gitea/gitea/commit/f69e15afe7496cc62e96dab244629c69eb31a7bf
- github.com/go-gitea/gitea/releases/tag/v1.27.0
- blog.gitea.com/gitea-1.27.0-is-released
Timeline
- Published
- Last updated by the source
- Latest EPSS score
Related advisories
| Advisory | Severity | Why it's related |
|---|---|---|
| GHSA-rcr6-4jqh-j84m Gitea: Remote Code Execution via diffpatch Git Hook Installation | Critical Known exploited | Also affects code.gitea.io/gitea |
| GHSA-fq2p-5p22-8g6j Gitea: Public-Only Personal access tokens scope bypass in Organization and Permission Endpoints | Medium | Also affects code.gitea.io/gitea |
| GHSA-2wm4-vwp6-v7xc Gitea: SSRF via Migration Asset Downloads Bypasses hostmatcher — Reads Internal Files and Cloud Metadata | High | Also affects code.gitea.io/gitea |
| GHSA-3r5c-2xxx-h872 Gitea: Webhook Authorization Header Returned in Plaintext via API | Low | Also affects code.gitea.io/gitea |
| GHSA-frpw-3h2q-4jj6 Gitea: Cross-Repo Information Disclosure via Org-Level Actions Run/Job APIs | Medium | Also affects code.gitea.io/gitea |
| GHSA-q423-49rw-g9mh Gitea: GHSA-8fwc-qjw5-rvgp ClearRepoWatches fix not applied to API EditRepo path — sister code path retains stale watches on public->private | Medium | Also affects code.gitea.io/gitea |
| GHSA-h56g-4qw7-2mxg Gitea: Public-only API token restriction is not enforced on team API routes | Medium | Also affects gitea.dev |
| GHSA-prr9-9mp4-5gp2 Gitea: Private org member list leaked via /members API endpoint — incomplete fix for PR #38145 | High | Also affects gitea.dev |
MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.
Check your repos with MergeHarbor