mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-16 13:25:02 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user