fix(forum): derive topic author from JWT session instead of request body#269
Merged
omkarhole merged 1 commit intoJun 2, 2026
Merged
Conversation
Closes omkarhole#263 addForum read the topic author from req.body.user_id or req.body.user, allowing any authenticated caller to supply another user's ObjectId and have the topic attributed to that user. req.user (the verified JWT payload) was never consulted. Replace the client-supplied field with req.user.id so the author is always the authenticated caller, regardless of what the request body contains.
|
@anshul23102 is attempting to deploy a commit to the omkarhole's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
Closes #263
addForuminbackend/controllers/forum.controller.jsusedreq.body.user_id || req.body.useras the topic author. Any authenticated caller could supply a different user's MongoDB ObjectId in the request body and have the forum topic attributed to that user, with the victim's name shown as the author.What Changed
backend/controllers/forum.controller.jsonly:user_id/userfields withreq.user.id || req.user._id(the verified JWT payload).Testing
/api/v1/forumswithuser_idset to User B's ID. Verify the created topic shows User A as the author.Type of Change
NSoC '26 contribution