Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Correct row-20 narrative: Vendor was the at-risk host, not Admin (ARCH-001 Phase 1)

KrzysztofPajaked2e8f0259fa
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseProductControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseProductControllerTests.cs
index d849739eb..9b57a660a 100644
--- a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseProductControllerTests.cs
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseProductControllerTests.cs
@@ -4242,9 +4242,12 @@ public class BaseProductControllerTests
}
// --- ProductAttributeValueCreatePopup (POST) ----------------------------------------------------
- // HasAccess added explicitly: Admin's original had no ownership check on this action at all (neither
- // explicit nor via validator). Vendor's original relied solely on IProductValidVendor + ModelState -
- // no explicit action-level check.
+ // HasAccess added explicitly. Admin has no ownership concept at all (GlobalAdminDataScope.HasAccess is
+ // always true), so Admin was never at risk here. The real risk is to VENDOR: Vendor's original relied
+ // solely on ProductAttributeValueModel : IProductValidVendor triggering ValidationFilter's
+ // ProductValidVendor check + Vendor's own `if (ModelState.IsValid)` gate - no explicit action-level
+ // check. Moving to the shared AdminShared model (no IProductValidVendor) would have silently dropped
+ // that guard for Vendor; scope.HasAccess replaces it explicitly and uniformly.
[TestMethod]
public async Task ProductAttributeValueCreatePopup_Post_MissingProduct_Throws()
@@ -4274,6 +4277,29 @@ public class BaseProductControllerTests
Times.Never);
}
+ [TestMethod]
+ public async Task ProductAttributeValueCreatePopup_Post_ScopeDeniesAccess_UsesVendorResourceKeyPrefix()
+ {
+ // The host/action combination this row's fix actually protects: Vendor losing its
+ // IProductValidVendor-driven guard in the merge. See the comment above the HasAccess check in
+ // BaseProductController.ProductAttributeValueCreatePopup(POST).
+ var product = new Product { Id = "p1" };
+ _productServiceMock.Setup(p => p.GetProductById("p1", false)).ReturnsAsync(product);
+ _scopeMock.Setup(s => s.HasAccess(product)).ReturnsAsync(false);
+ _scopeMock.Setup(s => s.ResourceKeyPrefix).Returns("Vendor");
+ var model = new ProductModel.ProductAttributeValueModel { ProductId = "p1" };
+
+ var result = await _controller.ProductAttributeValueCreatePopup(model);
+
+ var content = result as ContentResult;
+ Assert.IsNotNull(content);
+ _translationServiceMock.Verify(t => t.GetResource("Vendor.Catalog.Products.Permissions"), Times.Once);
+ _translationServiceMock.Verify(t => t.GetResource("Admin.Catalog.Products.Permissions"), Times.Never);
+ _productViewModelServiceMock.Verify(
+ s => s.InsertProductAttributeValueModel(It.IsAny<ProductModel.ProductAttributeValueModel>()),
+ Times.Never);
+ }
+
[TestMethod]
public async Task ProductAttributeValueCreatePopup_Post_ScopeGrantsAccess_MappingMissing_RedirectsToList()
{
diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs
index 571d78216..98a80fef5 100644
--- a/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs
+++ b/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs
@@ -2632,19 +2632,21 @@ public abstract class BaseProductController(
if (product == null)
throw new ArgumentException("No product found with the specified id");
- // HasAccess added explicitly rather than relying on validation-layer side effects: Admin's and
- // Store's shared ProductAttributeValueModelValidator (BaseStoreAccessValidator<...>) only enforces
- // ownership when StaffStoreId is set - i.e. it's active for Store, a no-op for Admin. Vendor's
- // model implements IProductValidVendor, so the global ValidationFilter resolves
- // IValidator<IProductValidVendor> (ProductValidVendor) and adds a ModelState error when
- // product.VendorId doesn't match the current vendor - a real check, not a no-op - but
- // ValidationFilter never short-circuits a non-JSON POST (see ValidationFilter.OnActionExecutionAsync),
- // so that protection only actually held because Vendor's original action gated the insert behind
- // `if (ModelState.IsValid)`. Admin's original had neither an explicit check nor that validator
- // wired up, so this was a real, unguarded IDOR: any caller reaching this shared action without the
- // Vendor marker-interface model could insert an attribute value onto a product they don't own.
- // scope.HasAccess makes the check explicit and uniform across all three hosts instead of leaning on
- // ModelState side effects that only covered one of them.
+ // HasAccess added explicitly rather than relying on validation-layer side effects. Admin has no
+ // ownership concept at all (GlobalAdminDataScope.HasAccess is always true), so Admin was never at
+ // risk here despite having neither an explicit check nor a validator. Store's shared
+ // ProductAttributeValueModelValidator (BaseStoreAccessValidator<...>) enforces ownership whenever
+ // StaffStoreId is set, so Store's original had validator-layer coverage. The actual risk this
+ // guards against is to VENDOR: Vendor's original model implements IProductValidVendor, so the
+ // global ValidationFilter resolves IValidator<IProductValidVendor> (ProductValidVendor) and adds a
+ // ModelState error when product.VendorId doesn't match the current vendor - a real check, not a
+ // no-op - but ValidationFilter never short-circuits a non-JSON POST (see
+ // ValidationFilter.OnActionExecutionAsync), so that protection only actually held because Vendor's
+ // original action gated the insert behind `if (ModelState.IsValid)`. Once this action moves to the
+ // shared AdminShared model (which does not implement IProductValidVendor), Vendor would silently
+ // lose that guard in the merge unless replaced - scope.HasAccess is that replacement, and now
+ // applies uniformly (a no-op for Admin, equivalent-or-stronger for Store/Vendor) instead of leaning
+ // on a marker-interface side effect that only one host had.
if (!await scope.HasAccess(product))
return Content(translationService.GetResource($"{scope.ResourceKeyPrefix}.Catalog.Products.Permissions"));
@@ -2706,9 +2708,11 @@ public abstract class BaseProductController(
throw new ArgumentException("No product found with the specified id");
// See the ProductAttributeValueCreatePopup(POST) comment above re: the validator's coverage gap -
- // the same applies here (this action shares the same model type). Vendor's original never checked
- // ownership on this POST at all (only its GET sibling did, via CheckAccessToProduct/HasAccessToProduct);
- // Admin's original had no check on either action.
+ // the same reasoning applies here (this action shares the same model type). Unlike CreatePopup(POST),
+ // Vendor's original for THIS action already had an explicit inline check
+ // (`if (product == null || !_contextAccessor.WorkContext.HasAccessToProduct(product)) throw ...`),
+ // so scope.HasAccess is a mechanical substitution there, not a fix. Admin's original had no check
+ // on either action of this pair.
if (!await scope.HasAccess(product))
return Content(translationService.GetResource($"{scope.ResourceKeyPrefix}.Catalog.Products.Permissions"));