Skip to content

Commit 5fb05a6

Browse files
Apply task security rules when fetching a single challenge
1 parent 3077356 commit 5fb05a6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/services/ChallengeService.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,14 @@ async function getChallenge (currentUser, id) {
895895
// }
896896
// delete challenge.typeId
897897

898+
// Check if challenge is task and apply security rules
899+
if (_.get(challenge, 'task.isTask', false) && _.get(challenge, 'task.isAssigned', false)) {
900+
const skipAccessCheck = !currentUser ? false : currentUser.isMachine || helper.hasAdminRole(currentUser)
901+
if (!skipAccessCheck && currentUser.userId !== _.get(challenge, 'task.memberId')) {
902+
throw new errors.ForbiddenError(`You don't have access to view this challenge`)
903+
}
904+
}
905+
898906
// Remove privateDescription for unregistered users
899907
if (currentUser) {
900908
if (!currentUser.isMachine) {

0 commit comments

Comments
 (0)