|
| 1 | +'use strict'; |
| 2 | +// ListLockBleed (GHSA-4734-8vrg-8j3w): a list whose exception refuses a role |
| 3 | +// write (#4527) refuses that role's checklist and checklist-item writes over |
| 4 | +// REST too, and the attempt is in Admin Panel -> Problems. A list without the |
| 5 | +// refusal still takes the same writes. |
| 6 | +const { test, expect } = require('../fixtures'); |
| 7 | +const db = require('../helpers/db'); |
| 8 | + |
| 9 | +test('a list refusing a role write refuses its checklist REST writes (ListLockBleed)', async ({ request, board, user, user2 }) => { |
| 10 | + const original = db.getBoard(board.boardId).members; |
| 11 | + const [lockedListId, openListId] = board.listIds; |
| 12 | + const card = id => db.find('cards', { boardId: board.boardId, listId: id })[0]; |
| 13 | + const locked = card(lockedListId), open = card(openListId); |
| 14 | + const api = (method, url, data) => request[method](url, { |
| 15 | + headers: { Authorization: `Bearer ${user2.token}`, 'Content-Type': 'application/json' }, ...(data ? { data } : {}) }); |
| 16 | + const recorded = () => db.findOne('eventlog', { bleed: 'ListLockBleed' })?.count || 0; |
| 17 | + db.updateOne('boards', { _id: board.boardId }, { $set: { members: [...original.filter(m => m.userId !== user2.id), |
| 18 | + { userId: user2.id, isActive: true, isAdmin: false }] } }); |
| 19 | + db.updateOne('lists', { _id: lockedListId }, { $set: { roleExceptions: { normal: { write: false } } } }); |
| 20 | + const checklist = { _id: db.uid('locked-checklist'), cardId: locked._id, title: 'Locked', sort: 0 }; |
| 21 | + const item = { _id: db.uid('locked-item'), cardId: locked._id, checklistId: checklist._id, title: 'Locked item', sort: 0, isFinished: false }; |
| 22 | + db.insertOne('checklists', checklist); |
| 23 | + db.insertOne('checklistItems', item); |
| 24 | + try { |
| 25 | + const before = recorded(); |
| 26 | + const base = `/api/boards/${board.boardId}/cards/${locked._id}/checklists`; |
| 27 | + for (const [method, url, data] of [ |
| 28 | + ['post', base, { title: 'x' }], |
| 29 | + ['put', `${base}/${checklist._id}`, { title: 'renamed' }], |
| 30 | + ['post', `${base}/${checklist._id}/items`, { title: 'new item' }], |
| 31 | + ['put', `${base}/${checklist._id}/items/${item._id}`, { isFinished: 'true', title: 'changed' }], |
| 32 | + ['delete', `${base}/${checklist._id}/items/${item._id}`], |
| 33 | + ['delete', `${base}/${checklist._id}`], |
| 34 | + ]) { |
| 35 | + const res = await api(method, url, data); |
| 36 | + expect(res.status(), `${method.toUpperCase()} ${url}`).toBe(403); |
| 37 | + } |
| 38 | + expect(db.find('checklists', { cardId: locked._id })).toEqual([expect.objectContaining({ _id: checklist._id, title: 'Locked' })]); |
| 39 | + expect(db.find('checklistItems', { cardId: locked._id })).toEqual([expect.objectContaining({ _id: item._id, title: 'Locked item', isFinished: false })]); |
| 40 | + expect(recorded()).toBeGreaterThan(before); |
| 41 | + expect(db.findOne('users', { _id: user2.id }).loginDisabled || false).toBe(false); |
| 42 | + |
| 43 | + // Negative: the same member writes the checklists of a list without the refusal. |
| 44 | + const made = await api('post', `/api/boards/${board.boardId}/cards/${open._id}/checklists`, { title: 'Open', items: ['one'] }); |
| 45 | + expect(made.status()).toBe(200); |
| 46 | + const openId = (await made.json())._id; |
| 47 | + expect((await api('put', `/api/boards/${board.boardId}/cards/${open._id}/checklists/${openId}`, { title: 'Open renamed' })).status()).toBe(200); |
| 48 | + expect((await api('delete', `/api/boards/${board.boardId}/cards/${open._id}/checklists/${openId}`)).status()).toBe(200); |
| 49 | + // And the board admin, whom no list exception binds, writes the locked list's. |
| 50 | + const admin = await request.post(base, { headers: { Authorization: `Bearer ${user.token}`, 'Content-Type': 'application/json' }, data: { title: 'Admin' } }); |
| 51 | + expect(admin.status()).toBe(200); |
| 52 | + } finally { |
| 53 | + db.updateOne('boards', { _id: board.boardId }, { $set: { members: original } }); |
| 54 | + db.updateOne('lists', { _id: lockedListId }, { $unset: { roleExceptions: '' } }); |
| 55 | + db.deleteMany('checklists', { cardId: { $in: [locked._id, open._id] } }); |
| 56 | + db.deleteMany('checklistItems', { cardId: { $in: [locked._id, open._id] } }); |
| 57 | + } |
| 58 | +}); |
0 commit comments