summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/CaptchaService.ts
diff options
context:
space:
mode:
authorCyberRex <hspwinx86@gmail.com>2022-10-13 09:19:57 +0900
committerGitHub <noreply@github.com>2022-10-13 09:19:57 +0900
commit1309367884197f4f4d94686fddfbd99fa20262bc (patch)
tree3f21e60ee1bc155a903c403106fbdc6c0e0440b9 /packages/backend/src/core/CaptchaService.ts
parentadd webhookId to api request (#9113) (diff)
downloadsharkey-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.ts11
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}`;
+ }
+ }
}