/

CVE-2026-52806

Severity:

CRITICAL RISK

(9.9)

Command Injection (CWE-77) in Gogs Git Rebase Merge Flow

CVE-2026-52806

Deferred

Vulnerability type

Category:

Command Injection

CWE:

CWE-77

Impact:

Remote Code Execution on Gogs application server

Severity:

CRITICAL RISK

(9.9)

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 flaw in Gogs allows an authenticated user to craft a malicious branch name that injects the --exec flag into an internal git rebase command during "Rebase before merging".

When this merge strategy is used, the attack can lead to remote code execution on the Gogs server, making any instance exposed to untrusted repository collaborators particularly risky.

Affected context

The vulnerability appears in Gogs instances that:

  • Allow authenticated users to create branches and pull requests
  • Offer the "Rebase before merging" option in the pull request workflow
  • Construct and execute git rebase commands using unvalidated branch names or user-controlled parameters

It primarily impacts environments where users with repository access are not fully trusted and where the Gogs server process has significant privileges on the host.

Exploit preconditions

  • Attack surface: Web application interface for pull requests and merge operations
  • Required access: Authenticated user with permission to push branches and open pull requests on a target repository
  • Trigger point: Performing a "Rebase before merging" operation on a pull request with a specially crafted branch name
  • Why exploitation is possible: User-controlled branch names are embedded into the git rebase command line without sufficient sanitization or escaping, allowing injection of additional flags (such as --exec) and shell-sensitive sequences.

Why this happens

The underlying issue is a classic command injection pattern where application logic composes shell or command-line invocations using untrusted user input.

In this case, Gogs builds a git rebase command that incorporates a branch name directly; because the branch name is not normalized or escaped, an attacker can embed special options (--exec) or other constructs that alter the behavior of the invoked tool.

This maps to CWE-77: Improper Neutralization of Special Elements used in a Command, as special characters and arguments in the branch name are not safely handled before being passed to git, enabling arbitrary command execution in the context of the server.

Potential impact

  • Remote execution of arbitrary commands with the privileges of the Gogs server process
  • Compromise of the host running Gogs, including data theft or destruction
  • Tampering with Git repositories and CI/CD pipelines connected to Gogs
  • Establishment of persistent backdoors or lateral movement within the infrastructure
  • Abuse of server resources for further attacks or cryptomining

General mitigation guidance

Effective mitigation focuses on removing direct command-line composition with untrusted inputs and tightening process privileges.

Common defensive patterns include:

  • Constructing git operations using safe APIs or argument vectors rather than concatenated command strings
  • Rigorously validating and normalizing branch names and other user-controlled repository identifiers to allowed character sets and formats
  • Escaping or rejecting any data that could introduce flags, separators, or shell metacharacters into command invocations
  • Running Gogs with least-privilege accounts and restricted filesystem access to reduce blast radius if a flaw is exploited
  • Applying defense-in-depth controls such as process-level restrictions (e.g., seccomp, AppArmor) and isolating the Git service from sensitive infrastructure components

How teams detect issues like this

Organizations can detect similar vulnerabilities by:

  • Using static analysis or linters to flag code paths that build shell commands via string concatenation or interpolation with user input
  • Reviewing integrations with external tools (like git) to confirm that arguments are passed as discrete parameters, not through raw shell command lines
  • Establishing secure coding guidelines that prohibit unsanitized user input in command execution utilities and enforcing them via pull request templates or automated checks
  • Logging and periodically analyzing command invocation patterns and merge operations for anomalous flags or unexpected parameters
  • Employing security scanners focused on web application command injection and unsafe process execution constructs in server-side code

Sources

SourceLink
github.comgithub.com/gogs/gogs/commit/a9dbafbfd8e1020bacc626420238c01d75d03364
github.comgithub.com/gogs/gogs/pull/8301
github.comgithub.com/gogs/gogs/releases/tag/v0.14.3
github.comgithub.com/gogs/gogs/security/advisories/GHSA-qf6p-p7ww-cwr9

Frequently asked

questions

Exploitation is limited to authenticated users who can interact with repositories and create pull requests, but in multi-tenant or collaborative environments this often includes untrusted or semi-trusted users, making the risk significant.

An attacker must be able to push a branch to a repository hosted on the Gogs instance and open a pull request that uses the "Rebase before merging" option; no administrative privileges are required.

The most robust fix pattern is to avoid constructing command strings from raw user input by using parameterized process execution APIs, validate branch names against strict formatting rules, and ensure that no user-controlled data can introduce flags or shell metacharacters into invoked commands.

Preventive strategies include adopting secure coding standards for command execution, integrating static analysis rules that detect dynamic command building, conducting code reviews focused on external tool integrations, and running services under least-privilege, isolated accounts so that any future flaws have constrained impact.

Find out what's already
exploitable in your codebase.