Skip to content

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

TypeScript fluxerfluxerapp

feat(instance): let admins list extra trusted link domains (#3583)

Hampus465ace797b54
diff --git a/fluxer_admin/openapi-admin.json b/fluxer_admin/openapi-admin.json
index c4c251b43..567115215 100644
--- a/fluxer_admin/openapi-admin.json
+++ b/fluxer_admin/openapi-admin.json
@@ -15872,7 +15872,8 @@
"premium_info_url": {"nullable": true, "type": "string"},
"sign_in_backdrop_url": {"nullable": true, "type": "string"},
"custom_css": {"nullable": true, "type": "string"},
- "upload_limit_message": {"nullable": true, "type": "string"}
+ "upload_limit_message": {"nullable": true, "type": "string"},
+ "trusted_domains": {"type": "array", "items": {"type": "string"}}
},
"required": [
"product_name",
@@ -15889,7 +15890,8 @@
"premium_info_url",
"sign_in_backdrop_url",
"custom_css",
- "upload_limit_message"
+ "upload_limit_message",
+ "trusted_domains"
],
"additionalProperties": false
},
@@ -16532,7 +16534,13 @@
"premium_info_url": {"nullable": true, "type": "string", "maxLength": 2048},
"sign_in_backdrop_url": {"nullable": true, "type": "string", "maxLength": 2048},
"custom_css": {"nullable": true, "type": "string", "maxLength": 32768},
- "upload_limit_message": {"nullable": true, "type": "string", "maxLength": 500}
+ "upload_limit_message": {"nullable": true, "type": "string", "maxLength": 500},
+ "trusted_domains": {
+ "nullable": true,
+ "maxItems": 50,
+ "type": "array",
+ "items": {"type": "string", "maxLength": 255}
+ }
}
},
"setup": {"nullable": true, "type": "object", "properties": {"configured": {"type": "boolean"}}},
diff --git a/fluxer_admin/src/api/types/instance_config.rs b/fluxer_admin/src/api/types/instance_config.rs
index 07d727b93..bbe449ca9 100644
--- a/fluxer_admin/src/api/types/instance_config.rs
+++ b/fluxer_admin/src/api/types/instance_config.rs
@@ -447,6 +447,8 @@ pub struct AppBrandingConfigResponse {
pub custom_css: Option<String>,
#[serde(default)]
pub upload_limit_message: Option<String>,
+ #[serde(default)]
+ pub trusted_domains: Vec<String>,
}
impl Default for AppBrandingConfigResponse {
@@ -467,6 +469,7 @@ impl Default for AppBrandingConfigResponse {
sign_in_backdrop_url: None,
custom_css: None,
upload_limit_message: None,
+ trusted_domains: Vec::new(),
}
}
}
@@ -1146,6 +1149,8 @@ pub struct AppBrandingConfigUpdateRequest {
pub custom_css: Option<Option<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub upload_limit_message: Option<Option<String>>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub trusted_domains: Option<Vec<String>>,
}
#[derive(Clone, Debug, Default, Serialize)]
diff --git a/fluxer_admin/src/routes/system_actions/app_public.rs b/fluxer_admin/src/routes/system_actions/app_public.rs
index 439a29b07..7baf3a28e 100644
--- a/fluxer_admin/src/routes/system_actions/app_public.rs
+++ b/fluxer_admin/src/routes/system_actions/app_public.rs
@@ -6,7 +6,9 @@ use crate::{
AppSetupConfigUpdateRequest, CUSTOM_CSS_MAX_CHARS, InstanceConfigUpdateRequest,
},
middleware::flash::FlashData,
- templates::pages::instance_branding::{CUSTOM_CSS_FIELD, UPLOAD_LIMIT_MESSAGE_FIELD},
+ templates::pages::instance_branding::{
+ CUSTOM_CSS_FIELD, TRUSTED_DOMAINS_FIELD, UPLOAD_LIMIT_MESSAGE_FIELD,
+ },
utils::{
forms::{MultiValueForm, clean_string},
plural::group_digits,
@@ -58,6 +60,9 @@ pub(super) fn build_app_public_update(
upload_limit_message: form
.contains_key(UPLOAD_LIMIT_MESSAGE_FIELD)
.then(|| form.clean(UPLOAD_LIMIT_MESSAGE_FIELD)),
+ trusted_domains: form
+ .contains_key(TRUSTED_DOMAINS_FIELD)
+ .then(|| form.list_values(TRUSTED_DOMAINS_FIELD)),
..Default::default()
}),
setup: Some(AppSetupConfigUpdateRequest {
diff --git a/fluxer_admin/src/templates/pages/instance_branding.rs b/fluxer_admin/src/templates/pages/instance_branding.rs
index 4d68c102b..009bf6d92 100644
--- a/fluxer_admin/src/templates/pages/instance_branding.rs
+++ b/fluxer_admin/src/templates/pages/instance_branding.rs
@@ -16,6 +16,7 @@ use maud::{Markup, PreEscaped, html};
pub const CUSTOM_CSS_FIELD: &str = "app_custom_css";
pub const UPLOAD_LIMIT_MESSAGE_FIELD: &str = "app_upload_limit_message";
+pub const TRUSTED_DOMAINS_FIELD: &str = "app_trusted_domains";
const FLUXER_LOGO_SVG: &str = include_str!("../../../static/fluxer-logo-color.svg");
const FLUXER_WORDMARK_SVG: &str = include_str!("../../../static/fluxer-wordmark.svg");
@@ -129,6 +130,19 @@ pub(super) fn branding_section(
"Shows when someone picks a file over their upload limit, in place of \"This limit is configured by your instance administrator.\" Markdown links work. Up to 500 characters. Leave it empty to keep the default sentence."
}
}
+ div class="flex flex-col gap-2 border-t border-neutral-200 pt-6" {
+ (textarea_input(
+ TRUSTED_DOMAINS_FIELD,
+ "Trusted link domains",
+ "example.com\n*.example.com",
+ &app_public.branding.trusted_domains.join("\n"),
+ 3,
+ false,
+ ))
+ p class="text-xs leading-5 text-neutral-500" {
+ "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",
diff --git a/fluxer_api/src/api/admin/controllers/InstanceConfigAdminController.ts b/fluxer_api/src/api/admin/controllers/InstanceConfigAdminController.ts
index 51b209b69..52d32a62f 100644
--- a/fluxer_api/src/api/admin/controllers/InstanceConfigAdminController.ts
+++ b/fluxer_api/src/api/admin/controllers/InstanceConfigAdminController.ts
@@ -26,6 +26,7 @@ import {
deriveSsoRedirectUri,
normalizeAndValidateSsoConfig,
normalizeSsoButtonLabel,
+ normalizeTrustedDomains,
} from '@app/api/instance/SsoConfigValidation';
import {requireAdminACL} from '@app/api/middleware/AdminMiddleware';
import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
@@ -119,6 +120,13 @@ function readOptionalField<T extends object, K extends keyof T>(value: T, key: K
return Object.hasOwn(value, key) ? value[key] : undefined;
}
+function readTrustedDomains(branding: {trusted_domains?: Array<string> | null}): Array<string> | undefined {
+ const domains = readOptionalField(branding, 'trusted_domains');
+ return domains === undefined
+ ? undefined
+ : normalizeTrustedDomains(domains ?? [], 'app_public.branding.trusted_domains');
+}
+
function readSmtpTlsModeUpdate(
smtp: {
tls_mode?: SmtpTlsMode | null;
@@ -332,6 +340,7 @@ function assertSelfHostedBillingSections(data: InstanceConfigUpdateRequest): voi
'favicon_dark_url',
'custom_css',
'upload_limit_message',
+ 'trusted_domains',
] as const) {
if (readOptionalField(branding, field) !== undefined) {
throw InputValidationError.create(
@@ -736,6 +745,7 @@ const INSTANCE_CONFIG_SECTION_APPLIERS = {
sign_in_backdrop_url: readOptionalField(appPublic.branding, 'sign_in_backdrop_url'),
custom_css: readOptionalField(appPublic.branding, 'custom_css'),
upload_limit_message: readOptionalField(appPublic.branding, 'upload_limit_message'),
+ trusted_domains: readTrustedDomains(appPublic.branding),
})
: undefined,
legal: appPublic.legal
diff --git a/fluxer_api/src/api/instance/InstanceConfigRepository.ts b/fluxer_api/src/api/instance/InstanceConfigRepository.ts
index cf2f4fed3..50cddb404 100644
--- a/fluxer_api/src/api/instance/InstanceConfigRepository.ts
+++ b/fluxer_api/src/api/instance/InstanceConfigRepository.ts
@@ -514,6 +514,7 @@ function getDefaultAppPublicConfig(): InstanceAppPublicConfig {
sign_in_backdrop_url: normalizeOptionalString(Config.instance.branding.signInBackdropUrl),
custom_css: null,
upload_limit_message: null,
+ trusted_domains: [],
},
setup: {
configured: !Config.instance.selfHosted || Config.instance.setup.configured,
@@ -982,6 +983,9 @@ function buildAppPublicConfig(config: z.infer<typeof StoredInstanceAppPublicSche
branding.upload_limit_message,
defaults.branding.upload_limit_message,
),
+ trusted_domains: Config.instance.selfHosted
+ ? (branding.trusted_domains ?? defaults.branding.trusted_domains)
+ : defaults.branding.trusted_domains,
},
setup: {
configured: setup.configured ?? defaults.setup.configured,
diff --git a/fluxer_api/src/api/instance/SsoConfigValidation.ts b/fluxer_api/src/api/instance/SsoConfigValidation.ts
index be44b0021..2e3a0c354 100644
--- a/fluxer_api/src/api/instance/SsoConfigValidation.ts
+++ b/fluxer_api/src/api/instance/SsoConfigValidation.ts
@@ -40,6 +40,7 @@ export function getSsoRequestUrlPolicy(): RequestUrlPolicy {
}
const DOMAIN_LABEL_REGEX = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
const SsoAllowedDomainsSchema = InstanceConfigResponse.shape.sso.shape.allowed_domains;
+const TrustedDomainsSchema = InstanceConfigResponse.shape.app_public.shape.branding.shape.trusted_domains;
function normalizeOptionalSsoString(value: string | null): string | null {
if (typeof value !== 'string') {
@@ -92,7 +93,20 @@ export function isTestSsoProvider(
}
export function normalizeAllowedEmailDomains(domains: unknown, field = 'allowed_domains'): Array<string> {
- const result = SsoAllowedDomainsSchema.safeParse(domains);
+ return normalizeDomainList(SsoAllowedDomainsSchema, domains, field, false);
+}
+
+export function normalizeTrustedDomains(domains: unknown, field: string): Array<string> {
+ return normalizeDomainList(TrustedDomainsSchema, domains, field, true);
+}
+
+function normalizeDomainList(
+ schema: typeof SsoAllowedDomainsSchema,
+ domains: unknown,
+ field: string,
+ allowWildcard: boolean,
+): Array<string> {
+ const result = schema.safeParse(domains);
if (!result.success) throw InputValidationError.fromCode(field, ValidationErrorCodes.INVALID_FORMAT);
const normalized = new Set<string>();
for (const rawDomain of result.data) {
@@ -101,19 +115,20 @@ export function normalizeAllowedEmailDomains(domains: unknown, field = 'allowed_
continue;
}
const lowered = entry.toLowerCase();
+ const wildcard = allowWildcard && lowered.startsWith('*.');
+ const host = wildcard ? lowered.slice(2) : lowered;
if (
- lowered.includes('@') ||
- lowered.includes('/') ||
- lowered.includes('\\') ||
- lowered.includes(':') ||
- lowered.startsWith('.') ||
- lowered.endsWith('.') ||
- lowered.startsWith('*.') ||
- lowered.includes('*')
+ host.includes('@') ||
+ host.includes('/') ||
+ host.includes('\\') ||
+ host.includes(':') ||
+ host.startsWith('.') ||
+ host.endsWith('.') ||
+ host.includes('*')
) {
throwInvalidDomain(field, entry);
}
- const asciiDomain = domainToASCII(lowered);
+ const asciiDomain = domainToASCII(host);
if (!asciiDomain || asciiDomain.length > 253 || !asciiDomain.includes('.')) {
throwInvalidDomain(field, entry);
}
@@ -121,7 +136,7 @@ export function normalizeAllowedEmailDomains(domains: unknown, field = 'allowed_
if (labels.some((label) => !DOMAIN_LABEL_REGEX.test(label)) || /^\d+$/.test(labels[labels.length - 1] ?? '')) {
throwInvalidDomain(field, entry);
}
- normalized.add(asciiDomain);
+ normalized.add(wildcard ? `*.${asciiDomain}` : asciiDomain);
}
return Array.from(normalized);
}
diff --git a/fluxer_api/src/api/openapi/openapi.json b/fluxer_api/src/api/openapi/openapi.json
index 280daebc0..84e995bb5 100644
--- a/fluxer_api/src/api/openapi/openapi.json
+++ b/fluxer_api/src/api/openapi/openapi.json
@@ -37424,6 +37424,11 @@
"upload_limit_message": {
"description": "Optional Markdown a self-hosted instance shows when a file is over the upload limit, in place of the default note",
"type": ["string", "null"]
+ },
+ "trusted_domains": {
+ "type": "array",
+ "items": {"type": "string"},
+ "description": "Extra domains a self-hosted instance trusts, so links to them open without a warning. Each entry is a hostname, or a hostname with a *. prefix that also covers its subdomains"
}
},
"required": [
@@ -37441,7 +37446,8 @@
"premium_info_url",
"sign_in_backdrop_url",
"custom_css",
- "upload_limit_message"
+ "upload_limit_message",
+ "trusted_domains"
],
"additionalProperties": false,
"description": "Branding values safe to expose to clients"
diff --git a/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts b/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts
index a9147d816..e9656b8db 100644
--- a/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts
+++ b/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts
@@ -484,6 +484,9 @@ function readAppPublic(value: unknown): InstanceAppPublic {
: null,
custom_css: readOptionalText(branding, 'custom_css'),
upload_limit_message: readOptionalText(branding, 'upload_limit_message'),
+ trusted_domains: Object.hasOwn(branding, 'trusted_domains')
+ ? readStringArray(branding.trusted_domains, 'appPublic.branding.trusted_domains')
+ : [],
},
setup: {
configured: readBoolean(setup, 'configured', 'appPublic.setup.configured'),
diff --git a/fluxer_app/src/features/trusted_domain/state/TrustedDomain.ts b/fluxer_app/src/features/trusted_domain/state/TrustedDomain.ts
index f1cb863be..6ebfebe56 100644
--- a/fluxer_app/src/features/trusted_domain/state/TrustedDomain.ts
+++ b/fluxer_app/src/features/trusted_domain/state/TrustedDomain.ts
@@ -34,8 +34,8 @@ function uniqueDomains(domains: ReadonlyArray<string>): Array<string> {
}
function configuredTrustedDomainPatterns(): Array<string> {
- return uniqueDomains(
- [
+ return uniqueDomains([
+ ...[
RuntimeConfig.webAppEndpoint,
RuntimeConfig.marketingEndpoint,
RuntimeConfig.apiPublicEndpoint,
@@ -44,7 +44,8 @@ function configuredTrustedDomainPatterns(): Array<string> {
RuntimeConfig.mediaEndpoint,
RuntimeConfig.staticCdnEndpoint,
].flatMap(domainPatternFromUrl),
- );
+ ...RuntimeConfig.appPublic.branding.trusted_domains.filter((domain) => domain !== TRUST_EVERYTHING_PATTERN),
+ ]);
}
function domainPatternFromUrl(endpoint: string): Array<string> {
diff --git a/fluxer_docs/src/content/docs/admin-api/instance.mdx b/fluxer_docs/src/content/docs/admin-api/instance.mdx
index 627c212d2..e21d93cf5 100644
--- a/fluxer_docs/src/content/docs/admin-api/instance.mdx
+++ b/fluxer_docs/src/content/docs/admin-api/instance.mdx
@@ -637,7 +637,7 @@ Merges the body into the saved configuration and returns the [instance configura
<sup>1</sup> While `enabled` is true, endpoint URLs must use `https` and point at a public address unless `FLUXER_SSO_ALLOW_PRIVATE_ADDRESSES` is true. Turning on both `enabled` and `enforced` fails with `SSO_MISCONFIGURED` unless there is an `issuer`, or an authorization endpoint, a token endpoint, a client ID and `jwks_url` or `userinfo_url`
-<sup>2</sup> `branding.product_name` is 1-80 characters, `branding.premium_product_name` 1-40, `branding.custom_css` up to 32,768 and `branding.upload_limit_message` up to 500. URLs are up to 2048 characters and `branding.theme_color` is a hex color. Setting `setup.configured` to true finishes setup, and accounts that register after that don't get the wildcard Admin ACL
+<sup>2</sup> `branding.product_name` is 1-80 characters, `branding.premium_product_name` 1-40, `branding.custom_css` up to 32,768 and `branding.upload_limit_message` up to 500. `branding.trusted_domains` holds up to 50 hostnames, each optionally starting with `*.`, and null clears it. URLs are up to 2048 characters and `branding.theme_color` is a hex color. Setting `setup.configured` to true finishes setup, and accounts that register after that don't get the wildcard Admin ACL
<sup>3</sup> A secret such as `klipy_api_key`, `api_key` or the SMTP `password` is saved when sent and kept when left out. `email.smtp` takes `host`, `port`, `username`, `password` and `tls_mode`. `bluesky.keys` replaces the signing keys with up to 8 entries of `kid` and `private_key`
diff --git a/fluxer_docs/src/content/docs/http-api/instance.mdx b/fluxer_docs/src/content/docs/http-api/instance.mdx
index c3edbf062..7d4b2d8c1 100644
--- a/fluxer_docs/src/content/docs/http-api/instance.mdx
+++ b/fluxer_docs/src/content/docs/http-api/instance.mdx
@@ -371,6 +371,7 @@ What a client needs before anyone signs in.
| sign_in_backdrop_url | ?string | Image shown behind the sign-in screens, or null for the default |
| custom_css | ?string | CSS the web and desktop app apply before the person's own theme, or null |
| upload_limit_message | ?string | Markdown shown when a file is over the upload limit, or null for the default text |
+| trusted_domains | string[] | Extra domains whose links open without a warning. Entries are hostnames, and a `*.` prefix also covers subdomains |
## Public setup state object
diff --git a/fluxer_rexctl/internal/adminapi/configschema.json b/fluxer_rexctl/internal/adminapi/configschema.json
index 41d4f4eb5..5da479ff5 100644
--- a/fluxer_rexctl/internal/adminapi/configschema.json
+++ b/fluxer_rexctl/internal/adminapi/configschema.json
@@ -172,6 +172,12 @@
"help": "Branding theme color",
"nullable": true
},
+ {
+ "key": "app_public.branding.trusted_domains",
+ "type": "list",
+ "help": "Branding trusted domains",
+ "nullable": true
+ },
{
"key": "app_public.branding.upload_limit_message",
"type": "string",
diff --git a/fluxer_rexctl/internal/adminapi/gen.go b/fluxer_rexctl/internal/adminapi/gen.go
index 440bd3bb0..452a13861 100644
--- a/fluxer_rexctl/internal/adminapi/gen.go
+++ b/fluxer_rexctl/internal/adminapi/gen.go
@@ -1994,21 +1994,22 @@ type InstanceConfigResponse struct {
Accounts AccountsConfigSchema `json:"accounts"`
AppPublic struct {
Branding struct {
- CustomCss *string `json:"custom_css"`
- FaviconDarkUrl *string `json:"favicon_dark_url"`
- FaviconUrl *string `json:"favicon_url"`
- IconUrl *string `json:"icon_url"`
- LogoUrl *string `json:"logo_url"`
- PremiumInfoUrl *string `json:"premium_info_url"`
- PremiumProductName string `json:"premium_product_name"`
- ProductName string `json:"product_name"`
- SignInBackdropUrl *string `json:"sign_in_backdrop_url"`
- StatusPageIncidentHistoryUrl *string `json:"status_page_incident_history_url"`
- StatusPageUrl *string `json:"status_page_url"`
- SymbolUrl *string `json:"symbol_url"`
- ThemeColor *string `json:"theme_color"`
- UploadLimitMessage *string `json:"upload_limit_message"`
- WordmarkUrl *string `json:"wordmark_url"`
+ CustomCss *string `json:"custom_css"`
+ FaviconDarkUrl *string `json:"favicon_dark_url"`
+ FaviconUrl *string `json:"favicon_url"`
+ IconUrl *string `json:"icon_url"`
+ LogoUrl *string `json:"logo_url"`
+ PremiumInfoUrl *string `json:"premium_info_url"`
+ PremiumProductName string `json:"premium_product_name"`
+ ProductName string `json:"product_name"`
+ SignInBackdropUrl *string `json:"sign_in_backdrop_url"`
+ StatusPageIncidentHistoryUrl *string `json:"status_page_incident_history_url"`
+ StatusPageUrl *string `json:"status_page_url"`
+ SymbolUrl *string `json:"symbol_url"`
+ ThemeColor *string `json:"theme_color"`
+ TrustedDomains []string `json:"trusted_domains"`
+ UploadLimitMessage *string `json:"upload_limit_message"`
+ WordmarkUrl *string `json:"wordmark_url"`
} `json:"branding"`
Legal struct {
GuidelinesUrl *string `json:"guidelines_url"`
@@ -2225,21 +2226,22 @@ type InstanceConfigUpdateRequest struct {
Accounts *AccountsConfigUpdateRequest `json:"accounts,omitempty"`
AppPublic *struct {
Branding *struct {
- CustomCss *string `json:"custom_css,omitempty"`
- FaviconDarkUrl *string `json:"favicon_dark_url,omitempty"`
- FaviconUrl *string `json:"favicon_url,omitempty"`
- IconUrl *string `json:"icon_url,omitempty"`
- LogoUrl *string `json:"logo_url,omitempty"`
- PremiumInfoUrl *string `json:"premium_info_url,omitempty"`
- PremiumProductName *string `json:"premium_product_name,omitempty"`
- ProductName *string `json:"product_name,omitempty"`
- SignInBackdropUrl *string `json:"sign_in_backdrop_url,omitempty"`
- StatusPageIncidentHistoryUrl *string `json:"status_page_incident_history_url,omitempty"`
- StatusPageUrl *string `json:"status_page_url,omitempty"`
- SymbolUrl *string `json:"symbol_url,omitempty"`
- ThemeColor *string `json:"theme_color,omitempty"`
- UploadLimitMessage *string `json:"upload_limit_message,omitempty"`
- WordmarkUrl *string `json:"wordmark_url,omitempty"`
+ CustomCss *string `json:"custom_css,omitempty"`
+ FaviconDarkUrl *string `json:"favicon_dark_url,omitempty"`
+ FaviconUrl *string `json:"favicon_url,omitempty"`
+ IconUrl *string `json:"icon_url,omitempty"`
+ LogoUrl *string `json:"logo_url,omitempty"`
+ PremiumInfoUrl *string `json:"premium_info_url,omitempty"`
+ PremiumProductName *string `json:"premium_product_name,omitempty"`
+ ProductName *string `json:"product_name,omitempty"`
+ SignInBackdropUrl *string `json:"sign_in_backdrop_url,omitempty"`
+ StatusPageIncidentHistoryUrl *string `json:"status_page_incident_history_url,omitempty"`
+ StatusPageUrl *string `json:"status_page_url,omitempty"`
+ SymbolUrl *string `json:"symbol_url,omitempty"`
+ ThemeColor *string `json:"theme_color,omitempty"`
+ TrustedDomains *[]string `json:"trusted_domains,omitempty"`
+ UploadLimitMessage *string `json:"upload_limit_message,omitempty"`
+ WordmarkUrl *string `json:"wordmark_url,omitempty"`
} `json:"branding,omitempty"`
Legal *struct {
GuidelinesUrl *string `json:"guidelines_url,omitempty"`
diff --git a/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts b/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts
index a7a624ecc..adef40443 100644
--- a/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts
+++ b/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts
@@ -138,6 +138,7 @@ function projectAppPublic(appPublic: InstanceDiscoveryDocument['appPublic']): In
sign_in_backdrop_url: value.branding.sign_in_backdrop_url ?? null,
custom_css: value.branding.custom_css ?? null,
upload_limit_message: value.branding.upload_limit_message ?? null,
+ trusted_domains: value.branding.trusted_domains ?? [],
},
setup: {
...value.setup,
diff --git a/packages/instance_bootstrap/src/Discovery.ts b/packages/instance_bootstrap/src/Discovery.ts
index 0e96badb6..f596a1798 100644
--- a/packages/instance_bootstrap/src/Discovery.ts
+++ b/packages/instance_bootstrap/src/Discovery.ts
@@ -861,6 +861,10 @@ function parseBranding(value: unknown): Readonly<Partial<InstanceBranding>> {
if (Object.hasOwn(source, 'upload_limit_message')) {
branding.upload_limit_message = readNonEmptyString(source, 'upload_limit_message');
}
+ const trustedDomains = readStringArray(source, 'trusted_domains');
+ if (trustedDomains != null) {
+ branding.trusted_domains = trustedDomains;
+ }
return branding;
}
diff --git a/packages/schema/src/domains/admin/AdminSchemas.ts b/packages/schema/src/domains/admin/AdminSchemas.ts
index 203e0abcd..8e40f77db 100644
--- a/packages/schema/src/domains/admin/AdminSchemas.ts
+++ b/packages/schema/src/domains/admin/AdminSchemas.ts
@@ -613,6 +613,7 @@ const AppPublicConfigResponse = z.object({
sign_in_backdrop_url: z.string().nullable(),
custom_css: z.string().nullable(),
upload_limit_message: z.string().nullable(),
+ trusted_domains: z.array(z.string()),
}),
setup: z.object({
configured: z.boolean(),
@@ -638,6 +639,8 @@ function isAbsoluteHttpUrl(value: string): boolean {
export const UPLOAD_LIMIT_MESSAGE_MAX_LENGTH = 500;
+export const TRUSTED_DOMAINS_MAX = 50;
+
const HEX_THEME_COLOR_PATTERN = /^(?:#?(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}))?$/;
const AppPublicConfigUpdateRequest = z.object({
@@ -658,6 +661,7 @@ const AppPublicConfigUpdateRequest = z.object({
sign_in_backdrop_url: z.string().trim().max(2048).nullish(),
custom_css: z.string().trim().max(32_768).nullish(),
upload_limit_message: z.string().trim().max(UPLOAD_LIMIT_MESSAGE_MAX_LENGTH).nullish(),
+ trusted_domains: z.array(z.string().max(255)).max(TRUSTED_DOMAINS_MAX).nullish(),
})
.register(schemaMetadata, {preserveNullFields: true})
.nullish(),
diff --git a/packages/schema/src/domains/instance/InstanceSchemas.ts b/packages/schema/src/domains/instance/InstanceSchemas.ts
index 960b17f5c..ddf9dd186 100644
--- a/packages/schema/src/domains/instance/InstanceSchemas.ts
+++ b/packages/schema/src/domains/instance/InstanceSchemas.ts
@@ -73,6 +73,11 @@ export const InstanceBrandingSchema = z
.describe(
'Optional Markdown a self-hosted instance shows when a file is over the upload limit, in place of the default note',
),
+ trusted_domains: z
+ .array(z.string())
+ .describe(
+ 'Extra domains a self-hosted instance trusts, so links to them open without a warning. Each entry is a hostname, or a hostname with a *. prefix that also covers its subdomains',
+ ),
})
.describe('Branding values safe to expose to clients');
export type InstanceBranding = z.infer<typeof InstanceBrandingSchema>;