From bca7840bf10812ba8423ca78d1b382f5c31a015b Mon Sep 17 00:00:00 2001 From: Krzysztof Pajak Date: Sun, 4 Oct 2026 19:41:52 +0200 Subject: [PATCH 01/21] Fix the GHCR release SBOM step and copy release images to Docker Hub (#874) (#875) --- .github/workflows/docker-ghcr.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/docker-ghcr.yml b/.github/workflows/docker-ghcr.yml index bc6711ec7..52047e63e 100644 --- a/.github/workflows/docker-ghcr.yml +++ b/.github/workflows/docker-ghcr.yml @@ -141,6 +141,10 @@ jobs: format: spdx-json output-file: sbom.spdx.json upload-artifact: true + # On a tag push the action also attaches the SBOM to the GitHub + # release, which needs contents: write. The SBOM ships as a signed + # attestation instead, so the job keeps contents: read. + upload-release-assets: false - name: Cosign attest SBOM env: @@ -202,3 +206,25 @@ jobs: --cert-identity "${IDENTITY}" \ --deny-self-hosted-runners \ --predicate-type "https://slsa.dev/provenance/v1" + + # Docker Hub gets the same verified digest, not a rebuild: the + # signature and attestations above stay valid for it. + - name: Login to Docker Hub + uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASS }} + + - name: Copy image to Docker Hub + env: + IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + DIGEST: ${{ steps.build.outputs.digest }} + DOCKERHUB_IMAGE: grandnode/grandnode2 + # 2.4.0 -> :2.4.0 and :2.4.x; a prerelease (2.4.0-beta) only gets its + # own tag. :latest stays with the push to main (docker-image.yml). + run: | + tags=(-t "${DOCKERHUB_IMAGE}:${VERSION}") + if [[ "${VERSION}" != *-* ]]; then + tags+=(-t "${DOCKERHUB_IMAGE}:${VERSION%.*}.x") + fi + docker buildx imagetools create "${tags[@]}" "${IMAGE}@${DIGEST}" From 427205e8706c96c012b3c2b0793d1d1778093985 Mon Sep 17 00:00:00 2001 From: Krzysztof Pajak Date: Sun, 11 Oct 2026 06:40:30 +0200 Subject: [PATCH 02/21] Restrict product XLSX import to the global admin scope (#890) --- .../Controllers/BaseProductControllerTests.cs | 34 +++++++++++++++++++ .../Controllers/BaseProductController.cs | 15 ++++---- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseProductControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseProductControllerTests.cs index ae616adbb..83f486777 100644 --- a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseProductControllerTests.cs +++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseProductControllerTests.cs @@ -2963,6 +2963,40 @@ public async Task ImportExcel_EmptyFile_DoesNotImport_RedirectsToListWithError() _translationServiceMock.Verify(t => t.GetResource("Admin.Common.UploadFile"), Times.Once); } + // --- ImportExcel: global scope only --- + + [TestMethod] + public async Task ImportExcel_StoreScope_DeniesAndNeverCallsImportManager() + { + _scopeMock.Setup(s => s.DefaultStoreId).Returns("store-1"); + var fileMock = new Mock(); + fileMock.Setup(f => f.Length).Returns(100); + var importManagerMock = new Mock>(); + + var result = await _controller.ImportExcel(fileMock.Object, importManagerMock.Object); + + var redirect = Assert.IsInstanceOfType(result); + Assert.AreEqual("List", redirect.ActionName); + importManagerMock.Verify(i => i.Import(It.IsAny()), Times.Never); + _translationServiceMock.Verify(t => t.GetResource("Admin.AccessDenied.Title"), Times.Once); + } + + [TestMethod] + public async Task ImportExcel_VendorScope_DeniesAndNeverCallsImportManager() + { + _scopeMock.Setup(s => s.DefaultVendorId).Returns("vendor-1"); + var fileMock = new Mock(); + fileMock.Setup(f => f.Length).Returns(100); + var importManagerMock = new Mock>(); + + var result = await _controller.ImportExcel(fileMock.Object, importManagerMock.Object); + + var redirect = Assert.IsInstanceOfType(result); + Assert.AreEqual("List", redirect.ActionName); + importManagerMock.Verify(i => i.Import(It.IsAny()), Times.Never); + _translationServiceMock.Verify(t => t.GetResource("Admin.AccessDenied.Title"), Times.Once); + } + [TestMethod] public async Task ImportExcel_NullFile_DoesNotImport_RedirectsToListWithError() { diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs index 457b334a8..28c5c8b70 100644 --- a/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs +++ b/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs @@ -1853,13 +1853,8 @@ public async Task ExportExcelSelected(string selectedIds, return File(bytes, "text/xls", "products.xlsx"); } - // Not virtual: Vendor's original ProductController has no ImportExcel action at all, and Vendor is - // never granted the "Products" permission's Import action (grep across src/Web/Grand.Web.Vendor found - // no PermissionActionName.Import usage anywhere) - vendors are deliberately not allowed to bulk-import - // products. [PermissionAuthorizeAction(PermissionActionName.Import)] below already 403s for any host - // whose role has no Import grant for Products, so this is safe to expose unconditionally on the base - // class; Vendor's (future) subclass simply never routes a view to it, same as any other - // permission-gated action already in this file. + // Global scope only, as for brands, categories and collections: the importer is not store- or + // vendor-aware. // // Concern (flagged, not fixed - out of scope for this row): ImportExcel only checks // `importexcelfile.Length > 0` before handing the raw stream to IImportManager.Import. @@ -1875,6 +1870,12 @@ public async Task ImportExcel(IFormFile importexcelfile, { try { + if (Scope.DefaultStoreId is not null || Scope.DefaultVendorId is not null) + { + Error(translationService.GetResource("Admin.AccessDenied.Title")); + return RedirectToAction("List"); + } + if (importexcelfile is { Length: > 0 }) { await importManager.Import(importexcelfile.OpenReadStream()); From 568ba953de75be374ed826feb7482d0215e19d1c Mon Sep 17 00:00:00 2001 From: Krzysztof Pajak Date: Sun, 11 Oct 2026 11:28:39 +0200 Subject: [PATCH 03/21] Authentication: a Bearer header without the Web API module no longer fails the request - the API customer lookup skips schemes that are not registered (#888) (#899) (cherry picked from commit 9b952f2aa8bb2cd6589f89baa38aeebb2a112598) --- .../Services/ApiAuthenticationService.cs | 13 +++- .../Services/ApiAuthenticationServiceTests.cs | 74 ++++++++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs b/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs index a0469ff14..c4a521b65 100644 --- a/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs +++ b/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs @@ -18,11 +18,14 @@ public class ApiAuthenticationService : IApiAuthenticationService private readonly ICustomerService _customerService; private readonly IGroupService _groupService; private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IAuthenticationSchemeProvider _schemeProvider; public ApiAuthenticationService( ICustomerService customerService, - IGroupService groupService, IHttpContextAccessor httpContextAccessor) + IGroupService groupService, IHttpContextAccessor httpContextAccessor, + IAuthenticationSchemeProvider schemeProvider) { + _schemeProvider = schemeProvider; _customerService = customerService; _groupService = groupService; _httpContextAccessor = httpContextAccessor; @@ -39,10 +42,18 @@ public virtual async Task GetAuthenticatedCustomer() if (IsApiFrontAuthenticated()) { + //the scheme exists only when the Web API module is enabled + if (await _schemeProvider.GetSchemeAsync(FrontendAPIConfig.AuthenticationScheme) == null) + return null; + customer = await ApiCustomer(); return customer; } + //the scheme exists only when the Web API module is enabled + if (await _schemeProvider.GetSchemeAsync(JwtBearerDefaults.AuthenticationScheme) == null) + return null; + var authenticateResult = await _httpContextAccessor.HttpContext.AuthenticateAsync(JwtBearerDefaults.AuthenticationScheme); if (!authenticateResult.Succeeded) return null; diff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/ApiAuthenticationServiceTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/ApiAuthenticationServiceTests.cs index 3a9e4625b..f51407e84 100644 --- a/src/Tests/Grand.Business.Authentication.Tests/Services/ApiAuthenticationServiceTests.cs +++ b/src/Tests/Grand.Business.Authentication.Tests/Services/ApiAuthenticationServiceTests.cs @@ -1,4 +1,4 @@ -using Grand.Business.Authentication.Services; +using Grand.Business.Authentication.Services; using Grand.Business.Core.Interfaces.Authentication; using Grand.Business.Core.Interfaces.Common.Directory; using Grand.Business.Core.Interfaces.Customers; @@ -6,6 +6,10 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Grand.Infrastructure.Configuration; +using Grand.SharedKernel.Attributes; +using Grand.SharedKernel.Extensions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System.Security.Claims; @@ -30,7 +34,7 @@ public void Init() _userApiServiceMock = new Mock(); _groupService = new Mock(); _authService = new ApiAuthenticationService(_customerService.Object, _groupService.Object, - _httpContextAccessorMoc.Object); + _httpContextAccessorMoc.Object, new Mock().Object); _jwtBearerAuthenticationService = new JwtBearerAuthenticationService(_customerService.Object, _userApiServiceMock.Object); } @@ -180,4 +184,70 @@ public async Task GetAuthenticatedCustomer_NullAuthHeader_GetNull() var result = await _authService.GetAuthenticatedCustomer(); Assert.IsNull(result); } + + private static HttpContext CreateHttpContext(Action configure, Endpoint endpoint = null) + { + var services = new ServiceCollection(); + services.AddLogging(); + var builder = services.AddAuthentication(); + configure?.Invoke(builder); + var context = new DefaultHttpContext { RequestServices = services.BuildServiceProvider() }; + context.Request.Headers["Authorization"] = "Bearer anything"; + if (endpoint != null) context.SetEndpoint(endpoint); + return context; + } + + private IApiAuthenticationService CreateService(HttpContext context) + { + _httpContextAccessorMoc.Setup(c => c.HttpContext).Returns(context); + return new ApiAuthenticationService(_customerService.Object, _groupService.Object, + _httpContextAccessorMoc.Object, + context.RequestServices.GetRequiredService()); + } + + [TestMethod] + public async Task GetAuthenticatedCustomer_BearerHeaderWithoutJwtScheme_ReturnsNull() + { + var context = CreateHttpContext(null); + var result = await CreateService(context).GetAuthenticatedCustomer(); + Assert.IsNull(result); + } + + [TestMethod] + public async Task GetAuthenticatedCustomer_FrontApiEndpointWithoutFrontScheme_ReturnsNull() + { + var endpoint = new Endpoint(null, + new EndpointMetadataCollection(new ApiGroupAttribute(ApiConstants.ApiGroupNameV2)), "front"); + var context = CreateHttpContext(null, endpoint); + var result = await CreateService(context).GetAuthenticatedCustomer(); + Assert.IsNull(result); + } + + [TestMethod] + public async Task GetAuthenticatedCustomer_JwtSchemeRegisteredAndSucceeds_ReturnsCustomer() + { + var customer = new Customer { Id = "c1", Active = true }; + _customerService.Setup(c => c.GetCustomerById("c1")).ReturnsAsync(customer); + _groupService.Setup(g => g.IsRegistered(customer)).ReturnsAsync(true); + var context = CreateHttpContext(b => b.AddScheme( + JwtBearerDefaults.AuthenticationScheme, null)); + var result = await CreateService(context).GetAuthenticatedCustomer(); + Assert.AreSame(customer, result); + } + + private class OkHandler : AuthenticationHandler + { + public OkHandler(Microsoft.Extensions.Options.IOptionsMonitor options, + Microsoft.Extensions.Logging.ILoggerFactory logger, System.Text.Encodings.Web.UrlEncoder encoder) + : base(options, logger, encoder) + { + } + + protected override Task HandleAuthenticateAsync() + { + var identity = new ClaimsIdentity(new[] { new Claim("CustomerId", "c1") }, "test"); + return Task.FromResult(AuthenticateResult.Success( + new AuthenticationTicket(new ClaimsPrincipal(identity), Scheme.Name))); + } + } } \ No newline at end of file From dd86ea3126a3be3794c1340671ff8a228266ba4a Mon Sep 17 00:00:00 2001 From: Krzysztof Pajak Date: Sun, 11 Oct 2026 11:29:55 +0200 Subject: [PATCH 04/21] Storefront: news and home page news/blog blocks render database HTML with v-pre (#887) (#898) * Storefront: news item, news list and home page news/blog blocks render their HTML with v-pre, like blog posts and pages - {{ }} in the content no longer reaches Vue's compiler * Storefront: news item and blog post headers render with v-pre - {{ }} in a title no longer reaches Vue's compiler (cherry picked from commit 3bdcc77b749d9c19bdb532df9d20f03c0d56e609) --- src/Web/Grand.Web/Views/Blog/BlogPost.cshtml | 2 +- src/Web/Grand.Web/Views/News/List.cshtml | 2 +- src/Web/Grand.Web/Views/News/NewsItem.cshtml | 4 ++-- .../Views/Shared/Components/HomePageBlog/Default.cshtml | 2 +- .../Views/Shared/Components/HomePageNews/Default.cshtml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Web/Grand.Web/Views/Blog/BlogPost.cshtml b/src/Web/Grand.Web/Views/Blog/BlogPost.cshtml index 6e2c07593..a78a02097 100644 --- a/src/Web/Grand.Web/Views/Blog/BlogPost.cshtml +++ b/src/Web/Grand.Web/Views/Blog/BlogPost.cshtml @@ -22,7 +22,7 @@
@await Component.InvokeAsync("Widget", new { widgetZone = "blogpost_page_top", additionalData = Model.Id })
-
+
@if (!string.IsNullOrEmpty(Model.PictureModel.ImageUrl)) { @Model.PictureModel.AlternateText diff --git a/src/Web/Grand.Web/Views/News/List.cshtml b/src/Web/Grand.Web/Views/News/List.cshtml index a2f28adf6..df75da3ae 100644 --- a/src/Web/Grand.Web/Views/News/List.cshtml +++ b/src/Web/Grand.Web/Views/News/List.cshtml @@ -25,7 +25,7 @@
-
+
@Html.Raw(item.Short)
diff --git a/src/Web/Grand.Web/Views/News/NewsItem.cshtml b/src/Web/Grand.Web/Views/News/NewsItem.cshtml index 34fba5222..0e03eebc2 100644 --- a/src/Web/Grand.Web/Views/News/NewsItem.cshtml +++ b/src/Web/Grand.Web/Views/News/NewsItem.cshtml @@ -10,7 +10,7 @@ }
-
+
@if (!string.IsNullOrEmpty(Model.PictureModel.ImageUrl)) { @Model.PictureModel.AlternateText @@ -23,7 +23,7 @@
@await Component.InvokeAsync("Widget", new { widgetZone = "newsitem_page_before_body", additionalData = Model.Id }) -
+
@Html.Raw(Model.Full)
diff --git a/src/Web/Grand.Web/Views/Shared/Components/HomePageBlog/Default.cshtml b/src/Web/Grand.Web/Views/Shared/Components/HomePageBlog/Default.cshtml index 548a1e277..1cb285d7e 100644 --- a/src/Web/Grand.Web/Views/Shared/Components/HomePageBlog/Default.cshtml +++ b/src/Web/Grand.Web/Views/Shared/Components/HomePageBlog/Default.cshtml @@ -23,7 +23,7 @@
-
+
@Html.Raw(item.Short)
-
+
@Html.Raw(item.Short)