karser / KarserRecaptcha3Bundle

Google ReCAPTCHA v3 for Symfony
MIT License
158 stars 21 forks source link

Your computer or network may be sending automated queries - error always showing on localhost #49

Closed NayanChauveau closed 2 years ago

NayanChauveau commented 2 years ago

Hi everyone,

After I followed the doc for the implementation of the bundle, I am facing an issue. I don't know if it is linked to the bundle or to Recaptcha itself but I have every time I submit my form in local :

"Your computer or network may be sending automated queries"

I am working with Symfony 5 and I have done the little configuration as possible as mentioned in the readme.

my karser_recaptcha3.yaml

karser_recaptcha3:
    site_key: "%env(RECAPTCHA3_KEY)%"
    secret_key: "%env(RECAPTCHA3_SECRET)%"
    score_threshold: 0.5
    enabled: true

my form

  namespace App\Form;

  use Symfony\Component\Form\AbstractType;
  use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  use Symfony\Component\Form\Extension\Core\Type\SubmitType;

  class VoteType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              ->add('captcha', Recaptcha3Type::class, [
                  'constraints' => new Recaptcha3(),
                  'action_name' => 'homepage'
              ])
              ->add('submit', SubmitType::class, [])
              ;
          ;
      }

      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver->setDefaults([]);
      }
  }

Thanks a lot for your answer,

Nayan

karser commented 2 years ago

Hello, have you tried lowering score_threshold? 0.2, 0.1 ...

NayanChauveau commented 2 years ago

Yes, I have put it at 0.1 and I have the same error...

karser commented 2 years ago

Can you please display the actual error using this example? Just add the {{ errorCodes }} variable to the message template:

$formBuilder->add('captcha', Recaptcha3Type::class, [
    'constraints' => new Recaptcha3(['message' => 'There were problems with your captcha. Please try again or contact with support and provide following code(s): {{ errorCodes }}']),
])

Also, you can get the actual ReCaptcha score you are getting this way

NayanChauveau commented 2 years ago

Hi ! Thanks a lot, I was not debugging properly. With the {{ errorCodes }} method, I found a "Could not connect to service" error which lead me to this issue : https://github.com/karser/KarserRecaptcha3Bundle/issues/41

I followed your advice to debug by putting

$response = $this->curl->exec($handle);
        $body = curl_error($handle);
        $http_status = curl_getinfo($handle, CURLINFO_HTTP_CODE);
        $curl_errno= curl_errno($handle);
        var_dump($body, $http_status, $curl_errno);
        $this->curl->close($handle);

in

google/recaptcha/src/ReCaptcha/RequestMethod/CurlPost.php

and I have an SSL error, which is normal since I am in localhost.

Thanks a lot for your help !

Nayan

karser commented 2 years ago

I'm glad it helped!