Forgejo <=16.0.3 Critical RCE

(codeberg.org)

84 points | by weierstass 3 hours ago

16 comments

  • amiga386 2 hours ago
    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.

    • embedding-shape 44 minutes ago
      Conciser: User's who can create new repositories, can exploit templates to do variable template expansion leading to being able to read arbitrary data from the Forgejo hosts.

      If you have open registrations or otherwise users you don't 100% trust with the ability to create new repository (which is the default I think?), they could potentially exploit this and you probably wanna upgrade ASAP.

      If you have only trusted users, or single user, seems it's fine. Of course, wanna upgrade anyway to not add escalation paths, but in the other situation it's graver.

  • techknowlogick 1 hour ago
    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.

    • tredre3 1 hour ago
      > Gitea is protected against both of these issues.

      Is Gitea's immunity just incidental because it was written by a different person, or is it due to a deliberate defensive system that prevents such bug/mistake from occurring?

      • embedding-shape 41 minutes ago
        Very interested in knowing too, since the issues seems to not be related at all, or similar, so now this must mean a Gitea "project leader" would only say this if they have some sort of layer that doesn't require them to manually patch issues individually. Meaning, firewall? Would be weird if that's built-in into Gitea though... Hmm.
  • keel-control 2 hours ago
    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.

    • burkaman 1 hour ago
      They did not disallow LLM contributions, and they definitely didn't disallow using LLMs to research security vulnerabilities. They only disallowed projects that are majority LLM-written.

      https://codeberg.org/Codeberg/org/commit/71149c7fc95ccfeae36...

      • badsectoracula 59 minutes ago
        That is about Codeberg, not Forgejo.

        Forgejo disallows LLM contributions, including using a "general AI" (they include LLMs under "general AI") for reviews[0]:

        > 5. Using general AI for review is forbidden. If the change contains changes to the UX it has to be approved by a human reviewer.

        [0] https://codeberg.org/forgejo/governance/src/branch/main/AIAg...

        • burkaman 41 minutes ago
          Ah sorry, didn't realize they had their own policy. This is a little stronger, but you can certainly still use an LLM to search for vulnerabilities, you would just need to write fixes yourself and mention if you used an LLM for assistance.

          The rule you quoted is about code reviews, they don't want you using an LLM to write reviews or leave comments.

          This is a pretty poorly written policy to be honest, so I understand if you interpret it to mean "no LLMs in any capacity", but I think if that's what they meant they would have said that. In fact they explicitly allow content "made with the help of AI", you just have to disclose it.

        • overfeed 13 minutes ago
          > Forgejo disallows LLM contributions

          You're misreading the rule.

          >> 5. Using general AI for review is forbidden.

          The second sentence makes it even clearer, as it would have been unnecessary under a blanket ban scenario

          >> ... If the change contains changes to the UX it has to be approved by a human reviewer.

    • titularcomment 2 hours ago
      I really disagree with their acceptable usage policy, but you can't say it with certainity that LLM contributions would be a fix for this. They generate so much noise (as the primary incentive behind an independent LLM scan is often cheap contributor brownie points for your CV) that it also could lead to bogus PRs being approved or helpful PRs being lost in the noise.
    • bdcravens 1 hour ago
      Why can't you use an LLM to find vulnerabilities and then hand-code the fix? You don't even have to clean-room implement it; let the LLM write the code, and then reimplement, doing what you can to de-LLM-ify it.
      • omnimus 1 hour ago
        You can. People on Codeberg use LLMs. They are just against spam of low quality projects generated with LLMs.
    • otherme123 2 hours ago
      Was this discovered by AI? Is all AI code 100% free of bugs?

      You are implying that just by allowing LLM contributions your product is free of bugs, and the LLM won't introduce new bugs. Of course, if the LLM introduces bugs, the solution is to add another layer of LLM looking for bugs, ad infinitum.

      Another post from today from Shopify, praising LLM to code their frontend, also stated that their LLM generated code is not ready to deploy, and needs to be reviewed:

      > It’s tempting to just point an LLM to the React Native codebase and try to one-shot the same features in native, but it doesn’t work. Even if you ask it to gather as much information as it can up front, freeze that into specs, task files, and then implement it, you end up with a huge amount of unmaintainable code that can’t be shipped. [...] each [build] must prove its behavior with tests, match the running app in a visual review, survive two adversarial code reviewers, and get a human's nod before it's committed and the next one starts.

      • 1matin 1 hour ago
        > They may not use AI to *check for vulnerabilities*

        you didn't read the comment, did you?

    • striking 1 hour ago
      Disallowing LLM contributions doesn't disqualify the use of LLMs to identify vulnerabilities.
  • Macha 2 hours ago
    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 restrictions, such as repo-specific access tokens. As a result, it was possible for an API access token with restricted permission to make modifications outside of that restricted permission. The specialized security control has been updated to take into account API authentication security restrictions.

    ---

    So if like me you run a private forgejo instance with closed signups and limited repository creation, you can wait for the update. Otherwise maybe take it off the public internet for a bit?

  • jzebedee 2 hours ago
    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.
    • hephaes7us 2 hours ago
      It looks like this is a bit less concerning if you have turned off open account registration.
  • rcleveng 2 hours ago
    ``` This git endpoint is seeing a high influx of requests for this repository, to preserve the availability of Codeberg your search request will not be processed. Sorry for the inconvenience and please try again later. ```

    Any mirror?

    • sbx320 2 hours ago
      The PR is still accessible https://codeberg.org/forgejo/forgejo/pulls/14300

          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.
  • miguelgrinberg 1 hour ago
    For those on version 15 LTS, this fix was released with v15.0.8.
  • nightpool 1 hour ago
    What does the error message mean by "Your search request"? Why is viewing a single file in a repository considered a search request? That smells like poor caching somewhere
  • PaoloBarbolini 2 hours ago
    If you are self-hosting Forgejo and haven't done it yet, consider creating a Codeberg account and following https://codeberg.org/forgejo/security-announcements/issues
    • xyst 1 hour ago
      Updates also posted to #forgejo-chat:matrix.org channel.
      • p4bl0 59 minutes ago
        They also have a releases RSS feed. I have those in my mail client (Thunderbird) directly for the projects that I must closely follow critical updates of.
  • innocent_name 1 hour ago
    The opex and security fine costs of moving off managed services like GitHub/GitLab are catching up.
  • Sphax 2 hours ago
    Can't load the page but hopefully it's on an endpoint sitting behind my Tinyauth protection.
  • dboreham 1 hour ago
    Quick note that this is not an RCE in the typical sense that I can rock up to a Forgejo installation and execute code on the server. The attack vector here is via a template repo specified when initializing a new repo. The template repo could contain malicious code that then executes on the host server. So if you don't create new repos from mystery meat template repos, you should be ok.
    • nightpool 1 hour ago
      Are you sure? The change says "A malicious template repository could be used to read arbitrary data from the Forgejo host" (emphasis added). Couldn't an attacker create a template repo and then immediately create a new repo from their own template, causing the Forgejo process to execute their template code on the server?
      • msm_ 1 hour ago
        They could, and this is definitely a RCE (a Remote Code Execution) vulnerability. GP confusion stems from the fact, that you (the forgejo user) must execute this attack on "your" instance. But of course the problem is that forgejo user can, in fact, be malicious, and use this vulnerability to escalate their priviliges from user to server.

        It can't be done without authenticating first, but there's nothing about RCE that says that it must be sent from unauthenticated connection.

    • msm_ 1 hour ago
      >So if you don't create new repos from mystery meat template repos, you should be ok.

      You should be OK, but if attacker takes over your user (or any user in your forgejo instance) they can execute code on the host server - as you said yourself. In other words, it allows them to achieve remote code execution, so it's a RCE.

  • rvz 59 minutes ago
    As I said before for patching vulnerabilities in the age of AI [0], attackers are going to build exploits around this RCE with AI or even find more flaws with AI.

    This means you have no choice but to use AI to defend, find and patch these flaws before attackers quickly build and use these exploits to target users.

    You cannot afford to disallow or have a 100% ban on LLM contributions while attackers do not care and will use AI to find the flaws and attack you faster than you can triage it.

    [0] https://news.ycombinator.com/item?id=49262849

  • bakugo 1 hour ago
    Trying to open any codeberg.org page from my main Helium browser results in a 403 just saying "Bye". Opening in Chrome or Firefox works fine. Very confusing.
  • vyftec_wpsec 36 minutes ago
    [flagged]