Repository navigation
Protect the guest cookie and save the guest before the action changes it - #1070
Merged
Merged
Conversation
The guest cookie held the bare customer GUID, which the shared wishlist URL also shows, and since the lazy guest change any GUID nobody has is accepted and saved as a new guest. The cookie is now protected with Data Protection; a bare or foreign value is ignored and a new guest is issued. AffiliateAttribute saved an unsaved guest after the action, together with whatever the action changed on it; the affiliate is now set before the action. The Google and Facebook login callbacks save the guest first, so a redirect back without the guest cookie still registers the account.
A guest cookie written before it was protected (a bare GUID) still finds its existing guest and is rewritten protected. It never creates a guest. Transition only, removed in 2.6.
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.
Issue
The guest cookie (
.Grand.Customer) held the bareCustomerGuid. The same GUID is public: the shared wishlist URL (/wishlist/{guid}) and the "email a friend" wishlist message show it. Anyone with that link could put the GUID in their own cookie and become that guest, with the guest's cart, the addresses entered at checkout and the guest's orders. Registered accounts are not affected, because the guest cookie never resolves a registered, system, inactive or deleted customer.Since the lazy guest change (#918), a cookie with any GUID that no customer has is also accepted and saved as a new guest. A client can choose its own guest GUID, and a bot sending a random GUID on every request still creates one customer per request.
Two smaller problems with the unsaved guest:
AffiliateAttributecalledEnsurePersisted()after the action. On a first GET with?affiliateid=it saved the unsaved guest together with whatever the action had changed on that object.CookieSameSite: Strict), registration ran against an unsaved guest. The partial updates did nothing (no upsert), theExternalAuthenticationrow pointed at a customer id that does not exist, and the sign-in cookie named that same missing id, so the registration was silently lost.Solution
CookieAuthenticationServiceprotects the guest cookie with Data Protection (purposeGrand.Web.Customer.Guest) and unprotects it on read. A bare GUID, a tampered value, or a value protected with another key reads as no cookie, so a new guest is issued. The public wishlist GUID is therefore no longer a credential, and only cookies the store issued can be saved as a returning guest.AffiliateAttributesets the affiliate (and saves the guest) before the action runs, as its doc comment already said.GoogleLoginCallbackandFacebookLoginCallbackare marked[PersistGuestCustomer].Breaking changes
Only the guest cookie (
.Grand.Customer) changes. The sign-in cookie (.Grand.Authentication) is untouched: signed-in customers stay signed in, and no account or customer data changes.None for guests: an old guest cookie keeps its guest, cart and wishlist, and is rewritten protected on the first visit. In 2.6 the bare-GUID read is removed; a guest who has not come back by then gets a new guest.
IGrandAuthenticationServicehas a new memberGetLegacyCustomerGuid()with a default implementation, so other implementations still compile.Data Protection keys must be shared between instances, which the sign-in cookie already requires (
PersistKeysToRedis/ Azure). If the keys are lost, guests get a new guest instead of an error.Testing
dotnet test Grand.Web.Common.Tests: 766 passed. New tests: the cookie is not the bare GUID and reads back; a bare GUID is rejected; a value protected with another key is rejected; no cookie gives null. Transition: a bare GUID of an existing guest resolves it and rewrites the cookie; a bare GUID with no guest resolves nothing and is not rewritten; a protected cookie is not rewritten. The affiliate test now asserts persist → write → action.Grand.Web,Authentication.GoogleandAuthentication.Facebookbuild..Grand.Customervalue (CfDJ8…, not a GUID).