Bug Summary
addForum in backend/controllers/forum.controller.js reads the topic author from the request body rather than from the authenticated session:
async function addForum(req, res, next) {
const topicData = {
title: req.body.title,
description: req.body.description,
user: req.body.user_id || req.body.user // client-supplied identity
};
const topic = await ForumTopic.create(topicData);
res.status(201).json(topic);
}
req.user (the verified JWT payload) is never used. Any authenticated user can supply another user's MongoDB ObjectId in user_id or user, and the forum topic will be attributed to that user. The impersonated user's name will then appear as the topic author in listForums (which populates user.name).
Steps to Reproduce
- Log in as User A and obtain a valid session cookie.
- Look up User B's
_id (visible in any alumni directory response).
- POST to
/api/v1/forums with { "title": "...", "description": "...", "user_id": "<User B _id>" }.
- Observe that the created topic shows User B's name as the author.
Expected Behavior
The user field on a new forum topic should always be set to req.user.id (the authenticated caller), never to a client-supplied value. The server is the authoritative source of identity.
Actual Behavior
Any authenticated user can author forum topics under any other user's identity by supplying a different user_id in the request body.
Affected File
backend/controllers/forum.controller.js, addForum function.
Hi @omkarhole, I would like to work on this fix under NSoC '26. Could you please assign/ this issue to me? Thank you.
Bug Summary
addForuminbackend/controllers/forum.controller.jsreads the topic author from the request body rather than from the authenticated session:req.user(the verified JWT payload) is never used. Any authenticated user can supply another user's MongoDB ObjectId inuser_idoruser, and the forum topic will be attributed to that user. The impersonated user's name will then appear as the topic author inlistForums(which populatesuser.name).Steps to Reproduce
_id(visible in any alumni directory response)./api/v1/forumswith{ "title": "...", "description": "...", "user_id": "<User B _id>" }.Expected Behavior
The
userfield on a new forum topic should always be set toreq.user.id(the authenticated caller), never to a client-supplied value. The server is the authoritative source of identity.Actual Behavior
Any authenticated user can author forum topics under any other user's identity by supplying a different
user_idin the request body.Affected File
backend/controllers/forum.controller.js,addForumfunction.Hi @omkarhole, I would like to work on this fix under NSoC '26. Could you please assign/ this issue to me? Thank you.