[4.x] Add token-based security for cart loading#4207
Open
lukeholder wants to merge 12 commits into
Open
Conversation
- Add secure token validation to load-cart action - Carts with email/addresses require valid token or owner authentication - Carts without sensitive data can load without token - Add email challenge flow for unauthenticated cart recovery - Register commerce_cart_recovery system message for recovery emails - Add cartLinkExpiry setting (default 24 hours) - Add getLoadCartUrl() to Carts service for generating secure URLs
|
Take a look at _getCart() in CartController.php as well because it is called by actionUpdateCart() and actionComplete() and any other cart modification actions, make sure the same validation is applied. I am not sure how this will affect the over all functionality, but from a cryptographic standpoint, for the generateCartNumber, I would move to something like bin2hex(random_bytes(16)). |
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
Adds token-based security to the cart loading action, with a cart recovery email flow for users whose token has expired or is missing.
Changes
Security
commerce/cart/load-cartnow validates atokenquery parameter. Without a valid token, the user must be logged in as the cart's owner to proceed.Cart Recovery Flow
commerce/cart/email-challenge).commerce_cart_recoverysystem message (customizable subject/body via Settings > Emails)._cart/email-challenge.twigand_cart/email-sent.twig.commerce/cart/load-cartreturns JSON with achallengeUrlkey forAccept: application/jsonrequests on failure.Settings
cartLoadUrlExpirysetting (int, seconds; default:604800/ 7 days) to control how long cart load links remain valid.CP "Share Cart" Element Action
commerce/orders/get-load-cart-urlrather than constructing a static URL client-side, so every copied URL has a valid token.New / Changed APIs
craft\commerce\services\Carts::getLoadCartUrl(Order $cart): string— creates a Craft token and returns the full load-cart URL.craft\commerce\elements\Order::getLoadCartUrl()— now delegates toCarts::getLoadCartUrl()and returns a tokenized URL.craft\commerce\controllers\CartController::actionEmailChallenge()— renders the cart recovery email challenge form.craft\commerce\controllers\CartController::actionCartChallenge()— handles form submission and sends the recovery email.craft\commerce\controllers\CartController::actionCartSent()— renders the post-send confirmation page.craft\commerce\controllers\OrdersController::actionGetLoadCartUrl()— JSON endpoint (requirescommerce-manageOrders) used by the CP "Share cart" element action.