recaptcha icon indicating copy to clipboard operation
recaptcha copied to clipboard

Recaptcha V2 just spins

Open autohpn opened this issue 2 years ago • 21 comments

Issue description I have a problem with recaptcha v2. It has stopped working without having changed anything. When checking, it only rotates and does not verify.

Environment

  • OS name and version: APACHE
  • PHP version: 5.3.29
  • Web server name and version: Linux 2.6.32-642.1.1.el6.x86_64
  • google/recaptcha version: V2
  • Browser name and version: ALL

Reproducing the issue

  • URL (optional): https://www.autohispania.com/contact_us.php

autohpn avatar Nov 14 '23 13:11 autohpn

This should be conflict with mootools: https://stackoverflow.com/questions/77473778/google-recaptcha-keeps-on-loading
https://stackoverflow.com/questions/77462429/joomla-recaptcha-v2-0-spinning
https://stackoverflow.com/questions/77454968/joomla-recaptcha-issues

Compatability bind, that could have worked earlier (https://gist.github.com/sleemanj/f076ed2c0b887ab08074b55dad2fd636 https://github.com/google/recaptcha/issues/374#issuecomment-729881795) also stop working.

stdex avatar Nov 15 '23 09:11 stdex

Thanks for your answer!

how can i solve this????? I don't found the solution :-(

autohpn avatar Nov 15 '23 12:11 autohpn

What version of Mootools do you use? 1.6.0 resolves some Array.from related issues.

dimov-cz avatar Nov 15 '23 18:11 dimov-cz

I can confirm problem on mootools 1.4.2

stdex avatar Nov 15 '23 19:11 stdex

the problem happens with both 1.4.2 and 1.6.

I have managed to solve the problem by not loading mootools in the urls where the captcha loads. It is the only radical way by which I have been able to do it.

autohpn avatar Nov 15 '23 19:11 autohpn

1.6.0 without comp. layer is working for me

dimov-cz avatar Nov 15 '23 19:11 dimov-cz

The problematic code in compatibility mode is: /<1.5compat>/ Array.from = Array.convert; /</1.5compat>/

and in 1.5.1 and earlier version Array.from implementation which doesn't handle objects like MapIterate and Set.

dimov-cz avatar Nov 15 '23 19:11 dimov-cz

For me it's worked in template index.php after <jdoc:include type="head"/> : <?php unset($this->_scripts[$this->baseurl.'/media/system/js/mootools-core.js']); ?>

SaintAnd avatar Nov 16 '23 10:11 SaintAnd

For me it's worked in template index.php after <jdoc:include type="head"/> : <?php unset($this->_scripts[$this->baseurl.'/media/system/js/mootools-core.js']); ?>

it removes core of mootools which can be used somewhere in your site. for example in my case it is used in virtuemart users/orders pages. removing it may lead to other issues.

am-unklown avatar Nov 16 '23 13:11 am-unklown

1.6.0 without comp. layer is working for me

for me it resolves problem with recaptcha but brings problems in admin part of site (e.g. on pages with availability to sort entities: articles, orders, etc). enabling compat layer even with fix form #374 brokes recaptcha.

am-unklown avatar Nov 16 '23 13:11 am-unklown

For me it's worked in template index.php after <jdoc:include type="head"/> : <?php unset($this->_scripts[$this->baseurl.'/media/system/js/mootools-core.js']); ?>

it removes core of mootools which can be used somewhere in your site. for example in my case it is used in virtuemart users/orders pages. removing it may lead to other issues.

I agree with you. This leads to other problems on the site. Spoilers and sliders break

SaintAnd avatar Nov 20 '23 08:11 SaintAnd

Unfortunately, this is the only option currently used.

_scripts[$this->baseurl.'/media/system/js/mootools-core.js']);} ?>

SaintAnd avatar Nov 22 '23 14:11 SaintAnd

Using @sleemanj's original bind compatibility approach and the Array.from hint from @dimov-cz I've come up with the following which seems to be working for me (mootools 1.4.5):

// Add this BEFORE mootools is loaded

Function.prototype._nativeBind = Function.prototype.bind;
Array._nativeFrom = Array.from;
// Add this AFTER mootools is loaded

var isRecaptcha = function() {
	var stack = new Error().stack;
	if (!stack) {
		try {
			throw new Error();
		} catch (e) {
			stack = e.stack;
		}
	}
	return stack.match(/recaptcha/);
}

Function.prototype._mootoolsBind = Function.prototype.bind;
Array._mootoolsFrom = Array.from;

Function.prototype.bind = function (...args) {
	return isRecaptcha() ? this._nativeBind(...args) : this._mootoolsBind(...args);
};
Array.from = function (...args) {
	return isRecaptcha() ? this._nativeFrom(...args) : this._mootoolsFrom(...args);
};

I've not tested this thoroughly yet and there could be issues with it! Improvements welcome.

jacksleight avatar Nov 23 '23 11:11 jacksleight

Okay, I have a much elegant solution for this.... Change this part of code

Array.from = function(item){
	if (item == null) return [];
	return (Type.isEnumerable(item) && typeof item != 'string') ? (typeOf(item) == 'array') ? item : slice.call(item) : [item];
};

with this

Array.from = function(item){
	if(new Error().stack.indexOf('recaptcha') >= 0) return [].slice.call(item); // Single line added for reCaptcha fix
	if (item == null) return [];
	return (Type.isEnumerable(item) && typeof item != 'string') ? (typeOf(item) == 'array') ? item : slice.call(item) : [item];
};

Patched files are below if anyone needs.... Unzip into JPATH_ROOT/media/system/js/ mootools.zip

pinta83 avatar Nov 23 '23 12:11 pinta83

post the file if it works please

AlexSmetaninGB avatar Nov 27 '23 10:11 AlexSmetaninGB

post the file if it works please

Edited and uploaded in thread above ;)

pinta83 avatar Nov 27 '23 12:11 pinta83

Cool, it seems to work... Could you write what the error was and what caused it? Thanks man!!!

AlexSmetaninGB avatar Nov 27 '23 14:11 AlexSmetaninGB

thx all ;_) pinta83-WO (dev) dimov-cz (dev) SaintAnd- ru (sql) Andrew Gospodin jacksleight-United Kingdom (j.s) Jack Sleight AlexSmetaninGB-ru (bug report) AlexSmetanin

AlexSmetaninGB avatar Nov 27 '23 22:11 AlexSmetaninGB

thx all ;_) pinta83-us (dev) dimov-cz (dev) SaintAnd-us (sql) jacksleight-us (j.s) AlexSmetaninGB-ru (dev, bug report)

pinta83-WO (dev) dimov-cz (dev) SaintAnd- ru (sql) Andrew Gospodin jacksleight-United Kingdom (j.s) Jack Sleight AlexSmetaninGB-ru (bug report) AlexSmetanin

AlexSmetaninGB avatar Nov 27 '23 22:11 AlexSmetaninGB

Note that you may need to clear the browser cache for this to work.

trinkel avatar Dec 11 '23 23:12 trinkel

This works without having to run a script before mootools is loaded:

// Add this AFTER mootools is loaded
(function fixMooToolsAndRecaptchaMapsIssueIffy() {
// restore native Array.from by getting the native implemenation from a new frame
var frame = document.createElement('iframe');
frame.sandbox = 'allow-same-origin';
document.body.appendChild(frame);
Array._nativeFrom = frame.contentWindow.Array.from
Function.prototype._nativeBind= frame.contentWindow.Function.prototype.bind
frame.remove();
var isRecaptchaOrMaps = function() {
	var stack = new Error().stack;
	if (!stack) {
		try {
			throw new Error();
		} catch (e) {
			stack = e.stack;
		}
	}
	return stack.match(/recaptcha/) || stack.match(/maps\.google\.com/);
}

Function.prototype._mootoolsBind = Function.prototype.bind;
Array._mootoolsFrom = Array.from;

Function.prototype.bind = function (...args) {
	return isRecaptchaOrMaps () ? this._nativeBind(...args) : this._mootoolsBind(...args);
};
Array.from = function (...args) {
	return isRecaptchaOrMaps () ? this._nativeFrom(...args) : this._mootoolsFrom(...args);
};
})();

sempostma avatar Dec 22 '23 21:12 sempostma