mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
fix(media): bound image work before public rendition
Check avatar uploads and raster fallbacks before decoding. Limit compressed bytes, decoded dimensions, GIF frames and the combined TIFF page budget.
This commit is contained in:
@@ -17,6 +17,7 @@ import { HttpException } from '@nestjs/common';
|
||||
|
||||
import type { Request, Response } from 'express';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { join } from 'node:path';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
|
||||
vi.mock('../../../src/nest/audit/client-ip', () => ({ getClientIp: vi.fn(() => '1.2.3.4') }));
|
||||
@@ -32,6 +33,7 @@ vi.mock('../../../src/nest/common/demo', () => ({ isDemoEmail: vi.fn(() => false
|
||||
const user = { id: 1, username: 'u', role: 'user', email: 'u@example.test' } as User;
|
||||
const req = { ip: '9.9.9.9', headers: {} } as Request;
|
||||
const res = {} as Response;
|
||||
const avatarFixture = join(__dirname, '../../fixtures/small-image.jpg');
|
||||
|
||||
function asvc(o: Partial<AuthService> = {}): AuthService {
|
||||
return {
|
||||
@@ -468,7 +470,10 @@ describe('AuthController (authenticated)', () => {
|
||||
});
|
||||
const saveAvatar = vi.fn().mockResolvedValue({ avatar: '/a.jpg' });
|
||||
expect(
|
||||
await ac(asvc({}), rl(), {}, { saveAvatar }).avatar(user, { filename: 'a.jpg' } as Express.Multer.File),
|
||||
await ac(asvc({}), rl(), {}, { saveAvatar }).avatar(user, {
|
||||
filename: 'a.jpg',
|
||||
path: avatarFixture,
|
||||
} as Express.Multer.File),
|
||||
).toEqual({ avatar: '/a.jpg' });
|
||||
});
|
||||
|
||||
@@ -972,9 +977,12 @@ describe('AuthController (authenticated)', () => {
|
||||
it('avatar saves when not in demo mode (env present but email is not a demo email)', async () => {
|
||||
process.env.DEMO_MODE = 'true';
|
||||
vi.mocked(isDemoEmail).mockReturnValue(false);
|
||||
const saveAvatar = vi.fn().mockResolvedValue({ avatar: '/b.png' });
|
||||
const saveAvatar = vi.fn().mockResolvedValue({ avatar: '/b.jpg' });
|
||||
expect(
|
||||
await ac(asvc({}), rl(), {}, { saveAvatar }).avatar(user, { filename: 'b.png' } as Express.Multer.File),
|
||||
).toEqual({ avatar: '/b.png' });
|
||||
await ac(asvc({}), rl(), {}, { saveAvatar }).avatar(user, {
|
||||
filename: 'b.jpg',
|
||||
path: avatarFixture,
|
||||
} as Express.Multer.File),
|
||||
).toEqual({ avatar: '/b.jpg' });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user