Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Add configurable footer links for self-hosted instances (#3030)
Luke Vellad5d7f26ec2f9
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 453cd9741..8af0ae352 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -326,6 +326,14 @@"feedback": "Feedback","feedbackDialogEnterFeedback": "Enter your feedback","fileTooLarge": "File too large",+ "footerLinkAdd": "Add link",+ "footerLinkLabel": "Label",+ "footerLinkLabelPlaceholder": "Privacy policy",+ "footerLinkRemove": "Remove link",+ "footerLinks": "Footer links",+ "footerLinksDescription": "Links shown on the login, invite and poll pages, for legal notices such as an imprint or privacy policy",+ "footerLinkUrl": "URL",+ "footerLinkUrlInvalid": "Enter a URL starting with http:// or https://","forgotPassword": "Forgot password?","forgotPasswordDescription": "Enter your email address and we'll send you a link to reset your password.","forgotPasswordFooter": "Remember your password? <a>Back to login</a>",diff --git a/apps/web/src/app/[locale]/(auth)/layout.tsx b/apps/web/src/app/[locale]/(auth)/layout.tsxindex ecaa57845..9e9a3401b 100644--- a/apps/web/src/app/[locale]/(auth)/layout.tsx+++ b/apps/web/src/app/[locale]/(auth)/layout.tsx@@ -1,5 +1,7 @@+import { InstanceFooterLinks } from "@/components/instance-footer-links";import { Logo } from "@/features/branding/components/logo";import { LOGO_VIEWBOX } from "@/features/branding/constants";+import { loadFooterLinks } from "@/features/instance-settings/loaders";import { QuickCreateButton } from "@/features/quick-create/components/quick-create-button";import { QuickCreateWidget } from "@/features/quick-create/components/quick-create-widget";import { isQuickCreateEnabled } from "@/features/quick-create/constants";@@ -12,9 +14,10 @@ export default async function Layout({}: {children: React.ReactNode;}) {- const [locale, deviceDateTimeConfig] = await Promise.all([+ const [locale, deviceDateTimeConfig, footerLinks] = await Promise.all([getLocale(),getDeviceDateTimeConfig(),+ loadFooterLinks(),]);return (@@ -41,9 +44,15 @@ export default async function Layout({<QuickCreateButton /></div>) : null}- {/* empty spacer matching the header's logo slot height so the- vertically centered content sits at the true middle of the page */}- <footer style={{ height: LOGO_VIEWBOX.height }} />+ {/* Balances the header's logo slot so the vertically centered+ content sits at the true middle of the page. Keeps its height+ as a bare spacer when no links are configured. */}+ <footer+ className="flex items-center justify-center"+ style={{ minHeight: LOGO_VIEWBOX.height }}+ >+ <InstanceFooterLinks links={footerLinks} />+ </footer></div>{isQuickCreateEnabled ? (<div className="relative hidden flex-1 flex-col justify-center rounded-lg border bg-muted/50 lg:flex lg:p-16">diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page-loader.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page-loader.tsxindex 49d8898a8..0a820beec 100644--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page-loader.tsx+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page-loader.tsx@@ -7,11 +7,15 @@ const AdminPage = dynamic({ ssr: false },);-export function AdminPageLoader() {+export function AdminPageLoader({+ footerLinks,+}: {+ footerLinks: { label: string; href: string }[];+}) {return (<><PollBrandingFromContext />- <AdminPage />+ <AdminPage footerLinks={footerLinks} /></>);}diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page.tsxindex 604d84e6d..8094fa0f1 100644--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page.tsx+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page.tsx@@ -6,7 +6,11 @@ import { ResponsiveResults } from "@/features/poll/components/responsive-resultsimport { VotingForm } from "@/features/poll/components/voting-form";import { GuestPollAlert } from "./guest-poll-alert";-export function AdminPage() {+export function AdminPage({+ footerLinks,+}: {+ footerLinks: { label: string; href: string }[];+}) {return (<div className="space-y-3 lg:space-y-4"><GuestPollAlert />@@ -17,7 +21,7 @@ export function AdminPage() {<div className="fixed right-4 bottom-15 z-40 lg:right-6 lg:bottom-6"><CommentsSheet className="rounded-full shadow-lg" /></div>- <PollFooter />+ <PollFooter footerLinks={footerLinks} /><div className="h-24 lg:hidden" /></div>);diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/page.tsxindex ce65a1d90..2dedb4e6a 100644--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/page.tsx+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/page.tsx@@ -1,5 +1,20 @@+import { Suspense } from "react";+import { loadFooterLinks } from "@/features/instance-settings/loaders";import { AdminPageLoader } from "./admin-page-loader";+// Keeps the route shell synchronous so it can flush before the footer links+// read resolves. The page below is client-only, so this is the one server+// boundary the links can be loaded from.+async function AdminPageWithFooterLinks() {+ const footerLinks = await loadFooterLinks();++ return <AdminPageLoader footerLinks={footerLinks} />;+}+export default function Page() {- return <AdminPageLoader />;+ return (+ <Suspense>+ <AdminPageWithFooterLinks />+ </Suspense>+ );}diff --git a/apps/web/src/app/[locale]/control-panel/settings/actions.ts b/apps/web/src/app/[locale]/control-panel/settings/actions.tsindex 1c51ca7e5..28d441b37 100644--- a/apps/web/src/app/[locale]/control-panel/settings/actions.ts+++ b/apps/web/src/app/[locale]/control-panel/settings/actions.ts@@ -1,7 +1,15 @@"use server";-import { updateInstanceSettings } from "@/features/instance-settings/mutations";-import { instanceSettingsSchema } from "@/features/instance-settings/schema";+import {+ updateInstanceFooterLinks,+ updateInstanceSettings,+} from "@/features/instance-settings/mutations";+import {+ footerLinksSchema,+ instanceSettingsSchema,+} from "@/features/instance-settings/schema";+import { isSelfHosted } from "@/lib/constants";+import { AppError } from "@/lib/errors/app-error";import { adminActionClient } from "@/lib/safe-action/server";export const updateInstanceSettingsAction = adminActionClient@@ -12,3 +20,22 @@ export const updateInstanceSettingsAction = adminActionClient.action(async ({ parsedInput }) => {await updateInstanceSettings(parsedInput);});++export const updateFooterLinksAction = adminActionClient+ .metadata({+ actionName: "update_footer_links",+ })+ .inputSchema(footerLinksSchema)+ .action(async ({ parsedInput }) => {+ // Cloud renders its own static links, so `loadFooterLinks` discards+ // whatever is stored. Without this, a cloud admin would save, see a+ // success toast, and reload into an empty form.+ if (!isSelfHosted) {+ throw new AppError({+ code: "FORBIDDEN",+ message: "Footer links are not available on this instance",+ });+ }++ await updateInstanceFooterLinks(parsedInput.footerLinks);+ });diff --git a/apps/web/src/app/[locale]/control-panel/settings/footer-links-field.tsx b/apps/web/src/app/[locale]/control-panel/settings/footer-links-field.tsxnew file mode 100644index 000000000..9a426dcf1--- /dev/null+++ b/apps/web/src/app/[locale]/control-panel/settings/footer-links-field.tsx@@ -0,0 +1,171 @@+"use client";++import { zodResolver } from "@hookform/resolvers/zod";+import { Button } from "@rallly/ui/button";+import { FieldError, FieldLabel } from "@rallly/ui/field";+import { Input } from "@rallly/ui/input";+import { toast } from "@rallly/ui/sonner";+import { PlusIcon, Trash2Icon } from "lucide-react";+import { Controller, useFieldArray, useForm } from "react-hook-form";+import * as z from "zod";+import type { FooterLink } from "@/features/instance-settings/schema";+import {+ FOOTER_LINK_MAX_COUNT,+ FOOTER_LINK_MAX_HREF_LENGTH,+ FOOTER_LINK_MAX_LABEL_LENGTH,+ isValidFooterLinkHref,+} from "@/features/instance-settings/schema";+import { Trans, useTranslation } from "@/i18n/client";+import { useSafeAction } from "@/lib/safe-action/client";+import { updateFooterLinksAction } from "./actions";++export function FooterLinksField({+ defaultValue,+}: {+ defaultValue: FooterLink[];+}) {+ const { t } = useTranslation();+ const updateFooterLinks = useSafeAction(updateFooterLinksAction);++ // Mirrors footerLinksSchema, with the href message translated. The server+ // action still validates against the un-localised schema.+ const formSchema = z.object({+ footerLinks: z+ .array(+ z.object({+ label: z+ .string()+ .trim()+ .min(1, t("requiredField", { defaultValue: "Required" }))+ .max(FOOTER_LINK_MAX_LABEL_LENGTH),+ href: z+ .string()+ .trim()+ .min(1, t("requiredField", { defaultValue: "Required" }))+ .max(FOOTER_LINK_MAX_HREF_LENGTH)+ .refine(isValidFooterLinkHref, {+ message: t("footerLinkUrlInvalid", {+ defaultValue: "Enter a URL starting with http:// or https://",+ }),+ }),+ }),+ )+ .max(FOOTER_LINK_MAX_COUNT),+ });++ const form = useForm({+ resolver: zodResolver(formSchema),+ defaultValues: {+ footerLinks: defaultValue,+ },+ });++ const { fields, append, remove } = useFieldArray({+ control: form.control,+ name: "footerLinks",+ });++ return (+ <form+ className="space-y-4"+ onSubmit={form.handleSubmit(async (data) => {+ const result = await updateFooterLinks.executeAsync(data);++ if (!result?.serverError && !result?.validationErrors) {+ form.reset(data);+ toast.success(t("saved", { defaultValue: "Saved" }));+ }+ })}+ >+ {fields.length > 0 ? (+ <ul className="space-y-3">+ {fields.map((field, index) => (+ <li+ key={field.id}+ className="flex flex-col gap-2 sm:flex-row sm:items-start"+ >+ <Controller+ control={form.control}+ name={`footerLinks.${index}.label`}+ render={({ field: labelField, fieldState }) => (+ <div className="sm:w-56">+ <FieldLabel className="sr-only" htmlFor={labelField.name}>+ <Trans i18nKey="footerLinkLabel" defaults="Label" />+ </FieldLabel>+ <Input+ {...labelField}+ id={labelField.name}+ aria-invalid={fieldState.invalid}+ placeholder={t("footerLinkLabelPlaceholder", {+ defaultValue: "Privacy policy",+ })}+ />+ {fieldState.invalid ? (+ <FieldError+ className="mt-1.5"+ errors={[fieldState.error]}+ />+ ) : null}+ </div>+ )}+ />+ <Controller+ control={form.control}+ name={`footerLinks.${index}.href`}+ render={({ field: hrefField, fieldState }) => (+ <div className="flex-1">+ <FieldLabel className="sr-only" htmlFor={hrefField.name}>+ <Trans i18nKey="footerLinkUrl" defaults="URL" />+ </FieldLabel>+ <Input+ {...hrefField}+ id={hrefField.name}+ aria-invalid={fieldState.invalid}+ placeholder="https://example.com/privacy"+ />+ {fieldState.invalid ? (+ <FieldError+ className="mt-1.5"+ errors={[fieldState.error]}+ />+ ) : null}+ </div>+ )}+ />+ <Button+ type="button"+ variant="ghost"+ size="icon"+ onClick={() => remove(index)}+ aria-label={t("footerLinkRemove", {+ defaultValue: "Remove link",+ })}+ >+ <Trash2Icon className="size-4" />+ </Button>+ </li>+ ))}+ </ul>+ ) : null}+ <div className="flex items-center gap-2">+ <Button+ type="button"+ variant="ghost"+ disabled={fields.length >= FOOTER_LINK_MAX_COUNT}+ onClick={() => append({ label: "", href: "" })}+ >+ <PlusIcon className="size-4" />+ <Trans i18nKey="footerLinkAdd" defaults="Add link" />+ </Button>+ <Button+ type="submit"+ variant="primary"+ loading={updateFooterLinks.isExecuting}+ disabled={!form.formState.isDirty}+ >+ <Trans i18nKey="save" defaults="Save" />+ </Button>+ </div>+ </form>+ );+}diff --git a/apps/web/src/app/[locale]/control-panel/settings/page.tsx b/apps/web/src/app/[locale]/control-panel/settings/page.tsxindex f4ffe8db0..b134791c2 100644--- a/apps/web/src/app/[locale]/control-panel/settings/page.tsx+++ b/apps/web/src/app/[locale]/control-panel/settings/page.tsx@@ -14,19 +14,26 @@ import {SettingsPageTitle,} from "@/components/settings-layout";import { getInstanceSettings } from "@/features/instance-settings/data";+import { loadFooterLinks } from "@/features/instance-settings/loaders";import { Trans } from "@/i18n/client";+import { isSelfHosted } from "@/lib/constants";+import { FooterLinksField } from "./footer-links-field";import { InstanceSettingsForm } from "./instance-settings-form";async function loadData() {- const instanceSettings = await getInstanceSettings();+ const [instanceSettings, footerLinks] = await Promise.all([+ getInstanceSettings(),+ loadFooterLinks(),+ ]);return {instanceSettings,+ footerLinks,};}export default async function InstanceSettingsPage() {- const { instanceSettings } = await loadData();+ const { instanceSettings, footerLinks } = await loadData();return (<SettingsPage>@@ -62,6 +69,24 @@ export default async function InstanceSettingsPage() {<InstanceSettingsForm defaultValue={instanceSettings} /></PageSectionContent></PageSection>+ {isSelfHosted ? (+ <PageSection variant="card">+ <PageSectionHeader>+ <PageSectionTitle>+ <Trans i18nKey="footerLinks" defaults="Footer links" />+ </PageSectionTitle>+ <PageSectionDescription>+ <Trans+ i18nKey="footerLinksDescription"+ defaults="Links shown on the login, invite and poll pages, for legal notices such as an imprint or privacy policy"+ />+ </PageSectionDescription>+ </PageSectionHeader>+ <PageSectionContent>+ <FooterLinksField defaultValue={footerLinks} />+ </PageSectionContent>+ </PageSection>+ ) : null}</PageSectionGroup></SettingsPageContent></SettingsPage>diff --git a/apps/web/src/app/[locale]/invite/[urlId]/invite-page-loader.tsx b/apps/web/src/app/[locale]/invite/[urlId]/invite-page-loader.tsxindex 0fea3d1ff..4f0e90cd2 100644--- a/apps/web/src/app/[locale]/invite/[urlId]/invite-page-loader.tsx+++ b/apps/web/src/app/[locale]/invite/[urlId]/invite-page-loader.tsx@@ -12,11 +12,15 @@ const InvitePage = dynamic({ ssr: false },);-export function InvitePageLoader() {+export function InvitePageLoader({+ footerLinks,+}: {+ footerLinks: { label: string; href: string }[];+}) {return (<><PollBrandingFromContext />- <InvitePage />+ <InvitePage footerLinks={footerLinks} /></>);}diff --git a/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx b/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsxindex 3bf774765..ae113090e 100644--- a/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx+++ b/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx@@ -45,7 +45,11 @@ const GoToApp = () => {);};-export function InvitePage() {+export function InvitePage({+ footerLinks,+}: {+ footerLinks: { label: string; href: string }[];+}) {return (<div className="page-bg-gray-100 h-dvh overflow-auto p-3 lg:p-6 dark:bg-gray-900"><main@@ -58,7 +62,7 @@ export function InvitePage() {<VotingForm><ResponsiveResults /></VotingForm>- <PollFooter />+ <PollFooter footerLinks={footerLinks} /><div className="fixed right-4 bottom-15 z-40 lg:right-6 lg:bottom-6"><CommentsSheet className="rounded-full shadow-lg" /></div>diff --git a/apps/web/src/app/[locale]/invite/[urlId]/page.tsx b/apps/web/src/app/[locale]/invite/[urlId]/page.tsxindex b0b088f6c..ea6975925 100644--- a/apps/web/src/app/[locale]/invite/[urlId]/page.tsx+++ b/apps/web/src/app/[locale]/invite/[urlId]/page.tsx@@ -5,6 +5,7 @@ import type { Metadata } from "next";import { notFound } from "next/navigation";import { cache } from "react";import { SessionRefresher } from "@/components/session-refresher";+import { loadFooterLinks } from "@/features/instance-settings/loaders";import { PermissionProvider } from "@/features/poll/client";import { UserProvider } from "@/features/user/client";import { getLocale } from "@/i18n/server/get-locale";@@ -50,14 +51,16 @@ export default async function Page(props: {const token = (await props.searchParams).token;- const [locale, session, deviceDateTimeConfig] = await Promise.all([- getLocale(),- getSession(),- getDeviceDateTimeConfig(),- trpc.polls.get.prefetch({ urlId: params.urlId }),- trpc.polls.participants.list.prefetch({ pollId: params.urlId, token }),- trpc.polls.comments.list.prefetch({ pollId: params.urlId }),- ]);+ const [locale, session, deviceDateTimeConfig, footerLinks] =+ await Promise.all([+ getLocale(),+ getSession(),+ getDeviceDateTimeConfig(),+ loadFooterLinks(),+ trpc.polls.get.prefetch({ urlId: params.urlId }),+ trpc.polls.participants.list.prefetch({ pollId: params.urlId, token }),+ trpc.polls.comments.list.prefetch({ pollId: params.urlId }),+ ]);let impersonatedUserId: string | null = null;if (token) {@@ -78,7 +81,7 @@ export default async function Page(props: {><Providers><PermissionProvider impersonatedUserId={impersonatedUserId}>- <InvitePageLoader />+ <InvitePageLoader footerLinks={footerLinks} /></PermissionProvider></Providers></DeviceDateTimeProvider>diff --git a/apps/web/src/components/instance-footer-links.tsx b/apps/web/src/components/instance-footer-links.tsxnew file mode 100644index 000000000..939dc8556--- /dev/null+++ b/apps/web/src/components/instance-footer-links.tsx@@ -0,0 +1,34 @@+/**+ * Footer links configured by a self-hosted instance administrator, typically+ * legal disclosures such as an Impressum or privacy policy.+ *+ * Labels are admin-typed and therefore not localised — the linked documents+ * are themselves single-language, so a German Datenschutzerklärung stays+ * labelled in German for an English-speaking visitor.+ *+ * Hrefs are validated on write and again on read (see instance-settings/data.ts).+ */+export function InstanceFooterLinks({+ links,+}: {+ links: { label: string; href: string }[];+}) {+ if (links.length === 0) {+ return null;+ }++ return (+ <nav className="flex flex-wrap items-center justify-center gap-x-4 gap-y-2">+ {links.map((link) => (+ <a+ key={`${link.href}:${link.label}`}+ href={link.href}+ className="text-muted-foreground text-sm underline-offset-4 hover:text-foreground hover:underline"+ rel="noreferrer"+ >+ {link.label}+ </a>+ ))}+ </nav>+ );+}diff --git a/apps/web/src/features/instance-settings/data.ts b/apps/web/src/features/instance-settings/data.tsindex bceac2822..9268df023 100644--- a/apps/web/src/features/instance-settings/data.ts+++ b/apps/web/src/features/instance-settings/data.ts@@ -4,6 +4,26 @@ import { prisma } from "@rallly/database";import { unstable_cache } from "next/cache";import { isFeatureEnabled } from "@/lib/feature-flags/server";import { instanceSettingsTag } from "./constants";+import type { FooterLink } from "./schema";+import { FOOTER_LINK_MAX_COUNT, footerLinkSchema } from "./schema";++// Stored links are re-validated on read, not just on write: a row edited+// directly in the database must not be able to put an unsafe href into an+// anchor, or turn the footer into a link farm. Invalid entries are dropped+// rather than failing the whole read, so one bad link cannot take down the+// login page.+function parseFooterLinks(value: unknown): FooterLink[] {+ if (!Array.isArray(value)) {+ return [];+ }++ return value+ .flatMap((entry) => {+ const parsed = footerLinkSchema.safeParse(entry);+ return parsed.success ? [parsed.data] : [];+ })+ .slice(0, FOOTER_LINK_MAX_COUNT);+}export const getInstanceSettings = unstable_cache(async () => {@@ -21,6 +41,7 @@ export const getInstanceSettings = unstable_cache(logoDark: true,logoIcon: true,hideAttribution: true,+ footerLinks: true,},});@@ -35,6 +56,7 @@ export const getInstanceSettings = unstable_cache(logoDark: instanceSettings?.logoDark ?? null,logoIcon: instanceSettings?.logoIcon ?? null,hideAttribution: instanceSettings?.hideAttribution ?? null,+ footerLinks: parseFooterLinks(instanceSettings?.footerLinks),};},[],diff --git a/apps/web/src/features/instance-settings/footer-links-roundtrip.test.ts b/apps/web/src/features/instance-settings/footer-links-roundtrip.test.tsnew file mode 100644index 000000000..9430183a9--- /dev/null+++ b/apps/web/src/features/instance-settings/footer-links-roundtrip.test.ts@@ -0,0 +1,41 @@+import { describe, expect, it } from "vitest";+import { footerLinksSchema } from "./schema";++/**+ * Guards the action's contract: whatever the control panel form submits must+ * survive `footerLinksSchema` (the action's inputSchema) in the exact shape+ * `updateInstanceFooterLinks` writes to the JSON column.+ */+describe("footer links action contract", () => {+ it("accepts the payload the form submits and yields a writable array", () => {+ const formValues = {+ footerLinks: [+ { label: "Impressum", href: "https://example.de/impressum" },+ { label: "Datenschutz", href: "https://example.de/datenschutz" },+ ],+ };++ const parsed = footerLinksSchema.parse(formValues);++ expect(Array.isArray(parsed.footerLinks)).toBe(true);+ expect(parsed.footerLinks).toEqual(formValues.footerLinks);+ // Must be plain JSON — Prisma writes this straight into a JSONB column+ expect(JSON.parse(JSON.stringify(parsed.footerLinks))).toEqual(+ parsed.footerLinks,+ );+ });++ it("accepts clearing every link", () => {+ expect(footerLinksSchema.parse({ footerLinks: [] }).footerLinks).toEqual(+ [],+ );+ });++ it("rejects a payload the server must never persist", () => {+ expect(+ footerLinksSchema.safeParse({+ footerLinks: [{ label: "Evil", href: "javascript:alert(1)" }],+ }).success,+ ).toBe(false);+ });+});diff --git a/apps/web/src/features/instance-settings/loaders.ts b/apps/web/src/features/instance-settings/loaders.tsindex 58204742f..1d6513673 100644--- a/apps/web/src/features/instance-settings/loaders.ts+++ b/apps/web/src/features/instance-settings/loaders.ts@@ -1,6 +1,7 @@import "server-only";import { cache } from "react";+import { isSelfHosted } from "@/lib/constants";import { getInstanceSettings } from "./data";import { getUpdateStatus } from "./service";@@ -13,3 +14,23 @@ export const loadUpdateStatus = cache(async () => {return getUpdateStatus({ instanceId });});++/**+ * Footer links for the login and invite page footers.+ *+ * Deliberately not routed through the branding config: these carry legal+ * disclosures (Impressum, privacy policy) that self-hosted instances are+ * required to make reachable, so they are not gated behind the white label+ * add-on the way the rest of the branding settings are.+ *+ * Cloud has its own static links (RAL-1563) and never reads this column.+ */+export const loadFooterLinks = cache(async () => {+ if (!isSelfHosted) {+ return [];+ }++ const { footerLinks } = await getInstanceSettings();++ return footerLinks;+});diff --git a/apps/web/src/features/instance-settings/mutations.ts b/apps/web/src/features/instance-settings/mutations.tsindex b5b6d1418..33169b897 100644--- a/apps/web/src/features/instance-settings/mutations.ts+++ b/apps/web/src/features/instance-settings/mutations.ts@@ -4,7 +4,7 @@ import { prisma } from "@rallly/database";import { updateTag } from "next/cache";import { replaceStoredAsset } from "@/lib/storage/asset-upload";import { instanceSettingsTag } from "./constants";-import type { BrandingLogoType } from "./schema";+import type { BrandingLogoType, FooterLink } from "./schema";export async function updateInstanceSettings(data: {disableUserRegistration?: boolean;@@ -59,3 +59,16 @@ export async function updateInstanceLogo({},});}++export async function updateInstanceFooterLinks(footerLinks: FooterLink[]) {+ await prisma.instanceSettings.update({+ where: {+ id: 1,+ },+ data: {+ footerLinks,+ },+ });++ updateTag(instanceSettingsTag);+}diff --git a/apps/web/src/features/instance-settings/schema.test.ts b/apps/web/src/features/instance-settings/schema.test.tsnew file mode 100644index 000000000..e26006983--- /dev/null+++ b/apps/web/src/features/instance-settings/schema.test.ts@@ -0,0 +1,107 @@+import { describe, expect, it } from "vitest";+import { footerLinksSchema, isValidFooterLinkHref } from "./schema";++describe("isValidFooterLinkHref", () => {+ it("accepts absolute http and https urls", () => {+ expect(isValidFooterLinkHref("https://example.com/impressum")).toBe(true);+ expect(isValidFooterLinkHref("http://example.com")).toBe(true);+ });++ it("rejects relative paths — these links must resolve from emails too", () => {+ expect(isValidFooterLinkHref("/legal/privacy")).toBe(false);+ expect(isValidFooterLinkHref("/impressum?lang=de#kontakt")).toBe(false);+ expect(isValidFooterLinkHref("legal/privacy")).toBe(false);+ });++ it("rejects javascript urls", () => {+ expect(isValidFooterLinkHref("javascript:alert(1)")).toBe(false);+ expect(isValidFooterLinkHref("JavaScript:alert(1)")).toBe(false);+ });++ it("rejects javascript urls disguised with control characters", () => {+ expect(isValidFooterLinkHref("java\tscript:alert(1)")).toBe(false);+ expect(isValidFooterLinkHref("java\nscript:alert(1)")).toBe(false);+ expect(isValidFooterLinkHref(" javascript:alert(1)")).toBe(false);+ });++ it("rejects other non-http schemes", () => {+ expect(+ isValidFooterLinkHref("data:text/html,<script>alert(1)</script>"),+ ).toBe(false);+ expect(isValidFooterLinkHref("vbscript:msgbox(1)")).toBe(false);+ expect(isValidFooterLinkHref("file:///etc/passwd")).toBe(false);+ expect(isValidFooterLinkHref("mailto:[email protected]")).toBe(false);+ });++ it("rejects scheme-relative urls that read as paths but leave the instance", () => {+ expect(isValidFooterLinkHref("//evil.example.com")).toBe(false);+ });++ it("keeps query strings and fragments on absolute urls", () => {+ expect(+ isValidFooterLinkHref("https://example.com/impressum?lang=de#kontakt"),+ ).toBe(true);+ });++ it("rejects bare hostnames, which are ambiguous rather than absolute", () => {+ expect(isValidFooterLinkHref("example.com/impressum")).toBe(false);+ });++ it("rejects empty and whitespace-only values", () => {+ expect(isValidFooterLinkHref("")).toBe(false);+ expect(isValidFooterLinkHref(" ")).toBe(false);+ });+});++describe("footerLinksSchema", () => {+ const link = { label: "Impressum", href: "https://example.com/impressum" };++ it("accepts an empty list", () => {+ expect(footerLinksSchema.parse({ footerLinks: [] }).footerLinks).toEqual(+ [],+ );+ });++ it("trims labels and hrefs", () => {+ const result = footerLinksSchema.parse({+ footerLinks: [+ { label: " Impressum ", href: " https://example.com " },+ ],+ });+ expect(result.footerLinks[0]).toEqual({+ label: "Impressum",+ href: "https://example.com",+ });+ });++ it("rejects a link with an empty label", () => {+ expect(+ footerLinksSchema.safeParse({ footerLinks: [{ ...link, label: " " }] })+ .success,+ ).toBe(false);+ });++ it("rejects a link with an unsafe href", () => {+ expect(+ footerLinksSchema.safeParse({+ footerLinks: [{ ...link, href: "javascript:alert(1)" }],+ }).success,+ ).toBe(false);+ });++ it("caps the number of links", () => {+ expect(+ footerLinksSchema.safeParse({+ footerLinks: Array.from({ length: 6 }, () => link),+ }).success,+ ).toBe(false);+ });++ it("caps label length", () => {+ expect(+ footerLinksSchema.safeParse({+ footerLinks: [{ ...link, label: "x".repeat(41) }],+ }).success,+ ).toBe(false);+ });+});diff --git a/apps/web/src/features/instance-settings/schema.ts b/apps/web/src/features/instance-settings/schema.tsindex f60de6cfd..2f2711176 100644--- a/apps/web/src/features/instance-settings/schema.ts+++ b/apps/web/src/features/instance-settings/schema.ts@@ -36,3 +36,57 @@ export const updateBrandingLogoSchema = z.object({export const removeBrandingLogoSchema = z.object({logoType: brandingLogoTypeSchema,});++export const FOOTER_LINK_MAX_COUNT = 5;+export const FOOTER_LINK_MAX_LABEL_LENGTH = 40;+export const FOOTER_LINK_MAX_HREF_LENGTH = 2048;++/**+ * Admin-typed hrefs are rendered into an anchor, so the scheme is the whole+ * security question: `javascript:` must never survive validation. Parsing with+ * `URL` rather than pattern matching avoids the usual bypasses — browsers strip+ * control characters and tolerate case and whitespace variants, so `jAvA\tscript:`+ * is one scheme to a browser and several to a regex.+ *+ * Absolute http(s) only. Relative paths were considered and rejected: Rallly+ * does not serve legal pages itself, so a path only resolves behind a reverse+ * proxy fronting another app on the same host — a narrow setup whose admin can+ * as easily paste the full URL. A leading slash is now far likelier to be a+ * mistake, and these links must also work from emails (RAL-1559), where there+ * is no base to resolve against.+ */+export function isValidFooterLinkHref(href: string) {+ const value = href.trim();++ if (!value) {+ return false;+ }++ try {+ const { protocol } = new URL(value);+ return protocol === "http:" || protocol === "https:";+ } catch {+ return false;+ }+}++export const footerLinkSchema = z.object({+ label: z.string().trim().min(1).max(FOOTER_LINK_MAX_LABEL_LENGTH),+ href: z+ .string()+ .trim()+ .min(1)+ .max(FOOTER_LINK_MAX_HREF_LENGTH)+ // Message is deliberately un-localised: this schema is the server-side+ // contract and validates without a request locale. The control panel form+ // layers a translated message over the same predicate.+ .refine(isValidFooterLinkHref, { message: "Invalid URL" }),+});++export type FooterLink = z.infer<typeof footerLinkSchema>;++export const footerLinksSchema = z.object({+ footerLinks: z.array(footerLinkSchema).max(FOOTER_LINK_MAX_COUNT),+});++export type FooterLinks = z.infer<typeof footerLinksSchema>;diff --git a/apps/web/src/features/poll/components/poll-footer.tsx b/apps/web/src/features/poll/components/poll-footer.tsxindex eb8678555..a871bf60c 100644--- a/apps/web/src/features/poll/components/poll-footer.tsx+++ b/apps/web/src/features/poll/components/poll-footer.tsx@@ -1,45 +1,63 @@"use client";import { posthog } from "@rallly/posthog/client";import Link from "next/link";+import { InstanceFooterLinks } from "@/components/instance-footer-links";import { useBranding } from "@/features/branding/client";import { usePoll } from "@/features/poll/client";import { Trans } from "@/i18n/client";-export function PollFooter() {+/**+ * Footer for the participant-facing poll surfaces: the invite page, and the+ * admin page which previews it.+ *+ * Attribution and footer links are independent. Attribution can be hidden per+ * instance or per space; the instance's footer links carry legal disclosures+ * and are shown regardless.+ */+export function PollFooter({+ footerLinks = [],+}: {+ footerLinks?: { label: string; href: string }[];+}) {const { hideAttribution } = useBranding();const poll = usePoll();- if (hideAttribution || poll.space?.hideAttribution) {+ const isAttributionHidden = hideAttribution || poll.space?.hideAttribution;++ if (isAttributionHidden && footerLinks.length === 0) {return null;}return (- <div className="py-6 text-center text-muted-foreground text-sm">- <Trans- defaults="Powered by <a>{name}</a>"- i18nKey="poweredByRallly"- values={{ name: "rallly.co" }}- components={{- a: (- <Link- prefetch={false}- className="rounded-none border-b border-b-gray-500 font-semibold hover:text-primary"- href="https://rallly.co?utm_source=rallly&utm_medium=poll&utm_campaign=powered_by"- onClick={() => {- posthog?.capture("poll_footer:powered_by_link_click", {- pollId: poll.id,- spaceId: poll.spaceId,- tier: poll.space?.tier,- $groups: {- poll: poll.id,- ...(poll.spaceId ? { space: poll.spaceId } : {}),- },- });- }}- />- ),- }}- />+ <div className="flex flex-col items-center gap-3 py-6 text-center text-muted-foreground text-sm">+ <InstanceFooterLinks links={footerLinks} />+ {isAttributionHidden ? null : (+ <Trans+ defaults="Powered by <a>{name}</a>"+ i18nKey="poweredByRallly"+ values={{ name: "rallly.co" }}+ components={{+ a: (+ <Link+ prefetch={false}+ className="rounded-none border-b border-b-gray-500 font-semibold hover:text-primary"+ href="https://rallly.co?utm_source=rallly&utm_medium=poll&utm_campaign=powered_by"+ onClick={() => {+ posthog?.capture("poll_footer:powered_by_link_click", {+ pollId: poll.id,+ spaceId: poll.spaceId,+ tier: poll.space?.tier,+ $groups: {+ poll: poll.id,+ ...(poll.spaceId ? { space: poll.spaceId } : {}),+ },+ });+ }}+ />+ ),+ }}+ />+ )}</div>);}diff --git a/packages/database/prisma/migrations/20260820130000_add_instance_footer_links/migration.sql b/packages/database/prisma/migrations/20260820130000_add_instance_footer_links/migration.sqlnew file mode 100644index 000000000..74d9b781d--- /dev/null+++ b/packages/database/prisma/migrations/20260820130000_add_instance_footer_links/migration.sql@@ -0,0 +1,3 @@+-- AlterTable+ALTER TABLE "instance_settings"+ ADD COLUMN "footer_links" JSONB NOT NULL DEFAULT '[]';diff --git a/packages/database/prisma/models/instance-settings.prisma b/packages/database/prisma/models/instance-settings.prismaindex e1eae10ac..42895ada8 100644--- a/packages/database/prisma/models/instance-settings.prisma+++ b/packages/database/prisma/models/instance-settings.prisma@@ -16,6 +16,11 @@ model InstanceSettings {logoIcon String? @map("logo_icon")hideAttribution Boolean? @map("hide_attribution")+ // Ordered [{ label, href }] rendered in the login and invite page footers.+ // Not branding: this is how self-hosted instances satisfy local legal+ // disclosure requirements (Impressum, privacy policy), so it is not gated.+ footerLinks Json @default("[]") @map("footer_links")+createdAt DateTime @default(now()) @map("created_at")updatedAt DateTime @default(now()) @updatedAt @map("updated_at")