Frontend form key is being overwrittenFrontend cookie not being set until first login attemptFrontend login...

Is it possible to have an Abelian group under two different binary operations but the binary operations are not distributive?

How do I express some one as a black person?

Algorithm to convert a fixed-length string to the smallest possible collision-free representation?

How do you like my writing?

Try Catch Block Affecting a Variable in an Enclosing Scope

Are the terms "stab" and "staccato" synonyms?

Is there any way to damage Intellect Devourer(s) when already within a creature's skull?

Latest web browser compatible with Windows 98

Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?

Solving "Resistance between two nodes on a grid" problem in Mathematica

The bar has been raised

infinitive telling the purpose

Things to avoid when using voltage regulators?

Is there a window switcher for GNOME that shows the actual window?

Peter's Strange Word

Offered promotion but I'm leaving. Should I tell?

Can Mathematica be used to create an Artistic 3D extrusion from a 2D image and wrap a line pattern around it?

Why is this plane circling around the Lucknow airport every day?

Built-In Shelves/Bookcases - IKEA vs Built

Is "history" a male-biased word ("his+story")?

Is Gradient Descent central to every optimizer?

Why does the negative sign arise in this thermodynamic relation?

Why is there a voltage between the mains ground and my radiator?

Set and print content of environment variable in cmd.exe subshell?



Frontend form key is being overwritten


Frontend cookie not being set until first login attemptFrontend login not working in Chrome with https enabled (1.9)dev.example.com Frontend Login Creates Sessions for example.com (Can't login)Which form file is being used currently? Registration doesn't workError - Invalid Form KeyForm Key Value in template and controllerAdmin login: invalid form key after SUPEE 7405Invalid form key data - cannot loginCustomer mini login form not working with form keyForm Key cookie is set twice - Magento 2.2.4













9















I am currently having issues with frontend forms where the form keys are somehow being overwritten and displaying incorrect form keys. I am currently debugging this issue on the customer login form.



This is snapshot of the code at login.phtml, that i setup to see what the formkey value is.



  <?php
$retrievedKey = $block->getBlockHtml('formkey');
echo $retrievedKey ;
// i made a breakpoint and inspected $retrievedKey, it returned a html output <input> ... </input> with a form key value of, let's name it 'keyA'.
?>


ok so now after i continued the code execution, it renders the page successfully.



And now i go to inspect the form key hidden input on my chrome browser, however, it prints out a totally different form key from 'KeyA'. Let's name this new form key 'KeyB'.



Now i try and do a login, and submit the form. I inspected the request that is sent over, and it indeed passes a form key variable of value that reflects 'KeyB'.



I have placed some breakpoints at 'validate' function of




MagentoFrameworkDataFormFormKeyValidator






This is my comparison checker. By right, $formKey and $a should match. However, it does not.



 $formKey = $request->getParam('form_key', null); // outputs 'KeyB'
$a = $this->_formKey->getFormKey(); // outputs 'KeyA'




Thus, the validation fails, and it redirects me back to the login page with no error message what so ever.



Things to note:




  1. This behavior only arises in chrome and Microsoft EDGE.

  2. Firefox works fine, no overwriting is happening

  3. The form key that is printed out seems to be changing on each refresh. $retrievedKey doesn't refresh each time though




Things i have tried:




  1. setup:upgrade and setup:static-content:deploy

  2. cleared var/cache and var/generation

  3. cleared browser cache and incognito mode



I just can't my head around why the form-key is being overwritten?




Any help or hints on why this is happening would be great. Thanks for reading




Update - I've done some debugging and i figured that page-cache.js is causing the issue by setting the form key again. This is due to the fact that, it is checking my cookies if a 'form_key' cookie is set, if not, create a new form key and save to cookies. The problem is, it is not able to save the cookie, that is why it keeps creating new form keys.



Update - I have solved the issue. This is due to cookie domain issues. Thanks











share|improve this question
















bumped to the homepage by Community 18 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Thanks a lot for documenting a fix. Spent some time debugging the issue seeing the same behavior - form key is generated again and again on the front-end

    – Paras Sood
    Dec 30 '17 at 13:31






  • 1





    In my case it was the magento system cache, as it was migrated from a staging env. Store -> Settings -> Confguration -> System -> Full Page Cache -> Caching Application: Set to Built-in Cache (if not sure whether varnish is up or not).

    – Miguel Felipe Guillen Calo
    May 31 '18 at 2:15











  • Having the exact same problem and was looking at the form keys in validation as well. You said this was due to cookie domain issues, can you share how you fixed that? Thanks

    – Long M K Nguyễn
    Sep 6 '18 at 19:11
















9















I am currently having issues with frontend forms where the form keys are somehow being overwritten and displaying incorrect form keys. I am currently debugging this issue on the customer login form.



This is snapshot of the code at login.phtml, that i setup to see what the formkey value is.



  <?php
$retrievedKey = $block->getBlockHtml('formkey');
echo $retrievedKey ;
// i made a breakpoint and inspected $retrievedKey, it returned a html output <input> ... </input> with a form key value of, let's name it 'keyA'.
?>


ok so now after i continued the code execution, it renders the page successfully.



And now i go to inspect the form key hidden input on my chrome browser, however, it prints out a totally different form key from 'KeyA'. Let's name this new form key 'KeyB'.



Now i try and do a login, and submit the form. I inspected the request that is sent over, and it indeed passes a form key variable of value that reflects 'KeyB'.



I have placed some breakpoints at 'validate' function of




MagentoFrameworkDataFormFormKeyValidator






This is my comparison checker. By right, $formKey and $a should match. However, it does not.



 $formKey = $request->getParam('form_key', null); // outputs 'KeyB'
$a = $this->_formKey->getFormKey(); // outputs 'KeyA'




Thus, the validation fails, and it redirects me back to the login page with no error message what so ever.



Things to note:




  1. This behavior only arises in chrome and Microsoft EDGE.

  2. Firefox works fine, no overwriting is happening

  3. The form key that is printed out seems to be changing on each refresh. $retrievedKey doesn't refresh each time though




Things i have tried:




  1. setup:upgrade and setup:static-content:deploy

  2. cleared var/cache and var/generation

  3. cleared browser cache and incognito mode



I just can't my head around why the form-key is being overwritten?




Any help or hints on why this is happening would be great. Thanks for reading




Update - I've done some debugging and i figured that page-cache.js is causing the issue by setting the form key again. This is due to the fact that, it is checking my cookies if a 'form_key' cookie is set, if not, create a new form key and save to cookies. The problem is, it is not able to save the cookie, that is why it keeps creating new form keys.



Update - I have solved the issue. This is due to cookie domain issues. Thanks











share|improve this question
















bumped to the homepage by Community 18 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Thanks a lot for documenting a fix. Spent some time debugging the issue seeing the same behavior - form key is generated again and again on the front-end

    – Paras Sood
    Dec 30 '17 at 13:31






  • 1





    In my case it was the magento system cache, as it was migrated from a staging env. Store -> Settings -> Confguration -> System -> Full Page Cache -> Caching Application: Set to Built-in Cache (if not sure whether varnish is up or not).

    – Miguel Felipe Guillen Calo
    May 31 '18 at 2:15











  • Having the exact same problem and was looking at the form keys in validation as well. You said this was due to cookie domain issues, can you share how you fixed that? Thanks

    – Long M K Nguyễn
    Sep 6 '18 at 19:11














9












9








9








I am currently having issues with frontend forms where the form keys are somehow being overwritten and displaying incorrect form keys. I am currently debugging this issue on the customer login form.



This is snapshot of the code at login.phtml, that i setup to see what the formkey value is.



  <?php
$retrievedKey = $block->getBlockHtml('formkey');
echo $retrievedKey ;
// i made a breakpoint and inspected $retrievedKey, it returned a html output <input> ... </input> with a form key value of, let's name it 'keyA'.
?>


ok so now after i continued the code execution, it renders the page successfully.



And now i go to inspect the form key hidden input on my chrome browser, however, it prints out a totally different form key from 'KeyA'. Let's name this new form key 'KeyB'.



Now i try and do a login, and submit the form. I inspected the request that is sent over, and it indeed passes a form key variable of value that reflects 'KeyB'.



I have placed some breakpoints at 'validate' function of




MagentoFrameworkDataFormFormKeyValidator






This is my comparison checker. By right, $formKey and $a should match. However, it does not.



 $formKey = $request->getParam('form_key', null); // outputs 'KeyB'
$a = $this->_formKey->getFormKey(); // outputs 'KeyA'




Thus, the validation fails, and it redirects me back to the login page with no error message what so ever.



Things to note:




  1. This behavior only arises in chrome and Microsoft EDGE.

  2. Firefox works fine, no overwriting is happening

  3. The form key that is printed out seems to be changing on each refresh. $retrievedKey doesn't refresh each time though




Things i have tried:




  1. setup:upgrade and setup:static-content:deploy

  2. cleared var/cache and var/generation

  3. cleared browser cache and incognito mode



I just can't my head around why the form-key is being overwritten?




Any help or hints on why this is happening would be great. Thanks for reading




Update - I've done some debugging and i figured that page-cache.js is causing the issue by setting the form key again. This is due to the fact that, it is checking my cookies if a 'form_key' cookie is set, if not, create a new form key and save to cookies. The problem is, it is not able to save the cookie, that is why it keeps creating new form keys.



Update - I have solved the issue. This is due to cookie domain issues. Thanks











share|improve this question
















I am currently having issues with frontend forms where the form keys are somehow being overwritten and displaying incorrect form keys. I am currently debugging this issue on the customer login form.



This is snapshot of the code at login.phtml, that i setup to see what the formkey value is.



  <?php
$retrievedKey = $block->getBlockHtml('formkey');
echo $retrievedKey ;
// i made a breakpoint and inspected $retrievedKey, it returned a html output <input> ... </input> with a form key value of, let's name it 'keyA'.
?>


ok so now after i continued the code execution, it renders the page successfully.



And now i go to inspect the form key hidden input on my chrome browser, however, it prints out a totally different form key from 'KeyA'. Let's name this new form key 'KeyB'.



Now i try and do a login, and submit the form. I inspected the request that is sent over, and it indeed passes a form key variable of value that reflects 'KeyB'.



I have placed some breakpoints at 'validate' function of




MagentoFrameworkDataFormFormKeyValidator






This is my comparison checker. By right, $formKey and $a should match. However, it does not.



 $formKey = $request->getParam('form_key', null); // outputs 'KeyB'
$a = $this->_formKey->getFormKey(); // outputs 'KeyA'




Thus, the validation fails, and it redirects me back to the login page with no error message what so ever.



Things to note:




  1. This behavior only arises in chrome and Microsoft EDGE.

  2. Firefox works fine, no overwriting is happening

  3. The form key that is printed out seems to be changing on each refresh. $retrievedKey doesn't refresh each time though




Things i have tried:




  1. setup:upgrade and setup:static-content:deploy

  2. cleared var/cache and var/generation

  3. cleared browser cache and incognito mode



I just can't my head around why the form-key is being overwritten?




Any help or hints on why this is happening would be great. Thanks for reading




Update - I've done some debugging and i figured that page-cache.js is causing the issue by setting the form key again. This is due to the fact that, it is checking my cookies if a 'form_key' cookie is set, if not, create a new form key and save to cookies. The problem is, it is not able to save the cookie, that is why it keeps creating new form keys.



Update - I have solved the issue. This is due to cookie domain issues. Thanks








magento2 frontend login form-validation form-key






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 30 at 11:34









Muhammad Hasham

2,2841630




2,2841630










asked Jan 10 '17 at 5:36









DerekDerek

816




816





bumped to the homepage by Community 18 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 18 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Thanks a lot for documenting a fix. Spent some time debugging the issue seeing the same behavior - form key is generated again and again on the front-end

    – Paras Sood
    Dec 30 '17 at 13:31






  • 1





    In my case it was the magento system cache, as it was migrated from a staging env. Store -> Settings -> Confguration -> System -> Full Page Cache -> Caching Application: Set to Built-in Cache (if not sure whether varnish is up or not).

    – Miguel Felipe Guillen Calo
    May 31 '18 at 2:15











  • Having the exact same problem and was looking at the form keys in validation as well. You said this was due to cookie domain issues, can you share how you fixed that? Thanks

    – Long M K Nguyễn
    Sep 6 '18 at 19:11



















  • Thanks a lot for documenting a fix. Spent some time debugging the issue seeing the same behavior - form key is generated again and again on the front-end

    – Paras Sood
    Dec 30 '17 at 13:31






  • 1





    In my case it was the magento system cache, as it was migrated from a staging env. Store -> Settings -> Confguration -> System -> Full Page Cache -> Caching Application: Set to Built-in Cache (if not sure whether varnish is up or not).

    – Miguel Felipe Guillen Calo
    May 31 '18 at 2:15











  • Having the exact same problem and was looking at the form keys in validation as well. You said this was due to cookie domain issues, can you share how you fixed that? Thanks

    – Long M K Nguyễn
    Sep 6 '18 at 19:11

















Thanks a lot for documenting a fix. Spent some time debugging the issue seeing the same behavior - form key is generated again and again on the front-end

– Paras Sood
Dec 30 '17 at 13:31





Thanks a lot for documenting a fix. Spent some time debugging the issue seeing the same behavior - form key is generated again and again on the front-end

– Paras Sood
Dec 30 '17 at 13:31




1




1





In my case it was the magento system cache, as it was migrated from a staging env. Store -> Settings -> Confguration -> System -> Full Page Cache -> Caching Application: Set to Built-in Cache (if not sure whether varnish is up or not).

– Miguel Felipe Guillen Calo
May 31 '18 at 2:15





In my case it was the magento system cache, as it was migrated from a staging env. Store -> Settings -> Confguration -> System -> Full Page Cache -> Caching Application: Set to Built-in Cache (if not sure whether varnish is up or not).

– Miguel Felipe Guillen Calo
May 31 '18 at 2:15













Having the exact same problem and was looking at the form keys in validation as well. You said this was due to cookie domain issues, can you share how you fixed that? Thanks

– Long M K Nguyễn
Sep 6 '18 at 19:11





Having the exact same problem and was looking at the form keys in validation as well. You said this was due to cookie domain issues, can you share how you fixed that? Thanks

– Long M K Nguyễn
Sep 6 '18 at 19:11










1 Answer
1






active

oldest

votes


















0














For my case, I am using localhost in URL so the following solution helps me.



If you are using localhost in your URL in the local computer,
so then replace it with IP.



I mean if your URL is



http://localhost/Magento2/



replace it with



http://127.0.0.1/Magento2/



Hope it will work for Chrome & Edge and Firefox also.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f153911%2ffrontend-form-key-is-being-overwritten%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    For my case, I am using localhost in URL so the following solution helps me.



    If you are using localhost in your URL in the local computer,
    so then replace it with IP.



    I mean if your URL is



    http://localhost/Magento2/



    replace it with



    http://127.0.0.1/Magento2/



    Hope it will work for Chrome & Edge and Firefox also.






    share|improve this answer




























      0














      For my case, I am using localhost in URL so the following solution helps me.



      If you are using localhost in your URL in the local computer,
      so then replace it with IP.



      I mean if your URL is



      http://localhost/Magento2/



      replace it with



      http://127.0.0.1/Magento2/



      Hope it will work for Chrome & Edge and Firefox also.






      share|improve this answer


























        0












        0








        0







        For my case, I am using localhost in URL so the following solution helps me.



        If you are using localhost in your URL in the local computer,
        so then replace it with IP.



        I mean if your URL is



        http://localhost/Magento2/



        replace it with



        http://127.0.0.1/Magento2/



        Hope it will work for Chrome & Edge and Firefox also.






        share|improve this answer













        For my case, I am using localhost in URL so the following solution helps me.



        If you are using localhost in your URL in the local computer,
        so then replace it with IP.



        I mean if your URL is



        http://localhost/Magento2/



        replace it with



        http://127.0.0.1/Magento2/



        Hope it will work for Chrome & Edge and Firefox also.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 27 '18 at 20:58









        Shuvankar PaulShuvankar Paul

        11212




        11212






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f153911%2ffrontend-form-key-is-being-overwritten%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            迭戈·戈丁...

            A phrase ”follow into" in a context The 2019 Stack Overflow Developer Survey Results Are...

            1960s short story making fun of James Bond-style spy fiction The 2019 Stack Overflow Developer...