From d14f7ad1e05fbf993fa85194e5d556255e851a32 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 7 Aug 2020 15:51:51 +0200 Subject: [PATCH 1/4] Fix #16269 - Implement CaptchaMethod config to support ReCaptcha v2 checkbox Signed-off-by: William Desportes --- doc/config.rst | 12 ++++++++++++ .../classes/Plugins/Auth/AuthenticationCookie.php | 12 +++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index abd835e5e9..be516c105d 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1872,6 +1872,18 @@ Cookie authentication options bypass regular expression by the suffix, while connecting to another server. +.. config:option:: $cfg['CaptchaMethod'] + + :type: string + :default: ``'invisible'`` + + Valid values are: + + * ``'invisible'`` Use an invisible captcha checking method; + * ``'checkbox'`` Use a checkbox to confirm the user is not a robot. + + .. versionadded:: 5.0.3 + .. config:option:: $cfg['CaptchaLoginPublicKey'] :type: string diff --git a/libraries/classes/Plugins/Auth/AuthenticationCookie.php b/libraries/classes/Plugins/Auth/AuthenticationCookie.php index a4835819f2..e5901cb5cd 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationCookie.php +++ b/libraries/classes/Plugins/Auth/AuthenticationCookie.php @@ -250,9 +250,15 @@ class AuthenticationCookie extends AuthenticationPlugin } else { echo ''; - echo ''; + if (isset($GLOBALS['cfg']['CaptchaMethod']) && $GLOBALS['cfg']['CaptchaMethod'] === 'checkbox') { + echo '
'; + echo ''; + } else { + echo ''; + } } $_form_params = []; if (! empty($GLOBALS['target'])) { From 38dbc7cb16fa878c06242120e0fc83097caa882c Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 7 Aug 2020 16:07:30 +0200 Subject: [PATCH 2/4] Fix #16269 - Add tests for CaptchaMethod Signed-off-by: William Desportes --- .../Plugins/Auth/AuthenticationCookieTest.php | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/test/classes/Plugins/Auth/AuthenticationCookieTest.php b/test/classes/Plugins/Auth/AuthenticationCookieTest.php index 5291d44a1c..0af2e45cb1 100644 --- a/test/classes/Plugins/Auth/AuthenticationCookieTest.php +++ b/test/classes/Plugins/Auth/AuthenticationCookieTest.php @@ -351,6 +351,91 @@ class AuthenticationCookieTest extends PmaTestCase ); } + /** + * Test for PhpMyAdmin\Plugins\Auth\AuthenticationConfig::showLoginForm + * + * @return void + * @group medium + */ + public function testAuthCaptchaCheckbox() + { + $mockResponse = $this->mockResponse(); + + $mockResponse->expects($this->once()) + ->method('isAjax') + ->with() + ->will($this->returnValue(false)); + + $mockResponse->expects($this->once()) + ->method('getFooter') + ->with() + ->will($this->returnValue(new Footer())); + + $mockResponse->expects($this->once()) + ->method('getHeader') + ->with() + ->will($this->returnValue(new Header())); + + $_REQUEST['old_usr'] = ''; + $GLOBALS['cfg']['LoginCookieRecall'] = false; + + $GLOBALS['pmaThemeImage'] = 'test'; + $GLOBALS['cfg']['Lang'] = ''; + $GLOBALS['cfg']['AllowArbitraryServer'] = false; + $GLOBALS['cfg']['Servers'] = [1]; + $GLOBALS['cfg']['CaptchaLoginPrivateKey'] = 'testprivkey'; + $GLOBALS['cfg']['CaptchaLoginPublicKey'] = 'testpubkey'; + $GLOBALS['cfg']['CaptchaMethod'] = 'checkbox'; + $GLOBALS['server'] = 0; + + $GLOBALS['error_handler'] = new ErrorHandler(); + + ob_start(); + $this->object->showLoginForm(); + $result = ob_get_clean(); + + // assertions + + $this->assertStringContainsString('id="imLogo"', $result); + + // Check for language selection if locales are there + $loc = LOCALE_PATH . '/cs/LC_MESSAGES/phpmyadmin.mo'; + if (is_readable($loc)) { + $this->assertStringContainsString( + '', + $result + ); + + $this->assertStringContainsString( + '', + $result + ); + + $this->assertStringContainsString( + '
', + $result + ); + + $this->assertStringContainsString( + '', + $result + ); + } + /** * Test for PhpMyAdmin\Plugins\Auth\AuthenticationConfig::showLoginForm with headers * From ac133f1f9241057e9e8ec76d5f530a9cc4c2b342 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 7 Aug 2020 16:15:27 +0200 Subject: [PATCH 3/4] #16269 - fix a coding standard issue Signed-off-by: William Desportes --- libraries/classes/Plugins/Auth/AuthenticationCookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/Plugins/Auth/AuthenticationCookie.php b/libraries/classes/Plugins/Auth/AuthenticationCookie.php index e5901cb5cd..2e57ca4e53 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationCookie.php +++ b/libraries/classes/Plugins/Auth/AuthenticationCookie.php @@ -252,7 +252,7 @@ class AuthenticationCookie extends AuthenticationPlugin , $GLOBALS['lang'] , '" async defer>'; if (isset($GLOBALS['cfg']['CaptchaMethod']) && $GLOBALS['cfg']['CaptchaMethod'] === 'checkbox') { echo '
'; + . htmlspecialchars($GLOBALS['cfg']['CaptchaLoginPublicKey']) . '">'; echo ''; } else { echo '