Skip to content
Snippets Groups Projects

#954 updates recaptcha

Merged Ruben A. Estrada requested to merge ruben.estrada/vtigercrm:fix_recaptcha into master

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
175 private function postCaptcha($recaptchaResponse) {
176 global $captchaConfig;
177
178 $fields_string = '';
179 $fields = array(
180 'secret' => $captchaConfig['VTIGER_RECAPTCHA_PRIVATE_KEY'],
181 'response' => $recaptchaResponse
182 );
183 foreach($fields as $key=>$value) {
184 $fields_string .= $key . '=' . $value . '&';
185 }
186
187 $fields_string = rtrim($fields_string, '&');
188
189 $ch = curl_init();
190 curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
  • 175 private function postCaptcha($recaptchaResponse) {
    176 global $captchaConfig;
    177
    178 $fields_string = '';
    179 $fields = array(
    180 'secret' => $captchaConfig['VTIGER_RECAPTCHA_PRIVATE_KEY'],
    181 'response' => $recaptchaResponse
    182 );
    183 foreach($fields as $key=>$value) {
    184 $fields_string .= $key . '=' . $value . '&';
    185 }
    186
    187 $fields_string = rtrim($fields_string, '&');
    188
    189 $ch = curl_init();
    190 curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
    • @ruben.estrada Below may be helpful, @prasad it requires openssl PHP extension, correct?

      protected function sendHttpClientRequest($url, $params, $method = 'GET', $headers = []) { require_once 'vtlib/Vtiger/Net/Client.php'; $httpClient = new Vtiger_Net_Client($url); if (count($headers)) { $httpClient->setHeaders($headers); } switch ($method) { case 'POST': $response = $httpClient->doPost($params); break; case 'GET': $response = $httpClient->doGet($params); break; } return $response; }

  • Prasad @prasad started a thread on the diff
  • 175 private function postCaptcha($recaptchaResponse) {
    176 global $captchaConfig;
    177
    178 $fields_string = '';
    179 $fields = array(
    180 'secret' => $captchaConfig['VTIGER_RECAPTCHA_PRIVATE_KEY'],
    181 'response' => $recaptchaResponse
    182 );
    183 foreach($fields as $key=>$value) {
    184 $fields_string .= $key . '=' . $value . '&';
    185 }
    186
    187 $fields_string = rtrim($fields_string, '&');
    188
    189 $ch = curl_init();
    190 curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
  • 175 private function postCaptcha($recaptchaResponse) {
    176 global $captchaConfig;
    177
    178 $fields_string = '';
    179 $fields = array(
    180 'secret' => $captchaConfig['VTIGER_RECAPTCHA_PRIVATE_KEY'],
    181 'response' => $recaptchaResponse
    182 );
    183 foreach($fields as $key=>$value) {
    184 $fields_string .= $key . '=' . $value . '&';
    185 }
    186
    187 $fields_string = rtrim($fields_string, '&');
    188
    189 $ch = curl_init();
    190 curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
  • 118 118 {/foreach}
    119 119 </table>
    120 120 {if $IS_CAPTCHA_ENABLED}
    121 <div id="captchaField"></div>
    122 <input type="hidden" id="captchaUrl" value="{$CAPTCHA_PATH}">
    123 <input type="hidden" id="recaptcha_validation_value" >
    121 <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    122 <div class="g-recaptcha" data-sitekey="{$CAPTCHA_CONFIG['VTIGER_RECAPTCHA_PUBLIC_KEY']}" data-callback="enableSubmitBtn"></div>
  • @ruben.estrada with this setup I am getting "reCAPTCHA placeholder element must be empty"

  • Prasad Status changed to merged

    Status changed to merged

  • Prasad mentioned in commit de70289c

    mentioned in commit de70289c

  • 118 118 {/foreach}
    119 119 </table>
    120 120 {if $IS_CAPTCHA_ENABLED}
    121 <div id="captchaField"></div>
    122 <input type="hidden" id="captchaUrl" value="{$CAPTCHA_PATH}">
    123 <input type="hidden" id="recaptcha_validation_value" >
    121 <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    122 <div class="g-recaptcha" data-sitekey="{$CAPTCHA_CONFIG['VTIGER_RECAPTCHA_PUBLIC_KEY']}" data-callback="enableSubmitBtn"></div>
  • @nilay.automatesmb it appears that, when generating the code and displaying it, some contents are appended inside the <div class="g-recaptcha".../> element:

    image

    If you take a look you'll see that the code highlighted in blue is not present in ShowForm.tpl. I think it is being dynamically added by JS. I suppose that if you remove that part of the code, your form will work fine.

    However, I'm not sure how to avoid that code being added when it is displayed in vtiger. I think it needs to be generated but only once the browser renders the form in your web page.

    @prasad you have any idea?

  • @ruben.estrada captcha code is automatically generated and should not be removed. @nilay.automatesmb what is the errors you are getting?

  • @sutharsan yes, the code is automatically generated. But it should be generated once it is in your web page and not when being displayed in vtiger. The code you put in your web page should not have the highlighted code. That code needs to be generated dynamically once the contact form is rendered by your browser.

    At least that is my understanding.

  • so this is again a security issue I feel. The code is injected due the inclusion of recaptcha js. When we click on the show form, the html which is inserted leads to the execution of included script tags!

    A small test: add console.log('js executed'); in the ShowForm.tpl and then click on the show form action in CRM, you would see the message being logged.

    
    						<script src="https://www.google.com/recaptcha/api.js" async defer></script>
    						<div class="g-recaptcha" data-sitekey="{$CAPTCHA_CONFIG['VTIGER_RECAPTCHA_PUBLIC_KEY']}" data-callback="enableSubmitBtn"></div>
    						<script type="text/javascript">     
    								console.log('js executed');
    						 </script>
    
  • 118 118 {/foreach}
    119 119 </table>
    120 120 {if $IS_CAPTCHA_ENABLED}
    121 <div id="captchaField"></div>
    122 <input type="hidden" id="captchaUrl" value="{$CAPTCHA_PATH}">
    123 <input type="hidden" id="recaptcha_validation_value" >
    121 <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    122 <div class="g-recaptcha" data-sitekey="{$CAPTCHA_CONFIG['VTIGER_RECAPTCHA_PUBLIC_KEY']}" data-callback="enableSubmitBtn"></div>
    • callback function needs to be there .

      Ideally the submit button should be disabled, and upon recaptcha, it shoudl get enabled.

      Something similar to:

      {if $IS_CAPTCHA_ENABLED}
      						<script src="https://www.google.com/recaptcha/api.js" async defer></script>
      						<div class="g-recaptcha" data-sitekey="{$CAPTCHA_CONFIG['VTIGER_RECAPTCHA_PUBLIC_KEY']}" data-callback="enableSubmitBtn"></div>
      						<script type="text/javascript">
      								function enableSubmitBtn() {
      									document.getElementById('submit').disabled=false;
      								};       
      						 </script>
      						 <input disabled="disabled" type="submit" value="Submit" id="submit"></input>
      					{else}
      						<input type="submit" value="Submit" id="submit"></input>
      					{/if}
      

      But we should also include check about timeouts and before enabling the submit button. So the enablesubmitbutton needs some finetuning.

  • Maintainer

    @nilay.automatesmb - please submit a revised MR if you have found the way.

  • @prasad haven't found yet, working on it. Will update asap.

  • Maintainer

    @ruben.estrada - please review this commit - special case handled for script tag inclusion.

  • Please register or sign in to reply
    Loading