4

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.

  • Does firefox and chrome get their own cached version of the page? Assuming that Chrome works with multiple sessions (e.g. incognito mode) how is the form key being solved in that case? I personally would just get rid of the form key validation for the add to cart action. It's a more straight forward approach and doesn't add any security concerns from the conversations I've had with other developers. – beeplogic Jun 12 '15 at 17:16
  • I've also run into this form_key problem several times and always ended up removing the check in controller. But the problem happened in all browsers I tested because the form_key was cached and thus different from the session-based one. – Hervé Guétin Jun 12 '15 at 20:05
1

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.

1

This could be related to external cache as initially formkey is not matching. Try to unset the product view block from cache.

<reference name="content">
    <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
        <action method="unsetData"><key>cache_lifetime</key></action>
        <action method="unsetData"><key>cache_tags</key></action>
    </block>
</reference>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.