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 v3 compatibility #331

Open
Olaf1989 opened this issue Aug 3, 2022 · 4 comments
Open

Recaptcha v3 compatibility #331

Olaf1989 opened this issue Aug 3, 2022 · 4 comments
Labels

Comments

@Olaf1989
Copy link

Olaf1989 commented Aug 3, 2022

Q A
Bug? no
New Feature? yes
Bundle Version 2.4.0
Sulu Version 2.4.4
Browser Version Mozilla firefox 103.0 (64-bits)

Actual Behavior

At the moment there is no direct support for Recaptcha v3.

Expected Behavior

Ability to use Recaptcha v3.

Steps to Reproduce

  1. Follow the guide https://github.com/sulu/SuluFormBundle/blob/2.4.0/Resources/doc/recaptcha.md
  2. Configure Recaptcha v3 in config/packages/ewz_recaptcha.yaml; https://github.com/excelwebzone/EWZRecaptchaBundle#main-configuration-for-both-v2-and-v3 (version: 3)

Possible Solutions

Add an additional Recaptcha v3 block next to the existing Recaptcha v2 block.

Additional links containing the relevant code:

@alexander-schranz
Copy link
Member

Thx for the issue but I'm not understanding it. As I know we are currently supporting EWZRecaptchaBundle and you define in the EWZRecaptchaBundle if your project uses Recaptcha v2 or Recaptcha v3. That is also why #247 was closed after EWZ added support for it.

If you want to give the content manager the ability to define if its v2 and v3. I'm not sure if we should support this. I don't see this as a task of a content manager to define what is the right way of protection for the website so there should only be one recaptcha block which just work and the developer defines if it uses v2 or v3.

Did you run into a bug when defining v3 in the EWZRecaptchaBundle in combination with SuluFormBundle?

@Keimpy
Copy link

Keimpy commented Aug 4, 2022

@alexander-schranz

The problem is that the SuluFormBundle is always using the v2 implementation. As you can see in https://github.com/sulu/SuluFormBundle/blob/2.4.0/Dynamic/Types/RecaptchaType.php on lines 39 and 45.

The following function works with recaptcha v3

public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void
{
    $options['mapped'] = false;
    $options['constraints'] = new IsTrueV3();

    $builder->add($field->getKey(), EWZRecaptchaV3Type::class, $options);
}

I think there should be an option in the SuluFormBundle to choose which recaptcha version you like to use. Based on that option the (SuluFormBundle)-RecaptchaType should change its behaviour.

@alexander-schranz
Copy link
Member

alexander-schranz commented Aug 4, 2022

@Keimpy I see:

I think it should depending on:

ewz_recaptcha:
    version: 2 # or 3

Use the V3 form type and v3 isTrue or not. We can detect that in a CompilserPass by check if the EWZBundle did register one of the following services https://github.com/excelwebzone/EWZRecaptchaBundle/blob/8dad97a2017dcb650c18ff17ff1b8c54c1847dac/src/DependencyInjection/EWZRecaptchaExtension.php#L41-L47 and check for its class. We can then write a $container->setParameter('sulu_form.recaptcha_version', $recaptchaVersion); which we inject inject constructor as $recaptchaVersion = 2 into our RecaptchaType.php constrcutor and depending on that use v2 or v3 type.

Do you want to give it a try to implement it this way?

@creatiombe
Copy link

I will try to make a pull request for this feature.

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

No branches or pull requests

4 participants