diff options
| author | CyberRex <hspwinx86@gmail.com> | 2022-10-13 09:19:57 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-13 09:19:57 +0900 |
| commit | 1309367884197f4f4d94686fddfbd99fa20262bc (patch) | |
| tree | 3f21e60ee1bc155a903c403106fbdc6c0e0440b9 /packages/backend/src/core/CaptchaService.ts | |
| parent | add webhookId to api request (#9113) (diff) | |
| download | sharkey-1309367884197f4f4d94686fddfbd99fa20262bc.tar.gz sharkey-1309367884197f4f4d94686fddfbd99fa20262bc.tar.bz2 sharkey-1309367884197f4f4d94686fddfbd99fa20262bc.zip | |
Add Cloudflare Turnstile CAPTCHA support (#9111)
* Add Cloudflare Turnstile CAPTCHA support
* Update packages/client/src/components/MkCaptcha.vue
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
Diffstat (limited to 'packages/backend/src/core/CaptchaService.ts')
| -rw-r--r-- | packages/backend/src/core/CaptchaService.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/packages/backend/src/core/CaptchaService.ts b/packages/backend/src/core/CaptchaService.ts index 67b4b90061..acfa7d5910 100644 --- a/packages/backend/src/core/CaptchaService.ts +++ b/packages/backend/src/core/CaptchaService.ts @@ -66,5 +66,16 @@ export class CaptchaService { throw `hcaptcha-failed: ${errorCodes}`; } } + + public async verifyTurnstile(secret: string, response: string): Promise<void> { + const result = await this.getCaptchaResponse('https://challenges.cloudflare.com/turnstile/v0/siteverify', secret, response).catch(e => { + throw `turnstile-request-failed: ${e}`; + }); + + if (result.success !== true) { + const errorCodes = result['error-codes'] ? result['error-codes'].join(', ') : ''; + throw `turnstile-failed: ${errorCodes}`; + } + } } |