Skip to content

Commit

Permalink
fix: improve query params sanitization (prod) (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
amateima authored Jan 16, 2023
1 parent cf8ec6e commit c57e44b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions src/modules/deposit/dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiProperty } from "@nestjs/swagger";
import { IsEnum, IsNumberString, IsOptional, IsString } from "class-validator";
import { Type } from "class-transformer";
import { IsEnum, IsInt, IsOptional, IsString, Max, Min } from "class-validator";

export class GetDepositsQuery {
@IsOptional()
Expand All @@ -16,13 +17,19 @@ export class GetDepositsQuery {
status: "filled" | "pending";

@IsOptional()
@IsNumberString({ no_symbols: true })
@ApiProperty({ example: "10", required: false })
@IsInt()
@Min(1)
@Max(100)
@Type(() => Number)
@ApiProperty({ example: 10, required: false })
limit: string;

@IsOptional()
@IsNumberString({ no_symbols: true })
@ApiProperty({ example: "0", required: false })
@IsInt()
@Min(0)
@Max(10_000_000)
@Type(() => Number)
@ApiProperty({ example: 0, required: false })
offset: string;

@IsOptional()
Expand Down
17 changes: 12 additions & 5 deletions src/modules/referral/entry-points/http/dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiProperty } from "@nestjs/swagger";
import { IsDate, IsDateString, IsNumberString, IsString, Length } from "class-validator";
import { Type } from "class-transformer";
import { IsDateString, IsInt, IsNumberString, IsString, Length, Max, Min } from "class-validator";

export class GetReferralsSummaryQuery {
@IsString()
Expand All @@ -14,12 +15,18 @@ export class GetReferralsQuery {
@ApiProperty({ example: "0x9A8f92a830A5cB89a3816e3D267CB7791c16b04D", minLength: 42, maxLength: 42, required: true })
address: string;

@IsNumberString()
@ApiProperty({ example: "10", required: false })
@IsInt()
@Min(1)
@Max(100)
@Type(() => Number)
@ApiProperty({ example: 10, required: true })
limit: string;

@IsNumberString()
@ApiProperty({ example: "0", required: false })
@IsInt()
@Min(0)
@Max(10_000_000)
@Type(() => Number)
@ApiProperty({ example: 0, required: true })
offset: string;
}

Expand Down

0 comments on commit c57e44b

Please sign in to comment.