From e67f74efc86116936aa8097ddfa7c835de4d6d48 Mon Sep 17 00:00:00 2001 From: Tobias Balle-Petersen Date: Wed, 30 Apr 2025 19:06:37 +0200 Subject: [PATCH] fix: do not return archive download URLs in API if downloads are disabled (#34324) If archive downloads are are disabled using _DISABLE_DOWNLOAD_SOURCE_ARCHIVES_, archive links are still returned by the API. This PR changes the data returned, so the fields _zipball_url_ and _tarball_url_ are omitted if archive downloads have been disabled. Resolve #32159 --- modules/structs/repo_tag.go | 4 ++-- services/convert/convert.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/structs/repo_tag.go b/modules/structs/repo_tag.go index 5722513f4f..bb8bfd10cb 100644 --- a/modules/structs/repo_tag.go +++ b/modules/structs/repo_tag.go @@ -11,8 +11,8 @@ type Tag struct { Message string `json:"message"` ID string `json:"id"` Commit *CommitMeta `json:"commit"` - ZipballURL string `json:"zipball_url"` - TarballURL string `json:"tarball_url"` + ZipballURL string `json:"zipball_url,omitempty"` + TarballURL string `json:"tarball_url,omitempty"` } // AnnotatedTag represents an annotated tag diff --git a/services/convert/convert.go b/services/convert/convert.go index 9d2afdea30..17bc83653f 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -197,13 +197,22 @@ func ToBranchProtection(ctx context.Context, bp *git_model.ProtectedBranch, repo // ToTag convert a git.Tag to an api.Tag func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag { + tarballURL := util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz") + zipballURL := util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip") + + // Archive URLs are "" if the download feature is disabled + if setting.Repository.DisableDownloadSourceArchives { + tarballURL = "" + zipballURL = "" + } + return &api.Tag{ Name: t.Name, Message: strings.TrimSpace(t.Message), ID: t.ID.String(), Commit: ToCommitMeta(repo, t), - ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"), - TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"), + ZipballURL: zipballURL, + TarballURL: tarballURL, } }