Magento – Initial Form Key not Matching with Varnish/Turpentine in Firefox

addtocartcsrfform-keyturpentinevarnish

I'm running into a weird issue with Varnish, Turpentine, and Firefox which is, in all likelihood, something very specific to the configuration of the system I'm working on. I'm asking about it here mainly to cover my bases and make sure there isn't some known science out there.

The Problem: When a user first navigates to the Magento site, then navigates a catalog listing page, and clicks the "add to cart" button from this page (which triggers a GET request to the Checkout Cart controller), their product is not added to the cart. Instead the page the user ends up on is the empty cart page.

Maddeningly, if they navigate to the catalog listing page again and click the "add to cart" button again, the product is added.

I've tracked this down to a form key problem. The first add to cart request is ignored because of a form key mismatch. I'm starting down the "investigate the ESI include form key implementation" road, but the whole "works fine in Chrome but not Firefox" thing makes me think the problem lies elsewhere.

Has anyone else run into this problem before, or does someone who does Varnish/Turpentine work more frequently have any known places to start digging? I didn't do the initial setup on this system, so I won't have any additional context there.

Update: Did a little more digging, when I added some logging to

#File: app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php
public function getFormKeyAction() {
    //
}

It seems like each ESI include on the category page is generating a unique form key and HTTP_X_VARNISH_FAKED_SESSION header.

Best Answer

Having the same form key doesn't seem to cause me issues on chrome. (We're not using Turpentine but instead using some custom varnish configuration)

Having said that we have a pass rule setup in varnish for anything on the checkout You could add something similar on a wilcard of checkout/cart/add which might do the trick.

Related Topic