---
id: "CVE-2026-126338"
page: "https://infrastack.ai/live/CVE-2026-126338"
kind: "vulnerability"
aliases: ["CVE-2026-126338", "GHSA-wgx7-537g-xfrg"]
title: "Code comment reply accepts foreign review ID, leaks private diff hunks"
severity: "high"
cvss: null
epss: null
exploited: false
status: "open"
category: "package"
products: [{"name": "gitea.dev", "fixed": ["28.4.0"], "affected": ">= 1.14.0, <= 28.3.0", "ecosystem": "go"}]
ecosystems: ["go"]
tags: ["cwe-639", "gitea", "package", "pull-requests", "self-hosted"]
not_affected_if: ["fixed-version", "no-untrusted-users", "pull-requests-disabled"]
published_at: "2026-11-15T21:03:06+00:00"
first_seen_at: "2026-11-15T21:12:48+00:00"
updated_at: "2026-11-15T21:14:23+00:00"
sources: [{"source": "ghsa-repo", "url": "https://github.com/go-gitea/gitea/security/advisories/GHSA-wgx7-537g-xfrg", "first_seen_at": "2026-11-15T21:12:48+00:00"}, {"source": "nvd", "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-126338", "first_seen_at": "2026-11-15T22:40:23+00:00"}]
exploit_sources: []
---

# Code comment reply accepts foreign review ID, leaks private diff hunks

Link for people: https://infrastack.ai/live/CVE-2026-126338 (this .md is for agents)

Gitea's code-comment reply path accepts a review ID from another repository and copies that review's stored diff hunk into the attacker's comment. A signed-in regular user can read up to four diff lines from pull requests in private repositories they cannot access.

_Summary, check and fix written by a model from the sources; labelled as such._

## Affected

- go:gitea.dev affected >= 1.14.0, <= 28.3.0 fixed 28.4.0

## How to check

- Check the installed Gitea version with `gitea --version` or the release shown in the admin dashboard; versions `>= 1.14.0` and `<= 28.3.0` are affected.
- Confirm the instance is not on `28.4.0` or later.
- Review the Gitea source at `services/pull/review.go` for an unbound `FindComments` call with `ReviewID` but no `IssueID`.

## Fix

- Gitea `28.4.0`
- Affected range `>= 1.14.0`, `<= 28.3.0`

## Timeline

- 2026-11-15T21:12:48+00:00 ghsa-repo https://github.com/go-gitea/gitea/security/advisories/GHSA-wgx7-537g-xfrg
- 2026-11-15T22:40:23+00:00 nvd https://nvd.nist.gov/vuln/detail/CVE-2026-126338

## Documents

- [advisory] Maintainer's advisory: github.com https://github.com/go-gitea/gitea/security/advisories/GHSA-wgx7-537g-xfrg
- [fix] Release notes: github.com https://github.com/go-gitea/gitea/releases/tag/v28.4.0

## From the sources

A missing authorization check in Gitea's code-comment reply path lets any signed-in regular user read diff hunks from pull requests in private repositories they have no access to. By submitting a reply whose `reply` form field names a review from another repository, the attacker gets that review's stored diff hunk and commit SHA copied into a comment on a pull request they can comment on. The hunk is up to `[ui] CODE_COMMENT_LINES` diff lines, 4 by default, ending at the commented line. On default settings, the attached reproducer recovers a `PASSWORD=s3cr3t-of-the-victim` line from `victim/private`, while the same attacker gets 404 when asking the API for that review's comments directly.

The bug is in `createCodeComment` in `services/pull/review.go`. When `reviewID != 0`, it calls `FindComments` with only `ReviewID`, `Line`, `TreePath` and `Type`, with no `IssueID` or `RepoID`. It then copies the first match's `Patch`, `CommitSHA` and `Invalidated` into the new comment. The caller, `pull_service.CreateCodeComment`, only checks that the caller's own pull request already has a code comment on that path and line. It never checks that `replyReviewID` belongs to that pull request. The attacker first comments on the matching path and line in a pull request they can comment on (they do not need a repository of their own). They then post the reply form to `POST /{owner}/{repo}/pulls/{index}/files/reviews/comments`, and read the copied `diff_hunk` back by replying to the planted comment through the API. The leak is narrow. Each hit needs a review ID, which is sequential instance-wide but does not reveal its repository. It also needs the exact file path and line of a review comment on the new side of the diff, although the response status confirms guesses (200 for a hit, 500 for a wrong path or line, 404 for a nonexistent review). Pending reviews are affected too, but only the diff under a draft comment leaks, not the draft text. The unbound lookup was introduced in b091c994b593 ("Comments on review should have the same sha (#13448)") and first released in v1.14.0. The API reply route used here to read the hunk back exists only since v1.27.0, so on older releases the hunk is still copied but cannot be read back this way.

## Details

When a code comment is posted as a reply, `createCodeComment` reuses the diff hunk stored with the first comment of the review
being replied to. The review ID is the form field `reply`, and the lookup is not limited to the pull request (or repository)
the request was authorized for:

```go
// services/pull/review.go:218
if line > 0 {
	if reviewID != 0 {
		first, err := issues_model.FindComments(ctx, &issues_model.FindCommentsOptions{
			ReviewID: reviewID,          // request-controlled; no IssueID, no RepoID
			Line:     line,
			TreePath: treePath,
			Type:     issues_model.CommentTypeCode,
			…
		})
		if err == nil && len(first) > 0 {
			commitID = first[0].CommitSHA
			invalidated = first[0].Invalidated
			patch = first[0].Patch      // diff hunk of whatever repository that review belongs to
		} …
```

Observed at commit `31626de2a6cdd3e1fe93216e4ac80f511297f1e7` with default settings: `victim/private` is a private repository whose
pull request changes line 3 of `deploy/settings.env` to `PASSWORD=s3cr3t-of-the-victim`; review 1 has a comment on that line.
The unrelated regular user `attacker` opens a pull request in their own `attacker/scratch`, comments on `deploy/settings.env`
line 3 there, and submits the reply form with `reply=1`. The API then hands the attacker a comment in `attacker/scratch` with

```
"diff_hunk": "@@ -1,4 +1,4 @@\n HOST=db.internal\n USER=app\n-PASSWORD=\n+PASSWORD=s3cr3t-of-the-victim"
```

and the `commit_id` of the victim's commit, while `GET /api/v1/repos/victim/private/pulls/1/reviews/1/comments` answers the
attacker 404.

The path from the request to the copy:

1. `POST /{username}/{reponame}/pulls/{index}/files/reviews/comments` (`routers/web/web.go:1662`) sits behind
   `context.RepoMustNotBeArchived()` (`:1664`) and `optSignIn, context.RepoAssignment, repo.MustAllowPulls, reqUnitPullsReader`
   (`:1667`). All of them look at the repository in the URL, which can be the attacker's own.
2. `repo.CreateCodeComment` (`routers/web/repo/pull_review.go:64`) loads the pull request from the URL with `GetActionIssue` and
   passes `form.Reply` (`services/forms/repo_form.go:471`) unchecked as `replyReviewID` (`:98`). In the UI the field is filled by
   `templates/repo/diff/comment_form.tmpl:34` with the review ID of the conversation being replied to.
3. `pull_service.CreateCodeComment` (`services/pull/review.go:119-125`) asks only `ReviewExists(ctx, issue, treePath, line)`
   (`models/issues/review.go:451`): does the *caller's* pull request already have a code comment on that path and line? The
   attacker creates that comment first; the path does not have to exist in their pull request. `replyReviewID` is never
   compared with `issue.ID`.
4. `createCodeComment(…, replyReviewID, …)` runs the lookup quoted above. `FindCommentsOptions.ToConds`
   (`models/issues/comment.go:1094-1119`) adds a repository or issue condition only when `RepoID` / `IssueID` are set, so the
   query is `review_id = ? AND line = ? AND tree_path = ? AND type = code` over all repositories. The new comment is then
   created on the caller's pull request with `CommitSHA: commitID`, `ReviewID: reviewID`, `Patch: patch`
   (`services/pull/review.go:287-300`).
5. Reading it back: the form's HTML response renders the conversation with the hunk of its first comment (the attacker's own).
   The stored hunk is exposed as `diff_hunk` / `commit_id` by `convert.ToPullReviewComment` (`services/convert/pull_review.go:113-115`).
   `POST /api/v1/repos/{owner}/{repo}/pulls/{index}/comments/{id}/replies` (`CreatePullReviewCommentReply`,
   `routers/api/v1/repo/pull_review.go:209`) returns that JSON for the reply it creates. This route cannot name a foreign
   review by itself, because it loads the parent comment with `GetCommentWithRepoID(ctx, ctx.Repo.Repository.ID, …)` and takes
   `parent.ReviewID`; but the comment planted in step 4 is in the attacker's repository and carries the foreign `ReviewID`, so
   a reply to it goes through the same unbound lookup and returns the victim's hunk.

The unbound lookup was introduced in `b091c994b593` ("Comments on review should have the same sha (#13448)", 2020-11-09) and
first released in v1.14.0. The API reply route used in step 5 to read the hunk back only exists since v1.27.0 (`331450b17a`,
2026-04-27), so on older releases the hunk is still copied into the attacker's comment but this way of reading it back is not
available. The notification mail template (`templates/mail/repo/issue/default.tmpl:56`) also prints the stored hunk; that
channel was not tested (no mail offline).

Other users of a request-supplied review ID bind it: `DismissReview` compares `review.Issue.RepoID` with the repository
(`services/pull/review.go:420-423`), and the API's `prepareSingleReview` rejects `review.IssueID != pr.IssueID` and pending
reviews of other users (`routers/api/v1/repo/pull_review.go:722-732`).

## Impact

A signed-in regular user on a default configuration reads diff hunks of pull requests in repositories they have no access to,
within narrow limits: each hit yields at most the last `[ui] CODE_COMMENT_LINES` (default 4) diff lines ending at a line that
carries a review comment, plus the commit SHA; only comments on the new side of the diff are reachable (the lookup runs for
`line > 0`); and for each hunk the attacker must supply the review ID, the exact file path and the line. They need one pull
request they can comment on. No repository of their own is needed: a third account with no repository got the same result
(HTTP 200) on somebody else's public pull request, once a code comment existed on that path and line there.

Review IDs are one auto-increment sequence for the whole instance, so the attacker's own r

---

_Free to read, with fair use of about 60 pages a minute. For higher limits or API access: sales@infrastack.ai_
