-
Notifications
You must be signed in to change notification settings - Fork 0
Add stricter authentication validation rules #52
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
Conversation
WalkthroughThe pull request strengthens authentication validation by enhancing the SigninSchema and SignupSchema in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/lib/validations/auth.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: lint-and-build
🔇 Additional comments (2)
src/lib/validations/auth.ts (2)
27-27: LGTM! Good addition for type consistency.The new
SignupFormValuestype export mirrors the existingSigninFormValuespattern and provides proper type inference for consumers of the schema.
4-4: The original review comment contains a false assumption about the codebase.The concern about existing users with whitespace in emails cannot cause authentication or duplicate account issues because:
- Normalization at logic layer: Both signin and signup normalize emails with
trim().toLowerCase()before any database operations (signin/logic.ts:19, signup/logic.ts:21)- Normalized on storage: During signup, the normalized email is stored in the database
- Normalized on lookup: During signin, the normalized email is used in the database query
- New application: This project is only ~6 weeks old (created Sept 6, 2025) with minimal existing user data
The validation-layer trimming (auth.ts lines 4, 16) is redundant but harmless since trimming already occurs at the logic layer before database operations. There is no risk of mismatches between trimmed input and stored data.
Likely an incorrect or invalid review comment.
| password: z.string() | ||
| .trim() | ||
| .min(8, { message: 'Password must be at least 8 characters long.' }) | ||
| .regex(/[A-Z]/, { message: 'Password must contain at least one uppercase letter.' }) | ||
| .regex(/[a-z]/, { message: 'Password must contain at least one lowercase letter.' }) | ||
| .regex(/[0-9]/, { message: 'Password must contain at least one digit.' }) | ||
| .regex(/[^a-zA-Z0-9]/, { message: 'Password must contain at least one special character.' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Remove password trimming and reconsider stricter rules for signin.
Two critical issues:
-
Trimming passwords is a security risk: The
.trim()on line 6 removes intentional leading/trailing whitespace from passwords. Users may include such whitespace as part of their password, and removing it will prevent authentication and reduce password entropy. -
Stricter validation breaks existing users: Applying enhanced password requirements (min 8 chars, character diversity) to the signin schema will reject existing users whose passwords meet the old requirements (min 6 chars) but not the new ones, preventing them from signing in.
Apply this diff to remove password trimming from both schemas:
export const SigninSchema = z.object({
email: z.string().trim().email({ message: 'Invalid email address.' }),
password: z.string()
- .trim()
.min(8, { message: 'Password must be at least 8 characters long.' })
.regex(/[A-Z]/, { message: 'Password must contain at least one uppercase letter.' })
.regex(/[a-z]/, { message: 'Password must contain at least one lowercase letter.' })
.regex(/[0-9]/, { message: 'Password must contain at least one digit.' })
.regex(/[^a-zA-Z0-9]/, { message: 'Password must contain at least one special character.' })
});
export const SignupSchema = z.object({
name: z.string().trim().min(2, { message: 'Name must be at least 2 characters long.' }),
email: z.string().trim().email({ message: 'Invalid email address.' }),
password: z.string()
- .trim()
.min(8, { message: 'Password must be at least 8 characters long.' })
.regex(/[A-Z]/, { message: 'Password must contain at least one uppercase letter.' })
.regex(/[a-z]/, { message: 'Password must contain at least one lowercase letter.' })
.regex(/[0-9]/, { message: 'Password must contain at least one digit.' })
.regex(/[^a-zA-Z0-9]/, { message: 'Password must contain at least one special character.' })
});For the signin schema, consider using the original lenient validation (min 6 chars) to avoid breaking existing users, or implement a password migration strategy:
export const SigninSchema = z.object({
email: z.string().trim().email({ message: 'Invalid email address.' }),
- password: z.string()
- .min(8, { message: 'Password must be at least 8 characters long.' })
- .regex(/[A-Z]/, { message: 'Password must contain at least one uppercase letter.' })
- .regex(/[a-z]/, { message: 'Password must contain at least one lowercase letter.' })
- .regex(/[0-9]/, { message: 'Password must contain at least one digit.' })
- .regex(/[^a-zA-Z0-9]/, { message: 'Password must contain at least one special character.' })
+ password: z.string().min(6, { message: 'Password must be at least 6 characters.' })
});Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In src/lib/validations/auth.ts around lines 5 to 11, the password validator
currently calls .trim() and applies strict complexity rules; remove the .trim()
call to preserve leading/trailing whitespace as valid password characters, and
for the signin schema revert to the original lenient validation (minimum length
6 and no added complexity regexes) so existing users are not rejected; ensure
the signup schema can keep stricter rules if desired but do not apply those
stricter rules to the signin schema without a documented migration strategy.
Overview: This PR introduces stricter validation rules for authentication inputs to enhance security and data integrity.
Changes
src/lib/validations/auth.ts.src/lib/validations/auth.ts.Summary by CodeRabbit