Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add uuid validation at controller level #1660

Merged
merged 1 commit into from
Jul 31, 2024
Merged
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
5 changes: 4 additions & 1 deletion backend/core/src/applications/applications.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Get,
Header,
Param,
ParseUUIDPipe,
Post,
Put,
Query,
Expand Down Expand Up @@ -82,7 +83,9 @@ export class ApplicationsController {

@Get(`:id`)
@ApiOperation({ summary: "Get application by id", operationId: "retrieve" })
async retrieve(@Param("id") applicationId: string): Promise<ApplicationDto> {
async retrieve(
@Param("id", new ParseUUIDPipe({ version: "4" })) applicationId: string
): Promise<ApplicationDto> {
const app = await this.applicationsService.findOne(applicationId)
return mapTo(ApplicationDto, app)
}
Expand Down
5 changes: 4 additions & 1 deletion backend/core/src/auth/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Get,
Header,
Param,
ParseUUIDPipe,
Post,
Put,
Query,
Expand Down Expand Up @@ -205,7 +206,9 @@ export class UserController {
@Get(`:id`)
@ApiOperation({ summary: "Get user by id", operationId: "retrieve" })
@UseGuards(DefaultAuthGuard, AuthzGuard)
async retrieve(@Param("id") userId: string): Promise<UserDto> {
async retrieve(
@Param("id", new ParseUUIDPipe({ version: "4" })) userId: string
): Promise<UserDto> {
return mapTo(UserDto, await this.userService.findOneOrFail({ id: userId }))
}

Expand Down
5 changes: 3 additions & 2 deletions backend/core/src/listings/listings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ClassSerializerInterceptor,
Headers,
Header,
ParseUUIDPipe,
} from "@nestjs/common"
import { ListingsService } from "./listings.service"
import { ApiBearerAuth, ApiExtraModels, ApiOperation, ApiTags } from "@nestjs/swagger"
Expand Down Expand Up @@ -101,7 +102,7 @@ export class ListingsController {
@UsePipes(new ValidationPipe(defaultValidationPipeOptions))
async retrieve(
@Headers("language") language: Language,
@Param("id") listingId: string,
@Param("id", new ParseUUIDPipe({ version: "4" })) listingId: string,
@Query() queryParams: ListingsRetrieveQueryParams
): Promise<ListingDto> {
if (listingId === undefined || listingId === "undefined") {
Expand All @@ -127,7 +128,7 @@ export class ListingsController {
@Delete(`:id`)
@ApiOperation({ summary: "Delete listing by id", operationId: "delete" })
@UsePipes(new ValidationPipe(defaultValidationPipeOptions))
async delete(@Param("id") listingId: string) {
async delete(@Param("id", new ParseUUIDPipe({ version: "4" })) listingId: string) {
await this.listingsService.delete(listingId)
}
}
Loading