summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/CaptchaService.ts
diff options
context:
space:
mode:
authorMarie <github@yuugi.dev>2024-11-02 02:20:35 +0100
committerMarie <github@yuugi.dev>2024-11-02 02:20:35 +0100
commitd786e96c2bb6d637be7289efdb6766ae4406af1f (patch)
tree806e3bd85e7b63c7c3e657e80c9ae4fcda5d91b9 /packages/backend/src/core/CaptchaService.ts
parentmerge: Add a clear filter option to the search widget if set (!722) (diff)
downloadsharkey-d786e96c2bb6d637be7289efdb6766ae4406af1f.tar.gz
sharkey-d786e96c2bb6d637be7289efdb6766ae4406af1f.tar.bz2
sharkey-d786e96c2bb6d637be7289efdb6766ae4406af1f.zip
upd: add FriendlyCaptcha as a captcha solution
FriendlyCaptcha is a german captcha solution which is GDPR compliant and has a non-commerical free license
Diffstat (limited to 'packages/backend/src/core/CaptchaService.ts')
-rw-r--r--packages/backend/src/core/CaptchaService.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/backend/src/core/CaptchaService.ts b/packages/backend/src/core/CaptchaService.ts
index f6b7955cd2..5a424890f2 100644
--- a/packages/backend/src/core/CaptchaService.ts
+++ b/packages/backend/src/core/CaptchaService.ts
@@ -10,6 +10,7 @@ import { bindThis } from '@/decorators.js';
type CaptchaResponse = {
success: boolean;
'error-codes'?: string[];
+ 'errors'?: string[];
};
@Injectable()
@@ -73,6 +74,35 @@ export class CaptchaService {
}
}
+ @bindThis
+ public async verifyFriendlyCaptcha(secret: string, response: string | null | undefined): Promise<void> {
+ if (response == null) {
+ throw new Error('recaptcha-failed: no response provided');
+ }
+
+ const result = await this.httpRequestService.send('https://api.friendlycaptcha.com/api/v1/siteverify', {
+ method: 'POST',
+ body: JSON.stringify({
+ secret: secret,
+ solution: response,
+ }),
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ });
+
+ if (result.status !== 200) {
+ throw new Error('frc-failed: frc didn\'t return 200 OK');
+ }
+
+ const resp = await result.json() as CaptchaResponse;
+
+ if (resp.success !== true) {
+ const errorCodes = resp['errors'] ? resp['errors'].join(', ') : '';
+ throw new Error(`frc-failed: ${errorCodes}`);
+ }
+ }
+
// https://codeberg.org/Gusted/mCaptcha/src/branch/main/mcaptcha.go
@bindThis
public async verifyMcaptcha(secret: string, siteKey: string, instanceHost: string, response: string | null | undefined): Promise<void> {