mirror of
https://github.com/docmost/docmost.git
synced 2026-05-25 20:12:45 +08:00
fix: validate public avatar path (#1416)
This commit is contained in:
@@ -50,6 +50,7 @@ import { validate as isValidUUID } from 'uuid';
|
|||||||
import { EnvironmentService } from '../../integrations/environment/environment.service';
|
import { EnvironmentService } from '../../integrations/environment/environment.service';
|
||||||
import { TokenService } from '../auth/services/token.service';
|
import { TokenService } from '../auth/services/token.service';
|
||||||
import { JwtAttachmentPayload, JwtType } from '../auth/dto/jwt-payload';
|
import { JwtAttachmentPayload, JwtType } from '../auth/dto/jwt-payload';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AttachmentController {
|
export class AttachmentController {
|
||||||
@@ -356,6 +357,11 @@ export class AttachmentController {
|
|||||||
throw new BadRequestException('Invalid image attachment type');
|
throw new BadRequestException('Invalid image attachment type');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const filenameWithoutExt = path.basename(fileName, path.extname(fileName));
|
||||||
|
if (!isValidUUID(filenameWithoutExt)) {
|
||||||
|
throw new BadRequestException('Invalid file id');
|
||||||
|
}
|
||||||
|
|
||||||
const filePath = `${getAttachmentFolderPath(attachmentType, workspace.id)}/${fileName}`;
|
const filePath = `${getAttachmentFolderPath(attachmentType, workspace.id)}/${fileName}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user