Skip to content

Commit d950d21

Browse files
committed
Prevent path traversal attack
1 parent 2dd7218 commit d950d21

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

backend/src/api/photos/PhotosController.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ export class PhotosController extends Controller {
195195
@Path() identifier: string,
196196
@Request() req: express.Request
197197
): Promise<void> {
198+
// Ensure this is a valid photo identifier so they can't get arbitrary s3 objects
199+
const photoRepo = getRepository(Photo);
200+
const photoExists = await photoRepo.exists({
201+
where: { identifier: identifier },
202+
});
203+
204+
if (!photoExists) {
205+
throw new NotFound();
206+
}
207+
198208
const command = new GetObjectCommand({
199209
Bucket: 'fourties-photos',
200210
Key: `jpg/${identifier}.jpg`,

0 commit comments

Comments
 (0)