From 5416198c329817cbd63305c5755a905d63f1fa64 Mon Sep 17 00:00:00 2001
From: syuilo <4439005+syuilo@users.noreply.github.com>
Date: Mon, 30 Sep 2024 18:19:44 +0900
Subject: [PATCH 01/32] wip
---
.../src/server/api/SigninApiService.ts | 37 +++++++++++++++++++
packages/frontend/src/components/MkSignin.vue | 13 +++++++
2 files changed, 50 insertions(+)
diff --git a/packages/backend/src/server/api/SigninApiService.ts b/packages/backend/src/server/api/SigninApiService.ts
index edac9b3beb62..2ccc75da00cc 100644
--- a/packages/backend/src/server/api/SigninApiService.ts
+++ b/packages/backend/src/server/api/SigninApiService.ts
@@ -9,6 +9,7 @@ import * as OTPAuth from 'otpauth';
import { IsNull } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type {
+ MiMeta,
SigninsRepository,
UserProfilesRepository,
UsersRepository,
@@ -20,6 +21,8 @@ import { IdService } from '@/core/IdService.js';
import { bindThis } from '@/decorators.js';
import { WebAuthnService } from '@/core/WebAuthnService.js';
import { UserAuthService } from '@/core/UserAuthService.js';
+import { CaptchaService } from '@/core/CaptchaService.js';
+import { FastifyReplyError } from '@/misc/fastify-reply-error.js';
import { RateLimiterService } from './RateLimiterService.js';
import { SigninService } from './SigninService.js';
import type { AuthenticationResponseJSON } from '@simplewebauthn/types';
@@ -31,6 +34,9 @@ export class SigninApiService {
@Inject(DI.config)
private config: Config,
+ @Inject(DI.meta)
+ private meta: MiMeta,
+
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
@@ -45,6 +51,7 @@ export class SigninApiService {
private signinService: SigninService,
private userAuthService: UserAuthService,
private webAuthnService: WebAuthnService,
+ private captchaService: CaptchaService,
) {
}
@@ -56,6 +63,10 @@ export class SigninApiService {
password: string;
token?: string;
credential?: AuthenticationResponseJSON;
+ 'hcaptcha-response'?: string;
+ 'g-recaptcha-response'?: string;
+ 'turnstile-response'?: string;
+ 'm-captcha-response'?: string;
};
}>,
reply: FastifyReply,
@@ -139,6 +150,32 @@ export class SigninApiService {
};
if (!profile.twoFactorEnabled) {
+ if (process.env.NODE_ENV !== 'test') {
+ if (this.meta.enableHcaptcha && this.meta.hcaptchaSecretKey) {
+ await this.captchaService.verifyHcaptcha(this.meta.hcaptchaSecretKey, body['hcaptcha-response']).catch(err => {
+ throw new FastifyReplyError(400, err);
+ });
+ }
+
+ if (this.meta.enableMcaptcha && this.meta.mcaptchaSecretKey && this.meta.mcaptchaSitekey && this.meta.mcaptchaInstanceUrl) {
+ await this.captchaService.verifyMcaptcha(this.meta.mcaptchaSecretKey, this.meta.mcaptchaSitekey, this.meta.mcaptchaInstanceUrl, body['m-captcha-response']).catch(err => {
+ throw new FastifyReplyError(400, err);
+ });
+ }
+
+ if (this.meta.enableRecaptcha && this.meta.recaptchaSecretKey) {
+ await this.captchaService.verifyRecaptcha(this.meta.recaptchaSecretKey, body['g-recaptcha-response']).catch(err => {
+ throw new FastifyReplyError(400, err);
+ });
+ }
+
+ if (this.meta.enableTurnstile && this.meta.turnstileSecretKey) {
+ await this.captchaService.verifyTurnstile(this.meta.turnstileSecretKey, body['turnstile-response']).catch(err => {
+ throw new FastifyReplyError(400, err);
+ });
+ }
+ }
+
if (same) {
return this.signinService.signin(request, reply, user);
} else {
diff --git a/packages/frontend/src/components/MkSignin.vue b/packages/frontend/src/components/MkSignin.vue
index 7942a84d66f3..6880d7802649 100644
--- a/packages/frontend/src/components/MkSignin.vue
+++ b/packages/frontend/src/components/MkSignin.vue
@@ -32,6 +32,10 @@ SPDX-License-Identifier: AGPL-3.0-only
+
+
+
+
{{ signing ? i18n.ts.loggingIn : i18n.ts.login }}
@@ -85,6 +89,7 @@ import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { login } from '@/account.js';
import { i18n } from '@/i18n.js';
+import { instance } from '@/instance.js';
const signing = ref(false);
const user = ref(null);
@@ -98,6 +103,10 @@ const isBackupCode = ref(false);
const queryingKey = ref(false);
let credentialRequest: CredentialRequestOptions | null = null;
const passkey_context = ref('');
+const hCaptchaResponse = ref(null);
+const mCaptchaResponse = ref(null);
+const reCaptchaResponse = ref(null);
+const turnstileResponse = ref(null);
const emit = defineEmits<{
(ev: 'login', v: any): void;
@@ -227,6 +236,10 @@ function onSubmit(): void {
misskeyApi('signin', {
username: username.value,
password: password.value,
+ 'hcaptcha-response': hCaptchaResponse.value,
+ 'm-captcha-response': mCaptchaResponse.value,
+ 'g-recaptcha-response': reCaptchaResponse.value,
+ 'turnstile-response': turnstileResponse.value,
token: user.value?.twoFactorEnabled ? token.value : undefined,
}).then(res => {
emit('login', res);
From a3fe00d2040c9e57b2d593d38bf1d495aabba10b Mon Sep 17 00:00:00 2001
From: syuilo <4439005+syuilo@users.noreply.github.com>
Date: Mon, 30 Sep 2024 19:31:40 +0900
Subject: [PATCH 02/32] Update MkSignin.vue
---
packages/frontend/src/components/MkSignin.vue | 1 +
1 file changed, 1 insertion(+)
diff --git a/packages/frontend/src/components/MkSignin.vue b/packages/frontend/src/components/MkSignin.vue
index 6880d7802649..546e58432e7b 100644
--- a/packages/frontend/src/components/MkSignin.vue
+++ b/packages/frontend/src/components/MkSignin.vue
@@ -90,6 +90,7 @@ import { misskeyApi } from '@/scripts/misskey-api.js';
import { login } from '@/account.js';
import { i18n } from '@/i18n.js';
import { instance } from '@/instance.js';
+import MkCaptcha, { type Captcha } from '@/components/MkCaptcha.vue';
const signing = ref(false);
const user = ref(null);
From 459784843836bf3a47a3038c548bb24e43dadaef Mon Sep 17 00:00:00 2001
From: syuilo <4439005+syuilo@users.noreply.github.com>
Date: Mon, 30 Sep 2024 20:21:29 +0900
Subject: [PATCH 03/32] Update MkSignin.vue
---
packages/frontend/src/components/MkSignin.vue | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/packages/frontend/src/components/MkSignin.vue b/packages/frontend/src/components/MkSignin.vue
index 546e58432e7b..f6da2db76f21 100644
--- a/packages/frontend/src/components/MkSignin.vue
+++ b/packages/frontend/src/components/MkSignin.vue
@@ -36,7 +36,7 @@ SPDX-License-Identifier: AGPL-3.0-only
- {{ signing ? i18n.ts.loggingIn : i18n.ts.login }}
+ {{ signing ? i18n.ts.loggingIn : i18n.ts.login }}
@@ -72,7 +72,7 @@ SPDX-License-Identifier: AGPL-3.0-only
+
+
diff --git a/packages/frontend/src/components/MkSignin.passkey.vue b/packages/frontend/src/components/MkSignin.passkey.vue
new file mode 100644
index 000000000000..febfdb5f993d
--- /dev/null
+++ b/packages/frontend/src/components/MkSignin.passkey.vue
@@ -0,0 +1,89 @@
+
+
+
+
+
+
+
+
{{ i18n.ts.useSecurityKey }}
+
+
+
{{ i18n.ts.retry }}
+
+
{{ i18n.ts.useTotp }}
+
+
+
+
+
+
+
diff --git a/packages/frontend/src/components/MkSignin.password.vue b/packages/frontend/src/components/MkSignin.password.vue
new file mode 100644
index 000000000000..13c93dd026a5
--- /dev/null
+++ b/packages/frontend/src/components/MkSignin.password.vue
@@ -0,0 +1,150 @@
+
+
+
+
+
+
+
+
+
diff --git a/packages/frontend/src/components/MkSignin.totp.vue b/packages/frontend/src/components/MkSignin.totp.vue
new file mode 100644
index 000000000000..cd2fa6323550
--- /dev/null
+++ b/packages/frontend/src/components/MkSignin.totp.vue
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
{{ i18n.ts['2fa'] }}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/frontend/src/components/MkSignin.vue b/packages/frontend/src/components/MkSignin.vue
index 6880d7802649..39dc63d3d9a0 100644
--- a/packages/frontend/src/components/MkSignin.vue
+++ b/packages/frontend/src/components/MkSignin.vue
@@ -4,252 +4,266 @@ SPDX-License-Identifier: AGPL-3.0-only
-->
-
@@ -44,7 +44,7 @@ export type PwResponse = {
From ee8e1b50cc32fd0fca66cd56e4c50780a33fd36b Mon Sep 17 00:00:00 2001
From: syuilo <4439005+syuilo@users.noreply.github.com>
Date: Tue, 1 Oct 2024 16:15:32 +0900
Subject: [PATCH 15/32] :art:
---
packages/frontend/src/components/MkSignin.input.vue | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/frontend/src/components/MkSignin.input.vue b/packages/frontend/src/components/MkSignin.input.vue
index 7bd6e2e6d7f1..67ebcbdd93c3 100644
--- a/packages/frontend/src/components/MkSignin.input.vue
+++ b/packages/frontend/src/components/MkSignin.input.vue
@@ -44,7 +44,7 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts.or }}
-
+
{{ i18n.ts.signinWithPasskey }}
From 6983287be2e57c81b2401c641a093468921689bf Mon Sep 17 00:00:00 2001
From: syuilo <4439005+syuilo@users.noreply.github.com>
Date: Thu, 3 Oct 2024 10:16:16 +0900
Subject: [PATCH 16/32] :art:
---
packages/frontend/src/components/MkSigninDialog.vue | 1 +
1 file changed, 1 insertion(+)
diff --git a/packages/frontend/src/components/MkSigninDialog.vue b/packages/frontend/src/components/MkSigninDialog.vue
index f9641e7c02a9..ea4ae5e50456 100644
--- a/packages/frontend/src/components/MkSigninDialog.vue
+++ b/packages/frontend/src/components/MkSigninDialog.vue
@@ -59,6 +59,7 @@ function onLogin(res) {
From 70e772ed28de5c4495f7fa733f66b97581796ee7 Mon Sep 17 00:00:00 2001
From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com>
Date: Fri, 4 Oct 2024 11:09:44 +0900
Subject: [PATCH 31/32] :art:
---
packages/frontend/src/components/MkSigninDialog.vue | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/packages/frontend/src/components/MkSigninDialog.vue b/packages/frontend/src/components/MkSigninDialog.vue
index bd338257a117..25e35a7876b7 100644
--- a/packages/frontend/src/components/MkSigninDialog.vue
+++ b/packages/frontend/src/components/MkSigninDialog.vue
@@ -77,13 +77,14 @@ function onLogin(res) {
top: 0;
left: 0;
width: 100%;
- min-height: 50px;
+ height: 50px;
+ box-sizing: border-box;
display: flex;
align-items: center;
font-weight: bold;
backdrop-filter: var(--blur, blur(15px));
background: var(--acrylicBg);
- border-bottom: solid .5px var(--divider);
+ border-bottom: solid 1px var(--divider);
z-index: 1;
}
@@ -96,6 +97,7 @@ function onLogin(res) {
margin-left: auto;
padding: 16px;
font-size: 16px;
+ line-height: 16px;
}
.content {
From 6efa4a3ef6573d53cce75c9fc56fb2a9cf474b25 Mon Sep 17 00:00:00 2001
From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com>
Date: Fri, 4 Oct 2024 12:00:11 +0900
Subject: [PATCH 32/32] remove border
---
packages/frontend/src/components/MkSigninDialog.vue | 1 -
1 file changed, 1 deletion(-)
diff --git a/packages/frontend/src/components/MkSigninDialog.vue b/packages/frontend/src/components/MkSigninDialog.vue
index 25e35a7876b7..8351d7d5e044 100644
--- a/packages/frontend/src/components/MkSigninDialog.vue
+++ b/packages/frontend/src/components/MkSigninDialog.vue
@@ -84,7 +84,6 @@ function onLogin(res) {
font-weight: bold;
backdrop-filter: var(--blur, blur(15px));
background: var(--acrylicBg);
- border-bottom: solid 1px var(--divider);
z-index: 1;
}