0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-01-24 21:46:31 +01:00
This commit is contained in:
Excellencedev 2025-12-26 12:05:51 +01:00
parent 26e47a58ef
commit 640004f70f

View File

@ -9,6 +9,7 @@ import (
actions_model "code.gitea.io/gitea/models/actions"
auth_model "code.gitea.io/gitea/models/auth"
packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@ -109,11 +110,15 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
// If package is not linked to any repo (org-level package), deny access from Actions
// Actions tokens should only access packages linked to repos
if packageRepoID == 0 {
pkgID := int64(0)
if ctx.Package.Descriptor != nil && ctx.Package.Descriptor.Package != nil {
pkgID = ctx.Package.Descriptor.Package.ID
if packageName := ctx.Params("packagename"); packageName != "" && ctx.Package.Owner != nil {
pkg, err := packages_model.GetPackageByName(ctx, ctx.Package.Owner.ID, packages_model.TypeGeneric, packageName)
if err == nil && pkg != nil {
packageRepoID = pkg.RepoID
}
}
fmt.Printf("DEBUG: packageRepoID is 0 for pkgID %d. Denying access.\n", pkgID)
}
if packageRepoID == 0 {
ctx.HTTPError(http.StatusForbidden, "reqPackageAccess", "Actions tokens cannot access packages not linked to a repository")
return
}