Skip to content

Commit 6cf5c66

Browse files
committed
fix: remote arbitrary file overwrite on file upload endpoint
1 parent 51478b6 commit 6cf5c66

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@types/qrcode-svg": "^1.1.5",
6969
"@types/sharp": "^0.32.0",
7070
"@types/supertest": "^6.0.2",
71+
"@types/uuid": "^10.0.0",
7172
"@typescript-eslint/eslint-plugin": "^8.6.0",
7273
"@typescript-eslint/parser": "^8.6.0",
7374
"cross-env": "^7.0.3",

backend/src/file/file.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as fs from "fs";
1212
import * as mime from "mime-types";
1313
import { ConfigService } from "src/config/config.service";
1414
import { PrismaService } from "src/prisma/prisma.service";
15+
import { validate as isValidUUID } from "uuid";
1516
import { SHARE_DIRECTORY } from "../constants";
1617

1718
@Injectable()
@@ -28,7 +29,11 @@ export class FileService {
2829
file: { id?: string; name: string },
2930
shareId: string,
3031
) {
31-
if (!file.id) file.id = crypto.randomUUID();
32+
if (!file.id) {
33+
file.id = crypto.randomUUID();
34+
} else if (!isValidUUID(file.id)) {
35+
throw new BadRequestException("Invalid file ID format");
36+
}
3237

3338
const share = await this.prisma.share.findUnique({
3439
where: { id: shareId },

0 commit comments

Comments
 (0)