GITEA.DEV · CVE-2026-123642 · Package
FIX → 28.4.0
Gitea's AGit push handling skips the pull-request permission check, so users with only code read access, such as read-only deploy keys or tokens, can open pull requests and write refs/pull/N/head. They cannot write branches or tags, merge, or read data they could not already read.
first public Nov 15, 2026 · 2 sources
Check it with your coding agent
It reads this page and tells you if your code or app is affected.
Self-hosted Gitea instances from 1.16 up to 28.3.0 are exposed, through HTTP or SSH, to anyone who can read a repository's code, including read-only deploy keys and tokens, team members with code read only, and signed-in users on public repositories with pull requests disabled. A second route exists over SSH for users with wiki write access. Instances on managed hosting that do not run this Gitea version can skip it.
Not affected if gitea-28.4.0-or-later, gitea-before-1.16, managed-hosting
Who cares git-hosting, gitea, self-hosted
gitea --version and compare it to the affected range >= 1.16, <= 28.3.0.[log] output for POST /api/internal/hook/proc-receive/... requests from read-only credentials.pull requests created by deploy keys or read-only tokens (author gitea:deploy-key).A missing permission check in Gitea's AGit flow lets anyone who can only read a repository's code open pull requests in it, even when they have no access to its pull requests. This includes a read-only deploy key or token, a team member granted repo.code: read only, or any signed-in user on a public repository whose pull-request unit is disabled. The pull request is created normally, with notifications, and a refs/pull/N/head ref pointing at the attacker's commit is written into the repository. The attached reproducer shows this in the default configuration over HTTP: a read-only deploy token on a private repository opens pull request #1, authored by gitea:deploy-key.
HookProcReceive (routers/private/hook_proc_receive.go) loads the doer's permission but never checks it or the IsWiki flag. pull_service.NewPullRequest also skips its own access check for AGit pull requests (services/pull/pull.go:69), so the pre-receive hook is the only gate. runHookPreReceive in cmd/hook.go lets commands slip past that gate in two ways:
Are you affected?
Ask from here. InfraStack checks the affected versions against your stack and answers in your inbox.
InfraStack checks the affected versions against your stack and answers in Slack, with the evidence and the fix.
InfraStack checks it against your stack and answers on your report, with the evidence and the fix.
Upgrade to 28.4.0
28.4.0 (fixed version in the product ranges).gitea hook proc-receive parses the same line with SplitN(..., 3) and acts on it, and git does not validate ref names it routes to proc-receive. So a push to refs/for/main/topic x never reaches the internal pre-receive API but still becomes a pull request.gitea serv hands the hooks the main repository's name. A principal with wiki write access but no pull-request access can therefore run git push owner/repo.wiki.git <commit>:refs/for/main/topic and open a pull request in the main repository. On this route the head must be a commit that already exists in the main repository.The impact has firm limits. No branch or tag can be written this way and nothing is disclosed. Nothing merges without a writer. Actions treats AGit pull requests like fork pull requests, so they get no secrets and no run without approval.
The behavior dates from "Add agit flow support in gitea" (#14295, commit 370516883717), first released in v1.16.0-rc1. A one-check fix in HookProcReceive closes both routes and is included in the attached patch.
Root cause. HookProcReceive (routers/private/hook_proc_receive.go:19-31), the internal handler that turns an AGit
push (refs/for/<base>/<topic>) into a pull request, checks neither the permission it has just loaded nor the IsWiki flag,
and pull_service.NewPullRequest waives its own access check for the AGit flow (services/pull/pull.go:69). The only gate is
the pre-receive hook (HookPreReceive → preReceiveFor), and gitea hook pre-receive does not show every command to it. Two
adjacent continues in the loop of runHookPreReceive keep a refs/for/* command away from the gate, and each is a separate
way to reach the unchecked handler:
cmd/hook.go:230-233), over HTTP or SSH, for anyone with code read access. This is the
route described first and the one the reproducer exercises;cmd/hook.go:226-228), for anyone with wiki write access. See "Second way
in" below.One check in HookProcReceive closes both (see "Suggested fix").
Scanned commit 31626de2a6cdd3e1fe93216e4ac80f511297f1e7, default configuration. For the first route the attacker is any
principal that may
start a git-receive-pack on the repository (POST /{owner}/{repo}.git/git-receive-pack, or git-receive-pack over SSH),
which means read access to the code unit. A push to an AGit ref whose name contains a space is never shown to the pre-receive
permission check, yet gitea hook proc-receive still turns it into a pull request.
With a read-only deploy token for the private repository owner/secret, this receive-pack command is refused with
pre-receive hook declined and the hook message "User permission denied for creating pull-request.":
0000000000000000000000000000000000000000 <commit> refs/for/main/topic
The same request with a space in the ref name creates pull request #1, authored by gitea:deploy-key, and refs/pull/1/head points at
the pushed commit:
0000000000000000000000000000000000000000 <commit> refs/for/main/topic x
With [log] LEVEL = info the router log shows POST /api/internal/hook/pre-receive/owner/secret → 403 for the first push. For
the second there is no pre-receive request at all, only POST /api/internal/hook/proc-receive/owner/secret → 200.
Why a reader gets this far. Both transports deliberately let readers start a push and leave the decision to pre-receive:
routers/web/repo/githttp.go:185-188 lowers the required mode to read for the code repository, and
routers/private/serv.go:246-252 does the same with the comment "The real permission check is done in HookPreReceive".
Benign path. For refs/for/main/topic, gitea hook pre-receive posts the command to HookPreReceive, which dispatches to
preReceiveFor → AssertCreatePullRequest → Permission.CanRead(unit.TypePullRequests)
(routers/private/hook_pre_receive.go:110, :343, :67-84). A deploy key has access to the code and wiki units only
(models/perm/access/repo_permission.go:403-407), so the answer is 403 and git refuses the push.
Buggy path. The pre-receive hook reads git's old new ref lines and skips whatever is not exactly three fields:
// cmd/hook.go:163
func parseGitHookCommitRefLine(line string) (...) {
fields := strings.Split(line, " ")
if len(fields) != 3 {
return "", "", "", false
}
…
// cmd/hook.go:230
oldCommitID, newCommitID, refFullName, ok := parseGitHookCommitRefLine(scanner.Text())
if !ok {
continue
}
old new refs/for/main/topic x has four fields. It is the only line, so count stays 0, the if count > 0 block that calls
private.HookPreReceive (cmd/hook.go:259-270) is not entered, and the hook exits 0. The skipped command is neither checked nor
rejected.
Nothing else rejects it. Gitea sets receive.procReceiveRefs = refs/for (modules/git/config.go:77), and git hands such
commands to the proc-receive hook without validating the ref name. Observed with the image's git 2.47.3: the owner pushing
refs/heads/x y gets ng refs/heads/x y funny refname, while refs/for/main/topic x reaches the hook. gitea hook proc-receive parses the same command differently and keeps everything after the second space as the ref name:
// cmd/hook.go:544
t := strings.SplitN(string(rs.Data), " ", 3)
…
hookOptions.RefFullNames = append(hookOptions.RefFullNames, git.RefName(t[2]))
HookProcReceive loads the doer's permission but never consults it (routers/private/hook_proc_receive.go:19-31).
agit.ProcReceive resolves main/topic x to base branch main and topic topic x (services/agit/agit.go:37-60, :110)
and calls pull_service.NewPullRequest (services/agit/agit.go:196), which waives its own access check for this flow
(services/pull/pull.go:69: canCreate := issue.Poster.IsAdmin || pr.Flow == issues_model.PullRequestFlowAGit) and writes
refs/pull/N/head through UpdateRefForAgit (services/pull/pull.go:138).
The hook then answers ok refs/for/main/topic x. git cuts that at the space ("proc-receive reported status on unknown ref:
refs/for/main/topic") and tells the client proc-receive failed to report status. The pull request already exists at that point.
Second way in: AGit push to the wiki over SSH. The same unchecked handler is reached with a well-formed ref name and a
stock git push, by a principal that may write the wiki but has no access to the pull-request unit:
$ git push -o title=… -o description=… ssh://git@host/acme/product.git origin/dev:refs/for/main/topic
remote: error: User permission denied for creating pull-request.
! [remote reject
NVD data is provided by NIST and is public domain. Posts quoted belong to their authors.