{"id":"CVE-2026-123642","kind":"vulnerability","aliases":["CVE-2026-123642","GHSA-9827-6wh6-634q"],"related":[],"title":"AGit proc-receive lets users without PR access create pull requests","description":"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`.\n\n`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:\n\n- **A ref name containing a space (HTTP or SSH).** The hook silently skips any stdin line that does not split into exactly three fields. `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.\n- **Any push to the wiki repository over SSH.** The hook skips every ref of a wiki push, while `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.\n\nThe 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.\n\nThe 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.\n\n## Details\n\n**Root cause.** `HookProcReceive` (`routers/private/hook_proc_receive.go:19-31`), the internal handler that turns an AGit\npush (`refs/for/<base>/<topic>`) into a pull request, checks neither the permission it has just loaded nor the `IsWiki` flag,\nand `pull_service.NewPullRequest` waives its own access check for the AGit flow (`services/pull/pull.go:69`). The only gate is\nthe pre-receive hook (`HookPreReceive` → `preReceiveFor`), and `gitea hook pre-receive` does not show every command to it. Two\nadjacent `continue`s in the loop of `runHookPreReceive` keep a `refs/for/*` command away from the gate, and each is a separate\nway to reach the unchecked handler:\n\n1. **a ref name containing a space** (`cmd/hook.go:230-233`), over HTTP or SSH, for anyone with code read access. This is the\n   route described first and the one the reproducer exercises;\n2. **any push to the wiki repository over SSH** (`cmd/hook.go:226-228`), for anyone with wiki write access. See \"Second way\n   in\" below.\n\nOne check in `HookProcReceive` closes both (see \"Suggested fix\").\n\nScanned commit `31626de2a6cdd3e1fe93216e4ac80f511297f1e7`, default configuration. For the first route the attacker is any\nprincipal that may\n*start* a `git-receive-pack` on the repository (`POST /{owner}/{repo}.git/git-receive-pack`, or `git-receive-pack` over SSH),\nwhich 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\npermission check, yet `gitea hook proc-receive` still turns it into a pull request.\n\nWith a **read-only deploy token** for the private repository `owner/secret`, this receive-pack command is refused with\n`pre-receive hook declined` and the hook message \"User permission denied for creating pull-request.\":\n\n    0000000000000000000000000000000000000000 <commit> refs/for/main/topic\n\nThe 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\nthe pushed commit:\n\n    0000000000000000000000000000000000000000 <commit> refs/for/main/topic x\n\nWith `[log] LEVEL = info` the router log shows `POST /api/internal/hook/pre-receive/owner/secret` → 403 for the first push. For\nthe second there is no pre-receive request at all, only `POST /api/internal/hook/proc-receive/owner/secret` → 200.\n\n**Why a reader gets this far.** Both transports deliberately let readers start a push and leave the decision to pre-receive:\n`routers/web/repo/githttp.go:185-188` lowers the required mode to read for the code repository, and\n`routers/private/serv.go:246-252` does the same with the comment \"The real permission check is done in HookPreReceive\".\n\n**Benign path.** For `refs/for/main/topic`, `gitea hook pre-receive` posts the command to `HookPreReceive`, which dispatches to\n`preReceiveFor` → `AssertCreatePullRequest` → `Permission.CanRead(unit.TypePullRequests)`\n(`routers/private/hook_pre_receive.go:110`, `:343`, `:67-84`). A deploy key has access to the code and wiki units only\n(`models/perm/access/repo_permission.go:403-407`), so the answer is 403 and git refuses the push.\n\n**Buggy path.** The pre-receive hook reads git's `old new ref` lines and skips whatever is not exactly three fields:\n\n```go\n// cmd/hook.go:163\nfunc parseGitHookCommitRefLine(line string) (...) {\n\tfields := strings.Split(line, \" \")\n\tif len(fields) != 3 {\n\t\treturn \"\", \"\", \"\", false\n\t}\n…\n// cmd/hook.go:230\n\t\toldCommitID, newCommitID, refFullName, ok := parseGitHookCommitRefLine(scanner.Text())\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n```\n\n`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\n`private.HookPreReceive` (`cmd/hook.go:259-270`) is not entered, and the hook exits 0. The skipped command is neither checked nor\nrejected.\n\nNothing else rejects it. Gitea sets `receive.procReceiveRefs = refs/for` (`modules/git/config.go:77`), and git hands such\ncommands to the proc-receive hook without validating the ref name. Observed with the image's git 2.47.3: the owner pushing\n`refs/heads/x y` gets `ng refs/heads/x y funny refname`, while `refs/for/main/topic x` reaches the hook. `gitea hook\nproc-receive` parses the same command differently and keeps everything after the second space as the ref name:\n\n```go\n// cmd/hook.go:544\n\t\tt := strings.SplitN(string(rs.Data), \" \", 3)\n\t\t…\n\t\thookOptions.RefFullNames = append(hookOptions.RefFullNames, git.RefName(t[2]))\n```\n\n`HookProcReceive` loads the doer's permission but never consults it (`routers/private/hook_proc_receive.go:19-31`).\n`agit.ProcReceive` resolves `main/topic x` to base branch `main` and topic `topic x` (`services/agit/agit.go:37-60`, `:110`)\nand calls `pull_service.NewPullRequest` (`services/agit/agit.go:196`), which waives its own access check for this flow\n(`services/pull/pull.go:69`: `canCreate := issue.Poster.IsAdmin || pr.Flow == issues_model.PullRequestFlowAGit`) and writes\n`refs/pull/N/head` through `UpdateRefForAgit` (`services/pull/pull.go:138`).\n\nThe hook then answers `ok refs/for/main/topic x`. git cuts that at the space (\"proc-receive reported status on unknown ref:\nrefs/for/main/topic\") and tells the client `proc-receive failed to report status`. The pull request already exists at that point.\n\n**Second way in: AGit push to the wiki over SSH.** The same unchecked handler is reached with a well-formed ref name and a\nstock `git push`, by a principal that may write the wiki but has no access to the pull-request unit:\n\n```\n$ git push -o title=… -o description=… ssh://git@host/acme/product.git origin/dev:refs/for/main/topic\nremote: error: User permission denied for creating pull-request.\n ! [remote rejected] origin/dev -> refs/for/main/topic (pre-receive hook declined)\n\n$ git push -o title=… -o description=… ssh://git@host/acme/product.wiki.git origin/dev:refs/for/main/topic\nremote: Visit the existing pull request:\nremote:   http://host/acme/product/pulls/1\n * [new reference]   origin/dev -> refs/pull/1/head\n```\n\nFor `acme/product.wiki`, `ServCommand` checks write access to the wiki unit and cuts the suffix from the name it returns\n(`routers/private/serv.go:83-87`, `results.RepoName = reqWikiRepoName`). `gitea serv` exports that name to the hooks together\nwith the wiki flag (`cmd/serv.go:317-320`), so the hooks address the **main** repository. `gitea hook pre-receive` then never\ncalls `HookPreReceive`, because it drops every ref of a wiki push:\n\n```go\n// cmd/hook.go:224\n\tfor scanner.Scan() {\n\t\t// TODO: support news feeds for wiki\n\t\tif isWiki {\n\t\t\tcontinue\n\t\t}\n```\n\nThe rule \"Pull requests are not supported on the wiki.\" exists, but only in `preReceiveFor`\n(`routers/private/hook_pre_receive.go:353-356`), which this push never reaches. Wiki repositories have the same delegate hooks\nand the same global `receive.procReceiveRefs = refs/for`, and `runHookProcReceive` has no wiki skip: it posts to\n`/api/internal/hook/proc-receive/acme/product` with `IsWiki: true` (`cmd/hook.go:522`). `RepoAssignment` loads the main\nrepository and `HookProcReceive` creates the pull request there. `UpdateRefForAgit` writes `refs/pull/N/head` in the main\nrepository, so the pushed commit has to exist there already; that is why the push above uses `origin/dev`, a commit fetched from\nthe main repository. A commit that exists only in the wiki ends in a 500 from the hook and no pull request.\n\nThe neighbouring post-receive handler shows the intent: `HookPostReceive` starts with `if opts.IsWiki { … return }`\n(`routers/private/hook_post_receive.go:95`). Over HTTP the same wiki push fails, by accident rather than by a check:\n`DoerPushingEnvironment` keeps the `.wiki` suffix (`modules/repository/env.go:44`), the hook asks for `acme/product.wiki`, the\nrepository is not found and the push ends with \"Internal Server Error\". This route therefore exists only over SSH.\n\n## Impact\n\nThe pull-request permission gate of the AGit flow is bypassed by every principal that has code read access but no access to the\npull-request unit. Each of the following was observed on a live instance at this commit: the well-formed ref is refused with\n\"User permission denied for creating pull-request.\", the ref with a space creates the pull request.\n\n- A read-only deploy token (HTTP, the shipped reproducer) or a read-only deploy key (SSH; checked through the built-in SSH\n  server, `START_SSH_SERVER = true`, since the image has no sshd). A credential issued for checkouts writes objects and a\n  `refs/pull/N/head` ref into the repository and opens pull requests with a title of its choice; it still cannot write a\n  branch or tag.\n- A member of an organization team that grants `repo.code: read` only, on a private repository. The owner sees the pull\n  request; the member's own `GET /repos/{owner}/{repo}/pulls` still answers 404.\n- Any signed-in user, on a public repository whose pull-request unit is disabled. The pull request and its ref are created\n  although `/pulls` answers 404 for the repository, and the pull request is listed once the unit is enabled again.\n\nThe pull request is created by the ordinary `pull_service.NewPullRequest`, so the usual new-pull-request notifications are sent\n(`notify_service.NewPullRequest`, `services/pull/pull.go:187`). Branches and tags cannot be written this way, because git itself\nrefuses such names outside `refs/for/`, and nothing is disclosed that the principal could not already read. Nothing merges\nwithout a writer, and Actions treats every AGit pull request as a fork pull request (`isForkPullRequestInput`,\n`services/actions/notifier_helper.go:688-702`), so these pull requests get no secrets and no run without approval. Principals\nthat can read the pull-request unit gain nothing: they may open AGit pull requests by design.\n\nThe wiki route (SSH only) gives the same result to principals that were given the wiki but not the pull requests, with a\nstock git client. Observed on a live instance at this commit (built-in SSH server) for a member of a team with\n`repo.code: read` and `repo.wiki: write` only, for a write deploy key (refused on `product.git`, pull request by\n`gitea:deploy-key` through `product.wiki.git`), and for a wiki writer while the repository has pull requests disabled. It is\nnarrower than the first route: the head must be a commit that already exists in the main repository, so no attacker-authored\ncommit enters the pull request; the title, description, base branch and topic are the attacker's, and further pushes move the\nhead of pull requests opened this way.\n\nBoth routes date back to `370516883717` (\"Add agit flow support in gitea (#14295)\", 2021-07-28), first released in v1.16.0-rc1,\nwhich lowered the transport check to read and added `gitea hook proc-receive` and `HookProcReceive`; the read-only deploy\ntoken principal exists only since deploy tokens were added (#37306).\n\n## Suggested fix\n\nThe attached patch makes two changes. The first is the root-cause fix and is sufficient for both routes; the second removes\nthe parser disagreement that made the first route possible.\n\n**1. Let `HookProcReceive` check for itself.** It is the component that decides to create the pull request, and nothing after\nit checks again, so it should not rely on an earlier hook having seen the same refs:\n\n```go\n// routers/private/hook_proc_receive.go, after loadContextDoerPermission (adds the \"gitea.dev/models/unit\" import)\n\tif opts.IsWiki {\n\t\tctx.PrivateUserErrorf(http.StatusForbidden, \"Pull requests are not supported on the wiki.\")\n\t\treturn\n\t}\n\tif !ctx.Repo.Permission.CanRead(unit.TypePullRequests) {\n\t\tctx.PrivateUserErrorf(http.StatusForbidden, \"User permission denied for creating pull-request.\")\n\t\treturn\n\t}\n```\n\nWith this change alone built into the server, the reproducer's attack push is refused at proc-receive with \"User permission\ndenied for creating pull-request.\" (no pull request, no `refs/pull/*`), and the wiki push is refused with \"Pull requests are\nnot supported on the wiki.\".\n\n**2. Make the hook commands agree.** Fail closed in pre-receive, and make proc-receive use the same parser, so that no command\nis acted on without having been checked. This change alone stops the reproducer but **not** the wiki route (checked: the wiki\npush still opens the pull request), which is why it cannot replace the handler check:\n\n```diff\n--- a/cmd/hook.go\n+++ b/cmd/hook.go\n@@ -229,7 +229,7 @@\n \n \t\toldCommitID, newCommitID, refFullName, ok := parseGitHookCommitRefLine(scanner.Text())\n \t\tif !ok {\n-\t\t\tcontinue\n+\t\t\treturn fail(ctx, \"Hook failed: invalid reference update\", \"pre-receive: invalid line: %q\", scanner.Text())\n \t\t}\n \n \t\ttotal++\n@@ -541,13 +541,13 @@\n \t\tif rs.Type == pktLineTypeFlush {\n \t\t\tbreak\n \t\t}\n-\t\tt := strings.SplitN(string(rs.Data), \" \", 3)\n-\t\tif len(t) != 3 {\n-\t\t\tcontinue\n+\t\toldCommitID, newCommitID, refFullName, ok := parseGitHookCommitRefLine(string(rs.Data))\n+\t\tif !ok {\n+\t\t\treturn fail(ctx, \"Hook failed: invalid reference update\", \"proc-receive: invalid line: %q\", rs.Data)\n \t\t}\n-\t\thookOptions.OldCommitIDs = append(hookOptions.OldCommitIDs, t[0])\n-\t\thookOptions.NewCommitIDs = append(hookOptions.NewCommitIDs, t[1])\n-\t\thookOptions.RefFullNames = append(hookOptions.RefFullNames, git.RefName(t[2]))\n+\t\thookOptions.OldCommitIDs = append(hookOptions.OldCommitIDs, oldCommitID)\n+\t\thookOptions.NewCommitIDs = append(hookOptions.NewCommitIDs, newCommitID)\n+\t\thookOptions.RefFullNames = append(hookOptions.RefFullNames, refFullName)\n \t}\n \n \tif hasPushOptions {\n```\n\nThe attached patch additionally has the shared parser `parseGitHookCommitRefLine` reject ref names that fail\n`git.IsValidRefPattern` (space, control characters, `..`), so the two hooks cannot disagree on what a line means. Post-receive\nkeeps skipping unparsable lines, since nothing can be undone there; ordinary branch and tag pushes are unaffected because git\nalready validates those names.\n\nWith the patch applied to a clean checkout and the binary rebuilt, the reproducer prints `OK`, the wiki push over SSH is\nrefused with \"Pull requests are not supported on the wiki.\", and AGit create/update by the owner and by a plain reader,\nbranches with unusual but valid names, tags, deletes and ordinary wiki pushes still work.\n\nRegression tests in the patch: new malformed-line cases (four fields, a trailing `\\r`, an empty line) in\n`TestParseGitHookCommitRefLine` (`cmd/hook_test.go`), and `TestAgitPushPermissionCheck` in\n`tests/integration/git_misc_test.go`. Its `InvalidRefName` subtest sends a hand-written `git-receive-pack` request to\n`refs/for/<default>/topic with-space` and expects `pre-receive hook declined` and no AGit pull request; since it pushes as the\nrepository owner, it exercises the parser rather than the permission. Its `ProcReceive` subtest calls the internal\nproc-receive API directly and expects 403 with \"Pull requests are not supported on the wiki.\" for a wiki push and \"User\npermission denied for creating pull-request.\" for a user without access. The test fails on the scanned commit and passes with\nthe patch; `TestAgitPullPush`, `TestAgitReviewStaleness` and `TestCreateAgitPullWithReadPermission` still pass. The fixtures' hooks\nexecute the tree's `gitea` binary, so rebuild it before running the integration test.\n\n## Suggested patch\n\n```diff\ndiff --git a/cmd/hook.go b/cmd/hook.go\nindex 2280d66a01..3ac7dc37cb 100644\n--- a/cmd/hook.go\n+++ b/cmd/hook.go\n@@ -165,6 +165,10 @@ func parseGitHookCommitRefLine(line string) (oldCommitID, newCommitID string, re\n \tif len(fields) != 3 {\n \t\treturn \"\", \"\", \"\", false\n \t}\n+\t// git doesn't validate the names of the refs which are handled by proc-receive (refs/for/*), so check them here\n+\tif !git.IsValidRefPattern(fields[2]) {\n+\t\treturn \"\", \"\", \"\", false\n+\t}\n \treturn fields[0], fields[1], git.RefName(fields[2]), true\n }\n \n@@ -229,7 +233,8 @@ Gitea or set your environment appropriately.`, \"\")\n \n \t\toldCommitID, newCommitID, refFullName, ok := parseGitHookCommitRefLine(scanner.Text())\n \t\tif !ok {\n-\t\t\tcontinue\n+\t\t\t// fail closed: a skipped line would never be checked, but git (or proc-receive) would still process it\n+\t\t\treturn fail(ctx, \"Hook failed: invalid reference update\", \"pre-receive: invalid line: %q\", scanner.Text())\n \t\t}\n \n \t\ttotal++\n@@ -541,13 +546,14 @@ Gitea or set your environment appropriately.`, \"\")\n \t\tif rs.Type == pktLineTypeFlush {\n \t\t\tbreak\n \t\t}\n-\t\tt := strings.SplitN(string(rs.Data), \" \", 3)\n-\t\tif len(t) != 3 {\n-\t\t\tcontinue\n+\t\t// parse the line in the same way as pre-receive does, otherwise a ref which hasn't been checked could be processed\n+\t\toldCommitID, newCommitID, refFullName, ok := parseGitHookCommitRefLine(string(rs.Data))\n+\t\tif !ok {\n+\t\t\treturn fail(ctx, \"Hook failed: invalid reference update\", \"proc-receive: invalid line: %q\", rs.Data)\n \t\t}\n-\t\thookOptions.OldCommitIDs = append(hookOptions.OldCommitIDs, t[0])\n-\t\thookOptions.NewCommitIDs = append(hookOptions.NewCommitIDs, t[1])\n-\t\thookOptions.RefFullNames = append(hookOptions.RefFullNames, git.RefName(t[2]))\n+\t\thookOptions.OldCommitIDs = append(hookOptions.OldCommitIDs, oldCommitID)\n+\t\thookOptions.NewCommitIDs = append(hookOptions.NewCommitIDs, newCommitID)\n+\t\thookOptions.RefFullNames = append(hookOptions.RefFullNames, refFullName)\n \t}\n \n \tif hasPushOptions {\ndiff --git a/cmd/hook_test.go b/cmd/hook_test.go\nindex fefc33c01c..2e2a72e6b4 100644\n--- a/cmd/hook_test.go\n+++ b/cmd/hook_test.go\n@@ -52,4 +52,13 @@ func TestParseGitHookCommitRefLine(t *testing.T) {\n \n \t_, _, _, ok = parseGitHookCommitRefLine(\"a b\")\n \tassert.False(t, ok)\n+\n+\t_, _, _, ok = parseGitHookCommitRefLine(\"a b c d\")\n+\tassert.False(t, ok)\n+\n+\t_, _, _, ok = parseGitHookCommitRefLine(\"a b c\\r\")\n+\tassert.False(t, ok)\n+\n+\t_, _, _, ok = parseGitHookCommitRefLine(\"\")\n+\tassert.False(t, ok)\n }\ndiff --git a/routers/private/hook_proc_receive.go b/routers/private/hook_proc_receive.go\nindex 2f8ba5203f..c7c0e7e4be 100644\n--- a/routers/private/hook_proc_receive.go\n+++ b/routers/private/hook_proc_receive.go\n@@ -8,6 +8,7 @@ import (\n \t\"net/http\"\n \n \tissues_model \"gitea.dev/models/issues\"\n+\t\"gitea.dev/models/unit\"\n \tuser_model \"gitea.dev/models/user\"\n \t\"gitea.dev/modules/private\"\n \t\"gitea.dev/modules/web\"\n@@ -22,6 +23,16 @@ func HookProcReceive(ctx *gitea_context.PrivateContext) {\n \t\treturn\n \t}\n \n+\t// don't rely on the pre-receive hook only: it skips wiki pushes, and creating the pull request doesn't check the permission again\n+\tif opts.IsWiki {\n+\t\tctx.PrivateUserErrorf(http.StatusForbidden, \"Pull requests are not supported on the wiki.\")\n+\t\treturn\n+\t}\n+\tif !ctx.Repo.Permission.CanRead(unit.TypePullRequests) {\n+\t\tctx.PrivateUserErrorf(http.StatusForbidden, \"User permission denied for creating pull-request.\")\n+\t\treturn\n+\t}\n+\n \tresults, err := agit.ProcReceive(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, &agit.ProcReceiveOptions{\n \t\tOldCommitIDs:   opts.OldCommitIDs,\n \t\tNewCommitIDs:   opts.NewCommitIDs,\ndiff --git a/tests/integration/git_misc_test.go b/tests/integration/git_misc_test.go\nindex af331b25a1..06e80587c2 100644\n--- a/tests/integration/git_misc_test.go\n+++ b/tests/integration/git_misc_test.go\n@@ -5,8 +5,12 @@ package integration\n \n import (\n \t\"bytes\"\n+\t\"crypto/sha1\"\n+\t\"fmt\"\n \t\"io\"\n+\t\"net/http\"\n \t\"net/url\"\n+\t\"strings\"\n \t\"sync\"\n \t\"testing\"\n \n@@ -17,6 +21,7 @@ import (\n \tuser_model \"gitea.dev/models/user\"\n \t\"gitea.dev/modules/git\"\n \t\"gitea.dev/modules/git/gitcmd\"\n+\t\"gitea.dev/modules/private\"\n \tfiles_service \"gitea.dev/services/repository/files\"\n \n \t\"github.com/stretchr/testify/assert\"\n@@ -144,6 +149,61 @@ func TestAgitPullPush(t *testing.T) {\n \t})\n }\n \n+func TestAgitPushPermissionCheck(t *testing.T) {\n+\tonGiteaRun(t, func(t *testing.T, u *url.URL) {\n+\t\trepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})\n+\t\tgitRepo, err := git.OpenRepository(t.Context(), repo)\n+\t\tassert.NoError(t, err)\n+\t\tdefer gitRepo.Close()\n+\t\tcommitID, err := gitRepo.GetBranchCommitID(t.Context(), repo.DefaultBranch)\n+\t\tassert.NoError(t, err)\n+\t\temptyCommitID := git.Sha1ObjectFormat.EmptyObjectID().String()\n+\n+\t\tt.Run(\"InvalidRefName\", func(t *testing.T) {\n+\t\t\t// git doesn't validate the names of the refs which are handled by proc-receive,\n+\t\t\t// and the git client refuses to send such a name, so the request must be written by hand\n+\t\t\tpktLine := func(s string) string { return fmt.Sprintf(\"%04x%s\", len(s)+4, s) }\n+\t\t\temptyPack := \"PACK\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x00\"\n+\t\t\temptyPackSum := sha1.Sum([]byte(emptyPack))\n+\n+\t\t\trefName := \"refs/for/\" + repo.DefaultBranch + \"/topic with-space\"\n+\t\t\tbody := pktLine(emptyCommitID+\" \"+commitID+\" \"+refName+\"\\x00report-status push-options\") + \"0000\" +\n+\t\t\t\tpktLine(\"title=invalid ref name\") + \"0000\" +\n+\t\t\t\temptyPack + string(emptyPackSum[:])\n+\t\t\treq := NewRequestWithBody(t, \"POST\", \"/user2/repo1.git/git-receive-pack\", strings.NewReader(body)).\n+\t\t\t\tAddBasicAuth(\"user2\").\n+\t\t\t\tSetHeader(\"Content-Type\", \"application/x-git-receive-pack-request\")\n+\t\t\tresp := MakeRequest(t, req, http.StatusOK)\n+\n+\t\t\t// the ref must not get to proc-receive without having been checked by pre-receive\n+\t\t\tassert.Contains(t, resp.Body.String(), \"ng \"+refName+\" pre-receive hook declined\")\n+\t\t\tunittest.AssertNotExistsBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, Flow: issues_model.PullRequestFlowAGit})\n+\t\t})\n+\n+\t\tt.Run(\"ProcReceive\", func(t *testing.T) {\n+\t\t\topts := private.HookOptions{\n+\t\t\t\tOldCommitIDs: []string{emptyCommitID},\n+\t\t\t\tNewCommitIDs: []string{commitID},\n+\t\t\t\tRefFullNames: []git.RefName{git.RefName(\"refs/for/\" + repo.DefaultBranch + \"/topic\")},\n+\t\t\t}\n+\n+\t\t\t// pre-receive doesn't check wiki pushes\n+\t\t\topts.UserID, opts.IsWiki = 2, true\n+\t\t\t_, extra := private.HookProcReceive(t.Context(), \"user2\", \"repo1\", opts)\n+\t\t\tassert.Equal(t, http.StatusForbidden, extra.StatusCode)\n+\t\t\tassert.Equal(t, \"Pull requests are not supported on the wiki.\", extra.UserMsg)\n+\n+\t\t\t// user4 can't access the private repo2\n+\t\t\topts.UserID, opts.IsWiki = 4, false\n+\t\t\t_, extra = private.HookProcReceive(t.Context(), \"user2\", \"repo2\", opts)\n+\t\t\tassert.Equal(t, http.StatusForbidden, extra.StatusCode)\n+\t\t\tassert.Equal(t, \"User permission denied for creating pull-request.\", extra.UserMsg)\n+\n+\t\t\tunittest.AssertNotExistsBean(t, &issues_model.PullRequest{Flow: issues_model.PullRequestFlowAGit})\n+\t\t})\n+\t})\n+}\n+\n func TestAgitReviewStaleness(t *testing.T) {\n \tonGiteaRun(t, func(t *testing.T, u *url.URL) {\n \t\tbaseAPITestContext := NewAPITestContext(t, \"user2\", \"repo1\", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)\n\n```\n\n\n_Reported by the Anthropic OSS scanner, finding ANT-2026-1V3RY0V7 (scan gitea-20261022-004), commit 31626de2a6cdd3e1fe93216e4ac80f511297f1e7._","summary":"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.","severity":"medium","cvss":null,"epss":null,"exploited":false,"exploited_at":null,"products":[{"name":"gitea.dev","fixed":["28.4.0"],"affected":">= 1.16, <= 28.3.0","ecosystem":"go"}],"ecosystems":["go"],"tags":["cwe-862","git-hosting","gitea","package","self-hosted"],"not_affected_if":["gitea-28.4.0-or-later","gitea-before-1.16","managed-hosting"],"how_to_check":"- Check the Gitea version with `gitea --version` and compare it to the affected range `>= 1.16, <= 28.3.0`.\n- Look at the instance's `[log]` output for `POST /api/internal/hook/proc-receive/...` requests from read-only credentials.\n- Review `pull` requests created by deploy keys or read-only tokens (author `gitea:deploy-key`).","fix":"- Gitea `28.4.0` (fixed version in the product ranges).","status":"open","published_at":"2026-11-15T21:03:17+00:00","first_seen_at":"2026-11-15T21:12:46+00:00","triaged_at":"2026-11-15T21:14:17+00:00","updated_at":"2026-11-15T21:14:17+00:00","category":"package","confidence":0.85,"triage":{"at":"2026-11-15T21:14:17Z","model":"claude-haiku-5-5","output":{"fix":"- Gitea `28.4.0` (fixed version in the product ranges).","reach":"network","title":"Gitea: read-only users can open pull requests via AGit flow","impact":"low","summary":"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.","audience":"businesses","category":"package","nicknames":[],"who_cares":["self-hosted","gitea","git-hosting"],"confidence":0.85,"fix_status":"available","needs_auth":"yes","worst_case":"Read-only users create pull requests and refs in private repositories","analyst_note":"","how_to_check":"- Check the Gitea version with `gitea --version` and compare it to the affected range `>= 1.16, <= 28.3.0`.\n- Look at the instance's `[log]` output for `POST /api/internal/hook/proc-receive/...` requests from read-only credentials.\n- Review `pull` requests created by deploy keys or read-only tokens (author `gitea:deploy-key`).","plain_action":"","product_name":"","needs_analyst":false,"not_affected_if":["managed-hosting","gitea-before-1.16","gitea-28.4.0-or-later"],"who_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.","user_interaction":"no","product_ecosystem":"","needs_special_setup":"no","severity_if_unknown":"unknown"},"cost_usd":0.001235,"input_tokens":9052,"output_tokens":659,"severity_before":"medium"},"analyst_status":null,"analyst_note":null,"search":"'-123642':15A,24A '-2026':14A,23A '-228':619C '-233':585C '-31':485C '-6':18A '-862':27B '-9827':17A '1':201C,576C '14295':455C '19':484C '2':608C '226':618C '230':584C '3':293C '31626de2a6cdd3e1fe93216e4ac80f511297f1e7':642C '370516883717':457C '634q':21A '69':235C,523C 'access':9A,54B,115C,228C,364C,370C,516C,595C,625C,679C 'act':295C 'action':426C 'add':449C 'adjac':549C 'agit':1A,38B,93C,231C,428C,450C,492C,520C,688C 'alreadi':84B,397C 'also':224C 'anyon':96C,591C,621C 'api':324C 'approv':444C 'attach':178C,477C 'attack':169C,650C 'author':202C 'away':561C 'becom':327C 'behavior':446C 'branch':74B,409C 'cannot':72B 'caus':481C 'check':47B,89C,217C,229C,465C,499C,517C,632C,704C 'close':469C,635C 'cmd/hook.go':248C,583C,617C 'code':52B,104C,593C,682C 'command':250C,545C,560C,734C 'commit':171C,395C,456C,641C 'configur':185C,644C 'contain':261C,580C,692C 'continu':550C 'could':82B 'creat':10A,158C 'cve':13A,22A 'cwe':26B 'data':80B 'date':447C 'default':184C,643C 'deploy':60B,126C,192C,206C,723C 'deploy-key':205C 'describ':600C 'detail':479C 'disabl':153C 'disclos':420C 'doer':212C 'even':110C 'everi':342C,544C 'exact':279C 'exercis':607C 'exist':398C 'field':281C 'firm':406C 'first':458C,601C,647C 'fix':466C,639C 'flag':222C,510C 'flow':94C,451C,521C 'fork':432C 'gate':245C,254C,526C,564C 'get':437C 'ghsa':16A 'git':29B,299C,374C,659C,671C 'git-host':28B 'git-receive-pack':658C,670C 'git/git-receive-pack':668C 'gitea':31B,36B,91C,204C,282C,349C,454C,536C,706C 'gitea.dev':25A 'grant':133C 'hand':351C 'handl':40B 'handler':488C,575C 'head':391C 'hook':241C,268C,283C,340C,353C,532C,537C,707C 'hookprerec':533C 'hookprocrec':208C,468C,482C,634C 'host':30B,35B 'http':187C,264C,587C 'impact':404C 'includ':121C,474C 'intern':320C,487C 'iswiki':221C,509C 'keep':557C 'key':61B,127C,207C 'let':5A,95C,249C 'like':431C 'limit':407C 'line':273C,290C 'load':210C,506C 'loop':554C 'main':355C,385C,401C 'may':655C 'mean':677C 'member':132C 'merg':77B,422C 'miss':87C 'must':392C 'name':260C,304C,358C,579C,691C 'neither':500C 'never':216C,317C,696C 'normal':159C 'noth':418C,421C 'notif':161C 'one':464C,604C,631C 'one-check':463C 'open':65B,105C,198C,379C 'owner':666C 'owner/repo.wiki.git':376C 'owner/secret':729C 'pack':661C,673C,733C 'packag':32B 'pars':287C 'past':252C 'patch':478C 'permiss':46B,88C,214C,502C,703C 'point':166C 'post':665C 'pr':8A 'pre':239C,322C,530C,539C,701C 'pre-rec':238C,321C,529C,538C,700C 'prereceivefor':534C 'princip':360C,653C 'privat':196C,727C 'proc':3A,285C,309C,709C 'proc-rec':2A,284C,308C,708C 'public':145C 'pull':11A,44B,66B,106C,118C,149C,155C,199C,232C,329C,368C,381C,429C,433C,497C,716C 'pull-request':43B,148C,367C 'pull_service.newpullrequest':223C,512C 'push':39B,313C,332C,347C,375C,493C,610C,685C 'reach':318C,572C 'read':53B,58B,79B,85B,100C,124C,135C,190C,594C,678C,721C 'read-on':57B,123C,189C,720C 'receiv':4A,240C,286C,310C,323C,531C,540C,660C,672C,702C,710C,732C 'receive-pack':731C 'ref':165C,259C,303C,343C,578C,689C 'refs/for':494C,559C 'refs/for/main/topic':315C,377C 'refs/pull/n/head':70B,164C 'refus':736C 'releas':459C 'repo':667C 'repo.code':134C 'repositori':102C,146C,176C,197C,336C,356C,386C,402C,614C,664C,728C 'reproduc':179C,606C 'request':12A,45B,67B,107C,119C,150C,156C,200C,233C,330C,369C,382C,430C,434C,498C,717C 'root':480C 'rout':306C,389C,471C,599C,648C 'routers/private/hook_proc_receive.go':209C,483C 'run':373C,442C 'runhookprerec':246C,556C 'scan':640C 'second':627C 'secret':439C 'see':626C,637C 'self':34B 'self-host':33B 'separ':569C 'serv':350C 'services/pull/pull.go':234C,522C 'show':180C,543C 'shown':697C 'sign':140C 'signed-in':139C 'silent':269C 'skip':41B,225C,270C,341C 'slip':251C 'space':263C,582C,694C 'split':277C 'splitn':292C 'ssh':266C,338C,589C,616C,675C 'start':656C 'stdin':272C 'still':326C,711C 'suggest':638C 'support':452C 'tag':76B,411C 'team':131C 'therefor':372C 'three':280C 'token':63B,129C,193C,724C 'treat':427C 'turn':490C,712C 'two':256C,548C 'uncheck':574C 'unit':151C,683C 'user':6A,49B,142C 'v1.16.0-rc1':461C 'valid':302C 'w':737C 'waiv':513C 'way':257C,416C,570C,628C 'wh6':20A 'wh6-634q':19A 'whose':147C,690C 'wiki':335C,346C,362C,613C,623C 'without':7A,423C,443C 'write':69B,73B,363C,624C 'writer':425C 'written':173C,414C 'x':316C 'yet':705C","nicknames":[],"mitigations":[],"who_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.","tier":"C","verified":{},"analyst_revisit_at":null,"fix_status":"available","audience":"businesses","plain_action":null,"pkeys":["giteadev"],"ptokens":["dev","gitea"],"labels":["cwe862","gitea","githosting","go","medium","package","selfhosted"],"campaign_type":null,"search_a":"'-123642':15A,24A '-2026':14A,23A '-6':18A '-9827':17A '634q':21A 'access':9A 'agit':1A 'creat':10A 'cve':13A,22A 'ghsa':16A 'gitea.dev':25A 'let':5A 'pr':8A 'proc':3A 'proc-rec':2A 'pull':11A 'receiv':4A 'request':12A 'user':6A 'wh6':20A 'wh6-634q':19A 'without':7A","search_b":"'-862':27B 'access':54B 'agit':38B 'alreadi':84B 'branch':74B 'cannot':72B 'check':47B 'code':52B 'could':82B 'cwe':26B 'data':80B 'deploy':60B 'git':29B 'git-host':28B 'gitea':31B,36B 'handl':40B 'host':30B,35B 'key':61B 'merg':77B 'open':65B 'packag':32B 'permiss':46B 'pull':44B,66B 'pull-request':43B 'push':39B 'read':53B,58B,79B,85B 'read-on':57B 'refs/pull/n/head':70B 'request':45B,67B 'self':34B 'self-host':33B 'skip':41B 'tag':76B 'token':63B 'user':49B 'write':69B,73B","search_c":"'-228':619C '-233':585C '-31':485C '1':201C,576C '14295':455C '19':484C '2':608C '226':618C '230':584C '3':293C '31626de2a6cdd3e1fe93216e4ac80f511297f1e7':642C '370516883717':457C '69':235C,523C 'access':115C,228C,364C,370C,516C,595C,625C,679C 'act':295C 'action':426C 'add':449C 'adjac':549C 'agit':93C,231C,428C,450C,492C,520C,688C 'alreadi':397C 'also':224C 'anyon':96C,591C,621C 'api':324C 'approv':444C 'attach':178C,477C 'attack':169C,650C 'author':202C 'away':561C 'becom':327C 'behavior':446C 'branch':409C 'caus':481C 'check':89C,217C,229C,465C,499C,517C,632C,704C 'close':469C,635C 'cmd/hook.go':248C,583C,617C 'code':104C,593C,682C 'command':250C,545C,560C,734C 'commit':171C,395C,456C,641C 'configur':185C,644C 'contain':261C,580C,692C 'continu':550C 'creat':158C 'date':447C 'default':184C,643C 'deploy':126C,192C,206C,723C 'deploy-key':205C 'describ':600C 'detail':479C 'disabl':153C 'disclos':420C 'doer':212C 'even':110C 'everi':342C,544C 'exact':279C 'exercis':607C 'exist':398C 'field':281C 'firm':406C 'first':458C,601C,647C 'fix':466C,639C 'flag':222C,510C 'flow':94C,451C,521C 'fork':432C 'gate':245C,254C,526C,564C 'get':437C 'git':299C,374C,659C,671C 'git-receive-pack':658C,670C 'git/git-receive-pack':668C 'gitea':91C,204C,282C,349C,454C,536C,706C 'grant':133C 'hand':351C 'handler':488C,575C 'head':391C 'hook':241C,268C,283C,340C,353C,532C,537C,707C 'hookprerec':533C 'hookprocrec':208C,468C,482C,634C 'http':187C,264C,587C 'impact':404C 'includ':121C,474C 'intern':320C,487C 'iswiki':221C,509C 'keep':557C 'key':127C,207C 'let':95C,249C 'like':431C 'limit':407C 'line':273C,290C 'load':210C,506C 'loop':554C 'main':355C,385C,401C 'may':655C 'mean':677C 'member':132C 'merg':422C 'miss':87C 'must':392C 'name':260C,304C,358C,579C,691C 'neither':500C 'never':216C,317C,696C 'normal':159C 'noth':418C,421C 'notif':161C 'one':464C,604C,631C 'one-check':463C 'open':105C,198C,379C 'owner':666C 'owner/repo.wiki.git':376C 'owner/secret':729C 'pack':661C,673C,733C 'pars':287C 'past':252C 'patch':478C 'permiss':88C,214C,502C,703C 'point':166C 'post':665C 'pre':239C,322C,530C,539C,701C 'pre-rec':238C,321C,529C,538C,700C 'prereceivefor':534C 'princip':360C,653C 'privat':196C,727C 'proc':285C,309C,709C 'proc-rec':284C,308C,708C 'public':145C 'pull':106C,118C,149C,155C,199C,232C,329C,368C,381C,429C,433C,497C,716C 'pull-request':148C,367C 'pull_service.newpullrequest':223C,512C 'push':313C,332C,347C,375C,493C,610C,685C 'reach':318C,572C 'read':100C,124C,135C,190C,594C,678C,721C 'read-on':123C,189C,720C 'receiv':240C,286C,310C,323C,531C,540C,660C,672C,702C,710C,732C 'receive-pack':731C 'ref':165C,259C,303C,343C,578C,689C 'refs/for':494C,559C 'refs/for/main/topic':315C,377C 'refs/pull/n/head':164C 'refus':736C 'releas':459C 'repo':667C 'repo.code':134C 'repositori':102C,146C,176C,197C,336C,356C,386C,402C,614C,664C,728C 'reproduc':179C,606C 'request':107C,119C,150C,156C,200C,233C,330C,369C,382C,430C,434C,498C,717C 'root':480C 'rout':306C,389C,471C,599C,648C 'routers/private/hook_proc_receive.go':209C,483C 'run':373C,442C 'runhookprerec':246C,556C 'scan':640C 'second':627C 'secret':439C 'see':626C,637C 'separ':569C 'serv':350C 'services/pull/pull.go':234C,522C 'show':180C,543C 'shown':697C 'sign':140C 'signed-in':139C 'silent':269C 'skip':225C,270C,341C 'slip':251C 'space':263C,582C,694C 'split':277C 'splitn':292C 'ssh':266C,338C,589C,616C,675C 'start':656C 'stdin':272C 'still':326C,711C 'suggest':638C 'support':452C 'tag':411C 'team':131C 'therefor':372C 'three':280C 'token':129C,193C,724C 'treat':427C 'turn':490C,712C 'two':256C,548C 'uncheck':574C 'unit':151C,683C 'user':142C 'v1.16.0-rc1':461C 'valid':302C 'w':737C 'waiv':513C 'way':257C,416C,570C,628C 'whose':147C,690C 'wiki':335C,346C,362C,613C,623C 'without':423C,443C 'write':363C,624C 'writer':425C 'written':173C,414C 'x':316C 'yet':705C","cause_entry":null,"cause_path":null,"disclosures_checked_at":null,"first_public_at":"2026-11-15T21:03:17+00:00","kev":null,"cvss_vector":null,"cvss_by":null,"poc_count":0,"sources":[{"source":"ghsa-repo","external_id":"GHSA-9827-6wh6-634q","url":"https://github.com/go-gitea/gitea/security/advisories/GHSA-9827-6wh6-634q","severity":"medium","published_at":"2026-11-15T21:03:17+00:00","modified_at":"2026-11-15T21:03:17+00:00","first_seen_at":"2026-11-15T21:12:46+00:00","fetched_at":"2026-11-15T21:12:46+00:00","note":null},{"source":"nvd","external_id":"CVE-2026-123642","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-123642","severity":null,"published_at":"2026-11-15T22:17:18+00:00","modified_at":"2026-11-15T22:17:18+00:00","first_seen_at":"2026-11-15T22:40:23+00:00","fetched_at":"2026-11-15T22:40:23+00:00","note":null}],"documents":[{"id":165564,"url":"https://github.com/go-gitea/gitea/security/advisories/GHSA-9827-6wh6-634q","title":"Maintainer's advisory: github.com","kind":"vendor","source":"ghsa-repo","publisher":"vendor","text":null,"published_at":"2026-11-15T21:03:17+00:00","relation":"advisory","confidence":null,"note":"Maintainer's advisory: github.com"},{"id":165694,"url":"https://github.com/go-gitea/gitea/releases/tag/v28.4.0","title":"Release notes: github.com","kind":"release","source":"nvd","publisher":"vendor","text":null,"published_at":null,"relation":"fix","confidence":null,"note":"Release notes: github.com"}],"disclosures":[],"exploit_sources":[],"notice":"Free to read, with fair use of about 60 pages a minute. For higher limits or API access: sales@infrastack.ai"}