Skip to content

Commit 7dc956f

Browse files
✨ Make view and deploy attachment endpoints public (as attachment id is unguessable and not disclosed)
1 parent 4a0b37d commit 7dc956f

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ node_modules
44

55
gen-api
66
caddy/data
7+
8+
/attachments

server/openapi.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ paths:
606606
responses:
607607
"200":
608608
description: ""
609+
content:
610+
application/octet-stream:
611+
schema:
612+
type: string
613+
format: binary
609614
/attachments/downloadById/{id}:
610615
get:
611616
operationId: downloadById
@@ -618,6 +623,11 @@ paths:
618623
responses:
619624
"200":
620625
description: ""
626+
content:
627+
application/octet-stream:
628+
schema:
629+
type: string
630+
format: binary
621631
/conversations/getAllByProjectId:
622632
get:
623633
operationId: getAllConversations

server/src/attachments/attachments.controller.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
BadRequestException,
33
Controller,
44
Get,
5+
HttpStatus,
56
NotFoundException,
67
Param,
78
Post,
@@ -11,6 +12,7 @@ import {
1112
UseInterceptors,
1213
} from '@nestjs/common';
1314
import { FileInterceptor } from '@nestjs/platform-express';
15+
import { ApiProduces, ApiResponse } from '@nestjs/swagger';
1416
import { Response } from 'express';
1517
import { RequireAuthMethod } from 'src/iam/iam.decorators';
1618
import { ServerSdkAuthenticatedRequest } from 'src/iam/iam.types';
@@ -59,18 +61,24 @@ export class AttachmentsController {
5961
});
6062
}
6163

64+
@ApiResponse({
65+
schema: {
66+
type: 'string',
67+
format: 'binary',
68+
},
69+
status: HttpStatus.OK,
70+
})
71+
@ApiProduces('application/octet-stream')
6272
@Get('viewById/:id')
6373
async serveById(@Param('id') id: string, @Res() res: Response) {
6474
const attachment = await this.attachmentsService.findById(id);
6575

66-
if (!attachment || !attachment.isPublic) {
76+
if (!attachment) {
6777
throw new NotFoundException('Attachment not found.');
6878
}
6979

7080
const data = await this.storageService.download(attachment.id);
7181

72-
console.log('attachment.mimeType', attachment.mimeType);
73-
7482
res.setHeader(
7583
'Content-Disposition',
7684
`inline; filename="${attachment.name}"`,
@@ -81,11 +89,19 @@ export class AttachmentsController {
8189
res.send(data);
8290
}
8391

92+
@ApiResponse({
93+
schema: {
94+
type: 'string',
95+
format: 'binary',
96+
},
97+
status: HttpStatus.OK,
98+
})
99+
@ApiProduces('application/octet-stream')
84100
@Get('downloadById/:id')
85101
async downloadById(@Param('id') id: string, @Res() res: Response) {
86102
const attachment = await this.attachmentsService.findById(id);
87103

88-
if (!attachment || !attachment.isPublic) {
104+
if (!attachment) {
89105
throw new NotFoundException('Attachment not found.');
90106
}
91107

0 commit comments

Comments
 (0)