I see that in magento 2 form_key is set in cookies. Is this cookie present in every page?

  • I can say yes. We can find the form_key in cookie in every page. May 30, 2017 at 14:33
  • Well i agree that it appears in pages. But do you what code renders it? May 30, 2017 at 14:47
  • Should take a look: vendor/magento/framework/App/PageCache/FormKey.php, vendor/magento/module-page-cache/Observer/RegisterFormKeyFromCookie.php May 30, 2017 at 14:50

1 Answer 1


I can say yes. We can find the form_key in cookie on every page.


<event name="controller_action_predispatch">
    <observer name="register_form_key"

As we can see, for each Action Dispatch request, Magento will try to register the form key from the cookie.

  • 1
    It works with varnish? It can't cache the page if page sets always the cookie right?
    – Wiliam
    Nov 27, 2017 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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