Details
The internal target's response is then visible on /{owner}/{repo}/settings/hooks/1, or in the SQLite column hook_task.response_content.
Suggested fix
Add an explicit non-routable prefix list to the external builtin:
--- a/modules/hostmatcher/hostmatcher.go
+++ b/modules/hostmatcher/hostmatcher.go
@@ -3,8 +3,9 @@ package hostmatcher
import (
"net"
+ "net/netip"
"path/filepath"
"slices"
"strings"
)
+var nonRoutablePrefixes = []netip.Prefix{
+ netip.MustParsePrefix("100.64.0.0/10"), // CGNAT, RFC 6598
+ netip.MustParsePrefix("64:ff9b::/96"), // NAT64 well-known, RFC 6052
+ netip.MustParsePrefix("64:ff9b:1::/48"), // NAT64 local-use, RFC 8215
+ netip.MustParsePrefix("2001::/32"), // Teredo, RFC 4380
+ netip.MustParsePrefix("2002::/16"), // 6to4, RFC 3056
+ netip.MustParsePrefix("::ffff:0:0/96"), // SIIT (deprecated, still routable through translators)
+ netip.MustParsePrefix("::/96"), // IPv4-compatible (deprecated)
+ netip.MustParsePrefix("2001:db8::/32"), // documentation
+ netip.MustParsePrefix("198.18.0.0/15"), // benchmarking
+ netip.MustParsePrefix("192.0.0.0/24"), // IETF protocol assignments
+ netip.MustParsePrefix("192.0.2.0/24"), // TEST-NET-1
+ netip.MustParsePrefix("198.51.100.0/24"), // TEST-NET-2
+ netip.MustParsePrefix("203.0.113.0/24"), // TEST-NET-3
+}
+
+func isNonRoutable(ip net.IP) bool {
+ a, ok := netip.AddrFromSlice(ip)
+ if !ok {
+ return true
+ }
+ for _, p := range nonRoutablePrefixes {
+ if p.Contains(a) {
+ return true
+ }
+ }
+ return false
+}
+
func (hl *HostMatchList) checkIP(ip net.IP) bool {
if slices.Contains(hl.patterns, "*") {
return true
}
for _, builtin := range hl.builtins {
switch builtin {
case MatchBuiltinExternal:
- if ip.IsGlobalUnicast() && !ip.IsPrivate() {
+ if ip.IsGlobalUnicast() && !ip.IsPrivate() && !isNonRoutable(ip) {
return true
}
hostmatcher_test.go currently has zero cases for any of the ten families. Suggested additions: at least one IPv4 (CGNAT 100.64.0.1) and four IPv6 (NAT64 well-known, NAT64 local-use, 6to4, IPv4-compatible).
---
Finding 2: OpenID discovery has no SSRF guard
The bug
routers/web/auth/openid.go:99:
url, err := openid.RedirectURL(id, redirectTo, setting.AppURL)
The thin wrapper at modules/auth/openid/openid.go:36 forwards directly to the package-level function in github.com/yohcop/openid-go. That package keeps a defaultInstance:
// github.com/yohcop/openid-go v1.0.1, openid.go:15
var defaultInstance = NewOpenID(http.DefaultClient)
http.DefaultClient has no transport customization, no Dialer.Control, no IP filtering. openid-go issues a server-side GET to the user-supplied URL to discover the OpenID endpoint. The fetch reaches any address Gitea can route to, including loopback, RFC 1918, link-local, and the same families listed in Finding 1.
The form does not enforce CSRF on this path. The endpoint accepts unauthenticated requests by design (it is the login page).
Default exposure
The setting that gates this endpoint is read from the [openid] section of app.ini:
// modules/setting/service.go:268-270
func loadOpenIDSetting(rootCfg ConfigProvider) {
sec := rootCfg.Section("openid")
Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)
It defaults to !InstallLock, so on a fresh container before the install wizard completes the endpoint is enabled. After INSTALL_LOCK=true it defaults off. Deployments that use OpenID for SSO set it explicitly. (Note for anyone reproducing in Docker: the entrypoint routes GITEA__service__ENABLE_OPENID_SIGNIN into [service], where the loader does not read it. Use GITEA__openid__ENABLE_OPENID_SIGNIN=true.)
History
Extends CVE-2021-45325. The 2019 fix (PR #5705) hid the error string that previously leaked internal topology to the requester. It did not add filtering to the discovery fetch itself. The underlying SSRF primitive remains.
Reproduce
One request, no cookie, no token:
curl -X POST http://localhost:3000/user/login/openid \
--data-urlencode 'openid=http://INTERNAL:PORT/path'
Captured by the internal target (also shown in run_poc.sh's [poc 3] block):
GET /poc3-openid from=100.64.0.10
GET /poc3-openid from=100.64.0.10
Two GETs (one for normalize, one for redirect-URL discovery), both unauthenticated, both with Accept: application/xrds+xml.
Exfiltration is blind. openid-go parses the response as XRDS or HTML for endpoint discovery and does not return the body to the caller. Useful for internal port scanning, IMDS probing, and timing oracles. Lower direct impact than Finding 1, but reachable without an account.
Suggested fix
Wire the hostmatcher into a custom *http.Client and create a dedicated openid-go instance:
--- a/modules/auth/openid/openid.go
+++ b/modules/auth/openid/openid.go
@@ -1,10 +1,28 @@
package openid
-import "github.com/yohcop/openid-go"
+import (
+ "net/http"
+ "time"
+
+ "code.gitea.io/gitea/modules/hostmatcher"
+ "code.gitea.io/gitea/modules/proxy"
+ "github.com/yohcop/openid-go"
+)
var (
nonceStore = openid.NewSimpleNonceStore()
discoveryCache = newTimedDiscoveryCache(24 * time.Hour)
+ instance = openid.NewOpenID(&http.Client{
+ Timeout: 30 * time.Second,
+ Transport: &http.Transport{
+ Proxy: proxy.Proxy(),
+ DialContext: hostmatcher.NewDialContext("openid",
+ hostmatcher.ParseHostMatchList("openid", hostmatcher.MatchBuiltinExternal),
+ nil, nil),
+ },
+ })
)
func Verify(fullURL string) (id string, err error) {
- return openid.Verify(fullURL, discoveryCache, nonceStore)
+ return instance.Verify(fullURL, discoveryCache, nonceStore)
}
// RedirectURL redirects browser
func RedirectURL(id, callbackURL, realm string) (string, error) {
- return openid.RedirectURL(id, callbackURL, realm)
+ return instance.RedirectURL(id, callbackURL, realm)
}
openid.Normalize does not perform HTTP and does not need to change. Once Finding 1 is fixed, this MatchBuiltinExternal instance picks up the new prefix coverage automatically.
---
POC script
run_poc.sh