Merge commit from fork
This PR fixes a security issue where authenticated users could access and modify data belonging to other users. The isOwnProfileOrAdmin() middleware was missing from several push subscription API routes. As a result, any authenticated user on the instance could manipulate the userId parameter in the URL to view or delete the push subscriptions of other users.
This commit is contained in:
30
server/utils/profileMiddleware.ts
Normal file
30
server/utils/profileMiddleware.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Permission } from '@server/lib/permissions';
|
||||
|
||||
export const isOwnProfile = (): Middleware => {
|
||||
return (req, res, next) => {
|
||||
if (req.user?.id !== Number(req.params.id)) {
|
||||
return next({
|
||||
status: 403,
|
||||
message: "You do not have permission to view this user's settings.",
|
||||
});
|
||||
}
|
||||
next();
|
||||
};
|
||||
};
|
||||
|
||||
export const isOwnProfileOrAdmin = (): Middleware => {
|
||||
const authMiddleware: Middleware = (req, res, next) => {
|
||||
if (
|
||||
!req.user?.hasPermission(Permission.MANAGE_USERS) &&
|
||||
req.user?.id !== Number(req.params.id)
|
||||
) {
|
||||
return next({
|
||||
status: 403,
|
||||
message: "You do not have permission to view this user's settings.",
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
return authMiddleware;
|
||||
};
|
||||
Reference in New Issue
Block a user