Fix missing CSRF protection across storefront controllers#740
Merged
Conversation
Apply [AutoValidateAntiforgeryToken] globally on BasePublicController (matching the existing Admin/Vendor/Store convention) instead of only on a subset of POST actions, closing the CSRF gaps flagged in the security report. Render the antiforgery token once in the storefront layouts and attach it as a header to all axios/jQuery AJAX requests by default so existing add-to-cart, wishlist, and reservation flows keep working under the new global validation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Theme.Modern has its own _Layout.cshtml (separate from the default theme's), which didn't render @Html.AntiForgeryToken(). Since it loads the same public.common.js/public.axios.js that now attach the token as an X-CSRF-TOKEN header, the hidden token was never found on pages using this theme, so AJAX requests (e.g. addproducttocart) were rejected with 400 once AutoValidateAntiforgeryToken went live. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Neither variable is reassigned. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
[AutoValidateAntiforgeryToken]globally onBasePublicController(storefront), matching the convention already used byBaseAdminController/BaseVendorController/BaseStoreController. Previously only ~35 of ~70 POST actions inGrand.Webhad the attribute applied manually, which is what the security report flagged as "Missing cross-site request forgery token validation" across many controllers.[AutoValidateAntiforgeryToken]attributes (35 occurrences across 12 controllers) since the base controller covers them.@Html.AntiForgeryToken()once in_Layout.cshtml/_LayoutPopup.cshtml(same pattern as_AdminLayout.cshtml), and attach that token as anX-CSRF-TOKENheader by default to all axios/jQuery AJAX requests inpublic.common.js. This was necessary because several existing AJAX call sites (add to cart, wishlist add/update, reservation date fill, push notification registration) posted without any CSRF token at all — enabling global validation without this fix would have broken those flows.Test plan
dotnet build src/Web/Grand.Web/Grand.Web.csprojsucceeds with 0 errors