fix: block verification field updates in profile endpoint#271
Conversation
|
Linter diff in the way? Review this PR in Change Stack to focus on meaningful changes and expand context only when needed. Warning Review limit reached
More reviews will be available in 49 minutes and 1 second. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ 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: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughupdateProfile now computes allowedFields from the users collection model, excludes verification-related keys ( ChangesVerification Field Protection
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
|
Hi @yash-pouranik, This PR addresses Issue #269 by preventing verification-related account state fields from being updated through the generic profile update endpoint. The fix explicitly removes Looking forward to your review. Thank you! |
|
does this PR requires any changes? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Get the PR diff
gh pr view 271 --repo geturbackend/urBackend --json files,body,title
# Get the diff of the changed files
gh pr diff 271 --repo geturbackend/urBackendLength of output: 3471
✅ What's good
|
|
Please follow this approach |
|
Thank you for the review @yash-pouranik. That's a good point regarding the denylist approach. I'll review the user schema and update the implementation to use an allowlist of profile fields that can be modified through the endpoint, which will provide better long-term protection for newly added sensitive fields. I'll push an updated revision shortly. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/public-api/src/controllers/userAuth.controller.js (1)
1531-1571:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winDuplicate
usersColConfigdeclaration causes syntax error.The pipeline failure indicates:
SyntaxError: Identifier 'usersColConfig' has already been declaredat line 1570. The new allowlist code correctly declaresusersColConfigat line 1531, but the original declaration at line 1570 was not removed, causing a duplicateconstin the same scope.🐛 Proposed fix: Remove the duplicate declaration
if (req.body[field] !== undefined) { updateData[field] = req.body[field]; } } if (updateData.username !== undefined) { const username = updateData.username; if (typeof username !== 'string' || username.length < 3 || username.length > 50) { return res.status(400).json({ error: "Username must be between 3 and 50 characters." }); } } const sanitizedUpdateData = sanitize(updateData); - const usersColConfig = project.collections.find(c => c.name === 'users'); - if (!usersColConfig) return res.status(404).json({ error: "Auth collection not found" }); const connection = await getConnection(project._id); const Model = getCompiledModel(connection, usersColConfig, project._id, project.resources.db.isExternal);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/public-api/src/controllers/userAuth.controller.js` around lines 1531 - 1571, The duplicate declaration of usersColConfig causes a SyntaxError; remove the second const usersColConfig = project.collections.find(c => c.name === 'users') and reuse the earlier usersColConfig variable instead, keeping the existence check (if (!usersColConfig) return res.status(404)... ) and the subsequent logic (allowedFields, updateData, sanitize) intact so no redeclaration occurs in the same scope.Source: Pipeline failures
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@apps/public-api/src/controllers/userAuth.controller.js`:
- Around line 1531-1571: The duplicate declaration of usersColConfig causes a
SyntaxError; remove the second const usersColConfig = project.collections.find(c
=> c.name === 'users') and reuse the earlier usersColConfig variable instead,
keeping the existence check (if (!usersColConfig) return res.status(404)... )
and the subsequent logic (allowedFields, updateData, sanitize) intact so no
redeclaration occurs in the same scope.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9ba60167-8c5c-462d-ba27-5c65b018de40
📒 Files selected for processing (1)
apps/public-api/src/controllers/userAuth.controller.js
|
Hi @yash-pouranik, I've updated the implementation to follow the allowlist approach as requested. Changes made:
I also ran the public-api test suite locally after the update:
Kindly review the updated changes. Thank you! |
|
@Nitin-kumar-yadav1307 |
🚀 Pull Request Description
Fixes #269
🛠️ Type of Change
Summary
This PR prevents verification-related account state fields from being modified through the generic
updateProfileendpoint.Root Cause
The
updateProfile()controller removed sensitive fields such aspassword,email, and_idbefore processing updates, but verification-related fields (emailVerified,isVerified, andisverified) were not restricted.As a result, authenticated users could include these fields in profile update requests and potentially modify verification state outside the intended verification workflow.
Changes Made
Added explicit removal of:
emailVerifiedisVerifiedisverifiedPreserved the existing profile update flow.
Kept existing sanitization and validation behavior unchanged.
🧪 Testing & Validation
Backend Verification:
Frontend Verification:
📸 Screenshots / Recordings
Not applicable.
✅ Checklist
Summary by CodeRabbit