Skip to main content

Boteraser | Website and Server Security Solutions

🛡️ CVE-2026-52797 — gogs

🟠 CVSS 8.5 — High ✅ No Known Exploit CWE-22 NVD
8.5
CVSS Score
0 Low4 Medium7 High9 Critical10

Description

Gogs: Overwriting critical files results in a denial of service

Vulnerability type: Path Traversal

Impact: DoS

Exploitation prerequisite: authorized user

Description: As an authorized user, an intruder can dictate the value which is passed to the git diff command which, together with bypassing the filtering of the passed value, allows the user to bypass the target directory and write the result of the comparison to any arbitrary path.

Researcher: Artyom Kulakov (Positive Technologies)

Mitigation:

1. https://github.com/gogs/gogs/blob/b7372b1f32cd0bb40984debfb049e3fc04efaee4/internal/route/repo/editor.go#L307 — on this line, instead of the treePath variable, which comes directly from the user unchanged, we should first filter and then pass the entry variable.

2. To filter the treePath variable, it is better to use the preexisting pathutil.Clean function instead of path.Clean from the standard Go library.

Exploitation

A Positive Technologies researcher discovered that the user has the ability to preview their changes when editing a file in the repository. The POST /:user/:repo/_preview/:branch/:path_to_file method is responsible for displaying the changes. The problem is how the POST /:user/:repo/_preview/:branch/:path_to_file method processes the value passed to the :path_to_file (see Listing 1).

Listing 1. _preview method processor

```Go

func DiffPreviewPost(c *context.Context, f form.EditPreviewDiff) {

// В treePath попадает значение из :path_to_file

treePath := c.Repo.TreePath

// Проверка, что файл существует в репозитории

entry, err := c.Repo.Commit.TreeEntry(treePath)

-cut-

// Значение, полученное от пользователя, передается в функцию в обход фильтра

diff, err := c.Repo.Repository.GetDiffPreview(c.Repo.BranchName, treePath, f.Content)

-cut-

```

The first problem to solve is to make the TreeEntry function think that the value passed in is a file that actually exists in the repository. To do this, we must consider how the TreeEntry function actually makes this decision (see Listing 2).

Listing 2. Path checking and cleaning function

```Go

func (t *Tree) TreeEntry(subpath string, opts ...LsTreeOptions) (*TreeEntry, error) {

-cut-

// Очистка пути от “.” И “/”

subpath = path.Clean(subpath)

// Разбиение результата на компоненты для их последующей верификации в цикле

paths := strings.Split(subpath, "/")

-cut-

for i, name := range paths {

-cut-

}

```

Thus, we have a two-level path verification system. At the first stage, extra characters are removed, and at the second stage the resulting path is divided into components, each of which is then checked to be present in the repository. If the TreeEntry function receives a path that has the format of ../../../../../../etc/passwd, it will be transformed into an [.., .., .., .., .., .., etc, passwd] array. The first element of this array will fail further validation and an error will be returned. This problem can be bypassed if the path is directly from the root directory and the corresponding directory hierarchy is present in the repository. A path in the format of /etc/passwd will turn into an [, etc, passwd] array and successfully pass through the filter (see Figure 1).

Figure 1. Example of filter bypass

![image](https://user-images.githubusercontent.com/100608357/287145762-2a3b83d8-8322-4044-b536-668c5771102a.png)

The resulting value will be passed unchanged to the GetDiffPreview function, which will execute the git diff /etc/passwd command in the current repository (see Listing 3).

Listing 3. Change comparison function

```Go

func (repo *Repository) GetDiffPreview(branch, treePath, content string) (diff *gitutil.Diff, err error) {

-cut-

cmd := exec.Command("git", "diff", treePath)

cmd.Dir = localPath

cmd.Stderr = os.Stderr

-cut-

}

```

However, we will not get any results because such a command will exit early with an error stating that the /etc/passwd is outside the repository boundaries. Because of the specifics of the exec.Command function, there is no way to embed commands or insert spaces to separate the arguments. So, we get one controllable command parameter diff.

Then a second task arises: to select a parameter which allows us to perform malicious actions. Such a parameter is --output=<file>. This option allows the result of the comparison to be written over the passed path. The malicious command looks like this: git diff —output=/data/gogs.db. It overwrites the database file with garbage, which leads to denial of service. Instead of a database file, we could also overwrite a app.ini configuration file.

The final challenge is to bypass the filter in order to pass the payload. This is possible through the use of some peculiarities in the library function path.Clean. By entering a specific sequence of characters, the path.Clean function discards everything that came before this sequence and the sequence itself,

How this vulnerability can be exploited

This issue can be reached over the network, attack complexity is low, an attacker needs low-level privileges on the target. No user interaction is required. The scope is changed, meaning a successful attack can affect components beyond the vulnerable one. Rated impact: confidentiality none, integrity low, availability high.

CVSS metrics in full

The score comes from this vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:N/I:L/A:H

  • Attack vector: Network — reachable from anywhere that can route to the service.
  • Attack complexity: Low — the attack works reliably, with no preparation.
  • Privileges required: Low — an ordinary user account is enough.
  • User interaction: None — nobody has to be tricked into anything.
  • Scope: Changed — a successful attack reaches components beyond the vulnerable one.
  • Confidentiality impact: None.
  • Integrity impact: Low — limited, and the attacker does not choose what is affected.
  • Availability impact: High — total loss, or loss the attacker controls.

Weakness class

CVE-2026-52797 is classified as CWE-22: Path Traversal. A file path built from user input is not confined to the intended directory, letting an attacker reach files elsewhere on the filesystem.

Affected software

CVE-2026-52797 is recorded against 2 packages.

  • gogs.io/gogs
  • unknown

Timeline and source

Published on 25 June 2026 and last revised on 21 July 2026. No public exploit is currently recorded for this entry. Record sourced from NVD.

References

github.com (Advisory)

Other advisories for this package

gogs.io/gogs has other advisories on record. If you are patching this one, these are worth checking on the same host:

Same weakness in other software

These advisories are the same class of weakness (CWE-22: Path Traversal) in other software:

Details

Severity HIGH
CVSS Score 8.5
CVSS Vector CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:N/I:L/A:H
CWE CWE-22
Public Exploit ✅ No
Source NVD
Published 2026-06-25
Updated 2026-08-20
Modified 2026-07-21
Fix URL N/A

Affected Packages

Software From version Fixed in
gogs.io/gogs
unknown

Similar Threats

Site Security Check

Is gogs part of your stack?

CVE-2026-52797 is rated CVSS 8.5 High. BotEraser scans your installation against known CVE records and tells you whether this vulnerability applies to the versions you actually run.

Scan My Site Free →

No credit card required  ·  Results in minutes

ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.

Browse related advisories

All advisoriesCVECVE 2026