Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

✨ Accept SVG uploads for the wordmark logos (#2951)

Luke Vella64924550f532
diff --git a/apps/web/next.config.ts b/apps/web/next.config.ts
index 088d2c314..fb075df02 100644
--- a/apps/web/next.config.ts
+++ b/apps/web/next.config.ts
@@ -112,7 +112,9 @@ const nextConfig: NextConfig = {
async headers() {
return [
{
- source: "/:path*",
+ // /api/storage sets its own CSP (sandbox + frame-ancestors) per
+ // response; a config header for the same key would override it
+ source: "/((?!api/storage).*)",
headers: [
{
key: "Content-Security-Policy",
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 03e9be53d..d8cf75fb7 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -352,12 +352,14 @@
"ifNeedBe": "If need be",
"imageCropDialogTitle": "Crop image",
"imageUploadDescription": "Up to 2MB, JPG or PNG",
+ "imageUploadSvgDescription": "Up to 2MB, SVG, JPG or PNG",
"inappropriateContent": "Inappropriate content",
"increaseSeats": "Increase seats",
"instanceSettingsDescription": "Configure your instance settings",
"invalidEmailAddress": "Please enter a valid email address",
"invalidFileType": "Invalid file type",
"invalidFileTypeDescription": "Please upload a JPG or PNG file.",
+ "invalidFileTypeSvgDescription": "Please upload an SVG, JPG or PNG file.",
"invalidSessionDescription": "Sign out and log in again to continue.",
"invalidSessionLabel": "Session",
"invalidSessionTitle": "Your session is no longer valid",
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/space-settings-form.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/space-settings-form.tsx
index cc84656f4..9c28d9c1e 100644
--- a/apps/web/src/app/[locale]/(space)/settings/general/components/space-settings-form.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/space-settings-form.tsx
@@ -19,6 +19,8 @@ import {
ImageUploadControl,
ImageUploadPreview,
} from "@/components/image-upload";
+import type { AllowedMimeType } from "@/components/image-upload/types";
+import { rasterMimeTypes } from "@/components/image-upload/types";
import { InputWithSaveButton } from "@/components/input-with-save-button";
import {
getSpaceImageUploadUrlAction,
@@ -63,10 +65,14 @@ export function SpaceSettingsForm({
});
const handleGetUploadUrl = async (input: {
- fileType: "image/jpeg" | "image/png";
+ fileType: AllowedMimeType;
fileSize: number;
}) => {
- const result = await getSpaceImageUploadUrlAction(input);
+ // The control only accepts raster types here (default accept list)
+ const result = await getSpaceImageUploadUrlAction({
+ fileType: rasterMimeTypes.parse(input.fileType),
+ fileSize: input.fileSize,
+ });
if (!result?.data) {
throw new Error("Failed to get upload URL");
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/components/profile-picture.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/components/profile-picture.tsx
index a7b2e4fd8..6cf5af331 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/components/profile-picture.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/components/profile-picture.tsx
@@ -5,6 +5,7 @@ import {
ImageUploadControl,
ImageUploadPreview,
} from "@/components/image-upload";
+import { rasterMimeTypes } from "@/components/image-upload/types";
import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
import {
getAvatarUploadUrlAction,
@@ -40,7 +41,11 @@ function ProfilePictureUpload({
</ImageUploadPreview>
<ImageUploadControl
getUploadUrl={async (input) => {
- const result = await getAvatarUploadUrl.executeAsync(input);
+ // The control only accepts raster types here (default accept list)
+ const result = await getAvatarUploadUrl.executeAsync({
+ fileType: rasterMimeTypes.parse(input.fileType),
+ fileSize: input.fileSize,
+ });
if (!result?.data) {
throw new Error("Failed to get upload URL");
}
diff --git a/apps/web/src/app/[locale]/control-panel/branding/components/logo-upload-field.tsx b/apps/web/src/app/[locale]/control-panel/branding/components/logo-upload-field.tsx
index 1b8cb07ed..c50b1ae97 100644
--- a/apps/web/src/app/[locale]/control-panel/branding/components/logo-upload-field.tsx
+++ b/apps/web/src/app/[locale]/control-panel/branding/components/logo-upload-field.tsx
@@ -2,6 +2,7 @@
import { cn } from "@rallly/ui";
import { ImageUploadControl } from "@/components/image-upload";
+import type { AllowedMimeType } from "@/components/image-upload/types";
import type { BrandingLogoType } from "@/features/instance-settings/schema";
import { useSafeAction } from "@/lib/safe-action/client";
import {
@@ -31,6 +32,13 @@ const previewVariants: Record<
},
};
+// The icon feeds emails, where SVG rendering is unreliable — raster only
+const acceptedMimeTypes: Record<BrandingLogoType, AllowedMimeType[]> = {
+ logo: ["image/jpeg", "image/png", "image/svg+xml"],
+ logoDark: ["image/jpeg", "image/png", "image/svg+xml"],
+ logoIcon: ["image/jpeg", "image/png"],
+};
+
export function LogoUploadField({
logoType,
previewUrl,
@@ -48,7 +56,7 @@ export function LogoUploadField({
const removeLogo = useSafeAction(removeBrandingLogoAction);
const handleGetUploadUrl = async (input: {
- fileType: "image/jpeg" | "image/png";
+ fileType: AllowedMimeType;
fileSize: number;
}) => {
const result = await getBrandingLogoUploadUrlAction({
@@ -135,6 +143,7 @@ export function LogoUploadField({
</div>
<ImageUploadControl
crop={false}
+ accept={acceptedMimeTypes[logoType]}
disabled={disabled}
getUploadUrl={handleGetUploadUrl}
onUploadSuccess={async (imageKey) => {
diff --git a/apps/web/src/app/api/storage/[...key]/route.ts b/apps/web/src/app/api/storage/[...key]/route.ts
index 6eed5ebee..6f8faf1c7 100644
--- a/apps/web/src/app/api/storage/[...key]/route.ts
+++ b/apps/web/src/app/api/storage/[...key]/route.ts
@@ -11,7 +11,14 @@ import { getS3Client } from "@/lib/storage/s3";
const logger = createLogger("api/storage");
const MAX_UPLOAD_BYTES = 2 * 1024 * 1024;
-const ALLOWED_UPLOAD_CONTENT_TYPES = new Set(["image/jpeg", "image/png"]);
+// The signed upload key's extension is derived server-side from the
+// validated file type, so it decides which content type a PUT may carry —
+// without this, any signed URL (e.g. an avatar's) could store an SVG
+const CONTENT_TYPE_BY_KEY_EXTENSION: Record<string, string> = {
+ jpg: "image/jpeg",
+ png: "image/png",
+ svg: "image/svg+xml",
+};
async function getAvatar(key: string) {
const s3Client = getS3Client();
@@ -56,6 +63,13 @@ export async function GET(
headers: {
"Content-Type": contentType,
"Cache-Control": "public, max-age=3600",
+ // Uploads are served from the app origin. The sandbox neutralizes
+ // scripts in SVGs when the file is opened directly; it does not
+ // apply to <img> subresource loads, so rendering is unaffected.
+ // frame-ancestors is carried over from the global header, which
+ // excludes this path so it can't override the sandbox directive.
+ "Content-Security-Policy": "sandbox; frame-ancestors 'none'",
+ "X-Content-Type-Options": "nosniff",
},
});
} catch (error) {
@@ -89,8 +103,10 @@ export async function PUT(
}
const contentType = req.headers.get("content-type") ?? "";
+ const keyExtension = key.split(".").pop() ?? "";
+ const expectedContentType = CONTENT_TYPE_BY_KEY_EXTENSION[keyExtension];
- if (!ALLOWED_UPLOAD_CONTENT_TYPES.has(contentType)) {
+ if (!expectedContentType || contentType !== expectedContentType) {
return new NextResponse("Unsupported content type", { status: 415 });
}
diff --git a/apps/web/src/components/image-upload/image-upload.tsx b/apps/web/src/components/image-upload/image-upload.tsx
index 925c935ea..c04c7047a 100644
--- a/apps/web/src/components/image-upload/image-upload.tsx
+++ b/apps/web/src/components/image-upload/image-upload.tsx
@@ -10,7 +10,10 @@ import type {
ImageUploadPreviewProps,
ImageUploadProps,
} from "@/components/image-upload/types";
-import { allowedMimeTypes } from "@/components/image-upload/types";
+import {
+ allowedMimeTypes,
+ defaultAcceptedMimeTypes,
+} from "@/components/image-upload/types";
import { Trans, useTranslation } from "@/i18n/client";
import { useFeatureFlag } from "@/lib/feature-flags/client";
import {
@@ -31,8 +34,10 @@ export function ImageUploadControl({
onRemoveSuccess,
hasCurrentImage = false,
crop = true,
+ accept = defaultAcceptedMimeTypes,
disabled = false,
}: ImageUploadControlProps) {
+ const acceptsSvg = accept.includes("image/svg+xml");
const isStorageEnabled = useFeatureFlag("storage");
const { t } = useTranslation();
@@ -57,7 +62,7 @@ export function ImageUploadControl({
if (!file) return;
// Validate the file
- const validation = validateImageFile(file);
+ const validation = validateImageFile(file, accept);
if (!validation.success) {
switch (validation.error) {
case "invalidFileType":
@@ -66,9 +71,13 @@ export function ImageUploadControl({
defaultValue: "Invalid file type",
}),
{
- description: t("invalidFileTypeDescription", {
- defaultValue: "Please upload a JPG or PNG file.",
- }),
+ description: acceptsSvg
+ ? t("invalidFileTypeSvgDescription", {
+ defaultValue: "Please upload an SVG, JPG or PNG file.",
+ })
+ : t("invalidFileTypeDescription", {
+ defaultValue: "Please upload a JPG or PNG file.",
+ }),
},
);
break;
@@ -193,15 +202,22 @@ export function ImageUploadControl({
) : null}
</div>
<p className="text-muted-foreground text-xs">
- <Trans
- i18nKey="imageUploadDescription"
- defaults="Up to 2MB, JPG or PNG"
- />
+ {acceptsSvg ? (
+ <Trans
+ i18nKey="imageUploadSvgDescription"
+ defaults="Up to 2MB, SVG, JPG or PNG"
+ />
+ ) : (
+ <Trans
+ i18nKey="imageUploadDescription"
+ defaults="Up to 2MB, JPG or PNG"
+ />
+ )}
</p>
<input
ref={fileInputRef}
type="file"
- accept="image/*"
+ accept={accept.join(",")}
onChange={handleFileChange}
className="hidden"
/>
diff --git a/apps/web/src/components/image-upload/types.ts b/apps/web/src/components/image-upload/types.ts
index e60b8a98a..84bee6138 100644
--- a/apps/web/src/components/image-upload/types.ts
+++ b/apps/web/src/components/image-upload/types.ts
@@ -1,8 +1,20 @@
import * as z from "zod";
-export const allowedMimeTypes = z.enum(["image/jpeg", "image/png"]);
+export const allowedMimeTypes = z.enum([
+ "image/jpeg",
+ "image/png",
+ "image/svg+xml",
+]);
export type AllowedMimeType = z.infer<typeof allowedMimeTypes>;
+/** The subset the canvas-based crop pipeline can process. */
+export const rasterMimeTypes = z.enum(["image/jpeg", "image/png"]);
+
+export const defaultAcceptedMimeTypes: AllowedMimeType[] = [
+ "image/jpeg",
+ "image/png",
+];
+
export interface ImageUploadControlProps {
getUploadUrl: (input: {
fileType: AllowedMimeType;
@@ -16,6 +28,12 @@ export interface ImageUploadControlProps {
* the 1:1 crop dialog. Use for images with a free aspect ratio (e.g. logos).
*/
crop?: boolean;
+ /**
+ * Mime types this uploader takes. Defaults to JPEG/PNG; SVG may only be
+ * accepted together with crop={false} since the crop canvas can't process
+ * it.
+ */
+ accept?: AllowedMimeType[];
disabled?: boolean;
}
diff --git a/apps/web/src/features/instance-settings/schema.ts b/apps/web/src/features/instance-settings/schema.ts
index c6308119c..43af35f07 100644
--- a/apps/web/src/features/instance-settings/schema.ts
+++ b/apps/web/src/features/instance-settings/schema.ts
@@ -19,15 +19,23 @@ export const brandingLogoTypeSchema = z.enum(["logo", "logoDark", "logoIcon"]);
export type BrandingLogoType = z.infer<typeof brandingLogoTypeSchema>;
-export const brandingLogoUploadSchema = z.object({
- logoType: brandingLogoTypeSchema,
- fileType: z.enum(["image/jpeg", "image/png"]),
- fileSize: z
- .number()
- .int()
- .positive()
- .max(2 * 1024 * 1024),
-});
+export const brandingLogoUploadSchema = z
+ .object({
+ logoType: brandingLogoTypeSchema,
+ fileType: z.enum(["image/jpeg", "image/png", "image/svg+xml"]),
+ fileSize: z
+ .number()
+ .int()
+ .positive()
+ .max(2 * 1024 * 1024),
+ })
+ // The icon renders in emails, where SVG support is unreliable across
+ // clients — raster only for that slot
+ .refine(
+ (value) =>
+ !(value.logoType === "logoIcon" && value.fileType === "image/svg+xml"),
+ { message: "The logo icon does not support SVG" },
+ );
export const updateBrandingLogoSchema = z.object({
logoType: brandingLogoTypeSchema,
diff --git a/apps/web/src/lib/image-processing.ts b/apps/web/src/lib/image-processing.ts
index d212475f5..fb408f362 100644
--- a/apps/web/src/lib/image-processing.ts
+++ b/apps/web/src/lib/image-processing.ts
@@ -153,9 +153,10 @@ export type ImageValidationResult =
* @param file - File to validate
* @returns Object with success boolean and optional error message
*/
-export function validateImageFile(file: File): ImageValidationResult {
- const allowedMimeTypes = ["image/jpeg", "image/png"];
-
+export function validateImageFile(
+ file: File,
+ allowedMimeTypes: string[] = ["image/jpeg", "image/png"],
+): ImageValidationResult {
if (!allowedMimeTypes.includes(file.type)) {
return {
success: false,
diff --git a/apps/web/src/lib/storage/image-upload.ts b/apps/web/src/lib/storage/image-upload.ts
index cf05ea3d7..2f25faa76 100644
--- a/apps/web/src/lib/storage/image-upload.ts
+++ b/apps/web/src/lib/storage/image-upload.ts
@@ -42,12 +42,13 @@ export function verifyUploadToken(key: string, token: string) {
const mimeToExtension = {
"image/jpeg": "jpg",
"image/png": "png",
+ "image/svg+xml": "svg",
} as const;
export interface GetImageUploadUrlParams {
keyPrefix: string;
entityId: string;
- fileType: "image/jpeg" | "image/png";
+ fileType: keyof typeof mimeToExtension;
fileSize: number;
}
diff --git a/apps/web/src/lib/storage/upload-client.ts b/apps/web/src/lib/storage/upload-client.ts
index 323a8ac77..3e32f9724 100644
--- a/apps/web/src/lib/storage/upload-client.ts
+++ b/apps/web/src/lib/storage/upload-client.ts
@@ -3,7 +3,7 @@ import { AppError } from "@/lib/errors/app-error";
export interface UploadImageParams {
file: File;
url: string;
- fileType: "image/jpeg" | "image/png";
+ fileType: "image/jpeg" | "image/png" | "image/svg+xml";
}
export async function uploadImage({