Skip to content

Commit 6a246e6

Browse files
committed
Revert "feat: enhance image upload validation across the application (calcom#22766)"
This reverts commit 5acdb20.
1 parent 3a0229f commit 6a246e6

16 files changed

Lines changed: 64 additions & 1128 deletions

File tree

apps/api/v1/pages/api/users/[userId]/_patch.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import type { NextApiRequest } from "next";
33
import { HttpError } from "@calcom/lib/http-error";
44
import { uploadAvatar } from "@calcom/lib/server/avatar";
55
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
6-
import { validateBase64Image } from "@calcom/lib/server/imageValidation";
7-
import { resizeBase64Image } from "@calcom/lib/server/resizeBase64Image";
86
import prisma from "@calcom/prisma";
97
import type { Prisma } from "@calcom/prisma/client";
108

@@ -126,25 +124,10 @@ export async function patchHandler(req: NextApiRequest) {
126124
}
127125

128126
if (avatar) {
129-
const validation = validateBase64Image(avatar);
130-
if (!validation.isValid) {
131-
throw new HttpError({
132-
statusCode: 400,
133-
message: `Invalid avatar image: ${validation.error}`,
134-
});
135-
}
136-
137-
try {
138-
body.avatarUrl = await uploadAvatar({
139-
userId: query.userId,
140-
avatar: await resizeBase64Image(avatar),
141-
});
142-
} catch (error) {
143-
throw new HttpError({
144-
statusCode: 400,
145-
message: error instanceof Error ? error.message : "Failed to upload avatar",
146-
});
147-
}
127+
body.avatarUrl = await uploadAvatar({
128+
userId: query.userId,
129+
avatar: await (await import("@calcom/lib/server/resizeBase64Image")).resizeBase64Image(avatar),
130+
});
148131
}
149132

150133
const data = await prisma.user.update({

apps/web/app/api/avatar/[uuid]/route.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { z } from "zod";
66

77
import { AVATAR_FALLBACK, WEBAPP_URL } from "@calcom/lib/constants";
88
import { convertSvgToPng } from "@calcom/lib/server/imageUtils";
9-
import { validateBase64Image } from "@calcom/lib/server/imageValidation";
109
import prisma from "@calcom/prisma";
1110

1211
const querySchema = z.object({
@@ -47,12 +46,6 @@ async function handler(req: NextRequest, { params }: { params: Promise<Params> }
4746
},
4847
});
4948

50-
const validation = validateBase64Image(data);
51-
if (!validation.isValid) {
52-
const url = new URL(AVATAR_FALLBACK, WEBAPP_URL).toString();
53-
return NextResponse.redirect(url, 302);
54-
}
55-
5649
// Convert SVG to PNG if needed and update the database
5750
if (data.startsWith("data:image/svg+xml;base64,")) {
5851
const pngData = await convertSvgToPng(data);
@@ -79,11 +72,6 @@ async function handler(req: NextRequest, { params }: { params: Promise<Params> }
7972
"Content-Type": "image/png",
8073
"Content-Length": imageResp.length.toString(),
8174
"Cache-Control": "max-age=86400",
82-
// Security headers to prevent XSS
83-
"X-Content-Type-Options": "nosniff",
84-
"Content-Disposition": "inline",
85-
"X-Frame-Options": "DENY",
86-
"Content-Security-Policy": "default-src 'none'; img-src 'self'",
8775
},
8876
status: 200,
8977
});

apps/web/public/static/locales/en/common.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,14 +3581,6 @@
35813581
"webhook_metadata": "Metadata",
35823582
"stats": "Stats",
35833583
"booking_status": "Booking status",
3584-
"unsupported_file_type": "{{type}} files cannot be uploaded as images",
3585-
"only_image_files_allowed": "Only image files are allowed",
3586-
"failed_to_validate_image_file": "Failed to validate image file",
3587-
"invalid_image_file_format": "Invalid image file format",
3588-
"svg_contains_dangerous_content": "SVG contains potentially dangerous content",
3589-
"unrecognized_image_format": "Unrecognized image format or invalid file",
3590-
"invalid_base64_format": "Invalid base64 format",
3591-
"empty_image_data": "Empty image data",
35923584
"visit": "Visit",
35933585
"location_custom_label_input_label": "Custom label on booking page",
35943586
"meeting_link": "Meeting link",

packages/app-store/_utils/oauth/updateProfilePhotoGoogle.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { OAuth2Client } from "googleapis-common";
33

44
import logger from "@calcom/lib/logger";
55
import { uploadAvatar } from "@calcom/lib/server/avatar";
6-
import { validateBase64Image } from "@calcom/lib/server/imageValidation";
76
import { UserRepository } from "@calcom/lib/server/repository/user";
87
import { resizeBase64Image } from "@calcom/lib/server/resizeBase64Image";
98
import prisma from "@calcom/prisma";
@@ -17,17 +16,12 @@ export async function updateProfilePhotoGoogle(oAuth2Client: OAuth2Client, userI
1716
return;
1817
}
1918

19+
// Handle base64 data
2020
if (
2121
avatarUrl.startsWith("data:image/png;base64,") ||
2222
avatarUrl.startsWith("data:image/jpeg;base64,") ||
2323
avatarUrl.startsWith("data:image/jpg;base64,")
2424
) {
25-
const validation = validateBase64Image(avatarUrl);
26-
if (!validation.isValid) {
27-
logger.error(`Invalid avatar image from Google OAuth: ${validation.error}`);
28-
return;
29-
}
30-
3125
const resizedAvatarUrl = await uploadAvatar({
3226
avatar: await resizeBase64Image(avatarUrl),
3327
userId,

packages/lib/constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ export const MAX_EVENT_DURATION_MINUTES = 1440;
6868
/** Minimum duration allowed for an event in minutes */
6969
export const MIN_EVENT_DURATION_MINUTES = 1;
7070

71-
/** Maximum file size allowed for banner uploads in bytes (5MB) */
72-
export const MAX_BANNER_SIZE = 5 * 1024 * 1024;
73-
7471
export const HOSTED_CAL_FEATURES = process.env.NEXT_PUBLIC_HOSTED_CAL_FEATURES || !IS_SELF_HOSTED;
7572

7673
export const PUBLIC_QUERY_RESERVATION_INTERVAL_SECONDS =

packages/lib/imageValidationConstants.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

packages/lib/server/avatar.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@ import { v4 as uuidv4 } from "uuid";
33
import { prisma } from "@calcom/prisma";
44

55
import { convertSvgToPng } from "./imageUtils";
6-
import { validateBase64Image } from "./imageValidation";
76

87
export const uploadAvatar = async ({ userId, avatar: data }: { userId: number; avatar: string }) => {
9-
const validation = validateBase64Image(data);
10-
if (!validation.isValid) {
11-
throw new Error(`Invalid image data: ${validation.error}`);
12-
}
13-
148
const objectKey = uuidv4();
159
const processedData = await convertSvgToPng(data);
1610

@@ -46,11 +40,6 @@ export const uploadLogo = async ({
4640
logo: string;
4741
isBanner?: boolean;
4842
}): Promise<string> => {
49-
const validation = validateBase64Image(data);
50-
if (!validation.isValid) {
51-
throw new Error(`Invalid image data: ${validation.error}`);
52-
}
53-
5443
const objectKey = uuidv4();
5544
const processedData = await convertSvgToPng(data);
5645

0 commit comments

Comments
 (0)