-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## ReqContainerAccess takes no container\n\nThe function as it ships in Gitea v1.25.4, `routers/api/packages/container/container.go`:\n\n```go\nfunc ReqContainerAccess(ctx *context.Context) {\n\tif ctx.Doer == nil || (setting.Service.RequireSignInViewStrict && ctx.Doer.IsGhost()) {\n\t\tapiUnauthorizedError(ctx)\n\t}\n}\n```\n\nThat is the entire function. Three lines, one `if`, two reads off `ctx`. The function name is `ReqContainerAccess`. By the convention Gitea's repository code observes, a function with that name should take a permission mode, look up the resource being accessed, and check the caller's authorization against it. The repository module has that shape. `routers/web/repo/setting/setting.go` and adjacent files reach for `access_model.GetDoerRepoPermission(ctx, repo, ctx.Doer)`, get back a granular `Permission` struct, and gate on it. The container middleware does none of that. It reads a global setting flag. It reads `ctx.Doer`. It decides nothing about any container.\n\nIt also does not `return` after calling `apiUnauthorizedError`. The 401 path writes a response header and a body, and the surrounding handler chain proceeds. That is a second hazard not relevant to the present bug, because under default settings no public-facing read path through this function takes the `if` branch at all.\n\nThe route registrations confirm what `ReqContainerAccess` is supposed to be guarding. From `routers/api/packages/api.go`:\n\n```go\nr.Get(\"/_catalog\", container.ReqContainerAccess, container.GetRepositoryList)\n// ...\ng.MatchPath(\"GET\", `//manifests/`,\n container.VerifyImageName, container.GetManifest)\ng.MatchPath(\"GET\", `//blobs/`,\n container.VerifyImageName, container.GetBlob)\n```\n\nThe `_catalog` endpoint enumerates every container repository on the instance. The `manifests` endpoint hands out OCI manifest JSON for any of them. The `blobs` endpoint hands out the actual layer bytes. All three sit behind `ReqContainerAccess` plus `reqPackageAccess(perm.AccessModeRead)`, the only auth checks the read path runs.\n\n## /v2/token hands every caller a ghost user with scope `*`\n\nOCI clients establish a session at `/v2/token` before issuing pulls. The Authenticate handler in v1.25.4:\n\n```go\nfunc Authenticate(ctx *context.Context) {\n\tu := ctx.Doer\n\tpackageScope := auth_service.GetAccessScope(ctx.Data)\n\tif u == nil {\n\t\tif setting.Service.RequireSignInViewStrict {\n\t\t\tapiUnauthorizedError(ctx)\n\t\t\treturn\n\t\t}\n\t\tu = user_model.NewGhostUser()\n\t} else {\n\t\tif has, err := packageScope.HasAnyScope(\n\t\t\tauth_model.AccessTokenScopeReadPackage,\n\t\t\tauth_model.AccessTokenScopeWritePackage,\n\t\t\tauth_model.AccessTokenScopeAll,\n\t\t); !has {\n\t\t\t// ...\n\t\t\tapiUnauthorizedError(ctx)\n\t\t\treturn\n\t\t}\n\t}\n\ttoken, err := packages_service.CreateAuthorizationToken(u, packageScope)\n\t// ...\n\tctx.JSON(http.StatusOK, map[string]string{\"token\": token})\n}\n```\n\nIf the caller arrives unauthenticated, and the operator has not enabled `RequireSignInViewStrict` (the default), the handler synthesizes a Ghost user. The Ghost is Gitea's sentinel for \"no account,\" `UserID: -1`. The scope is whatever the request asks for. The PoC's first network call:\n\n```\nGET /v2/token?service=container_registry&scope=*\n```\n\nThe handler returns a JWT signed by the server, `UserID: -1, Scope: \"*\"`. Every subsequent request the attacker makes carries that JWT as a Bearer token.\n\nFrom here the middleware chain reads:\n\n1. `ReqContainerAccess`. `ctx.Doer` is the Ghost (non-nil). `RequireSignInViewStrict` is false. Neither conjunct of the `if` holds. Falls through.\n2. `reqPackageAccess(perm.AccessModeRead)`. Checks the token scope against `read_package`, `write_package`, or `all`. The Ghost's `*` scope maps to `all`. Falls through.\n3. `context.PackageAssignment()`. Resolves the owner and package name from the URL path, loads the package row, attaches it to `ctx`. No predicate on the package's owner visibility runs.\n4. `VerifyImageName`. Format check on the image name. Falls through.\n5. `GetManifest` / `GetBlob` / `GetRepositoryList`. Serves the bytes.\n\nNo code path on the read side consults `package.Visibility` or `owner.Visibility`. The pipeline is \"the package exists, hand it over.\" The `_catalog` endpoint goes further: it returns the full list of repositories on the instance to any caller holding any valid token, ghost or otherwise. The enumeration step the PoC needs and the pull step it follows up with are both default-allow.\n\n## The 1.26.2 patch changed the bytes on the 401 response\n\nPR #37290 (April 19, 2026, author wxiaoguang) is the container-module change CVE-2026-27771 cites. Its title is \"Fix container auth for public instance.\" Its diff to `apiUnauthorizedError`:\n\n```diff\n func apiUnauthorizedError(ctx *context.Context) {\n \trealmURL := httplib.GuessCurrentHostURL(ctx) + \"/v2/token\"\n \tctx.Resp.Header().Add(\"WWW-Authenticate\",\n \t\t`Bearer realm=\"`+realmURL+`\",service=\"container_registry\",scope=\"*\"`)\n-\t// support apple container like: container registry login -u\n-\tctx.Resp.Header().Add(\"WWW-Authenticate\", `Basic realm=\"Gitea Container Registry\"`)\n+\n+\townerName := ctx.PathParam(\"username\")\n+\towner, _ := user_model.GetUserByName(ctx, ownerName)\n+\trequireSignIn := owner != nil && owner.Visibility != structs.VisibleTypePublic\n+\trequireSignIn = requireSignIn || setting.Service.RequireSignInViewStrict\n+\tif requireSignIn {\n+\t\tctx.Resp.Header().Add(\"WWW-Authenticate\",\n+\t\t\t`Basic realm=\"Gitea Container Registry\"`)\n+\t}\n \tapiErrorDefined(ctx, errUnauthorized)\n }\n```\n\nThe added block reads the path parameter `username`, looks the user up, derives a `requireSignIn` boolean from the owner's `Visibility`, and conditionally appends a `Basic realm` to the WWW-Authenticate header on the 401 response. The Bearer realm header is unchanged. The body of the response is unchanged.\n\nThe function the patch modifies is `apiUnauthorizedError`. It is the function that emits a 401. It runs when something upstream has already decided to deny the request. Under default `RequireSignInViewStrict=false`, no public-facing read of a ghost-token-authenticated pull reaches `apiUnauthorizedError`, because `ReqContainerAccess` and `Authenticate` both fall through without ever calling it. The patch changes the bytes Gitea sends when it would have denied the caller. It does not change what causes Gitea to deny.\n\nThe two functions on the success path, side by side across versions:\n\n```go\n// v1.25.4\nfunc ReqContainerAccess(ctx *context.Context) {\n\tif ctx.Doer == nil || (setting.Service.RequireSignInViewStrict && ctx.Doer.IsGhost()) {\n\t\tapiUnauthorizedError(ctx)\n\t}\n}\n```\n\n```go\n// v1.26.2\nfunc ReqContainerAccess(ctx *context.Context) {\n\tif ctx.Doer == nil || (setting.Service.RequireSignInViewStrict && ctx.Doer.IsGhost()) {\n\t\tAPIUnauthorizedError(ctx)\n\t}\n}\n```\n\nThe difference is one character. The lowercase `a` in `apiUnauthorizedError` was capitalized to `APIUnauthorizedError` so the helper could be referenced from outside the package. The body of the function, the predicate it tests, the container it does not look up, none of it changed. Authenticate is the same story: same Ghost user synthesis, same scope, same token, capitalization on the rename of the helper it calls when it does deny.\n\nNoScope's published writeup is candid about the scope of the fix. Their phrasing: the container registry access model \"remains a longer term work in progress.\" That is the researcher who discovered the bug telling readers the patch is incomplete. The CVE is closed. The bug class is not.\n\n## The shared utility exists. The container code does not call it.\n\nGitea has a function called `access_model.GetDoerRepoPermission`. It takes a request context, a repository, and a doer; it returns a `Permission` struct that encodes the granular access mode the caller holds against that resource. The repository module imports it. The web UI's tree views call it. The Git protocol handlers call it. Every code path in Gitea that decides whether a user can read a private repository runs through this function, and has for as long as Gitea has supported private repositories.\n\nThe package module does not call it.\n\nThe Composer fix in PR #37610 (May 11, 2026, author lunny) is the proof, because it is the diff in which Gitea finally imports `GetDoerRepoPermission` into a package handler for the first time. In `routers/api/packages/composer/api.go`:\n\n```go\npermission, err := access_model.GetDoerRepoPermission(ctx, pd.Repository, ctx.Doer)\nif err != nil {\n\tlog.Error(\"GetDoerRepoPermission: %v\", err)\n} else if permission.HasAnyUnitAccessOrPublicAccess() {\n\tpkg.Source = ...\n}\n```\n\nThe patch author wired the canonical utility into one package handler, called it before exposing the repository source URL on Composer package metadata, and stopped there. The container module two directories over, the same monorepo, the same PR window, is not touched. Generic packages, npm, Maven, Helm, NuGet, Conda, RubyGems, the other seven non-Composer package types Gitea ships, do not call `GetDoerRepoPermission` either. The shared utility exists. The package handlers do not import it.\n\nThis is [parallel-implementation-gap](/patterns/parallel-implementation-gap). The canonical implementation, the repository module, holds the permission check. The divergent implementations, the package handlers, expose the same client-facing contract (\"access to a resource the owner created\") without importing the canonical's security utility. Same shape as [CVE-2025-58179, Astro's Cloudflare adapter never importing `isRemoteAllowed`](/posts/astro-shipped-two-image-endpoints), and [CVE-2026-0545, MLflow's FastAPI routers missing from the basic-auth validator's table](/posts/mlflow-basic-auth-only-gated-flask). The difference here is the count of divergent implementations: Astro had two, MLflow had four, Gitea's package module shipped ten without the canonical's gate, and the Composer fix promoted one of them.\n\nPR #37610 also added `Private` and `Internal` visibility badges to the package UI templates. Operators can now see, in their package list view, that a package is private. The badge inherits from the owner's visibility column. The same column the container manifest and blob handlers do not select on.\n\n## 31,750 instances, four years, one column never read\n\nThe Gitea container registry shipped in v1.17 on July 24, 2022. `ReqContainerAccess` as quoted above has been the read-side gate since that release. NoScope's enumeration in April 2026 returned 34,144 internet-facing Gitea hosts and identified roughly 31,750 of them as exposing private container repositories to unauthenticated callers. China, the United States, and Germany held the largest concentrations. 52 percent of the hosts ran on major cloud providers. The exposed packages span healthcare providers, aerospace manufacturers, retail chains, internet service providers, software companies, and SaaS platforms.\n\nThe \"private\" label on a container package's UI is derived from the owner's `Visibility` column, the same column repository routes have read for years to gate access to private repositories. The container routes do not select on that column. The operator-facing claim and the runtime enforcement diverged at the moment the container registry shipped, and the divergence held for forty-five months, until an outside researcher counted internet-facing hosts and noticed the catalog endpoint was returning everything.\n\nThe 1.26.2 release credits NoScope. The credit is correct. What 1.26.2 ships, against the bug NoScope found, is one change to the bytes a 401 response carries, one Composer-specific call to the permission helper that has existed for a decade, and a set of templates that paint a \"private\" badge on resources the container routes still serve to anyone.\n\nPoC: [portbuster1337/CVE-2026-27771](https://github.com/portbuster1337/CVE-2026-27771)","closing_line":"The patch closed the dialog Docker clients see when they cannot reach a private package. The 200 response is unchanged.","hook_md":"Gitea ships a function called `ReqContainerAccess`. The function takes a `*context.Context` and reads two fields off it: `ctx.Doer` and the global setting `RequireSignInViewStrict`. It does not read the request path. It does not look up the container being requested. It does not consult the owner's visibility. CVE-2026-27771 is what that function lets through, four years' worth of private container images on roughly 31,750 internet-facing Gitea instances, exposed because the middleware named after requiring container access never knew which container was being accessed. The 1.26.2 patch changed the headers the function emits on 401 responses. The check on the 200 path is unchanged.","post_id":504,"slug":"gitea-cve-2026-27771-reqcontaineraccess-knows-no-container","title":"CVE-2026-27771: Gitea's ReqContainerAccess Does Not Know Which Container Is Being Accessed","type":"initial","unreadable_sentence":"Between v1.25.4 and v1.26.2, ReqContainerAccess's body changed by one character: the lowercase `a` in `apiUnauthorizedError` became uppercase. What the function decides did not change. Which container it does not look up did not change."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCawTwDwAKCRDeZjl4jgkQ JvWXAQDeO+9640uwGko6u6a7cfJ30uEDAejvcP8El+xhi353PgD/fDX3lTPIqmU1 B2B3D4aWz9cDYMraux9aJffJxa3Pag0= =qpyU -----END PGP SIGNATURE-----