/

CVE-2025-64111

Severity:

CRITICAL RISK

(9.8)

OS Command Injection in Gogs Git Service

CVE-2025-64111

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A command injection vulnerability in Gogs allows attackers to update files inside the .git directory and trigger remote command execution on the server.

When an instance accepts malicious repository content or file updates in .git, an attacker can influence how server-side Git operations are executed, leading to full compromise of the hosting environment.

Affected context

This vulnerability affects Gogs instances that host or interact with Git repositories where attackers can push or modify content impacting the .git directory.

It manifests when server-side Git operations (such as hooks, fetch, merge, or other repository management tasks) are influenced by repository-controlled files or configuration.

Environments that accept code from untrusted or semi-trusted users, CI-like automation on push, or integrate tightly with system-level tools are particularly exposed.

Exploit preconditions

  • Attack surface: Network-accessible Gogs instance handling Git repositories.
  • Required access: Ability to authenticate or otherwise push/modify repository content that impacts the .git directory (e.g., via Git over HTTP/SSH or web UI if permitted).
  • Trigger point: Server-side processing of the manipulated repository (such as Git hooks, configuration parsing, or command wrappers) that eventually pass attacker-controlled values to the OS command execution layer.
  • Why exploitation is possible: Certain .git-scoped files or configurations still influence how Gogs or underlying Git commands are built and executed, allowing attacker-controlled data to cross the trust boundary into shell or process execution without sufficient sanitization or isolation.

Why this happens

The underlying issue is an OS Command Injection pattern, captured by CWE-78, where external input is incorporated into system-level commands without adequate validation, escaping, or strict context separation.

In this case, repository-controlled content inside the .git directory can affect behavior of Git operations or associated logic that Gogs runs on the server.

Because the patch for the earlier CVE was incomplete, there are still paths where values derived from .git are trusted and used in command construction or execution flows.

The core bug class is treating repository metadata and configuration as implicitly safe, rather than constraining or ignoring .git contents that could impact execution environments.

Potential impact

  • Remote execution of arbitrary commands with the privileges of the Gogs service account.
  • Full compromise of the Gogs application and its data, including private repositories and credentials stored by the service.
  • Lateral movement within the hosting environment, potentially impacting other services on the same host.
  • Tampering with source code, build artifacts, or deployment pipelines that depend on the affected Gogs instance.
  • Use of the compromised server as a pivot point for further attacks or as infrastructure for malicious activity.

General mitigation guidance

Effective mitigation relies on hardening how repository data is handled and isolating command execution paths:

  • Treat all repository-controlled content (including .git internals) as untrusted and avoid allowing it to influence arguments, environment variables, or configuration used in OS command execution.
  • Introduce strict allowlisting of which .git files or settings the application will read, and ignore or neutralize inputs that are not explicitly required for core functionality.
  • Prefer safe, high-level library APIs for Git operations instead of constructing shell commands, and avoid invoking a shell where possible.
  • Apply rigorous input normalization and escaping when user- or repository-controlled values must be passed to subprocesses.
  • Run the Gogs service and associated Git operations under least-privilege accounts, with restricted filesystem and network permissions, and consider OS-level sandboxing or containerization to limit blast radius.
  • Separate build/CI runners from the Gogs host to reduce the impact of a compromise of the Git service itself.

How teams detect issues like this

Detection approaches can focus on both code-level indicators and runtime behavior:

  • Use static analysis or manual code review to identify places where values derived from repository metadata, .git configuration, or user-controlled repository paths are passed into command execution APIs (e.g., exec, popen, or shell-invoking helpers).
  • Enforce secure coding guidelines that prohibit direct shell command concatenation and require parameterized invocation of external tools; flag deviations in code review.
  • Implement configuration and policy checks ensuring that server-side hooks or Git-related scripts cannot be arbitrarily influenced by repository content.
  • Monitor runtime logs for unusual or unexpected command executions originating from the Gogs process, especially commands that are not part of normal Git workflows.
  • Deploy host-level intrusion detection or EDR solutions that can alert on anomalous process trees originating from the Gogs service account.

Sources

SourceLink
github.comgithub.com/gogs/gogs/security/advisories/GHSA-gg64-xxr9-qhjp

Frequently asked

questions

Yes. As long as an attacker can push or modify repository content that affects the .git directory and trigger the relevant server-side operations, they can attempt remote code execution over the network without local system access.

Typically, the attacker needs the ability to create or modify repositories on the affected Gogs instance—often via authenticated access, though in some deployments repositories may be open to broader collaboration. The exact access level depends on how repository creation and push permissions are configured.

The most robust fix is to ensure that repository-controlled data, particularly from .git, cannot influence OS command construction or execution. This means using parameterized subprocess calls, avoiding shell interpretation, strictly limiting which configuration entries are read, and treating all repository metadata as untrusted input.

Preventive practices include designing Git integrations so that all user- and repository-controlled data are processed through safe APIs, establishing coding standards that forbid shell command concatenation, mandating security-focused code review for features that interact with VCS internals, and integrating automated static analysis to flag potential command injection patterns before release.

Find out what's already
exploitable in your codebase.