GHSA-rqhx-647v-wx32 Gitea: SSRF via HTTP Redirect in Repository Migration
SummaryGitea 1.25.4 validates the initial URL provided to the repository migration endpoint (`POST /api/v1/repos/migrate`) and correctly blocks requests to internal addresses like `127.0.0.1` or RFC1918 ranges. However, if the initial URL points to an attacker-controlled server that responds with an HTTP 302 redirect to an internal address, Gitea follows the redirect without performing a second validation. This allows a low-privilege user to reach internal services through Gitea as a proxy.Affected VersionGitea 1.25.4 (latest stable at time of writing), default configuration.PrerequisitesA regular Gitea user account (no admin privileges required)An attacker-controlled server reachable from the internet that serves HTTP 302 redirectsReproductionEnvironment| Role             | Location                                                       | Network                                  |
|------------------|----------------------------------------------------------------|------------------------------------------|
| Attacker         | Any machine with internet access                               | External network (VLAN A)                |
| Gitea Server     | Windows 11 VM, Gitea 1.25.4, default config, SQLite           | Internal network (VLAN B)                |
| Internal service | Same VM, bound to `127.0.0.1:18082`                           | Localhost only                           |
| Redirect server  | Attacker-controlled public server, port 18080                 | Internet                                 |The attacker can reach Gitea on port 3000 but cannot reach port 18082 on the VM. This was verified by attempting a direct connection, which was refused.Step 1: Create an attacker account on GiteaRegister a normal user account on the Gitea instance (or use any existing non-admin account). Then generate an API token under **Settings > Applications** with the `repo: write` scope. The migration endpoint requires this because it creates a new repository. This token is referenced as `<USER_TOKEN>` in the steps below.Step 2: Set up an internal service on the Gitea hostOn the Gitea VM, create a bare Git repository that simulates an internal service:This serves a Git repository on localhost port 18082. It is not reachable from outside the machine.Step 3: Confirm Gitea blocks direct access to internal addressesFrom the attacker machine:Response:This confirms that Gitea correctly blocks migration from internal addresses when provided directly.Step 4: Set up a redirect serverOn an attacker-controlled public server, run a script that redirects all requests to the internal service:Step 5: Exploit the redirect bypassFrom the attacker machine:Response: **HTTP 201 Created**. The migration succeeds.Step 6: Retrieve the exfiltrated dataFrom the attacker machine:Output:The attacker now has the contents of the internal repository that was only accessible on localhost.What happens during the attackThe attacker sends a migration request pointing to their public server.Gitea validates the URL. The destination is a public IP, so it passes the check.Gitea contacts the attacker's server to clone the repository.The attacker's server responds with `302 Location: http://127.0.0.1:18082/...`Gitea follows the redirect to `127.0.0.1` without validating the new destination.The internal service responds and Gitea stores the result as a new repository owned by the attacker.The attacker clones their newly created repository and reads the internal data.ImpactAny authenticated user with permission to create repositories can use the migration feature to reach services that are only accessible from the Gitea server itself or its local network. Depending on the environment this could include:Internal Git repositories or other version control systems not exposed to the internetCloud metadata endpoints (`169.254.169.254`) which serve temporary credentials on AWS, GCP, and AzureInternal APIs, CI/CD systems, databases, or admin panels bound to localhost or private networksOther services within the same network segment that trust connections from the Gitea serverThe full content of internal Git repositories can be exfiltrated as demonstrated above. For non-Git services, the request still reaches the target (blind SSRF), which may be enough to trigger actions or leak information through error messages.Suggested FixValidate the destination of HTTP redirects against the same blocklist that is applied to the initial URL. If a redirect points to a blocked address (loopback, link-local, RFC1918), the request should be aborted before following the redirect.
CVSS v3.1 score: 6.5