mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
A guard that refuses in silence tells the operator nothing. Four of the five
findings have an ATTEMPT that can be told apart from ordinary use, so each
refusal is now recorded through server/lib/securityLog into the `security`
stream - which is what Admin Panel / Problems counts and lists - with a catalog
entry naming it after its Hall of Fame page:
authz.card-delete PurgeBleed critical CWE-639
authz.card-member GuestBleed high CWE-639
authz.board-list StaleBleed medium CWE-863
spoofing.author AuthorBleed medium CWE-345
What counts as an attempt is the part worth being careful about, because a log
that fires on ordinary use is a log nobody reads:
- PurgeBleed logs when the card id names a card that exists but is NOT on the
authorised board. A card id that names nothing is an ordinary 404 and writes
nothing. Telling those apart needs the bare lookup back, so it is there once
more - after the constrained one has already failed, named `elsewhere` for
what it is, and never handed to cardRemover.
- GuestBleed logs the ids dropped from a members/assignees array. An array whose
ids are all fine writes nothing.
- StaleBleed logs when the caller HAS revoked memberships that the listing
withheld - counted, not named, because the point is that somebody removed is
still asking and the titles are the thing being withheld. A caller with no
revoked membership writes nothing.
- AuthorBleed logs when the body still carries an authorId naming somebody
other than the session. Naming yourself is what an old client does and is not
an attempt.
HashBleed deliberately has NO key, and the catalog says why: every call to
GET/PUT /api/users/{userId} is a legitimate admin call. The fault was in what
the answer carried, not in who asked, so a log line there would fire on ordinary
use and say nothing about an attacker.
`req.body.authorId` is still READ - that is how the spoof is noticed - but never
used as an identity, and the guard pins that: not stored as userId, not passed
to cardCreation, cardRemover or customFieldCreation, and read exactly once in
cards.js, inside noteAuthorSpoof.
tests/restApiIdorBatch.test.cjs is at 14 checks, five of them negative: that
ordinary use writes nothing on all four, that HashBleed has no key and neither
endpoint logs, and that every securityLog call sits in a try/catch - a log that
throws would turn a refusal into a 500, which makes the logging its own denial
of service.
Thanks to ybsun0215 and xet7 !
317 lines
10 KiB
JavaScript
317 lines
10 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { WebApp } from 'meteor/webapp';
|
|
import { Random } from 'meteor/random';
|
|
import { Authentication } from '/server/authentication';
|
|
import { sendJsonResult } from '/server/apiMiddleware';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import Activities from '/models/activities';
|
|
import Cards from '/models/cards';
|
|
import CustomFields from '/models/customFields';
|
|
import { ensureIndex } from '/server/lib/mongoStartup';
|
|
|
|
async function customFieldCreation(userId, doc) {
|
|
await Activities.insertAsync({
|
|
userId,
|
|
activityType: 'createCustomField',
|
|
boardId: doc.boardIds[0],
|
|
customFieldId: doc._id,
|
|
});
|
|
}
|
|
|
|
async function customFieldDeletion(userId, doc) {
|
|
await Activities.insertAsync({
|
|
userId,
|
|
activityType: 'deleteCustomField',
|
|
boardId: doc.boardIds[0],
|
|
customFieldId: doc._id,
|
|
});
|
|
}
|
|
|
|
async function customFieldEdit(userId, doc) {
|
|
// #5390: deleting a custom field from a board ($pull boardIds) calls this; an
|
|
// activity may not exist (e.g. the field never had a value set), so guard the
|
|
// lookup instead of dereferencing `.value` on undefined, which threw and
|
|
// aborted the whole delete.
|
|
const activity = await ReactiveCache.getActivity({ customFieldId: doc._id });
|
|
const customFieldValue = activity ? activity.value : undefined;
|
|
await Activities.insertAsync({
|
|
userId,
|
|
activityType: 'setCustomField',
|
|
boardId: doc.boardIds[0],
|
|
customFieldId: doc._id,
|
|
customFieldValue,
|
|
listId: doc.listId,
|
|
swimlaneId: doc.swimlaneId,
|
|
});
|
|
}
|
|
|
|
Meteor.startup(async () => {
|
|
await ensureIndex(CustomFields, { modifiedAt: -1 });
|
|
await ensureIndex(CustomFields, { boardIds: 1 });
|
|
});
|
|
|
|
CustomFields.after.insert(async (userId, doc) => {
|
|
await customFieldCreation(userId, doc);
|
|
|
|
if (doc.alwaysOnCard) {
|
|
CustomFields.addToAllCards(doc);
|
|
}
|
|
});
|
|
|
|
CustomFields.before.update(async (userId, doc, fieldNames, modifier) => {
|
|
if (fieldNames.includes('boardIds') && modifier.$pull) {
|
|
await Cards.updateAsync(
|
|
{ boardId: modifier.$pull.boardIds, 'customFields._id': doc._id },
|
|
{ $pull: { customFields: { _id: doc._id } } },
|
|
{ multi: true },
|
|
);
|
|
await customFieldEdit(userId, doc);
|
|
await Activities.removeAsync({
|
|
customFieldId: doc._id,
|
|
boardId: modifier.$pull.boardIds,
|
|
listId: doc.listId,
|
|
swimlaneId: doc.swimlaneId,
|
|
});
|
|
} else if (fieldNames.includes('boardIds') && modifier.$push) {
|
|
await Activities.insertAsync({
|
|
userId,
|
|
activityType: 'createCustomField',
|
|
boardId: modifier.$push.boardIds,
|
|
customFieldId: doc._id,
|
|
});
|
|
}
|
|
});
|
|
|
|
CustomFields.after.update((userId, doc) => {
|
|
if (doc.alwaysOnCard) {
|
|
CustomFields.addToAllCards(doc);
|
|
}
|
|
});
|
|
|
|
CustomFields.before.remove(async (userId, doc) => {
|
|
await customFieldDeletion(userId, doc);
|
|
await Activities.removeAsync({
|
|
customFieldId: doc._id,
|
|
});
|
|
|
|
await Cards.updateAsync(
|
|
{ boardId: { $in: doc.boardIds }, 'customFields._id': doc._id },
|
|
{ $pull: { customFields: { _id: doc._id } } },
|
|
{ multi: true },
|
|
);
|
|
});
|
|
|
|
WebApp.handlers.get('/api/boards/:boardId/custom-fields', async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
await Authentication.checkBoardAccess(req.userId, paramBoardId);
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: (await ReactiveCache.getCustomFields({ boardIds: { $in: [paramBoardId] } })).map(cf => ({
|
|
_id: cf._id,
|
|
name: cf.name,
|
|
type: cf.type,
|
|
})),
|
|
});
|
|
});
|
|
|
|
WebApp.handlers.get('/api/boards/:boardId/custom-fields/:customFieldId', async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
const paramCustomFieldId = req.params.customFieldId;
|
|
await Authentication.checkBoardAccess(req.userId, paramBoardId);
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: await ReactiveCache.getCustomField({
|
|
_id: paramCustomFieldId,
|
|
boardIds: { $in: [paramBoardId] },
|
|
}),
|
|
});
|
|
});
|
|
|
|
WebApp.handlers.post('/api/boards/:boardId/custom-fields', async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
|
|
const board = await ReactiveCache.getBoard(paramBoardId);
|
|
const id = await CustomFields.direct.insertAsync({
|
|
name: req.body.name,
|
|
type: req.body.type,
|
|
settings: req.body.settings,
|
|
showOnCard: req.body.showOnCard,
|
|
automaticallyOnCard: req.body.automaticallyOnCard,
|
|
showLabelOnMiniCard: req.body.showLabelOnMiniCard,
|
|
showSumAtTopOfList: req.body.showSumAtTopOfList,
|
|
boardIds: [board._id],
|
|
});
|
|
|
|
const customField = await ReactiveCache.getCustomField({
|
|
_id: id,
|
|
boardIds: { $in: [paramBoardId] },
|
|
});
|
|
// GHSA-6jr3-42jf-vhm5: the createCustomField activity records the session
|
|
// identity, not an `authorId` the caller chose for itself. A body that still
|
|
// names somebody else is the attempt, and is recorded for Admin Panel /
|
|
// Problems the same way the card paths record it.
|
|
try {
|
|
const claimed = req.body && req.body.authorId;
|
|
if (claimed && String(claimed) !== String(req.userId)) {
|
|
require('/server/lib/securityLog').record({
|
|
key: 'spoofing.author', action: 'ignored', source: 'POST custom-fields',
|
|
userId: req.userId,
|
|
detail: `ignored authorId "${claimed}" from the body; recorded the session instead`,
|
|
});
|
|
}
|
|
} catch (e) { /* logging must never break the guard */ }
|
|
await customFieldCreation(req.userId, customField);
|
|
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: {
|
|
_id: id,
|
|
},
|
|
});
|
|
});
|
|
|
|
WebApp.handlers.put('/api/boards/:boardId/custom-fields/:customFieldId', async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
const paramFieldId = req.params.customFieldId;
|
|
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
|
|
|
|
const boardScopedField = {
|
|
_id: paramFieldId,
|
|
boardIds: { $in: [paramBoardId] },
|
|
};
|
|
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'name')) {
|
|
await CustomFields.direct.updateAsync(boardScopedField, { $set: { name: req.body.name } });
|
|
}
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'type')) {
|
|
await CustomFields.direct.updateAsync(boardScopedField, { $set: { type: req.body.type } });
|
|
}
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'settings')) {
|
|
await CustomFields.direct.updateAsync(boardScopedField, { $set: { settings: req.body.settings } });
|
|
}
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'showOnCard')) {
|
|
await CustomFields.direct.updateAsync(boardScopedField, { $set: { showOnCard: req.body.showOnCard } });
|
|
}
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'automaticallyOnCard')) {
|
|
await CustomFields.direct.updateAsync(boardScopedField, { $set: { automaticallyOnCard: req.body.automaticallyOnCard } });
|
|
}
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'alwaysOnCard')) {
|
|
await CustomFields.direct.updateAsync(boardScopedField, { $set: { alwaysOnCard: req.body.alwaysOnCard } });
|
|
}
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'showLabelOnMiniCard')) {
|
|
await CustomFields.direct.updateAsync(boardScopedField, { $set: { showLabelOnMiniCard: req.body.showLabelOnMiniCard } });
|
|
}
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'showSumAtTopOfList')) {
|
|
await CustomFields.direct.updateAsync(boardScopedField, { $set: { showSumAtTopOfList: req.body.showSumAtTopOfList } });
|
|
}
|
|
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: { _id: paramFieldId },
|
|
});
|
|
});
|
|
|
|
WebApp.handlers.post('/api/boards/:boardId/custom-fields/:customFieldId/dropdown-items', async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
const paramCustomFieldId = req.params.customFieldId;
|
|
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
|
|
const paramItems = req.body.items;
|
|
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'items') && Array.isArray(paramItems)) {
|
|
await CustomFields.direct.updateAsync(
|
|
{
|
|
_id: paramCustomFieldId,
|
|
boardIds: { $in: [paramBoardId] },
|
|
},
|
|
{
|
|
$push: {
|
|
'settings.dropdownItems': {
|
|
$each: paramItems
|
|
.filter(name => typeof name === 'string')
|
|
.map(name => ({
|
|
_id: Random.id(6),
|
|
name,
|
|
})),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: { _id: paramCustomFieldId },
|
|
});
|
|
});
|
|
|
|
WebApp.handlers.put(
|
|
'/api/boards/:boardId/custom-fields/:customFieldId/dropdown-items/:dropdownItemId',
|
|
async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
const paramDropdownItemId = req.params.dropdownItemId;
|
|
const paramCustomFieldId = req.params.customFieldId;
|
|
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
|
|
const paramName = req.body.name;
|
|
|
|
if (Object.prototype.hasOwnProperty.call(req.body, 'name')) {
|
|
await CustomFields.direct.updateAsync(
|
|
{
|
|
_id: paramCustomFieldId,
|
|
boardIds: { $in: [paramBoardId] },
|
|
'settings.dropdownItems._id': paramDropdownItemId,
|
|
},
|
|
{
|
|
$set: {
|
|
'settings.dropdownItems.$': {
|
|
_id: paramDropdownItemId,
|
|
name: paramName,
|
|
},
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: { _id: paramDropdownItemId },
|
|
});
|
|
},
|
|
);
|
|
|
|
WebApp.handlers.delete(
|
|
'/api/boards/:boardId/custom-fields/:customFieldId/dropdown-items/:dropdownItemId',
|
|
async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
const paramCustomFieldId = req.params.customFieldId;
|
|
const paramDropdownItemId = req.params.dropdownItemId;
|
|
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
|
|
|
|
await CustomFields.direct.updateAsync(
|
|
{ _id: paramCustomFieldId, boardIds: { $in: [paramBoardId] } },
|
|
{
|
|
$pull: {
|
|
'settings.dropdownItems': { _id: paramDropdownItemId },
|
|
},
|
|
},
|
|
);
|
|
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: { _id: paramCustomFieldId },
|
|
});
|
|
},
|
|
);
|
|
|
|
WebApp.handlers.delete('/api/boards/:boardId/custom-fields/:customFieldId', async function(req, res) {
|
|
const paramBoardId = req.params.boardId;
|
|
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
|
|
const id = req.params.customFieldId;
|
|
await CustomFields.removeAsync({ _id: id, boardIds: { $in: [paramBoardId] } });
|
|
sendJsonResult(res, {
|
|
code: 200,
|
|
data: {
|
|
_id: id,
|
|
},
|
|
});
|
|
});
|