Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
BadRequestException,
Controller,
Get,
Param,
Expand All @@ -10,6 +11,7 @@
import { JwtAuthGuard } from "./common/guards/keycloak.guard";
import { ApiBasicAuth, ApiHeader } from "@nestjs/swagger";
import { RbacAuthGuard } from "./common/guards/rbac.guard";
import * as path from "path";

Check warning on line 14 in src/app.controller.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `node:path` over `path`.

See more on https://sonarcloud.io/project/issues?id=tekdi_user-microservice&issues=AZ1E10b4Cq1enWct0Rcp&open=AZ1E10b4Cq1enWct0Rcp&pullRequest=710

@Controller()
export class AppController {
Expand All @@ -27,6 +29,10 @@

@Get("files/:fileName")
seeUploadedFile(@Param("fileName") fileName: string, @Res() res) {
return res.sendFile(fileName, { root: "./uploads" });
const sanitizedFileName = path.basename(fileName);
if (sanitizedFileName !== fileName) {
throw new BadRequestException("Invalid file name");
}
return res.sendFile(sanitizedFileName, { root: "./uploads" });
}
}
14 changes: 7 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ async function bootstrap() {
exclude: [{ path: "health", method: RequestMethod.GET }],
});

// app.useGlobalPipes(
// new ValidationPipe({
// whitelist: true,
// forbidNonWhitelisted: true,
// transform: true,
// }),
// );
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
transform: true,
}),
);

const config = new DocumentBuilder()
.setTitle("Shiksha Platform")
Expand Down