From 36ae755d38fc7b5eca332e8d20cd725aa460b2f8 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 13 Apr 2026 20:28:28 +0000
Subject: [PATCH 1/2] Improve push failure error message for package ID scope
mismatch
Agent-Logs-Url: https://github.com/NuGet/NuGetGallery/sessions/aa085293-31cc-41ec-b433-e820261dd577
Co-authored-by: chabiss <14151258+chabiss@users.noreply.github.com>
---
src/NuGetGallery/Controllers/ApiController.cs | 6 +++++-
src/NuGetGallery/Strings.resx | 3 +++
tests/NuGetGallery.Facts/Controllers/ApiControllerFacts.cs | 2 +-
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/NuGetGallery/Controllers/ApiController.cs b/src/NuGetGallery/Controllers/ApiController.cs
index 4ed74b15da..f2e9da80bf 100644
--- a/src/NuGetGallery/Controllers/ApiController.cs
+++ b/src/NuGetGallery/Controllers/ApiController.cs
@@ -1227,7 +1227,11 @@ private HttpStatusCodeWithBodyResult GetHttpResultFromFailedApiScopeEvaluationHe
}
string message;
- if (result.PermissionsCheckResult == PermissionsCheckResult.Allowed && !result.IsOwnerConfirmed)
+ if (!result.ScopesAreValid)
+ {
+ message = Strings.ApiKeyNotAuthorized_PackageIdScopeMismatch;
+ }
+ else if (result.PermissionsCheckResult == PermissionsCheckResult.Allowed && !result.IsOwnerConfirmed)
{
message = Strings.ApiKeyOwnerUnconfirmed;
}
diff --git a/src/NuGetGallery/Strings.resx b/src/NuGetGallery/Strings.resx
index c3be3e3533..8cee98ef96 100644
--- a/src/NuGetGallery/Strings.resx
+++ b/src/NuGetGallery/Strings.resx
@@ -138,6 +138,9 @@
The specified API key is invalid, has expired, or does not have permission to access the specified package.
+
+ The specified API key does not have permission to push to this package. The API key may have a package ID scope that does not include this package ID.
+
A package with ID '{0}' and version '{1}' already exists and cannot be modified.
diff --git a/tests/NuGetGallery.Facts/Controllers/ApiControllerFacts.cs b/tests/NuGetGallery.Facts/Controllers/ApiControllerFacts.cs
index cdbe6ddef3..ad39907c39 100644
--- a/tests/NuGetGallery.Facts/Controllers/ApiControllerFacts.cs
+++ b/tests/NuGetGallery.Facts/Controllers/ApiControllerFacts.cs
@@ -205,7 +205,7 @@ public static IEnumerable