Skip to content

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

TypeScript fluxerfluxerapp

fix: load instance and fluxer.com fonts in the desktop app (#3868)

Hampusb102f68046ad
diff --git a/fluxer_admin/src/templates/pages/instance_branding.rs b/fluxer_admin/src/templates/pages/instance_branding.rs
index 127c70d7f..93f2dfc52 100644
--- a/fluxer_admin/src/templates/pages/instance_branding.rs
+++ b/fluxer_admin/src/templates/pages/instance_branding.rs
@@ -137,7 +137,7 @@ pub(super) fn branding_section(
div class="flex flex-col gap-2 border-t border-neutral-200 pt-6" {
(custom_css_field(app_public.branding.custom_css.as_deref().unwrap_or("")))
p class="text-xs leading-5 text-neutral-500" {
- "Applies to the web and desktop app for everyone on this instance, except on sign-in pages and in security dialogs. The desktop app loads images and fonts for it only from this instance, Google Fonts and coolLabs Fonts. Each person's own theme and custom CSS load after it and can override it. Use the color variables on :root where you can, because class names can change between releases."
+ "Applies to the web and desktop app for everyone on this instance, except on sign-in pages and in security dialogs. The desktop app loads images and fonts for it only from this instance, Google Fonts and coolLabs Fonts, so link files with full https:// addresses. Fonts on this instance also need an Access-Control-Allow-Origin header. Each person's own theme and custom CSS load after it and can override it. Use the color variables on :root where you can, because class names can change between releases."
}
}
div class="flex flex-col gap-2 border-t border-neutral-200 pt-6" {
diff --git a/fluxer_app_proxy/src/csp.rs b/fluxer_app_proxy/src/csp.rs
index 0a160d0ba..864266224 100644
--- a/fluxer_app_proxy/src/csp.rs
+++ b/fluxer_app_proxy/src/csp.rs
@@ -125,12 +125,16 @@ const SCRIPT_SOURCES: &[&str] = &["https://*.fluxer.app"];
const STYLE_SOURCES: &[&str] = &[
"https://*.fluxer.app",
+ "https://*.fluxer.com",
+ "https://fluxer.com",
"https://fonts.googleapis.com",
"https://api.fonts.coollabs.io",
];
const FONT_SOURCES: &[&str] = &[
"https://*.fluxer.app",
+ "https://*.fluxer.com",
+ "https://fluxer.com",
"https://fonts.gstatic.com",
"https://cdn.fonts.coollabs.io",
];
diff --git a/fluxer_desktop/src/main/DesktopOutboundHTTP.ts b/fluxer_desktop/src/main/DesktopOutboundHTTP.ts
index 7a4c0aba3..52db78953 100644
--- a/fluxer_desktop/src/main/DesktopOutboundHTTP.ts
+++ b/fluxer_desktop/src/main/DesktopOutboundHTTP.ts
@@ -699,10 +699,13 @@ export class DesktopOutboundHTTP {
return this.registeredRequirements.has(requireDesktopHTTPOrigin(origin));
}
- public registeredCleartextOrigins(): Array<string> {
+ public registeredInstanceOrigins(): Array<string> {
const origins: Array<string> = [];
for (const [origin, requirement] of this.registeredRequirements) {
- if (requirement === DesktopAddressRequirement.ANY && origin.startsWith('http://')) {
+ if (
+ origin.startsWith('https://') ||
+ (requirement === DesktopAddressRequirement.ANY && origin.startsWith('http://'))
+ ) {
origins.push(origin);
}
}
diff --git a/fluxer_desktop/src/main/LocalAppCSP.ts b/fluxer_desktop/src/main/LocalAppCSP.ts
index de241a783..03a716694 100644
--- a/fluxer_desktop/src/main/LocalAppCSP.ts
+++ b/fluxer_desktop/src/main/LocalAppCSP.ts
@@ -28,12 +28,16 @@ const SCRIPT_SOURCES: ReadonlyArray<string> = Object.freeze(['https://*.fluxer.a
const STYLE_SOURCES: ReadonlyArray<string> = Object.freeze([
'https://*.fluxer.app',
+ 'https://*.fluxer.com',
+ 'https://fluxer.com',
'https://fonts.googleapis.com',
'https://api.fonts.coollabs.io',
]);
const FONT_SOURCES: ReadonlyArray<string> = Object.freeze([
'https://*.fluxer.app',
+ 'https://*.fluxer.com',
+ 'https://fluxer.com',
'https://fonts.gstatic.com',
'https://cdn.fonts.coollabs.io',
]);
@@ -64,12 +68,15 @@ const DIRECTIVE_SEPARATOR = '; ';
interface LocalAppCSPRequest {
readonly nonce: string;
- readonly cleartextInstanceOrigins?: ReadonlyArray<string>;
+ readonly instanceOrigins?: ReadonlyArray<string>;
}
-export function buildLocalAppCSP({nonce, cleartextInstanceOrigins = []}: LocalAppCSPRequest): string {
+export function buildLocalAppCSP({nonce, instanceOrigins = []}: LocalAppCSPRequest): string {
const cleartextSources = [...LOOPBACK_HTTP_SOURCES];
- extendFrom(cleartextSources, cleartextInstanceOrigins.filter(isCleartextOriginSource));
+ extendFrom(cleartextSources, instanceOrigins.filter(isCleartextOriginSource));
+ const instanceSources = instanceOrigins.filter(
+ (origin) => isCleartextOriginSource(origin) || isSecureOriginSource(origin),
+ );
const directives: Array<string> = [];
@@ -81,6 +88,7 @@ export function buildLocalAppCSP({nonce, cleartextInstanceOrigins = []}: LocalAp
const style = [SELF_SOURCE, "'unsafe-inline'"];
extendFrom(style, STYLE_SOURCES);
+ extendFrom(style, instanceSources);
directives.push(`style-src ${style.join(' ')}`);
const image = [SELF_SOURCE, 'blob:', 'data:'];
@@ -97,6 +105,7 @@ export function buildLocalAppCSP({nonce, cleartextInstanceOrigins = []}: LocalAp
const font = [SELF_SOURCE, 'blob:', 'data:'];
extendFrom(font, FONT_SOURCES);
+ extendFrom(font, instanceSources);
directives.push(`font-src ${font.join(' ')}`);
const connect = [SELF_SOURCE, 'blob:', 'data:'];
@@ -138,6 +147,16 @@ function isCleartextOriginSource(origin: string): boolean {
return url.protocol === 'http:' && url.origin === origin && !url.hostname.startsWith('[');
}
+function isSecureOriginSource(origin: string): boolean {
+ let url: URL;
+ try {
+ url = new URL(origin);
+ } catch {
+ return false;
+ }
+ return url.protocol === 'https:' && url.origin === origin && !url.hostname.startsWith('[');
+}
+
function extendFrom(target: Array<string>, defaults: ReadonlyArray<string>): void {
for (const source of defaults) {
if (!target.includes(source)) {
diff --git a/fluxer_desktop/src/main/LocalAppFileRequestHandler.ts b/fluxer_desktop/src/main/LocalAppFileRequestHandler.ts
index dc9fcc3ef..c9d8d19bb 100644
--- a/fluxer_desktop/src/main/LocalAppFileRequestHandler.ts
+++ b/fluxer_desktop/src/main/LocalAppFileRequestHandler.ts
@@ -31,7 +31,7 @@ const METHOD_NOT_ALLOWED_HEADERS: Readonly<Record<string, string>> = Object.free
export interface LocalAppIndexContext {
readonly prebootTheme: string | null;
readonly productName: string | null;
- readonly cleartextInstanceOrigins?: ReadonlyArray<string>;
+ readonly instanceOrigins?: ReadonlyArray<string>;
}
interface LocalAppFileRequestLogger {
@@ -149,10 +149,7 @@ export class DesktopLocalAppFileRequestHandler {
prebootTheme: context.prebootTheme,
productName: context.productName,
});
- headers.set(
- 'Content-Security-Policy',
- buildLocalAppCSP({nonce, cleartextInstanceOrigins: context.cleartextInstanceOrigins}),
- );
+ headers.set('Content-Security-Policy', buildLocalAppCSP({nonce, instanceOrigins: context.instanceOrigins}));
return buildRewrittenResponse(request, headers, file, html);
}
}
diff --git a/fluxer_desktop/src/main/LocalAppProtocol.ts b/fluxer_desktop/src/main/LocalAppProtocol.ts
index 689eced14..72d099011 100644
--- a/fluxer_desktop/src/main/LocalAppProtocol.ts
+++ b/fluxer_desktop/src/main/LocalAppProtocol.ts
@@ -195,7 +195,7 @@ export class DesktopLocalAppProtocol {
return {
prebootTheme: readPrebootTheme(),
productName: getLaunchProductName(),
- cleartextInstanceOrigins: getDesktopOutboundHTTP().registeredCleartextOrigins(),
+ instanceOrigins: getDesktopOutboundHTTP().registeredInstanceOrigins(),
};
}