//nefariousplan

CVE-2026-27771: Gitea's ReqContainerAccess Does Not Know Which Container Is Being Accessed

vendor

pattern

cve

proof of concept

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.

ReqContainerAccess takes no container

The function as it ships in Gitea v1.25.4, routers/api/packages/container/container.go:

func ReqContainerAccess(ctx *context.Context) {
	if ctx.Doer == nil || (setting.Service.RequireSignInViewStrict && ctx.Doer.IsGhost()) {
		apiUnauthorizedError(ctx)
	}
}

That 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.

It 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.

The route registrations confirm what ReqContainerAccess is supposed to be guarding. From routers/api/packages/api.go:

r.Get("/_catalog", container.ReqContainerAccess, container.GetRepositoryList)
// ...
g.MatchPath("GET", `/<image:*>/manifests/<reference>`,
    container.VerifyImageName, container.GetManifest)
g.MatchPath("GET", `/<image:*>/blobs/<digest>`,
    container.VerifyImageName, container.GetBlob)

The _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.

/v2/token hands every caller a ghost user with scope *

OCI clients establish a session at /v2/token before issuing pulls. The Authenticate handler in v1.25.4:

func Authenticate(ctx *context.Context) {
	u := ctx.Doer
	packageScope := auth_service.GetAccessScope(ctx.Data)
	if u == nil {
		if setting.Service.RequireSignInViewStrict {
			apiUnauthorizedError(ctx)
			return
		}
		u = user_model.NewGhostUser()
	} else {
		if has, err := packageScope.HasAnyScope(
			auth_model.AccessTokenScopeReadPackage,
			auth_model.AccessTokenScopeWritePackage,
			auth_model.AccessTokenScopeAll,
		); !has {
			// ...
			apiUnauthorizedError(ctx)
			return
		}
	}
	token, err := packages_service.CreateAuthorizationToken(u, packageScope)
	// ...
	ctx.JSON(http.StatusOK, map[string]string{"token": token})
}

If 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:

GET /v2/token?service=container_registry&scope=*

The handler returns a JWT signed by the server, UserID: -1, Scope: "*". Every subsequent request the attacker makes carries that JWT as a Bearer token.

From here the middleware chain reads:

  1. ReqContainerAccess. ctx.Doer is the Ghost (non-nil). RequireSignInViewStrict is false. Neither conjunct of the if holds. Falls through.
  2. reqPackageAccess(perm.AccessModeRead). Checks the token scope against read_package, write_package, or all. The Ghost's * scope maps to all. Falls through.
  3. 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.
  4. VerifyImageName. Format check on the image name. Falls through.
  5. GetManifest / GetBlob / GetRepositoryList. Serves the bytes.

No 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.

The 1.26.2 patch changed the bytes on the 401 response

PR #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:

 func apiUnauthorizedError(ctx *context.Context) {
 	realmURL := httplib.GuessCurrentHostURL(ctx) + "/v2/token"
 	ctx.Resp.Header().Add("WWW-Authenticate",
 		`Bearer realm="`+realmURL+`",service="container_registry",scope="*"`)
-	// support apple container like: container registry login <gitea-host> -u
-	ctx.Resp.Header().Add("WWW-Authenticate", `Basic realm="Gitea Container Registry"`)
+
+	ownerName := ctx.PathParam("username")
+	owner, _ := user_model.GetUserByName(ctx, ownerName)
+	requireSignIn := owner != nil && owner.Visibility != structs.VisibleTypePublic
+	requireSignIn = requireSignIn || setting.Service.RequireSignInViewStrict
+	if requireSignIn {
+		ctx.Resp.Header().Add("WWW-Authenticate",
+			`Basic realm="Gitea Container Registry"`)
+	}
 	apiErrorDefined(ctx, errUnauthorized)
 }

The 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.

The 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.

The two functions on the success path, side by side across versions:

// v1.25.4
func ReqContainerAccess(ctx *context.Context) {
	if ctx.Doer == nil || (setting.Service.RequireSignInViewStrict && ctx.Doer.IsGhost()) {
		apiUnauthorizedError(ctx)
	}
}
// v1.26.2
func ReqContainerAccess(ctx *context.Context) {
	if ctx.Doer == nil || (setting.Service.RequireSignInViewStrict && ctx.Doer.IsGhost()) {
		APIUnauthorizedError(ctx)
	}
}

The 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.

NoScope'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.

The shared utility exists. The container code does not call it.

Gitea 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.

The package module does not call it.

The 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:

permission, err := access_model.GetDoerRepoPermission(ctx, pd.Repository, ctx.Doer)
if err != nil {
	log.Error("GetDoerRepoPermission: %v", err)
} else if permission.HasAnyUnitAccessOrPublicAccess() {
	pkg.Source = ...
}

The 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.

This is 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, and CVE-2026-0545, MLflow's FastAPI routers missing from the basic-auth validator's table. 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.

PR #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.

31,750 instances, four years, one column never read

The 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.

The "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.

The 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.

PoC: portbuster1337/CVE-2026-27771

The patch closed the dialog Docker clients see when they cannot reach a private package. The 200 response is unchanged.