Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(web): check base64 length before decoding logo upload

Richie McIlroy972de6dbdda6
diff --git a/apps/web/app/api/desktop/[...route]/organization-branding.ts b/apps/web/app/api/desktop/[...route]/organization-branding.ts
index 8dd280d35..ab78d4f0c 100644
--- a/apps/web/app/api/desktop/[...route]/organization-branding.ts
+++ b/apps/web/app/api/desktop/[...route]/organization-branding.ts
@@ -211,16 +211,17 @@ export function decodeOrganizationLogoUpdate(
throw new OrganizationBrandingValidationError("Invalid logo data");
}
- const buffer = Buffer.from(logo.data, "base64");
- if (buffer.byteLength === 0) {
+ const decodedLength = Buffer.byteLength(logo.data, "base64");
+ if (decodedLength === 0) {
throw new OrganizationBrandingValidationError("Logo file is empty");
}
- if (buffer.byteLength > MAX_ORGANIZATION_LOGO_BYTES) {
+ if (decodedLength > MAX_ORGANIZATION_LOGO_BYTES) {
throw new OrganizationBrandingValidationError(
"Logo file must be less than 1MB",
);
}
+ const buffer = Buffer.from(logo.data, "base64");
const data = new Uint8Array(buffer);
if (!isImageDataForContentType(data, logo.contentType)) {
throw new OrganizationBrandingValidationError("Logo file type is invalid");