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:
@@ -4,13 +4,13 @@ const ErrorResponse = require("../utils/errorResponse");
|
||||
|
||||
module.exports.createComment = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
const { slug, title, description, body, authorId } = req.body;
|
||||
const { slug, title, description, body } = req.body;
|
||||
const comment = await CommentService.createComment({
|
||||
slug,
|
||||
title,
|
||||
description,
|
||||
body,
|
||||
authorId
|
||||
authorId: req.payload.id
|
||||
});
|
||||
|
||||
res.status(201).json({
|
||||
|
||||
Reference in New Issue
Block a user