Skip to content

Commit 3a01de6

Browse files
authored
Merge pull request #1814 from CVEProject/dr_cross_admin_conversation_bug
Fixes a cross-admin conversation bug where users could post conversations to targets outside of their own organization.
2 parents 588a76a + abc5073 commit 3a01de6

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/controller/conversation.controller/conversation.controller.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ async function createConversationForTargetUUID (req, res, next) {
5050
}
5151

5252
const isSecretariat = await orgRepo.isSecretariatByShortName(req.ctx.org)
53+
54+
if (!isSecretariat) {
55+
const orgUUID = await orgRepo.getOrgUUID(req.ctx.org)
56+
if (targetUUID !== orgUUID) {
57+
return res.status(403).json({ error: 'UNAUTHORIZED', message: 'Unauthorized' })
58+
}
59+
}
60+
5361
const result = await repo.createConversation(targetUUID, body, user, isSecretariat, { session })
5462
await session.commitTransaction()
5563
if (!result) {

test/integration-tests/conversation/conversationTest.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ describe('Testing Conversation endpoints', () => {
160160
})
161161

162162
context('Negative Tests', () => {
163+
it('Should fail to post a conversation to a different org as a non-Secretariat Admin', async () => {
164+
const conversation = {
165+
visibility: 'public',
166+
body: 'test'
167+
}
168+
const randomUUID = '123e4567-e89b-12d3-a456-426614174000'
169+
await chai.request(app)
170+
.post(`/api/conversation/target/${randomUUID}`)
171+
.set(constants.nonSecretariatUserHeaders2) // Admin of win_5
172+
.send(conversation)
173+
.then((res, err) => {
174+
expect(err).to.be.undefined
175+
expect(res).to.have.status(403)
176+
expect(res.body).to.haveOwnProperty('error')
177+
expect(res.body.error).to.equal('UNAUTHORIZED')
178+
})
179+
})
180+
163181
it('Should fail to post a conversation with no body', async () => {
164182
await chai.request(app)
165183
.post(`/api/conversation/target/${orgUUID}`)

0 commit comments

Comments
 (0)