studioforty9-dev / Recaptcha

Magento Module for the most recent version of Google reCAPTCHA. (This module is no longer actively supported)
BSD 3-Clause "New" or "Revised" License
50 stars 45 forks source link

Recaptcha error #9

Closed dzmcclure closed 9 years ago

dzmcclure commented 9 years ago

When trying the recaptcha, we get the error "There was an error with the recaptcha code, please try again."

Our exception log shows entries like this:

2015-08-25T15:07:54+00:00 ERR (3): exception 'Zend_Http_Exception' with message 'Error parsing body - doesn't seem to be a chunked message' in /mnt/magento/lib/Zend/Http/Response.php:579 Stack trace: 0 /mnt/magento/lib/Zend/Http/Response.php(262): Zend_Http_Response::decodeChunkedBody('\x1F\x8B\x08\x00\x00\x00\x00\x00\x00\x00\xAB\xE6RPP...') 1 /mnt/magento/app/code/community/Studioforty9/Recaptcha/Helper/Request.php(80): Zend_Http_Response->getBody() 2 /mnt/magento/app/code/community/Studioforty9/Recaptcha/Model/Observer.php(70): Studioforty9_Recaptcha_Helper_Request->verify() 3 /mnt/magento/app/code/core/Mage/Core/Model/App.php(1338): Studioforty9_Recaptcha_Model_Observer->onPostPreDispatch(Object(Varien_Event_Observer)) 4 /mnt/magento/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Studioforty9_Recaptcha_Model_Observer), 'onPostPreDispat...', Object(Varien_Event_Observer)) 5 /mnt/magento/app/Mage.php(447): Mage_Core_Model_App->dispatchEvent('controller_acti...', Array) 6 /mnt/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(532): Mage::dispatchEvent('controller_acti...', Array) 7 /mnt/magento/app/code/core/Mage/Core/Controller/Front/Action.php(64): Mage_Core_Controller_Varien_Action->preDispatch() 8 /mnt/magento/app/code/core/Mage/Review/controllers/ProductController.php(46): Mage_Core_Controller_Front_Action->preDispatch() 9 /mnt/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(408): Mage_Review_ProductController->preDispatch() 10 /mnt/magento/app/code/local/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('post') 11 /mnt/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http)) 12 /mnt/magento/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch() 13 /mnt/magento/app/Mage.php(683): Mage_Core_Model_App->run(Array) 14 /mnt/magento/index.php(87): Mage::run('theindustrysour...', 'store') 15 {main}

dzmcclure commented 9 years ago

Looks like Google messed up the headers on the JSON response, because when I manually told Zend to ignore the chunking, it passed just fine. Disregard the issue above for now.

chromatics commented 9 years ago

I'm having the same issue/error in logs. Is it working now for you?

dzmcclure commented 9 years ago

No, it is still not working. I posted on the Google reCaptcha discussion group about it, and I'm still waiting for a response. The only workaround I've found is to rewrite the Zend http response script to ignore the chunking header, but that seems like it could cause other issues with good JSON responses.

dzmcclure commented 9 years ago

Got it fixed. Line 80 of /app/code/community/Studioforty9/Recaptcha/Helper/Request.php, change $data = Mage::helper('core')->jsonDecode($response->getBody()); to $data = Mage::helper('core')->jsonDecode($response->decodeGzip($response->getRawBody()));

This problem appears when 3 different elements play together: if your Google reCaptcha response is chunked (might not always be the case), and then Varien and Zend are used by this module. The problem is that Varien uses CURL, which automatically decodes the chunked JSON, but then getBody() in Zend tries to decode it again and fails. Changing Zend would probably break other things, and I could not get Varien to take the appropriate change to remove the header after decode as the Zend Curl.php and Socket.php do. These issues are documented and fixed in future versions of Zend, but Magento is using it's own implementation of the Zend framework, which is problematic in cases like this.

Anyway, this fix should work with all of the recaptcha responses, because if the body is chunked then Varien handles that automatically, and if it is not chunked then it will still be gzip encoded, so give this a try and see if it works for you as well.

eoghanobrien commented 9 years ago

Hi @dzmcclur, thanks for the investigation work, I've committed and pushed the change.

Veenamol commented 6 years ago

hi, I have faced the same issue "There was an error with the recaptcha code, please try again" with one specific user and after updating the code in Request.php as mentioned above, I am getting the same error for many users and could not sign in. I am currently using Magento 1.9.1.0 (PHP 5.4).