Impacts of Lightning Web Security on Cookie Usage

lightning-web-componentslightning-web-securitylws

I reference B2B LEX but I believe this is not a problem specific to B2B LEX – I just want my use case to be kept in mind in case it's relevant. Our current implementation has a Salesforce Experience that we use as a storefront for B2B LEX. The OOTB search is not sufficient for us, nor is implementing the built-in search functionality using custom components, so we have a custom search with a third party. We need to keep track of what the user's last search was or what they clicked on so we can pull up the correct results if they hit the back button on a product detail page for example. To accomplish this, we make use of cookies. This seems to work as required.

That said, I'm going through the new Trailhead module on Lightning Web Security and it indicates that LWCs modifying cookies will be affected. I cannot test how this will affect our implementation because we use both custom LWCs and Aura components, and the module indicates that currently LWS will cause issues in such instances.

Has anyone tested LWS with LWCs that make use of cookies? Are we going to have to somehow overhaul our solution here? Any help or insight would be appreciated.

Best Answer

The LWS distortion viewer describes how the distortions work. In summary, if you're reading and writing your own cookies, there won't be any problems. If a third party library reads and writes its own cookies, there also won't be any problems. There may be problems if you try to read cookies between sandboxes, or between the third-party library and your component. Realistically, it would be unusual to have written code such that your cookie behavior would change between Locker Service and Lightning Web Security, since both LS and LWS share similar behavior characteristics in regards to cookies.

Related Topic