Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): explain blocked captcha checks on plain HTTP instances

Hampus4ac3047e5840
diff --git a/fluxer_app/src/features/auth/altcha/AltchaSolver.ts b/fluxer_app/src/features/auth/altcha/AltchaSolver.ts
index 7032ee045..31e7080cd 100644
--- a/fluxer_app/src/features/auth/altcha/AltchaSolver.ts
+++ b/fluxer_app/src/features/auth/altcha/AltchaSolver.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {CaptchaProviders} from '@fluxer/constants/src/CaptchaConstants';
import {solveChallengeWorkers} from 'altcha-lib';
import type {Challenge} from 'altcha-lib/types';
@@ -20,7 +21,7 @@ function createSolverWorker(): Worker {
export function readAltchaChallenge(body: unknown): AltchaChallenge | null {
if (typeof body !== 'object' || body === null) return null;
const {captcha_provider: provider, altcha_challenge: challenge} = body as Record<string, unknown>;
- if (provider !== 'altcha' || typeof challenge !== 'object' || challenge === null) return null;
+ if (provider !== CaptchaProviders.ALTCHA || typeof challenge !== 'object' || challenge === null) return null;
const {parameters, signature} = challenge as Record<string, unknown>;
if (typeof parameters !== 'object' || parameters === null || typeof signature !== 'string') return null;
return challenge as AltchaChallenge;
diff --git a/fluxer_app/src/features/auth/altcha/CaptchaInterceptor.ts b/fluxer_app/src/features/auth/altcha/CaptchaInterceptor.ts
index c8aa90920..288117b29 100644
--- a/fluxer_app/src/features/auth/altcha/CaptchaInterceptor.ts
+++ b/fluxer_app/src/features/auth/altcha/CaptchaInterceptor.ts
@@ -17,6 +17,13 @@ const STILL_WORKING_DESCRIPTOR = msg({
'Small toast shown only when an automatic background check before sign-in, sign-up or a similar request takes more than a couple of seconds. No user action needed. Keep it short and calm.',
});
+const INSECURE_CONTEXT_DESCRIPTOR = msg({
+ message:
+ 'This check only runs when the app is opened over HTTPS or on localhost. Ask the instance owner to serve it over HTTPS, or open it from localhost.',
+ comment:
+ 'Error shown when signing in or signing up on a self-hosted instance opened over plain HTTP or a bare IP address, where the browser blocks the automatic background check. HTTPS and localhost are technical terms, keep them as is.',
+});
+
const logger = new Logger('CaptchaInterceptor');
const MAX_SOLVES = 2;
@@ -49,9 +56,18 @@ class CaptchaInterceptor {
): Promise<RestResponse | undefined> | undefined {
const challenge = readCaptchaChallenge(reply.status, reply.body);
if (!challenge) return undefined;
+ if (!window.isSecureContext) {
+ this.explainInsecureContext(reply);
+ return undefined;
+ }
return this.solveAndRetry(challenge, retry);
}
+ private explainInsecureContext(reply: RestResponse): void {
+ if (!this.i18n || typeof reply.body !== 'object' || reply.body === null) return;
+ (reply.body as Record<string, unknown>).message = this.i18n._(INSECURE_CONTEXT_DESCRIPTOR);
+ }
+
private async solveAndRetry(
initialChallenge: AltchaChallenge,
retry: (extraHeaders: Record<string, string>) => Promise<RestResponse>,