mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-05 18:16:17 +00:00
fix: various security fixes (#38406)
Addresses a batch of privately reported security issues, grouped by area: - **SSRF** - migration PR-patch/asset fetches, OAuth2 avatar & OpenID discovery, pull-mirror URL re-validation, and the outbound proxy path. - **Access-token scope** - prevent scope escalation on token creation; keep public-only tokens confined (feeds, packages, Actions listings, star/watch lists, limited/private owners). - **Access control / disclosure** - go-get default-branch leak, webhook authorization-header leak, watch clearing on private transitions, label/attachment scoping. - **Denial of service** - input bounds for npm dist-tags, Debian control files, Arch file lists, and SSH keys. ### 📌 Attention for site admins Not breaking - existing configs keep working - but two changes are worth a look: - **New SSRF protection** Outbound requests (migrations, OAuth2 avatars, OpenID discovery, pull mirrors, proxy path) are now validated against the allow/block host lists. If your instance legitimately reaches internal hosts, you may need to add them to `[security].ALLOWED_HOST_LIST` (and the relevant `ALLOW_LOCALNETWORKS` settings). - **Deprecation** `[webhook].ALLOWED_HOST_LIST` is deprecated and will be removed in a future release. Use `[security].ALLOWED_HOST_LIST` instead; the old key still works for now. --------- Co-authored-by: TheFox0x7 <thefox0x7@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Zettat123 <zettat123@gmail.com>
This commit is contained in:
@@ -4,7 +4,10 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/db"
|
||||
@@ -14,6 +17,9 @@ import (
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/gitrepo"
|
||||
"gitea.dev/modules/migration"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/test"
|
||||
migrations "gitea.dev/services/migrations"
|
||||
mirror_service "gitea.dev/services/mirror"
|
||||
release_service "gitea.dev/services/release"
|
||||
repo_service "gitea.dev/services/repository"
|
||||
@@ -124,3 +130,48 @@ func TestMirrorPull(t *testing.T) {
|
||||
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
||||
assert.Equal(t, lastMirrorSync, mirror.LastSyncUnix)
|
||||
}
|
||||
|
||||
// TestMirrorPullSSRFRevalidation ensures a pull mirror re-validates its remote URL against
|
||||
// the migration allow/block list on every sync, so a mirror whose (network) remote now
|
||||
// points at a disallowed internal host is never fetched.
|
||||
func TestMirrorPullSSRFRevalidation(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
ctx := t.Context()
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
repoPath := repo_model.RepoPath(user.Name, repo.Name)
|
||||
|
||||
// an "internal" server that records whether it was reached
|
||||
var reached atomic.Bool
|
||||
internal := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
reached.Store(true)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}))
|
||||
defer internal.Close()
|
||||
|
||||
mirrorRepo, err := repo_service.CreateRepositoryDirectly(ctx, user, user, repo_service.CreateRepoOptions{
|
||||
Name: "ssrf_mirror",
|
||||
IsMirror: true,
|
||||
Status: repo_model.RepositoryBeingMigrated,
|
||||
}, false)
|
||||
require.NoError(t, err)
|
||||
_, err = repo_service.MigrateRepositoryGitData(ctx, user, mirrorRepo, migration.MigrateOptions{
|
||||
RepoName: "ssrf_mirror",
|
||||
Mirror: true,
|
||||
CloneAddr: repoPath,
|
||||
}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
mirror, err := repo_model.GetMirrorByRepoID(ctx, mirrorRepo.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// repoint the mirror at the loopback server, which is disallowed once local networks are off
|
||||
require.NoError(t, mirror_service.UpdateAddress(ctx, mirror, internal.URL+"/repo.git"))
|
||||
defer test.MockVariableValue(&setting.Migrations.AllowLocalNetworks, false)()
|
||||
require.NoError(t, migrations.Init())
|
||||
t.Cleanup(func() { _ = migrations.Init() })
|
||||
|
||||
assert.False(t, mirror_service.SyncPullMirror(ctx, mirrorRepo.ID))
|
||||
assert.False(t, reached.Load(), "the disallowed internal remote must not be reached")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user