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

Added max length validation in user registration, company name and password which solve unhandled error in backend #495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
44 changes: 23 additions & 21 deletions libraries/nestjs-libraries/src/dtos/auth/create.org.user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import {IsDefined, IsEmail, IsString, MinLength, ValidateIf} from "class-validator";
import {IsDefined, IsEmail, IsString, MaxLength, MinLength, ValidateIf} from "class-validator";
import {Provider} from '@prisma/client';

export class CreateOrgUserDto {
@IsString()
@MinLength(3)
@IsDefined()
@ValidateIf(o => !o.providerToken)
password: string;
@IsString()
@MinLength(3)
@MaxLength(64)
@IsDefined()
@ValidateIf((o) => !o.providerToken)
password: string;

@IsString()
@IsDefined()
provider: Provider;
@IsString()
@IsDefined()
provider: Provider;

@IsString()
@IsDefined()
@ValidateIf(o => !o.password)
providerToken: string;
@IsString()
@IsDefined()
@ValidateIf((o) => !o.password)
providerToken: string;

@IsEmail()
@IsDefined()
@ValidateIf(o => !o.providerToken)
email: string;
@IsEmail()
@IsDefined()
@ValidateIf((o) => !o.providerToken)
email: string;
Comment on lines +21 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding MaxLength validation for email field

While email validation is present, consider adding a MaxLength validator to prevent excessive input lengths, similar to other fields.

 @IsEmail()
 @IsDefined()
 @ValidateIf((o) => !o.providerToken)
+@MaxLength(254)  // RFC 5321 maximum length
 email: string;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@IsEmail()
@IsDefined()
@ValidateIf((o) => !o.providerToken)
email: string;
@IsEmail()
@IsDefined()
@ValidateIf((o) => !o.providerToken)
@MaxLength(254) // RFC 5321 maximum length
email: string;


@IsString()
@IsDefined()
@MinLength(3)
company: string;
@IsString()
@IsDefined()
@MinLength(3)
@MaxLength(128)
company: string;
}