Forgejo 16.0.3 and below hit by critical RCE via malicious template repos

Forgejo <=16.0.3 Critical RCE

A critical vulnerability in Forgejo up to version 16.0.3 lets a malicious template repository plant a .git folder during variable expansion, which git then adopts — enabling arbitrary data reads and remote code execution on the host. A second fix closes an API access-token bypass for restricted permissions. Commenters note closed registration and limited repo creation reduce exposure.

A malicious template repository could be used to read arbitrary data from the Forgejo host, and to execute arbitrary processes on the Forgejo host, as a remote code execution attack.
  1. amiga386

    You should change the URL to https://codeberg.org/forgejo/forgejo/milestone/139655

    > PR: Critical: fix: prevent template expansion from interfering with git repo initialization. When generating a new repository from a template repository, Forgejo clones the template repository, removes the .git folder, performs variable template expansion on files listed in .forgejo/template, and initializes a new git repository. During this process, variable template expansion could be misused in order to create a new .git folder, which git would adopt and incorporate during its initialization of a new git repository. A malicious template repository could be used to read arbitrary data from the Forgejo host, and to execute arbitrary processes on the Forgejo host, as a remote code execution attack. To address this issue, after variable expansion is completed, any existing .git folder is removed from the directory before the git repository is initialized.

  2. techknowlogick

    Only posting here because I've been asked about it. Gitea is protected against both of these issues.

    (bias note: part of project leadership of Gitea)

    Edit: As a note, security incidents happen to everyone and we shouldn't shame anyone for reporting them, especially as that'd otherwise cause less issues to be reported overall.

  3. keel-control

    This was my first thought after they disallowed LLM contributions.

    They may not use AI to check for vulnerabilities but attackers are going to which puts themselves at the disadvantage.

  4. Macha

    Since the release notes is currently unreadable due to codeberg rate limits, the two fixes in the release notes are:

    https://codeberg.org/forgejo/forgejo/pulls/14301:

    *Critical:* fix: prevent template expansion from interfering with git repo initialization. When generating a new repository from a template repository, Forgejo clones the template repository, removes the `.git` folder, performs variable template expansion on files listed in `.forgejo/template`, and initializes a new git repository. During this process, variable template expansion could be misused in order to create a new `.git` folder, which git would adopt and incorporate during its initialization of a new git repository. A malicious template repository could be used to read arbitrary data from the Forgejo host, and to execute arbitrary processes on the Forgejo host, as a remote code execution attack. To address this issue, after variable expansion is completed, any existing `.git` folder is removed from the directory before the git repository is initialized.

    https://codeberg.org/forgejo/forgejo/pulls/14301:

    ensure authorization reducer is accessed when checking editable PRs in APIs. When editing a git repo contents through Forgejo's API, a specialized security control is used to permit repository maintainers to edit branches that they do not own when an open pull request with the "allow maintainer edit" option is present. This specialized security control did not take into account API-specific security res […]

  5. jzebedee

    Relevant change:

    Security bug fixes

    PR: Critical: fix: prevent template expansion from interfering with git repo initialization. When generating a new repository from a template repository, Forgejo clones the template repository, removes the .git folder, performs variable template expansion on files listed in .forgejo/template, and initializes a new git repository. During this process, variable template expansion could be misused in order to create a new .git folder, which git would adopt and incorporate during its initialization of a new git repository. A malicious template repository could be used to read arbitrary data from the Forgejo host, and to execute arbitrary processes on the Forgejo host, as a remote code execution attack. To address this issue, after variable expansion is completed, any existing .git folder is removed from the directory before the git repository is initialized.

More from this day

2026-09-10