fix(packages): validate debian distribution and component names (#38116)

**Newline injection into the Debian Release and Packages indices**

The `distribution` and `component` come straight from the request path
and are written line by line into the generated `Release` and `Packages`
files (the `Suite`/`Codename`/`Components` lines and the `Filename:
pool/<distribution>/<component>/...` line), but `UploadPackageFile` only
checked they were non-empty. `ctx.PathParam` url-decodes the segment, so
an encoded newline such as `main%0AInjected-Field: x` is accepted,
stored and then re-emitted for that distribution, which lets an
authenticated uploader forge extra fields in the index apt consumes.
Restricted both values to a conservative name pattern in the handler,
since that is the layer that accepts them; this should also keep the
pool paths well formed.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
metsw24-max
2026-06-29 12:20:22 +05:30
committed by GitHub
parent 762c674bc5
commit 0c67849e68
3 changed files with 79 additions and 24 deletions
+3 -3
View File
@@ -120,9 +120,9 @@ func GetRepositoryFileByHash(ctx *context.Context) {
}
func UploadPackageFile(ctx *context.Context) {
distribution := strings.TrimSpace(ctx.PathParam("distribution"))
component := strings.TrimSpace(ctx.PathParam("component"))
if distribution == "" || component == "" {
distribution := ctx.PathParam("distribution")
component := ctx.PathParam("component")
if !debian_module.IsValidDistributionOrComponent(distribution) || !debian_module.IsValidDistributionOrComponent(component) {
apiError(ctx, http.StatusBadRequest, "invalid distribution or component")
return
}