RainLoop /
rainloop-webmail
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | class RecaptchaPlugin extends \RainLoop\Plugins\AbstractPlugin |
||
|
0 ignored issues
–
show
|
|||
| 4 | {
|
||
| 5 | /** |
||
| 6 | * @return void |
||
| 7 | */ |
||
| 8 | public function Init() |
||
| 9 | {
|
||
| 10 | $this->UseLangs(true); |
||
| 11 | |||
| 12 | $this->addJs('js/recaptcha.js');
|
||
| 13 | |||
| 14 | $this->addHook('ajax.action-pre-call', 'AjaxActionPreCall');
|
||
| 15 | $this->addHook('filter.ajax-response', 'FilterAjaxResponse');
|
||
| 16 | } |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @return array |
||
| 20 | */ |
||
| 21 | public function configMapping() |
||
| 22 | {
|
||
| 23 | return array( |
||
| 24 | \RainLoop\Plugins\Property::NewInstance('public_key')->SetLabel('Site key')
|
||
| 25 | ->SetAllowedInJs(true) |
||
| 26 | ->SetDefaultValue(''),
|
||
| 27 | \RainLoop\Plugins\Property::NewInstance('private_key')->SetLabel('Secret key')
|
||
| 28 | ->SetDefaultValue(''),
|
||
| 29 | \RainLoop\Plugins\Property::NewInstance('theme')->SetLabel('Theme')
|
||
| 30 | ->SetAllowedInJs(true) |
||
| 31 | ->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION) |
||
| 32 | ->SetDefaultValue(array('light', 'dark')),
|
||
| 33 | \RainLoop\Plugins\Property::NewInstance('error_limit')->SetLabel('Limit')
|
||
| 34 | ->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION) |
||
| 35 | ->SetDefaultValue(array(0, 1, 2, 3, 4, 5)) |
||
| 36 | ->SetDescription('')
|
||
| 37 | ); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @return string |
||
| 42 | */ |
||
| 43 | private function getCaptchaCacherKey() |
||
| 44 | {
|
||
| 45 | return 'CaptchaNew/Login/'.\RainLoop\Utils::GetConnectionToken(); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return int |
||
| 50 | */ |
||
| 51 | View Code Duplication | private function getLimit() |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 52 | {
|
||
| 53 | $iConfigLimit = $this->Config()->Get('plugin', 'error_limit', 0);
|
||
| 54 | if (0 < $iConfigLimit) |
||
| 55 | {
|
||
| 56 | $oCacher = $this->Manager()->Actions()->Cacher(); |
||
| 57 | $sLimit = $oCacher && $oCacher->IsInited() ? $oCacher->Get($this->getCaptchaCacherKey()) : '0'; |
||
| 58 | |||
| 59 | if (0 < \strlen($sLimit) && \is_numeric($sLimit)) |
||
| 60 | {
|
||
| 61 | $iConfigLimit -= (int) $sLimit; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | return $iConfigLimit; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @return void |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function FilterAppDataPluginSection($bAdmin, $bAuth, &$aData) |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 72 | {
|
||
| 73 | if (!$bAdmin && !$bAuth && \is_array($aData)) |
||
| 74 | {
|
||
| 75 | $aData['show_captcha_on_login'] = 1 > $this->getLimit(); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param string $sAction |
||
| 81 | */ |
||
| 82 | public function AjaxActionPreCall($sAction) |
||
| 83 | {
|
||
| 84 | if ('Login' === $sAction && 0 >= $this->getLimit())
|
||
| 85 | {
|
||
| 86 | $bResult = false; |
||
| 87 | |||
| 88 | $sResult = $this->Manager()->Actions()->Http()->SendPostRequest( |
||
| 89 | 'https://www.google.com/recaptcha/api/siteverify', |
||
| 90 | array( |
||
| 91 | 'secret' => $this->Config()->Get('plugin', 'private_key', ''),
|
||
| 92 | 'response' => $this->Manager()->Actions()->GetActionParam('RecaptchaResponse', '')
|
||
| 93 | ) |
||
| 94 | ); |
||
| 95 | |||
| 96 | if ($sResult) |
||
| 97 | {
|
||
| 98 | $aResp = @\json_decode($sResult, true); |
||
| 99 | if (\is_array($aResp) && isset($aResp['success']) && $aResp['success']) |
||
| 100 | {
|
||
| 101 | $bResult = true; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | if (!$bResult) |
||
| 106 | {
|
||
| 107 | $this->Manager()->Actions()->Logger()->Write('RecaptchaResponse:'.$sResult);
|
||
| 108 | throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CaptchaError); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param string $sAction |
||
| 115 | * @param array $aResponseItem |
||
| 116 | */ |
||
| 117 | View Code Duplication | public function FilterAjaxResponse($sAction, &$aResponseItem) |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 118 | {
|
||
| 119 | if ('Login' === $sAction && $aResponseItem && isset($aResponseItem['Result']))
|
||
|
0 ignored issues
–
show
The expression
$aResponseItem of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 120 | {
|
||
| 121 | $oCacher = $this->Manager()->Actions()->Cacher(); |
||
| 122 | $iConfigLimit = (int) $this->Config()->Get('plugin', 'error_limit', 0);
|
||
| 123 | |||
| 124 | $sKey = $this->getCaptchaCacherKey(); |
||
| 125 | |||
| 126 | if (0 < $iConfigLimit && $oCacher && $oCacher->IsInited()) |
||
| 127 | {
|
||
| 128 | if (false === $aResponseItem['Result']) |
||
| 129 | {
|
||
| 130 | $iLimit = 0; |
||
| 131 | $sLimut = $oCacher->Get($sKey); |
||
| 132 | if (0 < \strlen($sLimut) && \is_numeric($sLimut)) |
||
| 133 | {
|
||
| 134 | $iLimit = (int) $sLimut; |
||
| 135 | } |
||
| 136 | |||
| 137 | $oCacher->Set($sKey, ++$iLimit); |
||
| 138 | |||
| 139 | if ($iConfigLimit <= $iLimit) |
||
| 140 | {
|
||
| 141 | $aResponseItem['Captcha'] = true; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | else |
||
| 145 | {
|
||
| 146 | $oCacher->Delete($sKey); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 |
This check looks for classes that have been defined more than once.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.