Gitea: Repository Migration Follows Git HTTP Redirects After URL Allow/Block Validation, Enabling Internal Git Repository Exfiltration
Gitea validates the user-supplied repository migration URL, but the actual clone and later mirror fetch operations are performed by the Git command-line client without disabling HTTP redirects. Git's default http.followRedirects=initial follows the first redirect and then uses the redirected URL as the base for later repository object requests.
This creates a URL-policy bypass, SSRF, and repository exfiltration primitive. A low-privileged authenticated user can submit an allowed public Git URL that redirects the Gitea server to an otherwise blocked or internal Git HTTP(S) endpoint. Local validation confirmed that Git followed a first-hop redirect to 127.0.0.1, fetched Git objects, and completed the clone; git -c http.followRedirects=false clone blocked the same path.
The main impact is internal Git repository exfiltration into an attacker-controlled Gitea repository. Pull mirrors increase risk because scheduled git fetch --tags operations can keep following the redirect and collect future internal commits.
This is High severity by default for internet-accessible instances with migrations enabled, and can become Critical where internal repositories contain deploy keys, CI/CD secrets, cloud credentials, Terraform state, kubeconfigs, signing material, or production configuration. Direct unauthenticated exploitation, direct Gitea server RCE, arbitrary file:// import, and default Actions runner execution are not confirmed.
The root cause is a validation/enforcement mismatch across a trust boundary. This should be treated as a product security issue rather than a pure deployment misconfiguration: deployment choices influence reachability and impact, but Gitea applies policy to the originally submitted URL while the Git subprocess is allowed to reach a different effective URL after redirection.
Gitea validates the original migration URL:
C:\Users\One\Desktop\gitea_new\gitea\routers\web\repo\migrate.go:180 parses the submitted web migration clone address.C:\Users\One\Desktop\gitea_new\gitea\routers\web\repo\migrate.go:182 calls migrations.IsMigrateURLAllowed.C:\Users\One\Desktop\gitea_new\gitea\routers\api\v1\repo\migrate.go:101 parses the submitted API migration clone address.C:\Users\One\Desktop\gitea_new\gitea\routers\api\v1\repo\migrate.go:103 calls migrations.IsMigrateURLAllowed.The URL validator resolves and checks the initially supplied host:
C:\Users\One\Desktop\gitea_new\gitea\services\migrations\migrate.go:44 defines IsMigrateURLAllowed.C:\Users\One\Desktop\gitea_new\gitea\services\migrations\migrate.go:75 rejects unsupported schemes.C:\Users\One\Desktop\gitea_new\gitea\services\migrations\migrate.go:79 extracts the host.C:\Users\One\Desktop\gitea_new\gitea\services\migrations\migrate.go:85 performs DNS resolution.C:\Users\One\Desktop\gitea_new\gitea\services\migrations\migrate.go:86 enforces the allow/block list on the originally resolved host.After this validation, the actual repository data transfer is delegated to Git:
C:\Users\One\Desktop\gitea_new\gitea\services\repository\migrate.go:93 calls gitrepo.CloneExternalRepo with opts.CloneAddr.C:\Users\One\Desktop\gitea_new\gitea\modules\gitrepo\clone.go:13 delegates to git.Clone.C:\Users\One\Desktop\gitea_new\gitea\modules\git\repo.go:123 constructs a git clone command.C:\Users\One\Desktop\gitea_new\gitea\modules\git\repo.go:125 conditionally sets only http.sslVerify=false.C:\Users\One\Desktop\gitea_new\gitea\modules\git\repo.go:154 appends the source and destination arguments.No equivalent network policy is applied to the final URL reached by Git after HTTP redirection. The protected migration HTTP client exists for service-specific migration API calls, but it is not used for the raw Git clone/fetch operation:
C:\Users\One\Desktop\gitea_new\gitea\services\migrations\http_client.go:16 defines NewMigrationHTTPClient.C:\Users\One\Desktop\gitea_new\gitea\services\migrations\http_client.go:27 applies a host-matching dialer.That protection does not wrap git clone or git fetch.
The behavior depends on Git's documented redirect handling. The current Git documentation states that http.followRedirects=initial follows the initial request redirect and uses the redirected URL as the base for follow-up requests. The default value is initial: https://git-scm.com/docs/git-config#Documentation/git-config.txt-httpfollowRedirects
This means the effective enforcement point is not the same as the actual network sink. Gitea checks https://attacker.example/repo.git; Git later retrieves http://127.0.0.1:PORT/internal.git/... or another internal target selected by the redirector.
For mirrors, the issue extends beyond initial migration:
C:\Users\One\Desktop\gitea_new\gitea\services\repository\migrate.go:177 creates a mirror record when migration is requested as a mirror.C:\Users\One\Desktop\gitea_new\gitea\services\repository\migrate.go:188 stores the sanitized original remote address.C:\Users\One\Desktop\gitea_new\gitea\services\mirror\mirror_pull.go:120 later performs mirror synchronization with git fetch --tags.C:\Users\One\Desktop\gitea_new\gitea\services\mirror\mirror_pull.go:126 fetches from the configured remote.Because the mirror sync path also delegates to Git, a redirecting remote can continue to redirect scheduled fetches into an internal target.
Affected features are URL-based repository migration, API repository migration, pull mirror creation through migration, and scheduled pull mirror synchronization. The relevant entrypoints are POST /repo/migrate for signed-in web users (C:\Users\One\Desktop\gitea_new\gitea\routers\web\web.go:1062) and POST /api/v1/repos/migrate for API-token users (C:\Users\One\Desktop\gitea_new\gitea\routers\api\v1\api.go:1170).
Important preconditions are:
C:\Users\One\Desktop\gitea_new\gitea\modules\setting\repository.go:181, C:\Users\One\Desktop\gitea_new\gitea\custom\conf\app.example.ini:1078).C:\Users\One\Desktop\gitea_new\gitea\modules\setting\mirror.go:20).High-value targets include internal Gitea, GitLab, GitHub Enterprise, Bitbucket, cgit, git-http-backend, and static bare Git repositories, especially repositories containing CI/CD definitions, deployment manifests, IaC, credentials, or production configuration.
The key trust boundary is that low-privileged user input influences server-side Git network access. Gitea validates the initially supplied URL, then hands control to a Git subprocess whose redirected destination is not constrained by the same allow/block policy. An attacker can discover exposure by using a controlled redirector, observing outbound Git requests, and testing whether scheduled mirror requests continue to arrive.
https://attacker.example/public.git.http://internal-git.company.local/team/private.git/info/refs?service=git-upload-pack.attacker.example, which passes the migration allow/block list.git clone --mirror against the public URL.git fetch --tags against the stored remote.This materially increases impact because the exposure is not limited to one migration event. The attacker can continue collecting internal commits for as long as the mirror remains enabled and the redirect target remains reachable.
This chain is conditional but realistic in DevOps environments.
This is not direct RCE in Gitea from the currently validated evidence. It is a credible post-exploitation chain from server-side internal repository exfiltration to infrastructure compromise.
Actions-related escalation is configuration-dependent.
Relevant code behavior:
C:\Users\One\Desktop\gitea_new\gitea\services\actions\notifier_helper.go:138C:\Users\One\Desktop\gitea_new\gitea\services\actions\notifier_helper.go:146C:\Users\One\Desktop\gitea_new\gitea\services\actions\notifier_helper.go:184C:\Users\One\Desktop\gitea_new\gitea\services\actions\notifier_helper.go:186C:\Users\One\Desktop\gitea_new\gitea\services\actions\notifier_helper.go:321C:\Users\One\Desktop\gitea_new\gitea\services\actions\notifier_helper.go:347C:\Users\One\Desktop\gitea_new\gitea\services\actions\notifier_helper.go:401C:\Users\One\Desktop\gitea_new\gitea\services\actions\notifier_helper.go:405Default mirror repository units do not include Actions:
C:\Users\One\Desktop\gitea_new\gitea\models\unit\unit.go:88C:\Users\One\Desktop\gitea_new\gitea\models\unit\unit.go:96Therefore, the Actions chain should not be presented as default direct impact. It is a critical conditional chain if an operator enables Actions on migrated/mirrored repositories, customizes default mirror units to include Actions, or manually enables Actions on a mirror. In such cases, redirected repository content containing workflow files may enqueue jobs in a context that is not treated as an untrusted fork pull request.
The vulnerable flow is:
IsMigrateURLAllowed.git clone --mirror.Key code locations:
C:\Users\One\Desktop\gitea_new\gitea\routers\web\repo\migrate.go:180C:\Users\One\Desktop\gitea_new\gitea\routers\web\repo\migrate.go:182C:\Users\One\Desktop\gitea_new\gitea\routers\api\v1\repo\migrate.go:101C:\Users\One\Desktop\gitea_new\gitea\routers\api\v1\repo\migrate.go:103C:\Users\One\Desktop\gitea_new\gitea\services\migrations\migrate.go:44C:\Users\One\Desktop\gitea_new\gitea\services\migrations\migrate.go:85C:\Users\One\Desktop\gitea_new\gitea\services\migrations\migrate.go:86C:\Users\One\Desktop\gitea_new\gitea\services\repository\migrate.go:93C:\Users\One\Desktop\gitea_new\gitea\modules\gitrepo\clone.go:13C:\Users\One\Desktop\gitea_new\gitea\modules\git\repo.go:123C:\Users\One\Desktop\gitea_new\gitea\modules\git\repo.go:125C:\Users\One\Desktop\gitea_new\gitea\modules\git\repo.go:154C:\Users\One\Desktop\gitea_new\gitea\services\repository\migrate.go:177C:\Users\One\Desktop\gitea_new\gitea\services\repository\migrate.go:188C:\Users\One\Desktop\gitea_new\gitea\services\mirror\mirror_pull.go:120C:\Users\One\Desktop\gitea_new\gitea\services\mirror\mirror_pull.go:126A local safe PoC was run with two HTTP services:
Observed behavior:
git clone was invoked against the redirector URL./info/refs/HEADThe local PoC result showed:
code: 0
redirector hit count: 1
target hit count: 5
cloned content: "internal repo data via redirected git clone"
Mirror fetch behavior was also validated locally:
git fetch --tags origin followed the redirect into the internal target.The mirror PoC result showed:
code: 0
target object requests observed: 5
hasFetchedBranchRef: true
Mitigation behavior was validated locally:
git -c http.followRedirects=false clone.The failed mitigation test behavior was:
fatal: unable to access '<redirector-url>': The requested URL returned error: 302
Negative validation:
file:// was attempted.Protocol "file" disabled (in redirect).file:// redirection.Validation scope:
POST /repo/migrate or POST /api/v1/repos/migrate, and confirm that the resulting attacker-owned Gitea repository contains the internal repository content. For mirror mode, add a new commit to the internal target and confirm a later mirror sync imports it.Confirmed impact is server-side Git network access to a redirected destination, resulting in internal Git repository import when the redirected target is reachable from the Gitea server. This can expose private source code, full Git history, deleted secrets, internal architecture, deployment pipelines, service names, and future commits if pull mirrors continue syncing.
The highest-risk secondary impact is secret extraction. Internal repositories often contain CI/CD definitions, deployment scripts, kubeconfigs, Terraform state, cloud keys, registry tokens, package publishing tokens, PATs, SSH deploy keys, webhook secrets, and historical credentials. Exposure of these materials can escalate to CI/CD compromise, cloud compromise, production access, or supply-chain compromise.
Direct Gitea server RCE is not confirmed. The clone path uses git clone --mirror, remote Git hooks are not executed by a normal clone, local validation showed Git rejects file:// redirects, and the reviewed command construction does not show obvious shell injection. Indirect RCE remains plausible through stolen CI/CD, cloud, deployment, package, or Actions runner credentials.
Incident responders should treat exploitation as potential source-code and secret disclosure, not just SSRF probing. Recommended triage is to review recently migrated repositories and mirrors, identify unusual migration sources or redirector domains, inspect Gitea and egress logs around migration/mirror sync times, secret-scan affected full histories, rotate exposed credentials, and remove malicious mirror configurations.
Disable Git HTTP redirects for migration clone and mirror fetch operations unless every redirect hop is explicitly revalidated under the same migration allow/block policy.
Recommended immediate code changes:
git -c http.followRedirects=false clone ... (C:\Users\One\Desktop\gitea_new\gitea\modules\git\repo.go:123).git -c http.followRedirects=false fetch ... (C:\Users\One\Desktop\gitea_new\gitea\services\mirror\mirror_pull.go:122).Local mitigation testing confirmed that http.followRedirects=false prevents the redirect-based clone from succeeding. If redirect support is required for compatibility, Gitea should follow redirects in controlled code, validate each hop against the migration network policy, and then invoke Git with redirects disabled.
Defense in depth:
Severity: High by default for internet-accessible instances with repository migrations enabled; Critical in environments where Gitea can reach sensitive internal Git services containing secrets, deploy keys, CI/CD credentials, cloud credentials, or production configuration.
Critical escalation conditions:
Critical escalation conditions include sensitive internal Git reachability, weak egress controls, repositories containing production or CI/CD secrets, enabled pull mirrors that continue syncing future commits, or configurations where imported workflow content can reach shared/self-hosted Actions runners.
Not confirmed:
Direct unauthenticated exploitation, direct Gitea server RCE from the migration clone path, arbitrary local filesystem read via file:// redirect, and default Actions runner execution from mirror sync without configuration changes.
为什么是这个 VPI(可解释·实验性)
VPI 计算依据
| 影响度 | 85.00 |
| 利用信号(无额外利用信号) | ×1.00 |
| VPI | 85.00 |
VPI 公式 vpi-v1