fix : add typeof string validation for password fields in user endpoints#2360
fix : add typeof string validation for password fields in user endpoints#2360tmdeveloper007 wants to merge 1 commit into
Conversation
|
@tmdeveloper007 is attempting to deploy a commit to the Nisshchaya's projects Team on Vercel. A member of the Team first needs to authorize it. |
🎉 Thanks for your contribution, @tmdeveloper007!Your PR has passed our automated GSSoC quality checks. Here's a quick summary:
A maintainer will review your PR soon. Please be patient and available for feedback. 💪 GSSoC'26 automation · Maintainer: @nisshchayarathi |
|
Warning Review limit reached
More reviews will be available in 49 minutes and 59 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughTwo API route handlers receive explicit ChangesPassword Input Type Validation
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
🎉 Thanks for your contribution, @tmdeveloper007!Your PR has passed our automated GSSoC quality checks. Here's a quick summary:
A maintainer will review your PR soon. Please be patient and available for feedback. 💪 GSSoC'26 automation · Maintainer: @nisshchayarathi |
Prevents type confusion attacks where arrays or objects are passed as password values. The type check is placed after presence/length guards to preserve existing error messages for missing/invalid-length inputs. Arrays bypass the .length guard ([x].length >= 1) and would reach bcrypt as non-strings without this fix. Fixes nisshchayarathi#2355
🎉 Thanks for your contribution, @tmdeveloper007!Your PR has passed our automated GSSoC quality checks. Here's a quick summary:
A maintainer will review your PR soon. Please be patient and available for feedback. 💪 GSSoC'26 automation · Maintainer: @nisshchayarathi |
|
CI status: Build, Type Check, Lint, CodeQL, GSSoC checks all green. Note: Unit Tests job reports a pre-existing failure in app/api/auth/sessions/tests/route.test.ts due to a Jest/ESM module compatibility issue (jose/dist/browser/index.js). This failure exists on the upstream main branch and is unrelated to this PR. Ready for merge. |
Fixes #2355
Summary
The
POST /api/users/change-passwordandDELETE /api/users/meendpoints extractedcurrentPasswordandnewPasswordfrom the JSON body without validating that they are strings. Since both endpoints use.lengthfor validation (e.g.newPassword.length < 8), arrays like["p","a","s","s"]bypass those checks because arrays have a.lengthproperty.Malformed payloads could reach
bcrypt.compare()andbcrypt.hash()with non-string values, causing unhandled type errors or unpredictable coercion.Changes
app/api/users/change-password/route.ts: Addedtypeof currentPassword !== string || typeof newPassword !== stringguard before any other validation. Returns 400 if either field is not a string.app/api/users/me/route.ts: Addedtypeof body.password !== stringguard in theDELETEhandler before callingbcrypt.compare().Security Impact
Prevents type confusion attacks on sensitive authentication endpoints. All password fields are now strictly validated as string type before cryptographic operations.
Summary by CodeRabbit