Summary
A Server-Side Request Forgery issue in Gogs' repository migration feature allows an attacker to abuse HTTP redirects during git clone --mirror operations.
When an authenticated user supplies a migration URL that initially appears safe but later redirects to internal addresses, they can access and mirror internal Git repositories into attacker-controlled projects.
Affected context
This vulnerability occurs in Gogs instances that expose the repository migration functionality to authenticated users.
The risk is present when the application validates only the hostname of the initially submitted migration URL, while the underlying git clone --mirror command is allowed to follow HTTP redirects without additional checks.
Deployments with internal Git services or sensitive endpoints reachable from the Gogs server, but not from the public internet, are particularly exposed.
Exploit preconditions
- Attack surface: Repository migration endpoint used to import external Git repositories.
- Required access: Authenticated user account with permission to perform repository migrations.
- Trigger point: Submission of a migration URL that resolves to a public endpoint initially, then returns an HTTP redirect to a blocked or internal address (e.g.,
127.0.0.1or internal Git service). - Why exploitation is possible: The application validates only the first URL hostname and does not re-validate or restrict subsequent redirect targets followed by
git clone --mirror, allowing internal endpoints to be reached from the server side.
Why this happens
The core issue is incomplete validation of outbound requests initiated by server-side repository migration logic.
Gogs checks only the hostname of the user-supplied URL at submission time, treating it as safe if it appears public, but delegates the actual network access to git clone --mirror, which transparently follows HTTP redirects.
Because redirect destinations are not revalidated or constrained, an attacker can craft URLs that first point to a benign host and then redirect into internal IP ranges or services, matching CWE-918: Server-Side Request Forgery, where user input controls server-initiated network requests to unintended locations.
Potential impact
- An attacker may clone and exfiltrate internal or otherwise non-public Git repositories accessible only from the Gogs server.
- Internal application source code could be exposed, enabling further vulnerability discovery and targeted attacks.
- Configuration files, secrets, or credentials stored in internal repositories could be leaked and reused for lateral movement.
- The attacker could gain visibility into internal development workflows, branches, and commit history.
General mitigation guidance
Effective mitigation focuses on constraining server-initiated network requests and reducing trust in user-supplied URLs.
Common defensive patterns include:
- Implementing strict allow/deny lists for outbound request destinations, specifically blocking private IP ranges, loopback addresses, and internal hostnames from migration logic.
- Re-validating and enforcing hostname and network policies on every redirect followed by the migration process, rather than only the initial URL.
- Isolating migration functionality in a network-restricted environment, such as a proxy or sandbox that can only reach approved external Git hosts.
- Applying least-privilege networking at the infrastructure level so application components cannot access sensitive internal services by default.
- Logging and monitoring outbound connections initiated by repository migrations to detect suspicious access patterns.
How teams detect issues like this
Detection typically involves reviewing both application behavior and outbound network flows:
- Use static analysis or code review to identify server-side features where user-provided URLs are passed to tools or libraries that may follow redirects, and verify that all redirect targets are validated and constrained.
- Look for patterns where external clone or fetch commands are constructed directly from user input without robust host/IP filtering.
- Monitor application logs for repository migration operations targeting unusual domains or IP ranges, especially private address spaces or localhost.
- Employ network monitoring and firewall rules that alert on or block unexpected HTTP/HTTPS traffic from the application server to internal services.
- Incorporate automated security testing and policy enforcement in CI/CD pipelines to flag SSRF-prone URL handling and missing network egress restrictions.

