Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(profile): validate a picture's base64 even when a url is sent

Yudhi Armyndharis1ca6d3aaca27
diff --git a/src/modules/profile/dto/profile.dto.spec.ts b/src/modules/profile/dto/profile.dto.spec.ts
index e861d4dfd..135b4466c 100644
--- a/src/modules/profile/dto/profile.dto.spec.ts
+++ b/src/modules/profile/dto/profile.dto.spec.ts
@@ -35,6 +35,13 @@ describe('profile DTO validation', () => {
expect(await errorsFor(SetProfilePictureDto, { url: 'not-a-url', base64: 'QUJD' })).toHaveLength(0);
});
+ it('rejects a non-string base64 even when a url is also sent', async () => {
+ for (const url of ['https://example.com/a.jpg', 'not-a-url']) {
+ const body = { url, base64: ['x'], mimetype: 'image/png' };
+ expect((await errorsFor(SetProfilePictureDto, body)).length).toBeGreaterThan(0);
+ }
+ });
+
it('accepts only an absolute http(s) url, the only form the engines fetch', async () => {
for (const url of ['example.com/a.jpg', 'ftp://example.com/a.jpg']) {
expect((await errorsFor(SetProfilePictureDto, { url })).length).toBeGreaterThan(0);
diff --git a/src/modules/profile/dto/profile.dto.ts b/src/modules/profile/dto/profile.dto.ts
index a13c56a56..73bdff993 100644
--- a/src/modules/profile/dto/profile.dto.ts
+++ b/src/modules/profile/dto/profile.dto.ts
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
-import { IsString, IsNotEmpty, MaxLength, IsOptional, Matches, ValidateIf } from 'class-validator';
+import { IsString, IsNotEmpty, MaxLength, IsOptional, Matches } from 'class-validator';
import { IsMediaUrl } from '../../../common/media/media-url';
import { stripBase64DataUri } from '../../message/media-cap.util';
@@ -41,7 +41,6 @@ export class SetProfilePictureDto {
})
@IsOptional()
@IsString()
- @ValidateIf((o: SetProfilePictureDto) => !o.url)
base64?: string;
@ApiPropertyOptional({