GHSA-PM6V-2H4W-4RP2

Vulnerability from github – Published: 2026-06-16 23:40 – Updated: 2026-06-16 23:40
VLAI
Summary
Gogs: Overwriting critical files results in a denial of service
Details

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
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
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 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
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, leaving only the remains. This behavior is best demonstrated by the following table (see Table 1).

Table 1. Results of the path.Clean function operation
Input data Result
any ../../target target
any1/…/any2/../any3/../target target
./target target
/../target /target
a/b/../../../../target ../../target

So, the payload that will bypass the filters and do as we wish, will look like this: —output=/../data/gogs.db. Attack steps: 1. Create a data directory in the repository and an empty gogs.db file in that directory. 2. Send a payload request and check that the code returned is a 200 OK (see Figure 2).

Figure 2. Example of a successful attack

image

Show details on source website

{
  "affected": [
    {
      "database_specific": {
        "last_known_affected_version_range": "\u003c= 0.13.4"
      },
      "package": {
        "ecosystem": "Go",
        "name": "gogs.io/gogs"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "0.14.0"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-52797"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-22"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-06-16T23:40:04Z",
    "nvd_published_at": null,
    "severity": "HIGH"
  },
  "details": "**Vulnerability type:** Path Traversal\n**Impact:** DoS\n**Exploitation prerequisite:** authorized user\n**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.\n**Researcher:** Artyom Kulakov (Positive Technologies)\n**Mitigation:**\n1. https://github.com/gogs/gogs/blob/b7372b1f32cd0bb40984debfb049e3fc04efaee4/internal/route/repo/editor.go#L307 \u2014 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.\n2. To filter the `treePath` variable, it is better to use the preexisting `pathutil.Clean` function instead of `path.Clean` from the standard Go library.\n### Exploitation\nA 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).\n###### Listing 1. _preview method processor\n```Go\nfunc DiffPreviewPost(c *context.Context, f form.EditPreviewDiff) {\n\t// \u0412 treePath \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 :path_to_file\n\ttreePath := c.Repo.TreePath\n\n    // \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0447\u0442\u043e \u0444\u0430\u0439\u043b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438\n\tentry, err := c.Repo.Commit.TreeEntry(treePath)\n\n\t-cut-\n\n\t// \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043e\u0431\u0445\u043e\u0434 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\n\tdiff, err := c.Repo.Repository.GetDiffPreview(c.Repo.BranchName, treePath, f.Content)\n\n\t-cut-\n```\nThe 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).\n###### Listing 2. Path checking and cleaning function\n```Go\nfunc (t *Tree) TreeEntry(subpath string, opts ...LsTreeOptions) (*TreeEntry, error) {\n\t\n\t-cut-\n\t// \u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u043f\u0443\u0442\u0438 \u043e\u0442 \u201c.\u201d \u0418 \u201c/\u201d\n\tsubpath = path.Clean(subpath)\n\t\n\t// \u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0432\u0435\u0440\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 \u0446\u0438\u043a\u043b\u0435\n\tpaths := strings.Split(subpath, \"/\")\n\t\n\t-cut-\n\t\n\tfor i, name := range paths {\n\t\t-cut-\n\t}\n```\nThus, 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).\n###### Figure 1. Example of filter bypass\n![image](https://user-images.githubusercontent.com/100608357/287145762-2a3b83d8-8322-4044-b536-668c5771102a.png)\nThe 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).\n###### Listing 3. Change comparison function\n```Go\nfunc (repo *Repository) GetDiffPreview(branch, treePath, content string) (diff *gitutil.Diff, err error) {\n\t-cut-\n\n\tcmd := exec.Command(\"git\", \"diff\", treePath)\n\tcmd.Dir = localPath\n\tcmd.Stderr = os.Stderr\n\n\t-cut-\n}\n```\nHowever, 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`.\n\nThen a second task arises: to select a parameter which allows us to perform malicious actions. Such a parameter is `--output=\u003cfile\u003e`. This option allows the result of the comparison to be written over the passed path. The malicious command looks like this: `git diff \u2014output=/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.\n\nThe 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, leaving only the remains. This behavior is best demonstrated by the following table (see Table 1).\n###### Table 1. Results of the `path.Clean` function operation\n| Input data | Result |\n| ----------- | ----------- |\n| any ../../target    | target   |\n| any1/\u2026/any2/../any3/../target    | target   |\n| ./target    | target   |\n| /../target    | /target   |\n| a/b/../../../../target    | ../../target   |\n\nSo, the payload that will bypass the filters and do as we wish, will look like this: `\u2014output=/../data/gogs.db`.\n**Attack steps:**\n1. Create a data directory in the repository and an empty `gogs.db` file in that directory.\n2. Send a payload request and check that the code returned is a 200 OK (see Figure 2).\n###### Figure 2. Example of a successful attack\n![image](https://user-images.githubusercontent.com/100608357/287148063-21356d09-b847-4d46-9a03-86bfa71f306d.png)",
  "id": "GHSA-pm6v-2h4w-4rp2",
  "modified": "2026-06-16T23:40:04Z",
  "published": "2026-06-16T23:40:04Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/gogs/gogs/security/advisories/GHSA-pm6v-2h4w-4rp2"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/gogs/gogs"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:N/I:L/A:H",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Gogs: Overwriting critical files results in a denial of service"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…