fix: corriger l'IDOR sur update/delete (parole, artiste, commentaire)

This commit is contained in:
2026-07-04 11:36:20 +04:00
parent bc5d0fb498
commit 291aa54912
5 changed files with 126 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
'use strict';
const { UnauthorizedError, NotFoundError } = require('@strapi/utils').errors
module.exports = async (policyContext, config, {strapi}) => {
const {request, params} = policyContext
if (!request?.header?.authorization) {
throw new UnauthorizedError('Opération non autorisée')
}
let jwtUserId
try {
({id: jwtUserId} = await strapi.plugins['users-permissions'].services.jwt.getToken(policyContext))
} catch (err) {
throw new UnauthorizedError('Opération non autorisée')
}
const documentId = params?.id ?? request.body?.data?.documentId
const document = await strapi.db.query(config.uid).findOne({
where: {documentId},
populate: {user: true}
})
if (!document) {
throw new NotFoundError('Ressource introuvable.')
}
if (document.user?.id !== jwtUserId) {
throw new UnauthorizedError('Opération non autorisée')
}
return true
}