fix(chat): use authenticated session identity for sendMessage username [NSoC'26]#164
Open
anshul23102 wants to merge 1 commit into
Open
Conversation
…est body [NSoC'26] sendMessage read the username field directly from req.body and stored it in Supabase. Any authenticated user could supply username: 'other_user' in the request body to post messages appearing to come from a different person. The route already requires authenticateUser, so req.user is always populated. The username is now derived from req.user.user_metadata (falling back to req.user.email) so it always reflects the real authenticated identity. Closes Shriii19#160
|
@anshul23102 is attempting to deploy a commit to the shreemp194-gmailcom's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
👋 Thank you for opening this pull request! I will review your changes and assist you soon. |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
sendMessageread theusernamefield fromreq.bodyand stored it in Supabase without any server-side identity verification. Any authenticated user could supplyusername: "teammate"in the request body to post messages that appear to come from a different person.Root Cause
The route already requires
authenticateUser, which populatesreq.userfrom the Supabase session. The handler ignored this and trusted the client-supplied value instead.Changes Made
backend/controllers/chat.controller.jsusernamefrom destructuredreq.body. Derivedusernamefromreq.user.user_metadata.username, falling back toreq.user.user_metadata.name, thenreq.user.email, then"Anonymous".Testing Done
username: "other_user"in body now stores the real authenticated user's name.Checklist
Closes #160