A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(app): read status incidents only from Instatus pages (#3701)
Hampusf538b67f7020
diff --git a/fluxer_admin/src/templates/pages/instance_branding.rs b/fluxer_admin/src/templates/pages/instance_branding.rsindex 6fad1da4b..f42aef615 100644--- a/fluxer_admin/src/templates/pages/instance_branding.rs+++ b/fluxer_admin/src/templates/pages/instance_branding.rs@@ -145,19 +145,24 @@ pub(super) fn branding_section("Links to these domains open without the external link warning for everyone on this instance. Put one domain on each line, up to 50. Start a line with *. to also cover its subdomains, as in *.example.com. Your instance's own addresses are always trusted."}}- div class="grid grid-cols-1 gap-4 border-t border-neutral-200 pt-6 sm:grid-cols-2" {- (text_input(- "app_status_page_url",- "Status page URL",- app_public.branding.status_page_url.as_deref().unwrap_or(""),- "https://fluxerstatus.com",- ))- (text_input(- "app_status_page_incident_history_url",- "Status page history URL",- app_public.branding.status_page_incident_history_url.as_deref().unwrap_or(""),- "https://fluxerstatus.com/history",- ))+ div class="flex flex-col gap-2 border-t border-neutral-200 pt-6" {+ div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {+ (text_input(+ "app_status_page_url",+ "Status page URL",+ app_public.branding.status_page_url.as_deref().unwrap_or(""),+ "https://fluxerstatus.com",+ ))+ (text_input(+ "app_status_page_incident_history_url",+ "Status page history URL",+ app_public.branding.status_page_incident_history_url.as_deref().unwrap_or(""),+ "https://fluxerstatus.com/history",+ ))+ }+ p class="text-xs leading-5 text-neutral-500" {+ "The web app links to the status page when loading takes a long time. Fluxer checks whether it is an Instatus page. If it is, the web app also reads its current incidents and maintenance automatically. Pages from other providers are only linked."+ }}div class="space-y-2" {(Checkbox {diff --git a/fluxer_api/src/api/instance/InstanceConfigRepository.ts b/fluxer_api/src/api/instance/InstanceConfigRepository.tsindex d38b5ab07..9e93ab1c1 100644--- a/fluxer_api/src/api/instance/InstanceConfigRepository.ts+++ b/fluxer_api/src/api/instance/InstanceConfigRepository.ts@@ -219,11 +219,14 @@ export interface InstanceRegistrationConfig extends InstanceRegistration {allowed_email_domains: Array<string>;}-interface InstanceAppPublicConfig extends Omit<InstanceAppPublic, 'setup'> {+type InstanceBrandingConfig = Omit<InstanceBranding, 'status_page_instatus'>;++interface InstanceAppPublicConfig extends Omit<InstanceAppPublic, 'setup' | 'branding'> {+ branding: InstanceBrandingConfig;setup: Pick<InstanceSetup, 'configured'>;}-type InstanceBrandingPatch = Partial<Omit<InstanceBranding, 'premium_product_name'>> & {+type InstanceBrandingPatch = Partial<Omit<InstanceBrandingConfig, 'premium_product_name'>> & {premium_product_name?: string | null;};@@ -943,6 +946,7 @@ function parseStoredCollection<T>(schema: z.ZodType<T>, raw: string | null, sectconst StoredInstanceAppPublicSchema = InstanceAppPublicSchema.extend({branding: InstanceAppPublicSchema.shape.branding+ .omit({status_page_instatus: true}).extend({premium_product_name: z.string().max(40).nullable()}).partial().optional(),diff --git a/fluxer_api/src/api/instance/InstanceController.ts b/fluxer_api/src/api/instance/InstanceController.tsindex c9277cf34..f1e6a669d 100644--- a/fluxer_api/src/api/instance/InstanceController.ts+++ b/fluxer_api/src/api/instance/InstanceController.ts@@ -11,6 +11,7 @@ import {import {customBadgeImageUrl} from '@app/api/instance/InstanceAssetReferences';import type {CustomBadgeDefinition} from '@app/api/instance/InstanceConfigRepository';import {assertSetupToken} from '@app/api/instance/SetupToken';+import {getStatusPageDetector} from '@app/api/instance/StatusPageDetector';import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';import {RateLimitConfigs} from '@app/api/RateLimitConfig';@@ -199,6 +200,7 @@ export function InstanceController(app: Hono<HonoEnv>) {instanceConfigRepository.getActiveInstanceNotice(),instanceConfigRepository.getCustomBadges(),]);+ const statusPageInstatus = await getStatusPageDetector().isInstatus(appPublicConfig.branding.status_page_url);const lockReason =Config.instance.selfHosted && !appPublicConfig.setup.configured? await instanceConfigRepository.getAccountIdentityLockReason()@@ -216,6 +218,7 @@ export function InstanceController(app: Hono<HonoEnv>) {gifService,{...appPublicConfig,+ branding: {...appPublicConfig.branding, status_page_instatus: statusPageInstatus},setup: {...appPublicConfig.setup,admin_url: Config.endpoints.admin || null,diff --git a/fluxer_api/src/api/instance/StatusPageDetector.ts b/fluxer_api/src/api/instance/StatusPageDetector.tsnew file mode 100644index 000000000..8d23182ae--- /dev/null+++ b/fluxer_api/src/api/instance/StatusPageDetector.ts@@ -0,0 +1,170 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {Config} from '@app/api/Config';+import {Logger} from '@app/api/Logger';+import {EXTERNAL_RESPONSE_LIMITS} from '@app/api/utils/ExternalResponseLimits';+import * as FetchUtils from '@app/api/utils/FetchUtils';+import {isJsonRecord, parseJsonOrNull} from '@app/api/utils/JsonBoundaryUtils';+import type {RequestUrlPolicy} from '@pkgs/http_client/src/HttpClientTypes';+import {ms} from 'itty-time';++const PROBE_TIMEOUT_MS = ms('5 seconds');+const FIRST_PROBE_WAIT_MS = ms('2 seconds');+const INSTATUS_RECHECK_MS = ms('6 hours');+const NOT_INSTATUS_RECHECK_MS = ms('24 hours');+const RETRY_DELAYS_MS = [ms('1 minute'), ms('5 minutes'), ms('15 minutes'), ms('30 minutes')];++type ProbeResult = 'instatus' | 'not_instatus' | 'transient';++interface DetectorEntry {+ readonly url: string;+ verdict: boolean | null;+ failures: number;+ nextProbeAt: number;+ probe: Promise<void> | null;+}++interface StatusPageDetectorOptions {+ requestUrlPolicy?: RequestUrlPolicy;+ now?: () => number;+}++function isInstatusSummary(value: unknown): boolean {+ return (+ isJsonRecord(value) &&+ (isJsonRecord(value['page']) ||+ Array.isArray(value['activeIncidents']) ||+ Array.isArray(value['activeMaintenances']))+ );+}++function isTransientStatus(status: number): boolean {+ return status === 408 || status === 429 || status >= 500;+}++function allowsOrigin(headers: Headers, origin: string): boolean {+ const allowed = headers.get('access-control-allow-origin')?.trim();+ return allowed === '*' || allowed === origin;+}++function webAppOrigin(): string | null {+ try {+ return new URL(Config.endpoints.webApp).origin;+ } catch {+ return null;+ }+}++async function waitAtMost(promise: Promise<void>, timeoutMs: number): Promise<void> {+ let timer: ReturnType<typeof setTimeout> | undefined;+ try {+ await Promise.race([+ promise,+ new Promise<void>((resolve) => {+ timer = setTimeout(resolve, timeoutMs);+ }),+ ]);+ } finally {+ clearTimeout(timer);+ }+}++export class StatusPageDetector {+ private entry: DetectorEntry | null = null;+ private readonly requestUrlPolicy: RequestUrlPolicy | undefined;+ private readonly now: () => number;++ constructor(options: StatusPageDetectorOptions = {}) {+ this.requestUrlPolicy = options.requestUrlPolicy;+ this.now = options.now ?? Date.now;+ }++ async isInstatus(statusPageUrl: string | null): Promise<boolean> {+ if (!statusPageUrl) {+ this.entry = null;+ return false;+ }+ if (this.entry?.url !== statusPageUrl) {+ this.entry = {url: statusPageUrl, verdict: null, failures: 0, nextProbeAt: 0, probe: null};+ }+ const entry = this.entry;+ if (entry.probe === null && this.now() >= entry.nextProbeAt) {+ entry.probe = this.runProbe(entry);+ }+ if (entry.verdict === null && entry.probe !== null) {+ await waitAtMost(entry.probe, FIRST_PROBE_WAIT_MS);+ }+ return entry.verdict ?? false;+ }++ private async runProbe(entry: DetectorEntry): Promise<void> {+ const result = await this.probe(entry.url);+ entry.probe = null;+ const now = this.now();+ if (result === 'transient') {+ entry.failures += 1;+ entry.nextProbeAt = now + RETRY_DELAYS_MS[Math.min(entry.failures, RETRY_DELAYS_MS.length) - 1]!;+ return;+ }+ const verdict = result === 'instatus';+ if (entry.verdict !== verdict) {+ Logger.info(+ {statusPageUrl: entry.url, instatus: verdict},+ verdict+ ? 'Status page is an Instatus page, the apps will show its incidents'+ : 'Status page is not an Instatus page the apps can read, they will only link to it',+ );+ }+ entry.verdict = verdict;+ entry.failures = 0;+ entry.nextProbeAt = now + (verdict ? INSTATUS_RECHECK_MS : NOT_INSTATUS_RECHECK_MS);+ }++ private async probe(statusPageUrl: string): Promise<ProbeResult> {+ const origin = webAppOrigin();+ if (origin === null) {+ return 'not_instatus';+ }+ const summaryUrl = `${statusPageUrl}/summary.json`;+ try {+ const response = await FetchUtils.sendRequest(+ {+ url: summaryUrl,+ method: 'GET',+ headers: {Accept: 'application/json', Origin: origin},+ timeout: PROBE_TIMEOUT_MS,+ serviceName: 'status_page_probe',+ },+ {requestUrlPolicy: this.requestUrlPolicy},+ );+ if (response.status < 200 || response.status >= 300) {+ FetchUtils.discardResponseBody(response.stream, response.status);+ return isTransientStatus(response.status) ? 'transient' : 'not_instatus';+ }+ if (!allowsOrigin(response.headers, origin)) {+ FetchUtils.discardResponseBody(response.stream, response.status);+ return 'not_instatus';+ }+ const body = await FetchUtils.streamToStringWithLimit(response.stream, {+ maxBytes: EXTERNAL_RESPONSE_LIMITS.statusPageSummaryBytes,+ headers: response.headers,+ url: summaryUrl,+ description: 'Status page summary',+ signal: AbortSignal.timeout(PROBE_TIMEOUT_MS),+ });+ return isInstatusSummary(parseJsonOrNull(body)) ? 'instatus' : 'not_instatus';+ } catch (error) {+ if (error instanceof FetchUtils.ResponseBodyTooLargeError) {+ return 'not_instatus';+ }+ Logger.warn({error, statusPageUrl}, 'Status page check failed, it will be retried later');+ return 'transient';+ }+ }+}++const detector = new StatusPageDetector();++export function getStatusPageDetector(): StatusPageDetector {+ return detector;+}diff --git a/fluxer_api/src/api/instance/tests/DiscoverySelfHostFields.test.ts b/fluxer_api/src/api/instance/tests/DiscoverySelfHostFields.test.tsindex fc72da02f..166038163 100644--- a/fluxer_api/src/api/instance/tests/DiscoverySelfHostFields.test.ts+++ b/fluxer_api/src/api/instance/tests/DiscoverySelfHostFields.test.ts@@ -1,16 +1,33 @@// SPDX-License-Identifier: AGPL-3.0-or-laterimport {createAuthHarness} from '@app/api/auth/tests/AuthTestUtils';+import {getConfig} from '@app/api/Config';import {getInstanceConfigRepository} from '@app/api/middleware/ServiceSingletons';import type {ApiTestHarness} from '@app/api/test/ApiTestHarness';+import {server} from '@app/api/test/msw/server';import {createBuilderWithoutAuth} from '@app/api/test/TestRequestBuilder';import {parseInstanceDiscoveryDocument} from '@fluxer/instance_bootstrap/src/Discovery';import type {WellKnownFluxerResponse} from '@fluxer/schema/src/domains/instance/InstanceSchemas';+import {HttpResponse, http} from 'msw';import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from 'vitest';+const INSTATUS_SUMMARY = {page: {name: 'Status', status: 'UP'}, activeIncidents: [], activeMaintenances: []};+describe('discovery fields for self-hosted clients', () => {let harness: ApiTestHarness;+ async function withSelfHostedStatusPage(statusPageUrl: string): Promise<WellKnownFluxerResponse> {+ const config = getConfig().instance;+ const originalSelfHosted = config.selfHosted;+ config.selfHosted = true;+ try {+ await getInstanceConfigRepository().setAppPublicConfig({branding: {status_page_url: statusPageUrl}});+ return await createBuilderWithoutAuth<WellKnownFluxerResponse>(harness).get('/.well-known/fluxer').execute();+ } finally {+ config.selfHosted = originalSelfHosted;+ }+ }+beforeAll(async () => {harness = await createAuthHarness();});@@ -35,6 +52,33 @@ describe('discovery fields for self-hosted clients', () => {expect(discovery.community).toMatchObject({direct_messages_disabled: true, friends_disabled: true});});+ it('detects an existing Instatus status page on a self-hosted instance with no extra setting', async () => {+ const statusPageUrl = 'https://93.184.215.14';+ server.use(+ http.get(`${statusPageUrl}/summary.json`, () =>+ HttpResponse.json(INSTATUS_SUMMARY, {headers: {'access-control-allow-origin': '*'}}),+ ),+ );+ const discovery = await withSelfHostedStatusPage(statusPageUrl);+ expect(discovery.app_public.branding).toMatchObject({+ status_page_url: statusPageUrl,+ status_page_instatus: true,+ });+ expect(parseInstanceDiscoveryDocument(discovery).appPublic?.branding.status_page_instatus).toBe(true);+ });++ it('tells clients not to read incidents from a status page that is not Instatus', async () => {+ const statusPageUrl = 'https://93.184.215.15';+ server.use(+ http.get(`${statusPageUrl}/summary.json`, () => new HttpResponse('<!doctype html><html></html>', {status: 404})),+ );+ const discovery = await withSelfHostedStatusPage(statusPageUrl);+ expect(discovery.app_public.branding).toMatchObject({+ status_page_url: statusPageUrl,+ status_page_instatus: false,+ });+ });+it('fills friends_disabled from the direct message flag for an older server', () => {const document = parseInstanceDiscoveryDocument({api_code_version: 1,diff --git a/fluxer_api/src/api/instance/tests/StatusPageDetector.test.ts b/fluxer_api/src/api/instance/tests/StatusPageDetector.test.tsnew file mode 100644index 000000000..a2fa18a3b--- /dev/null+++ b/fluxer_api/src/api/instance/tests/StatusPageDetector.test.ts@@ -0,0 +1,147 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {Config} from '@app/api/Config';+import {StatusPageDetector} from '@app/api/instance/StatusPageDetector';+import {server} from '@app/api/test/msw/server';+import {createPublicInternetRequestUrlPolicy} from '@pkgs/http_client/src/PublicInternetRequestUrlPolicy';+import {HttpResponse, http} from 'msw';+import {beforeEach, describe, expect, it} from 'vitest';++const URL_A = 'https://status.example.com';+const URL_B = 'https://status.example.org';+const SUMMARY = {page: {name: 'Status', status: 'UP'}, activeIncidents: [], activeMaintenances: []};+const ALLOW_ANY_ORIGIN = {'access-control-allow-origin': '*'};+const MINUTE = 60 * 1000;+const HOUR = 60 * MINUTE;++type Answer = () => Response;++const instatus: Answer = () => HttpResponse.json(SUMMARY, {headers: ALLOW_ANY_ORIGIN});+const unavailable: Answer = () => new HttpResponse('busy', {status: 503});+const notFound: Answer = () => new HttpResponse('not found', {status: 404});++describe('StatusPageDetector', () => {+ let now = 0;+ let detector: StatusPageDetector;+ let requests: Array<{url: string; origin: string | null}>;++ function answer(url: string, answers: Array<Answer>): void {+ server.use(+ http.get(`${url}/summary.json`, ({request}) => {+ requests.push({url, origin: request.headers.get('origin')});+ const next = answers.length > 1 ? answers.shift()! : answers[0]!;+ return next();+ }),+ );+ }++ function requestsTo(url: string): number {+ return requests.filter((request) => request.url === url).length;+ }++ beforeEach(() => {+ now = 1_000_000;+ requests = [];+ detector = new StatusPageDetector({+ now: () => now,+ requestUrlPolicy: createPublicInternetRequestUrlPolicy({lookupHost: async () => ['93.184.215.14']}),+ });+ });++ it('detects an Instatus page that allows the web app origin', async () => {+ answer(URL_A, [instatus]);+ await expect(detector.isInstatus(URL_A)).resolves.toBe(true);+ expect(requests).toEqual([{url: URL_A, origin: new URL(Config.endpoints.webApp).origin}]);+ });++ it('publishes false for a page that is not Instatus and waits a day before checking it again', async () => {+ answer(URL_A, [notFound]);+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ now += 23 * HOUR;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ expect(requestsTo(URL_A)).toBe(1);+ now += HOUR;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ expect(requestsTo(URL_A)).toBe(2);+ });++ it('publishes false for HTML and for JSON from another provider', async () => {+ answer(URL_A, [() => new HttpResponse('<!doctype html><html></html>', {status: 200, headers: ALLOW_ANY_ORIGIN})]);+ answer(URL_B, [() => HttpResponse.json({monitors: [], heartbeatList: {}}, {headers: ALLOW_ANY_ORIGIN})]);+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ await expect(detector.isInstatus(URL_B)).resolves.toBe(false);+ });++ it('publishes false for an Instatus summary the browser may not read across origins', async () => {+ answer(URL_A, [() => HttpResponse.json(SUMMARY)]);+ answer(URL_B, [+ () => HttpResponse.json(SUMMARY, {headers: {'access-control-allow-origin': 'https://other.example'}}),+ ]);+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ await expect(detector.isInstatus(URL_B)).resolves.toBe(false);+ });++ it('retries a transient failure after 1 and then 5 minutes and recovers', async () => {+ answer(URL_A, [unavailable, unavailable, instatus]);+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ now += MINUTE - 1;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ expect(requestsTo(URL_A)).toBe(1);+ now += 1;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ expect(requestsTo(URL_A)).toBe(2);+ now += 5 * MINUTE - 1;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ expect(requestsTo(URL_A)).toBe(2);+ now += 1;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(true);+ expect(requestsTo(URL_A)).toBe(3);+ });++ it('treats a timeout status, a rate limit and a network error as transient', async () => {+ answer(URL_A, [+ () => new HttpResponse(null, {status: 408}),+ () => new HttpResponse(null, {status: 429}),+ () => HttpResponse.error(),+ instatus,+ ]);+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ now += MINUTE;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ now += 5 * MINUTE;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ now += 15 * MINUTE;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(true);+ expect(requestsTo(URL_A)).toBe(4);+ });++ it('keeps a known Instatus page while a later recheck fails', async () => {+ answer(URL_A, [instatus, unavailable]);+ await expect(detector.isInstatus(URL_A)).resolves.toBe(true);+ now += 6 * HOUR;+ await expect(detector.isInstatus(URL_A)).resolves.toBe(true);+ expect(requestsTo(URL_A)).toBe(2);+ });++ it('checks a new status page URL straight away and forgets the old verdict', async () => {+ answer(URL_A, [notFound]);+ answer(URL_B, [instatus]);+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ await expect(detector.isInstatus(URL_B)).resolves.toBe(true);+ await expect(detector.isInstatus(URL_A)).resolves.toBe(false);+ expect(requestsTo(URL_A)).toBe(2);+ expect(requestsTo(URL_B)).toBe(1);+ });++ it('sends nothing when no status page is set', async () => {+ await expect(detector.isInstatus(null)).resolves.toBe(false);+ expect(requests).toEqual([]);+ });++ it('sends nothing to a status page on a private address', async () => {+ const privateDetector = new StatusPageDetector({now: () => now});+ answer('http://10.0.0.5', [instatus]);+ await expect(privateDetector.isInstatus('http://10.0.0.5')).resolves.toBe(false);+ expect(requests).toEqual([]);+ });+});diff --git a/fluxer_api/src/api/openapi/openapi.json b/fluxer_api/src/api/openapi/openapi.jsonindex 1e27d7915..3eabf283f 100644--- a/fluxer_api/src/api/openapi/openapi.json+++ b/fluxer_api/src/api/openapi/openapi.json@@ -37628,6 +37628,10 @@},"theme_color": {"description": "Optional browser theme color", "type": ["string", "null"]},"status_page_url": {"description": "Optional public status page URL", "type": ["string", "null"]},+ "status_page_instatus": {+ "type": "boolean",+ "description": "Whether the server detected that the status page is an Instatus page that clients can read current incidents from"+ },"status_page_incident_history_url": {"description": "Optional public status page incident history URL","type": ["string", "null"]@@ -37668,6 +37672,7 @@"favicon_dark_url","theme_color","status_page_url",+ "status_page_instatus","status_page_incident_history_url","premium_product_name","premium_info_url",diff --git a/fluxer_api/src/api/utils/ExternalResponseLimits.ts b/fluxer_api/src/api/utils/ExternalResponseLimits.tsindex 14ebdc29b..54749a1e2 100644--- a/fluxer_api/src/api/utils/ExternalResponseLimits.ts+++ b/fluxer_api/src/api/utils/ExternalResponseLimits.ts@@ -6,6 +6,7 @@ export const EXTERNAL_RESPONSE_LIMITS = {ssoDiscoveryBytes: 256 * 1024,ssoJwksBytes: 256 * 1024,pwnedPasswordsBytes: 1024 * 1024,+ statusPageSummaryBytes: 1024 * 1024,fileBlocklistBytes: 25 * 1024 * 1024,urlBlocklistBytes: 25 * 1024 * 1024,} as const;diff --git a/fluxer_app/src/features/app/state/RuntimeConfig.ts b/fluxer_app/src/features/app/state/RuntimeConfig.tsindex 39e42b76d..0f86b245e 100644--- a/fluxer_app/src/features/app/state/RuntimeConfig.ts+++ b/fluxer_app/src/features/app/state/RuntimeConfig.ts@@ -709,7 +709,12 @@ class RuntimeConfig {applyAdminInstanceConfig(config: InstanceConfigResponse): void {const current = this.requireActiveSnapshot();const appPublic: InstanceAppPublic = {- branding: config.app_public.branding,+ branding: {+ ...config.app_public.branding,+ status_page_instatus:+ current.appPublic.branding.status_page_instatus &&+ current.appPublic.branding.status_page_url === config.app_public.branding.status_page_url,+ },setup: {configured: config.app_public.setup.configured,admin_url: current.appPublic.setup.admin_url,@@ -776,6 +781,10 @@ class RuntimeConfig {return this.activeRuntime?.snapshot.appPublic.branding.status_page_url ?? '';}+ get statusPageInstatus(): boolean {+ return this.activeRuntime?.snapshot.appPublic.branding.status_page_instatus ?? false;+ }+isSelfHosted(): boolean {return DeveloperOptions.selfHostedModeOverride || this.features.self_hosted;}diff --git a/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts b/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.tsindex b2558c1d7..40ce32a2a 100644--- a/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts+++ b/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts@@ -480,6 +480,8 @@ function readAppPublic(value: unknown): InstanceAppPublic {: null,theme_color: normalizeThemeColor(branding.theme_color),status_page_url: readOptionalText(branding, 'status_page_url'),+ status_page_instatus:+ readOptionalBoolean(branding, 'status_page_instatus', 'appPublic.branding.status_page_instatus') ?? false,status_page_incident_history_url: readOptionalText(branding, 'status_page_incident_history_url'),premium_product_name: readOptionalText(branding, 'premium_product_name') ?? DEFAULT_PREMIUM_PRODUCT_NAME,premium_info_url: Object.hasOwn(branding, 'premium_info_url')diff --git a/fluxer_app/src/features/user/state/StatusPage.ts b/fluxer_app/src/features/user/state/StatusPage.tsindex 1c32f33a9..89969b9a4 100644--- a/fluxer_app/src/features/user/state/StatusPage.ts+++ b/fluxer_app/src/features/user/state/StatusPage.ts@@ -90,11 +90,36 @@ const POLL_AFTER_MAINTENANCE_START_MS = 5 * 1000;const POLL_MIN_DELAY_MS = 10 * 1000;const POLL_RESUME_STALE_MS = 30 * 1000;const STATUS_PAGE_FETCH_TIMEOUT_MS = 10 * 1000;+const STATUS_PAGE_RETRY_DELAYS_MS = [60 * 1000, 5 * 60 * 1000, 15 * 60 * 1000, 30 * 60 * 1000];function statusPageFetchOptions(): RequestInit {return {cache: 'no-store', signal: AbortSignal.timeout(STATUS_PAGE_FETCH_TIMEOUT_MS)};}+function isRecord(value: unknown): value is Record<string, unknown> {+ return typeof value === 'object' && value !== null && !Array.isArray(value);+}++function isInstatusSummary(data: unknown): data is InstatusSummary {+ return (+ isRecord(data) &&+ (isRecord(data.page) || Array.isArray(data.activeIncidents) || Array.isArray(data.activeMaintenances))+ );+}++function isUnsupportedStatusPageResponse(response: Response): boolean {+ return response.status >= 400 && response.status < 500 && response.status !== 408 && response.status !== 429;+}++function computeRetryDelay(consecutiveFailures: number): number {+ const index = Math.min(consecutiveFailures, STATUS_PAGE_RETRY_DELAYS_MS.length) - 1;+ return STATUS_PAGE_RETRY_DELAYS_MS[index];+}++function getIncidentStatusPageUrl(): string {+ return RuntimeConfig.statusPageInstatus ? RuntimeConfig.statusPageUrl : '';+}+function computePollDelay(scheduledMaintenance: StatusPageMaintenance | null): number {if (scheduledMaintenance?.status === 'in_progress') {return POLL_ACTIVE_MAINTENANCE_INTERVAL_MS + Math.random() * POLL_ACTIVE_MAINTENANCE_JITTER_MS;@@ -197,11 +222,20 @@ class StatusPage {private lastCheckedAt = 0;private pollingRequested = false;private pollingStarted = false;+ private unsupportedStatusPageUrl: string | null = null;+ private consecutiveFailures = 0;constructor() {makeAutoObservable<StatusPage,- 'checkInFlight' | 'checkInFlightUrl' | 'lastCheckedAt' | 'pollingRequested' | 'pollingStarted' | 'pollTimerId'+ | 'checkInFlight'+ | 'checkInFlightUrl'+ | 'lastCheckedAt'+ | 'pollingRequested'+ | 'pollingStarted'+ | 'pollTimerId'+ | 'unsupportedStatusPageUrl'+ | 'consecutiveFailures'>(this,{@@ -211,11 +245,13 @@ class StatusPage {pollingRequested: false,pollingStarted: false,pollTimerId: false,+ unsupportedStatusPageUrl: false,+ consecutiveFailures: false,},{autoBind: true},);reaction(- () => RuntimeConfig.statusPageUrl,+ () => getIncidentStatusPageUrl(),() => this.handleStatusPageUrlChange(),);}@@ -226,6 +262,8 @@ class StatusPage {this.checkInFlight = null;this.checkInFlightUrl = null;this.lastCheckedAt = 0;+ this.unsupportedStatusPageUrl = null;+ this.consecutiveFailures = 0;this.stopActivePolling();this.reconcilePolling();}@@ -241,7 +279,8 @@ class StatusPage {}private reconcilePolling(): void {- if (!this.pollingRequested || !RuntimeConfig.statusPageUrl) {+ const statusPageUrl = getIncidentStatusPageUrl();+ if (!this.pollingRequested || !statusPageUrl || statusPageUrl === this.unsupportedStatusPageUrl) {this.stopActivePolling();return;}@@ -275,12 +314,19 @@ class StatusPage {} else {this.schedulePoll();}- }, computePollDelay(this.scheduledMaintenance));+ }, this.computeNextDelay());+ }++ private computeNextDelay(): number {+ if (this.consecutiveFailures > 0) {+ return computeRetryDelay(this.consecutiveFailures);+ }+ return computePollDelay(this.scheduledMaintenance);}async checkIncidents(): Promise<void> {- const statusPageUrl = RuntimeConfig.statusPageUrl;- if (!statusPageUrl) {+ const statusPageUrl = getIncidentStatusPageUrl();+ if (!statusPageUrl || statusPageUrl === this.unsupportedStatusPageUrl) {return;}if (this.checkInFlight !== null && this.checkInFlightUrl === statusPageUrl) {@@ -304,18 +350,37 @@ class StatusPage {try {const response = await fetch(`${statusPageUrl}/summary.json`, statusPageFetchOptions());if (!response.ok) {+ if (isUnsupportedStatusPageResponse(response)) {+ this.markStatusPageUnsupported(statusPageUrl);+ } else {+ this.recordFailure(statusPageUrl);+ }+ return;+ }+ let data: unknown;+ try {+ data = await response.json();+ } catch (error) {+ if (!(error instanceof SyntaxError)) {+ throw error;+ }+ this.markStatusPageUnsupported(statusPageUrl);+ return;+ }+ if (!isInstatusSummary(data)) {+ this.markStatusPageUnsupported(statusPageUrl);return;}- const data: InstatusSummary = await response.json();const activeIncident = data.activeIncidents?.find((inc) => inc.status !== 'RESOLVED' && inc.resolved == null);let activeMaintenance = selectActiveStatusPageMaintenance(data.activeMaintenances);if (shouldFetchComponentMaintenances(data, activeMaintenance)) {activeMaintenance = selectActiveStatusPageMaintenance(await this.fetchComponentMaintenances(statusPageUrl));}runInAction(() => {- if (statusPageUrl !== RuntimeConfig.statusPageUrl) {+ if (statusPageUrl !== getIncidentStatusPageUrl()) {return;}+ this.consecutiveFailures = 0;if (activeIncident) {this.incident = {id: activeIncident.id,@@ -340,10 +405,33 @@ class StatusPage {this.scheduledMaintenance = activeMaintenance;});} catch {- logger.warn('Failed to fetch status page');+ this.recordFailure(statusPageUrl);}}+ private recordFailure(statusPageUrl: string): void {+ runInAction(() => {+ if (statusPageUrl !== getIncidentStatusPageUrl()) {+ return;+ }+ this.consecutiveFailures += 1;+ logger.warn('Failed to fetch status page');+ });+ }++ private markStatusPageUnsupported(statusPageUrl: string): void {+ runInAction(() => {+ if (statusPageUrl !== getIncidentStatusPageUrl()) {+ return;+ }+ logger.warn('Stopped polling the status page because it is not an Instatus page');+ this.unsupportedStatusPageUrl = statusPageUrl;+ this.incident = null;+ this.scheduledMaintenance = null;+ this.stopActivePolling();+ });+ }+private async fetchComponentMaintenances(statusPageUrl: string): Promise<Array<InstatusMaintenance>> {try {const response = await fetch(`${statusPageUrl}/components.json`, statusPageFetchOptions());@@ -379,7 +467,9 @@ class StatusPage {if (document.visibilityState !== 'visible') {return;}- if (Date.now() - this.lastCheckedAt < POLL_RESUME_STALE_MS) {+ const staleAfter =+ this.consecutiveFailures > 0 ? computeRetryDelay(this.consecutiveFailures) : POLL_RESUME_STALE_MS;+ if (Date.now() - this.lastCheckedAt < staleAfter) {return;}this.refreshNow();diff --git a/fluxer_docs/src/content/docs/http-api/instance.mdx b/fluxer_docs/src/content/docs/http-api/instance.mdxindex fbeefec07..6d7d66536 100644--- a/fluxer_docs/src/content/docs/http-api/instance.mdx+++ b/fluxer_docs/src/content/docs/http-api/instance.mdx@@ -381,6 +381,7 @@ What a client needs before anyone signs in.| favicon_dark_url | ?string | Favicon URL for a dark color scheme, or null to use `favicon_url` || theme_color | ?string | Brand color as lowercase `#rrggbb`, or null || status_page_url | ?string | Status page URL, or null |+| status_page_instatus | boolean | Whether the status page is an Instatus page browsers can read. Clients show its incidents only when this is true || status_page_incident_history_url | ?string | Status page incident history URL, or null || premium_product_name | string | The name of the premium tier, `Premium` unless an admin sets one || premium_info_url | ?string | URL of a page about the premium tier, or null |diff --git a/fluxer_docs/src/content/docs/operator/environment.mdx b/fluxer_docs/src/content/docs/operator/environment.mdxindex 236310227..2d0631e2d 100644--- a/fluxer_docs/src/content/docs/operator/environment.mdx+++ b/fluxer_docs/src/content/docs/operator/environment.mdx@@ -1121,7 +1121,7 @@ The brand colour of the web app and the browser theme colour, as a hex value suc### `FLUXER_APP_STATUS_PAGE_URL`-The URL of your public status page. The web app links to it when loading takes a long time. On an Instatus page, the web app also shows its current incidents and maintenance. With rexctl, use `rexctl config set app_public.branding.status_page_url`.+The URL of your public status page. The web app links to it when loading takes a long time. Fluxer checks whether it is an Instatus page. If it is, the web app also reads its current incidents and maintenance automatically. With rexctl, use `rexctl config set app_public.branding.status_page_url`.### `FLUXER_APP_STATUS_PAGE_INCIDENT_HISTORY_URL`diff --git a/fluxer_rexctl/internal/instance/envvars.go b/fluxer_rexctl/internal/instance/envvars.goindex 9ce0a1601..c571dcf01 100644--- a/fluxer_rexctl/internal/instance/envvars.go+++ b/fluxer_rexctl/internal/instance/envvars.go@@ -297,7 +297,7 @@ var envVars = []envVar{{"FLUXER_APP_FAVICON_DARK_URL", "instance", "The URL of the favicon for browsers in dark mode."},{"FLUXER_APP_SIGN_IN_BACKDROP_URL", "instance", "The URL of the image behind the sign-in screen."},{"FLUXER_APP_THEME_COLOR", "instance", "The brand colour of the web app and the browser theme colour, as a hex value such as `#4641d9`."},- {"FLUXER_APP_STATUS_PAGE_URL", "instance", "The URL of your public status page. The web app links to it when loading takes a long time. On an Instatus page, the web app also shows its current incidents and maintenance."},+ {"FLUXER_APP_STATUS_PAGE_URL", "instance", "The URL of your public status page. The web app links to it when loading takes a long time. Fluxer checks whether it is an Instatus page. If it is, the web app also reads its current incidents and maintenance automatically."},{"FLUXER_APP_STATUS_PAGE_INCIDENT_HISTORY_URL", "instance", "The URL of the incident history on your status page. The apps don't use it yet."},{"FLUXER_INSTANCE_SETUP_CONFIGURED", "instance", "Whether a new instance starts as already set up. Use `true` or `false`. With `true`, the setup wizard is skipped and registration opens without making the first account an admin. Once a setup state is saved, this has no effect. When it's empty, Fluxer uses `false`."},{"FLUXER_ACCOUNT_IDENTITY", "instance", "How people sign in on a new instance. Use `username` or `email`. Fluxer uses it only on the first start with no saved sign-in method. When it's empty, Fluxer uses `email` if email delivery is set up and `username` otherwise. When FLUXER_INSTANCE_SETUP_CONFIGURED is `true` or any account exists, Fluxer uses email sign-in with random tags and ignores this. Otherwise the setup wizard asks again, and its answer replaces this value."},diff --git a/fluxer_rexctl/internal/instance/shipped.json b/fluxer_rexctl/internal/instance/shipped.jsonindex b8ee32fff..30704ed34 100644--- a/fluxer_rexctl/internal/instance/shipped.json+++ b/fluxer_rexctl/internal/instance/shipped.json@@ -2,6 +2,7 @@".env.example": ["013e26017b51e7310d7e044090b50d0b4ae33cd1d91f0ac380a0a6783d9edab1","039e161673ae76f5b8cc5562a7e6acebc1a211ffaf65d488a993f16ca481fb94",+ "04a85d483aeaf1425fbd2134f6914ebac513646f160300e0c968ea7d6b0f33a4","0b718956b039a8d8402bd9c6102322fb273159f2834509fdf23a95459c7537b9","0e54ce3bfec7340d76214240c4bb9dc8dd9a33dc9ce57eff70d8d15f909cf7ab","1263f66b22074f380e55198a32d759ae5196bb9b44d8a62473c6f41dfb770905",diff --git a/fluxer_rexctl/internal/stack/files/.env.example b/fluxer_rexctl/internal/stack/files/.env.exampleindex 6109f9b66..bd2905ac4 100644--- a/fluxer_rexctl/internal/stack/files/.env.example+++ b/fluxer_rexctl/internal/stack/files/.env.example@@ -1696,8 +1696,8 @@ FLUXER_VAPID_PRIVATE_KEY=# FLUXER_APP_THEME_COLOR=# The URL of your public status page. The web app links to it when loading-# takes a long time. On an Instatus page, the web app also shows its current-# incidents and maintenance.+# takes a long time. Fluxer checks whether it is an Instatus page. If it is,+# the web app also reads its current incidents and maintenance automatically.# rexctl: rexctl config set app_public.branding.status_page_url# FLUXER_APP_STATUS_PAGE_URL=diff --git a/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts b/packages/instance_bootstrap/src/ClientRuntimeDiscovery.tsindex 931e493a6..42ebcbbc8 100644--- a/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts+++ b/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts@@ -135,6 +135,7 @@ function projectAppPublic(appPublic: InstanceDiscoveryDocument['appPublic']): Infavicon_dark_url: value.branding.favicon_dark_url ?? null,theme_color: requireDefined(value.branding.theme_color, 'app_public.branding.theme_color'),status_page_url: value.branding.status_page_url ?? null,+ status_page_instatus: value.branding.status_page_instatus ?? false,status_page_incident_history_url: value.branding.status_page_incident_history_url ?? null,premium_product_name: value.branding.premium_product_name ?? DEFAULT_PREMIUM_PRODUCT_NAME,premium_info_url: value.branding.premium_info_url ?? null,diff --git a/packages/instance_bootstrap/src/Discovery.ts b/packages/instance_bootstrap/src/Discovery.tsindex 0a8ee4dbd..4b0ea6e26 100644--- a/packages/instance_bootstrap/src/Discovery.ts+++ b/packages/instance_bootstrap/src/Discovery.ts@@ -884,6 +884,10 @@ function parseBranding(value: unknown): Readonly<Partial<InstanceBranding>> {branding[key] = readAbsoluteHTTPURL(source, key);}}+ const statusPageInstatus = readBoolean(source, 'status_page_instatus');+ if (statusPageInstatus != null) {+ branding.status_page_instatus = statusPageInstatus;+ }if (Object.hasOwn(source, 'theme_color')) {branding.theme_color = readNonEmptyString(source, 'theme_color');}diff --git a/packages/schema/src/domains/instance/InstanceSchemas.ts b/packages/schema/src/domains/instance/InstanceSchemas.tsindex 646591e57..18baa31c1 100644--- a/packages/schema/src/domains/instance/InstanceSchemas.ts+++ b/packages/schema/src/domains/instance/InstanceSchemas.ts@@ -58,6 +58,11 @@ export const InstanceBrandingSchema = z.describe('Optional favicon URL a self-hosted instance shows when the browser uses a dark color scheme'),theme_color: z.string().nullable().describe('Optional browser theme color'),status_page_url: z.string().nullable().describe('Optional public status page URL'),+ status_page_instatus: z+ .boolean()+ .describe(+ 'Whether the server detected that the status page is an Instatus page that clients can read current incidents from',+ ),status_page_incident_history_url: z.string().nullable()