Skip to content
RCE Write-up Advanced

Critical Alert: CVE-2026–60004 — Pre-Auth Remote Code Execution in Gitea (CVSS 9.8)

A flaw in Gitea's patch application routine lets an attacker write a malicious Git hook into a temporary bare repository, which then executes with the Gitea daemon's permissions. Because public self-registration is enabled by default, an unauthenticated attacker can create an account and trigger remote code execution.

synthex Follow

Published on synthex.medium.com

Cve 2026 60004

Synthex, on synthex.medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

Gitea is a lightweight, self-hosted Git platform. Among its features is a repository patch application routine, reachable through the REST API, which accepts unified diff patches and applies them to a repository. The report concerns that routine and the way it handles patch conflicts.

The vulnerability is tracked as CVE-2026-60004 and carries a CVSS v3 score of 9.8 (Critical). Under default system configurations it allows unauthenticated remote attackers to achieve arbitrary code execution on the host server.

Setup

The report describes the exploitation conditions rather than a lab build. The relevant preconditions are:

  1. A Gitea instance reachable over the network, with the REST API exposed.
  2. Default registration settings, that is DISABLE_REGISTRATION = false, so that public self-registration is enabled without admin approval.
  3. The ability to create an account and a repository, which the default configuration grants to anyone.

No specific Gitea version below the fixed release is named in the report; the fix is stated as version 1.27.1 or higher.

Finding it

The root cause is in Gitea's repository patch application routine, exposed through the REST API endpoint:

HTTP
POST /api/v1/repos/{owner}/{repo}/diffpatch

When handling incoming unified diff patches, Gitea creates temporary bare repositories with git init --bare. When patch conflicts occur, Git's underlying three-way merge fallback strategy forces intermediate files to be written out relative to the repository root. Because the temporary clone is bare, its root directory doubles directly as $GIT_DIR. That overlap between the working area and the Git directory is what makes the write primitive interesting: a file that Git writes as an intermediate artefact during a conflicted merge lands in a location that Git itself treats as control data.

Exploitation

Step 1: Reach the patch endpoint

Send a unified diff patch to the diffpatch endpoint of a repository you can write to:

HTTP
POST /api/v1/repos/{owner}/{repo}/diffpatch

The endpoint is the entry point to the vulnerable patch application routine. The report does not include the request body, headers or a sample patch.

Step 2: Force a patch conflict

Craft the patch so that applying it produces a conflict. On conflict, Git's three-way merge fallback writes intermediate files relative to the repository root. Since the temporary repository is bare, that root is $GIT_DIR.

Step 3: Write the hook

Use the conflict handling to force a malicious script to be written into:

Text
$GIT_DIR/hooks/post-index-change
From the original on synthex.medium.com

The image accompanies the description of the malicious script being written into the hook path and of what happens when Gitea next runs a Git operation on that repository.

Step 4: Wait for a Git operation

The moment Gitea runs any subsequent Git operation on that repository, the system automatically executes the injected hook with the host permissions of the Gitea daemon. That execution is the code execution step, triggered by any subsequent Git operation on the repository.

The pre-auth factor

Exploiting the endpoint requires repository write privileges. The report is explicit that this is not a barrier in default installations: public self-registration is enabled without admin approval (DISABLE_REGISTRATION = false). An unauthenticated external actor can create an account, spin up a repository, gain write access, and trigger host takeover in minutes. That chain is why the flaw is described as pre-auth despite the write privilege requirement.

Root cause

The mistake is the combination of two behaviours. Gitea creates temporary bare repositories for patch application, and Git's three-way merge fallback on conflict writes intermediate files relative to the repository root. In a bare repository the root is $GIT_DIR, so those intermediate writes can land on paths that Git executes, specifically $GIT_DIR/hooks/post-index-change. The report does not describe any check that would have prevented a hook path from being written during patch application.

Impact

An attacker who can reach the endpoint and hold write access to a repository can achieve full arbitrary code execution on the host server. The injected hook runs with the host permissions of the Gitea daemon, so the impact is host takeover rather than repository-level tampering. Because default installations allow self-registration without admin approval, the write privilege requirement is met by simply registering an account, which makes the attack unauthenticated in practice under those defaults. The report says the chain can be completed in minutes.

Fix

  • Primary fix: upgrade all Gitea instances to version 1.27.1 or higher immediately.
  • Workaround: if you cannot update right away, set DISABLE_REGISTRATION = true in app.ini to block external account creation.

The report presents the upgrade as the primary fix and the configuration change as a workaround.

Variants to test

  1. Other hook names. The report names post-index-change; try writing to other hook paths under $GIT_DIR/hooks through the same conflicted-patch route.
  2. Other endpoints that create temporary bare repositories. Any feature that runs git init --bare and then applies patches or merges may share the primitive.
  3. Other conflict-driven merge fallbacks. Trigger three-way merge conflicts in other code paths and observe where intermediate files land.
  4. Registration defaults on other instances. Check whether self-registration without approval is enabled, since that is what turns a write-privilege bug into a pre-auth one.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

A piece of software called Gitea had a serious security hole. Gitea is a program that people install on their own computers or servers to run a private version of a service like GitHub: a place where teams store code, track changes to it, and share it with each other. Because it is self-hosted, the person or company running it is responsible for keeping it safe.

The hole is tracked under the name CVE-2026-60004. A CVE is a public catalogue number given to a known security flaw so that everyone can refer to the same problem by the same name. This one was rated 9.8 out of 10 on a scale called CVSS, which measures how bad a flaw is. A score of 9.8 is labelled Critical, the top band.

What makes it so bad is that a stranger on the internet, with no account and no password, could take over the server that runs Gitea. Taking over means running their own commands on the machine, with the same powers as the Gitea program itself. Security people call that remote code execution, or RCE: remote because it happens over the network, and code execution because the attacker gets their own instructions to run.

From the original on synthex.medium.com

The image above is the article's title card, naming the flaw, the product and the severity.

The product and the feature involved

Gitea has a feature that lets you send it a patch and have it applied to a repository. A patch is a small text file describing changes to files: lines to add, lines to remove. It is the same idea as the "tracked changes" you see in a word processor, but written in a strict text format that programs can read. The particular format here is called a unified diff, which is the standard way of writing such changes in the Git world.

Git is the tool that records the history of a code project. A repository (often shortened to repo) is the folder Git watches, together with its recorded history. A bare repository is a repository with no working folder of files: it holds only Git's internal bookkeeping. Servers use bare repositories because nobody edits files directly inside them.

Gitea exposes this patch feature through its REST API. An API is a way for one program to talk to another over the network, like a service counter: you send a request in a fixed format, and you get a response back. REST is just a common style for such APIs, built on ordinary web requests. You do not need a browser to use one; any program can send the request.

The endpoint, meaning the specific address on the server that handles this feature, is:

HTTP
POST /api/v1/repos/{owner}/{repo}/diffpatch

Line by line:

  • POST is the type of request. Web requests come in kinds; POST means "here is some data, please do something with it".
  • /api/v1/repos/ is the path that says "this is the API, version 1, and we are dealing with repositories".
  • {owner} is a placeholder for the username that owns the repository.
  • {repo} is a placeholder for the repository's name.
  • /diffpatch names the feature: apply a diff as a patch.

So the whole line reads: "send this patch to this person's repository and apply it".

The flaw, step by step

Step 1: Reach the patch endpoint

To use the feature, you send your patch to that same address:

HTTP
POST /api/v1/repos/{owner}/{repo}/diffpatch

This is the entry point. It is the door the attacker knocks on. The report does not include the request body, the headers or a sample patch, so the exact contents of the request are not shown here.

Why this step matters: the flaw lives inside the code that handles this request. Without reaching this endpoint, the rest of the attack cannot happen.

Step 2: Force a patch conflict

When Git applies a patch, it sometimes finds that the file has changed since the patch was written. The lines the patch expects are not where it thought they were. That situation is called a conflict, and it is the same thing you see in a word processor when two people edited the same paragraph.

Git has a fallback for conflicts, called a three-way merge. A merge is Git's attempt to combine two versions of the same files. Three-way means it looks at three things: the common ancestor (the version both sides started from), your version, and the other version. When it cannot decide, it writes intermediate files: scratch copies it uses while working out the result.

The problem is where those scratch files land. In a normal repository, Git keeps its internal data in a hidden subfolder called $GIT_DIR, and the visible files sit outside it. In a bare repository there is no visible area, so the repository's root folder and $GIT_DIR are the same place. Scratch files written "relative to the repository root" therefore land inside Git's own control area.

Why this step matters: the attacker deliberately crafts a patch that will conflict, because the conflict is what triggers the scratch-file writing into the wrong place.

Step 3: Write the hook

Git has a feature called hooks: small scripts that Git runs automatically at certain moments, such as before or after a particular operation. A script is just a list of commands saved in a file. Hooks are meant for legitimate automation, but because Git runs them without asking, a hook file is effectively a program that Git will execute on its own.

The attacker uses the conflict handling to force a malicious script to be written into this path:

Text
$GIT_DIR/hooks/post-index-change

Line by line:

  • $GIT_DIR is Git's internal data folder. In a bare repository, as explained, this is the repository root itself.
  • hooks is the subfolder where Git looks for its automatic scripts.
  • post-index-change is the name of one such hook. Git runs it after the index changes. The index is Git's staging area, the list of changes queued up for the next save.

So the line names a file that Git will treat as a program to run. Writing an attacker's script there is like slipping your own instructions into a to-do list that a robot reads and follows without checking who wrote it.

From the original on synthex.medium.com

The image accompanies the description of the malicious script being written into the hook path and of what happens when Gitea next runs a Git operation on that repository.

Why this step matters: this is the moment the attacker stops merely influencing data and starts planting executable instructions.

Step 4: Wait for a Git operation

The moment Gitea runs any subsequent Git operation on that repository, the system automatically executes the injected hook with the host permissions of the Gitea daemon. A daemon is a program that runs in the background, always on, waiting to do its job; here it is the Gitea service itself. Host permissions means the rights that program has on the machine: whatever files it can read or write, the hook can too.

That execution is the code execution step. The report describes no further interaction from the attacker: once the hook is in place, any subsequent Git operation on that repository sets it off.

Why this step matters: this is the payoff. The planted script runs, and the attacker's commands now run on the server.

Why it is called pre-auth

"Pre-auth" means "before authentication", that is, before logging in. Normally you would expect that planting a file in someone's repository requires an account with write access to that repository. The report is clear that this is not a barrier in default installations.

Gitea, by default, allows anyone to register an account without an administrator approving it. The setting that controls this is DISABLE_REGISTRATION, and by default it is set to false, meaning registration is not disabled. So a stranger can create an account, create their own repository, and therefore have write access to it, all in a few minutes and with no human approval.

That chain is why the flaw is described as pre-auth even though write access is technically needed: the write access is free for the taking under the defaults.

Root cause

The mistake is the combination of two behaviours. Gitea creates temporary bare repositories to apply patches, and Git's three-way merge fallback on conflict writes intermediate files relative to the repository root. In a bare repository the root is $GIT_DIR, so those intermediate writes can land on paths that Git executes, specifically $GIT_DIR/hooks/post-index-change. The report does not describe any check that would have prevented a hook path from being written during patch application.

In plain terms: two features that are each reasonable on their own, temporary bare repositories and conflict scratch files, combine into a way to drop a program exactly where Git will run it.

Impact

An attacker who can reach the endpoint and hold write access to a repository can achieve full arbitrary code execution on the host server. The injected hook runs with the host permissions of the Gitea daemon, so the impact is host takeover rather than repository-level tampering. Because default installations allow self-registration without admin approval, the write privilege requirement is met by simply registering an account, which makes the attack unauthenticated in practice under those defaults. The report says the chain can be completed in minutes.

Fix

  • Primary fix: upgrade all Gitea instances to version 1.27.1 or higher immediately.
  • Workaround: if you cannot update right away, set DISABLE_REGISTRATION = true in app.ini to block external account creation.

app.ini is Gitea's main settings file. Setting DISABLE_REGISTRATION to true turns off public sign-up, so strangers can no longer create accounts on their own. The report presents the upgrade as the primary fix and the configuration change as a workaround.

Variants to test

These are directions for further checking, for people who want to look for related problems.

  1. Other hook names. The report names post-index-change; try writing to other hook paths under $GIT_DIR/hooks through the same conflicted-patch route.
  2. Other endpoints that create temporary bare repositories. Any feature that runs git init --bare and then applies patches or merges may share the primitive.
  3. Other conflict-driven merge fallbacks. Trigger three-way merge conflicts in other code paths and observe where intermediate files land.
  4. Registration defaults on other instances. Check whether self-registration without approval is enabled, since that is what turns a write-privilege bug into a pre-auth one.

Glossary

  • API: a fixed way for one program to send requests to another over the network, like a service counter with set forms.
  • app.ini: Gitea's main configuration file, where settings such as registration are stored.
  • Authentication: proving who you are, usually by logging in. "Pre-auth" means before that step.
  • Bare repository: a Git repository with no working folder of files, holding only Git's internal data. Servers use them.
  • Conflict: the situation where a patch or merge does not fit the current files because they have changed.
  • CVE: a public catalogue number for a known security flaw, so everyone can refer to the same problem.
  • CVSS: a 0 to 10 scale for rating how severe a security flaw is. 9.8 is Critical.
  • Daemon: a program that runs in the background, always on, waiting to do its job.
  • Endpoint: the specific address on a server that handles a particular feature.
  • Git: the tool that records the history of a code project.
  • Hook: a script Git runs automatically at a certain moment, such as after the index changes.
  • Host: the machine (physical or virtual) that runs a program.
  • Host permissions: the rights a program has on its machine; anything it can do, code it runs can do too.
  • Index: Git's staging area, the list of changes queued for the next save.
  • Merge: Git's attempt to combine two versions of the same files.
  • Patch: a text file describing changes to files, in lines to add and remove.
  • POST: a kind of web request that carries data and asks the server to act on it.
  • Remote code execution (RCE): making a server run your own instructions over the network.
  • Repository (repo): the folder Git watches, together with its recorded history.
  • REST: a common style for web APIs, built on ordinary web requests.
  • Script: a list of commands saved in a file, which a computer can run.
  • Self-hosted: software you install and run on your own machine or server, rather than using someone else's service.
  • Three-way merge: Git's conflict fallback that compares the common ancestor, your version and the other version.
  • Unified diff: the standard text format for writing changes to files in the Git world.
  • $GIT_DIR: Git's internal data folder. In a bare repository it is the repository root itself.
  • Write access: permission to change the contents of a repository.

More by synthex

View all

6 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.