mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-19 05:55:34 +09:00
fix(captcha): drop the body-email contact policy exemption (#2343)
This commit is contained in:
1 parent
0f7ad484ce
commit
e86e24a2db
1 file changed
+3
-14
@@ -1,5 +1,6 @@
|
|||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
import {Headers} from '@fluxer/constants/src/Headers';
|
||||||
import {UserFlags} from '@fluxer/constants/src/UserConstants';
|
import {UserFlags} from '@fluxer/constants/src/UserConstants';
|
||||||
import {CaptchaRequiredError, InvalidCaptchaError} from '@fluxer/errors/src/CaptchaErrors';
|
import {CaptchaRequiredError, InvalidCaptchaError} from '@fluxer/errors/src/CaptchaErrors';
|
||||||
import {extractClientIp} from '@fluxer/ip_utils/src/ClientIp';
|
import {extractClientIp} from '@fluxer/ip_utils/src/ClientIp';
|
||||||
@@ -55,13 +56,12 @@ export async function verifyCaptchaToken(ctx: Context<HonoEnv>): Promise<void> {
|
|||||||
const user = ctx.get('user') as User | undefined;
|
const user = ctx.get('user') as User | undefined;
|
||||||
if (accountPolicyContactHasCapability(user?.email, 'captcha_exempt')) return;
|
if (accountPolicyContactHasCapability(user?.email, 'captcha_exempt')) return;
|
||||||
if (userHasCaptchaExemptFlag(user)) return;
|
if (userHasCaptchaExemptFlag(user)) return;
|
||||||
if (await requestContactHasCaptchaExemption(ctx.req.raw)) return;
|
|
||||||
if (await requestUserHasCaptchaExemptFlag(ctx)) return;
|
if (await requestUserHasCaptchaExemptFlag(ctx)) return;
|
||||||
const token = ctx.req.header('x-captcha-token');
|
const token = ctx.req.header(Headers.X_CAPTCHA_TOKEN);
|
||||||
if (!token) {
|
if (!token) {
|
||||||
throw new CaptchaRequiredError();
|
throw new CaptchaRequiredError();
|
||||||
}
|
}
|
||||||
const provider = resolveCaptchaProvider(captchaConfig, ctx.req.header('x-captcha-type'));
|
const provider = resolveCaptchaProvider(captchaConfig, ctx.req.header(Headers.X_CAPTCHA_TYPE));
|
||||||
const isValid = await provider.verify({
|
const isValid = await provider.verify({
|
||||||
token,
|
token,
|
||||||
remoteIp:
|
remoteIp:
|
||||||
@@ -75,17 +75,6 @@ export async function verifyCaptchaToken(ctx: Context<HonoEnv>): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function requestContactHasCaptchaExemption(request: Request): Promise<boolean> {
|
|
||||||
try {
|
|
||||||
const body = (await request.clone().json()) as unknown;
|
|
||||||
if (!body || typeof body !== 'object' || Array.isArray(body)) return false;
|
|
||||||
const email = (body as Record<string, unknown>).email;
|
|
||||||
return typeof email === 'string' && accountPolicyContactHasCapability(email, 'captcha_exempt');
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function userHasCaptchaExemptFlag(user: User | null | undefined): boolean {
|
function userHasCaptchaExemptFlag(user: User | null | undefined): boolean {
|
||||||
return user != null && (user.flags & UserFlags.APP_STORE_REVIEWER) !== 0n;
|
return user != null && (user.flags & UserFlags.APP_STORE_REVIEWER) !== 0n;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user