Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recaptcha V2 just spins #539

Open
autohpn opened this issue Nov 14, 2023 · 21 comments
Open

Recaptcha V2 just spins #539

autohpn opened this issue Nov 14, 2023 · 21 comments

Comments

@autohpn
Copy link

autohpn commented Nov 14, 2023

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

@autohpn
Copy link
Author

autohpn commented Nov 15, 2023

Thanks for your answer!

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

@dimov-cz
Copy link

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

@stdex
Copy link

stdex commented Nov 15, 2023

I can confirm problem on mootools 1.4.2

@autohpn
Copy link
Author

autohpn commented Nov 15, 2023

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.

@dimov-cz
Copy link

1.6.0 without comp. layer is working for me

@dimov-cz
Copy link

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.

@SaintAnd
Copy link

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']); ?>

@am-unklown
Copy link

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
Copy link

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.

@SaintAnd
Copy link

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
Copy link

Unfortunately, this is the only option currently used.

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

@jacksleight
Copy link

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.

@pinta83
Copy link

pinta83 commented Nov 23, 2023

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

@AlexSmetaninGB
Copy link

post the file if it works please

@pinta83
Copy link

pinta83 commented Nov 27, 2023

post the file if it works please

Edited and uploaded in thread above ;)

@AlexSmetaninGB
Copy link

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

@AlexSmetaninGB
Copy link

AlexSmetaninGB commented Nov 27, 2023

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
Copy link

AlexSmetaninGB commented Nov 27, 2023

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

@trinkel
Copy link

trinkel commented Dec 11, 2023

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

@sempostma
Copy link

sempostma commented Dec 22, 2023

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);
};
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants