fix(comments): use authenticated user id as authorId instead of req.body

Accepting authorId from the request body allowed any authenticated user
to create comments impersonating another user. The author is now always
the authenticated user from req.payload.
This commit is contained in:
2026-04-26 20:31:37 +02:00
parent 6245d1eabd
commit ece5506904
+2 -2
View File
@@ -4,13 +4,13 @@ const ErrorResponse = require("../utils/errorResponse");
module.exports.createComment = asyncHandler(async (req, res, next) => { module.exports.createComment = asyncHandler(async (req, res, next) => {
try { try {
const { slug, title, description, body, authorId } = req.body; const { slug, title, description, body } = req.body;
const comment = await CommentService.createComment({ const comment = await CommentService.createComment({
slug, slug,
title, title,
description, description,
body, body,
authorId authorId: req.payload.id
}); });
res.status(201).json({ res.status(201).json({