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

Setup invisible Captcha service on login/signup form #3546

Closed
FelixMalfait opened this issue Jan 18, 2024 · 6 comments
Closed

Setup invisible Captcha service on login/signup form #3546

FelixMalfait opened this issue Jan 18, 2024 · 6 comments
Assignees
Labels
for experienced contributor scope: back+front Issues requiring full-stack knowledge

Comments

@FelixMalfait
Copy link
Member

We should introduce an invisible Captcha on the login/signup form.

As always we try to have a driver-driven instance to allow each self-hosted instance to pick their provider of choice so let's try to use env variables for the validation URL / KEY (and PROVIDER var eventually if the implementation detail change from one to another).

The 3 services we should look to support are:

@i-am-chitti
Copy link
Contributor

Hi @FelixMalfait,
I'm interested in working on this. Please have a review of below notes to be on same page -

      <Helmet>
        <script
          src="https://www.google.com/recaptcha/api.js?render=6Le-alYpAAAAAEW_lYoHgrVofgdZRfeLjU4TcjtJ"
          async
          defer
        ></script>
      </Helmet>

To make it driver driven, I'll be taking inspiration from existing drivers like SMTP for email.

One doubt though -

  • By Google invisible recaptcha, I think you're referring to v3, right?

@FelixMalfait
Copy link
Member Author

Legend @i-am-chitti you're everywhere 😅 - thanks!!!

Agree with everything you said. And yes v3.

I just have a doubt on react-helmet, I'm not the most qualified to answer technical questions.
What you suggest seems like a nice and clean approach, actually cleaner than what we do here in my opinion:
https://github.com/twentyhq/twenty/blob/main/packages/twenty-front/src/modules/support/components/SupportChat.tsx
But it would be great to get confirmation from @lucasbordeau

@lucasbordeau
Copy link
Contributor

lucasbordeau commented Jan 22, 2024

Current implementation with insertScript seems fine, although we could extract it in an external hook.

@i-am-chitti
Copy link
Contributor

Thanks @FelixMalfait and @lucasbordeau for the notes.
I've started working on this.

i-am-chitti added a commit to i-am-chitti/twenty that referenced this issue Mar 3, 2024
i-am-chitti added a commit to i-am-chitti/twenty that referenced this issue Mar 3, 2024
i-am-chitti added a commit to i-am-chitti/twenty that referenced this issue Mar 3, 2024
@FelixMalfait
Copy link
Member Author

Hey @i-am-chitti let us know if you have questions! I know this isn't a small task and you have other things to do :)

@i-am-chitti
Copy link
Contributor

Hi @FelixMalfait,
The backend is ready and on frontend, I've completed integrating the Google recaptcha. Currently, hCaptcha and Turnstile is pending on frontend.

Didn't get time to work on this past two weeks. Just synced my main branch and found I've lots of merge conflicts. I'm resolving them. Will complete the pending integrations and raise PR in some days.

i-am-chitti added a commit to i-am-chitti/twenty that referenced this issue Mar 22, 2024
i-am-chitti added a commit to i-am-chitti/twenty that referenced this issue Mar 22, 2024
i-am-chitti added a commit to i-am-chitti/twenty that referenced this issue Apr 9, 2024
i-am-chitti added a commit to i-am-chitti/twenty that referenced this issue Apr 9, 2024
i-am-chitti added a commit to i-am-chitti/twenty that referenced this issue Apr 11, 2024
charlesBochet added a commit that referenced this issue Apr 25, 2024
## Description

This PR adds recaptcha on login form. One can add any one of three
recaptcha vendor -
1. Google Recaptcha -
https://developers.google.com/recaptcha/docs/v3#programmatically_invoke_the_challenge
2. HCaptcha -
https://docs.hcaptcha.com/invisible#programmatically-invoke-the-challenge
3. Turnstile -
https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/#execution-modes

### Issue
- #3546 

### Environment variables - 
1. `CAPTCHA_DRIVER` - `google-recaptcha` | `hcaptcha` | `turnstile`
2. `CAPTCHA_SITE_KEY` - site key
3. `CAPTCHA_SECRET_KEY` - secret key

### Engineering choices
1. If some of the above env variable provided, then, backend generates
an error -
<img width="990" alt="image"
src="https://github.com/twentyhq/twenty/assets/60139930/9fb00fab-9261-4ff3-b23e-2c2e06f1bf89">
    Please note that login/signup form will keep working as expected.
2. I'm using a Captcha guard that intercepts the request. If
"captchaToken" is present in the body and all env is set, then, the
captcha token is verified by backend through the service.
3. One can use this guard on any resolver to protect it by the captcha.
4. On frontend, two hooks `useGenerateCaptchaToken` and
`useInsertCaptchaScript` is created. `useInsertCaptchaScript` adds the
respective captcha JS script on frontend. `useGenerateCaptchaToken`
returns a function that one can use to trigger captcha token generation
programatically. This allows one to generate token keeping recaptcha
invisible.

### Note
This PR contains some changes in unrelated files like indentation,
spacing, inverted comma etc. I ran "yarn nx fmt:fix twenty-front" and
"yarn nx lint twenty-front -- --fix".

### Screenshots

<img width="869" alt="image"
src="https://github.com/twentyhq/twenty/assets/60139930/a75f5677-9b66-47f7-9730-4ec916073f8c">

---------

Co-authored-by: Félix Malfait <[email protected]>
Co-authored-by: Charles Bochet <[email protected]>
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in Product development ✅ May 15, 2024
arnavsaxena17 pushed a commit to arnavsaxena17/twenty that referenced this issue Oct 6, 2024
## Description

This PR adds recaptcha on login form. One can add any one of three
recaptcha vendor -
1. Google Recaptcha -
https://developers.google.com/recaptcha/docs/v3#programmatically_invoke_the_challenge
2. HCaptcha -
https://docs.hcaptcha.com/invisible#programmatically-invoke-the-challenge
3. Turnstile -
https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/#execution-modes

### Issue
- twentyhq#3546 

### Environment variables - 
1. `CAPTCHA_DRIVER` - `google-recaptcha` | `hcaptcha` | `turnstile`
2. `CAPTCHA_SITE_KEY` - site key
3. `CAPTCHA_SECRET_KEY` - secret key

### Engineering choices
1. If some of the above env variable provided, then, backend generates
an error -
<img width="990" alt="image"
src="https://github.com/twentyhq/twenty/assets/60139930/9fb00fab-9261-4ff3-b23e-2c2e06f1bf89">
    Please note that login/signup form will keep working as expected.
2. I'm using a Captcha guard that intercepts the request. If
"captchaToken" is present in the body and all env is set, then, the
captcha token is verified by backend through the service.
3. One can use this guard on any resolver to protect it by the captcha.
4. On frontend, two hooks `useGenerateCaptchaToken` and
`useInsertCaptchaScript` is created. `useInsertCaptchaScript` adds the
respective captcha JS script on frontend. `useGenerateCaptchaToken`
returns a function that one can use to trigger captcha token generation
programatically. This allows one to generate token keeping recaptcha
invisible.

### Note
This PR contains some changes in unrelated files like indentation,
spacing, inverted comma etc. I ran "yarn nx fmt:fix twenty-front" and
"yarn nx lint twenty-front -- --fix".

### Screenshots

<img width="869" alt="image"
src="https://github.com/twentyhq/twenty/assets/60139930/a75f5677-9b66-47f7-9730-4ec916073f8c">

---------

Co-authored-by: Félix Malfait <[email protected]>
Co-authored-by: Charles Bochet <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for experienced contributor scope: back+front Issues requiring full-stack knowledge
Projects
Status: ✅ Done
Development

No branches or pull requests

4 participants
@FelixMalfait @lucasbordeau @i-am-chitti and others