Skip to content

feat(api): express-validator middleware for auth#170

Open
imsanupm wants to merge 1 commit intogothinkster:masterfrom
imsanupm:feat/input-validation-middleware
Open

feat(api): express-validator middleware for auth#170
imsanupm wants to merge 1 commit intogothinkster:masterfrom
imsanupm:feat/input-validation-middleware

Conversation

@imsanupm
Copy link
Copy Markdown

feat(api): Add express-validator middleware for authentication security

What does this PR do?

Implements input validation middleware using express-validator for user registration and login endpoints, preventing malicious/invalid data from reaching the business logic.

Security + UX Improvements*

  • Registration validation: Username (min 3 chars), valid email format, password (min 6 chars)
  • Login validation: Email format + non-empty password
  • Email normalization: Converts Test@Example.comtest@example.com
  • RealWorld spec compliant: Returns 422 Unprocessable Entity with detailed error messages
Screenshot From 2026-02-26 22-45-59 Screenshot From 2026-02-26 22-46-37 Screenshot From 2026-02-26 22-47-48 Screenshot From 2026-02-26 22-48-18

 Security hardening:
- src/middleware/validation.ts → Registration/Login validation
- Username (3+ chars), email format, password (6+ chars)
- RealWorld spec 422 error responses
- Email normalization + sanitization

 Thunder Client proof:
- Invalid inputs → 422 validation errors
- Valid inputs → 201/200 success

 Open Source Contribution PR gothinkster#2/3 ✓
@secure-code-warrior-for-github
Copy link
Copy Markdown

Micro-Learning Topic: Weak password policy (Detected by phrase)

Matched on "empty password"

What is this? (2min video)

A weak password policy will allow users to select poor passwords that are vulnerable to dictionary attacks.

Try a challenge in Secure Code Warrior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant