Files
wekan/server/migrations/deleteDuplicateEmptyLists.js
T
Lauri Ojansivu ebcd02be6f Hall of Fame regression audit: every fixed vulnerability still fixed, siblings of six of them closed.
Every Hall of Fame vulnerability without a test naming it (24 names, 30
advisories) was checked against the current source. No fix had been
reverted. Looking for the same mistake elsewhere found siblings:

- FloppyBleed: the fs-path-heal upgrade step joined an attachment's
  stored name into candidate paths as-is; a record a client inserted
  named ../../../etc/passwd made the next upgrade copy that file into
  storage - an arbitrary file read. Only the name's last component is
  used now; the bulk move limits a legacy name's extension the same way.
- FilePathBleed (GHSA-g6vm-7757-pr88): the insert guard looked only
  inside versions; with versions left out ostrio:files falls back to a
  top-level path, which removing the record deletes and validation
  reads. A client's top-level path is refused for attachments and
  avatars, recorded by the existing canaries.
- MoveStorageBleed: validateAttachment, which deletes a file failing the
  current upload rules, was open to anybody who could see the board, a
  public one included. Only who may change the file, or a site admin,
  validates now; a refusal is recorded (authz.attachment-validate).
- HookUrlBleed / IntegrationBleed: the REST reads of a board's
  integrations gave the webhook URL - whose path is its secret - to
  every member reading the board; non-admins get what the publication
  gives them.
- AttachmentMigrationBleed: four migration methods answered any
  logged-in user about any board, deleteDuplicateEmptyLists.getStatus
  with a private board's list titles; they require a visible board and
  record refusals (authz.migration-board).
- LegacyAttachBleed (GHSA-xcxp-hx9w-q5q9) and MimeStorageBleed
  (GHSA-rv5g-5p4g-3v89): the legacy route judged a name dangerous only
  for .svg, the response policy missed x-javascript, ecmascript, xsl and
  +xml types, and the sniffers missed <tag/onx= handlers.

OIDCBleed refusals are now recorded in Admin Panel / Problems too. New
suites name the vulnerabilities they guard, existing ones name the
advisories they already covered, and tests/securityRegressionCoverage
counts 128 of 137 published vulnerabilities with a named test (was 125).

Thanks to xet7 !
2026-10-27 16:28:12 +02:00

373 lines
12 KiB
JavaScript

/**
* Delete Duplicate Empty Lists Migration
*
* Safely deletes empty duplicate lists from a board:
* 1. First converts any shared lists to per-swimlane lists
* 2. Only deletes per-swimlane lists that:
* - Have no cards
* - Have another list with the same title on the same board that DOES have cards
* 3. This prevents deleting unique empty lists and only removes redundant duplicates
*/
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { ReactiveCache } from '/imports/reactiveCache';
import { assertMigrationBoardVisible } from '/server/lib/migrationBoardAccess';
import Boards from '/models/boards';
import Lists from '/models/lists';
import Cards from '/models/cards';
import Swimlanes from '/models/swimlanes';
class DeleteDuplicateEmptyListsMigration {
constructor() {
this.name = 'deleteDuplicateEmptyLists';
this.version = 1;
}
/**
* Check if migration is needed for a board
*/
async needsMigration(boardId) {
try {
const lists = await ReactiveCache.getLists({ boardId });
const cards = await ReactiveCache.getCards({ boardId });
// Check if there are any empty lists that have a duplicate with the same title containing cards
for (const list of lists) {
// Skip shared lists
if (!list.swimlaneId || list.swimlaneId === '') {
continue;
}
// Check if list is empty
const listCards = cards.filter(card => card.listId === list._id);
if (listCards.length === 0) {
// Check if there's a duplicate list with the same title that has cards
const duplicateListsWithSameTitle = lists.filter(l =>
l._id !== list._id &&
l.title === list.title &&
l.boardId === boardId
);
for (const duplicateList of duplicateListsWithSameTitle) {
const duplicateListCards = cards.filter(card => card.listId === duplicateList._id);
if (duplicateListCards.length > 0) {
return true; // Found an empty list with a duplicate that has cards
}
}
}
}
return false;
} catch (error) {
console.error('Error checking if deleteDuplicateEmptyLists migration is needed:', error);
return false;
}
}
/**
* Execute the migration
*/
async executeMigration(boardId) {
try {
const results = {
sharedListsConverted: 0,
listsDeleted: 0,
errors: []
};
// Step 1: Convert shared lists to per-swimlane lists first
const conversionResult = await this.convertSharedListsToPerSwimlane(boardId);
results.sharedListsConverted = conversionResult.listsConverted;
// Step 2: Delete empty per-swimlane lists
const deletionResult = await this.deleteEmptyPerSwimlaneLists(boardId);
results.listsDeleted = deletionResult.listsDeleted;
return {
success: true,
changes: [
`Converted ${results.sharedListsConverted} shared lists to per-swimlane lists`,
`Deleted ${results.listsDeleted} empty per-swimlane lists`
],
results
};
} catch (error) {
console.error('Error executing deleteDuplicateEmptyLists migration:', error);
return {
success: false,
error: error.message
};
}
}
/**
* Convert shared lists (lists without swimlaneId) to per-swimlane lists
*/
async convertSharedListsToPerSwimlane(boardId) {
const lists = await ReactiveCache.getLists({ boardId });
const swimlanes = await ReactiveCache.getSwimlanes({ boardId, archived: false });
const cards = await ReactiveCache.getCards({ boardId });
let listsConverted = 0;
// Find shared lists (lists without swimlaneId)
const sharedLists = lists.filter(list => !list.swimlaneId || list.swimlaneId === '');
if (sharedLists.length === 0) {
return { listsConverted: 0 };
}
for (const sharedList of sharedLists) {
// Get cards in this shared list
const listCards = cards.filter(card => card.listId === sharedList._id);
// Group cards by swimlane
const cardsBySwimlane = {};
for (const card of listCards) {
const swimlaneId = card.swimlaneId || 'default';
if (!cardsBySwimlane[swimlaneId]) {
cardsBySwimlane[swimlaneId] = [];
}
cardsBySwimlane[swimlaneId].push(card);
}
// Create per-swimlane lists for each swimlane that has cards
for (const swimlane of swimlanes) {
const swimlaneCards = cardsBySwimlane[swimlane._id] || [];
if (swimlaneCards.length > 0) {
// Check if per-swimlane list already exists
const existingList = lists.find(l =>
l.title === sharedList.title &&
l.swimlaneId === swimlane._id &&
l._id !== sharedList._id
);
if (!existingList) {
// Create new per-swimlane list
const newListId = await Lists.insertAsync({
title: sharedList.title,
boardId: boardId,
swimlaneId: swimlane._id,
sort: sharedList.sort,
createdAt: new Date(),
updatedAt: new Date(),
archived: false
});
// Move cards to the new list
for (const card of swimlaneCards) {
await Cards.updateAsync(card._id, {
$set: {
listId: newListId,
swimlaneId: swimlane._id
}
});
}
if (process.env.DEBUG === 'true') {
console.log(`Created per-swimlane list "${sharedList.title}" for swimlane ${swimlane.title || swimlane._id}`);
}
} else {
// Move cards to existing per-swimlane list
for (const card of swimlaneCards) {
await Cards.updateAsync(card._id, {
$set: {
listId: existingList._id,
swimlaneId: swimlane._id
}
});
}
if (process.env.DEBUG === 'true') {
console.log(`Moved cards to existing per-swimlane list "${sharedList.title}" in swimlane ${swimlane.title || swimlane._id}`);
}
}
}
}
// Remove the shared list (now that all cards are moved)
await Lists.removeAsync(sharedList._id);
listsConverted++;
if (process.env.DEBUG === 'true') {
console.log(`Removed shared list "${sharedList.title}"`);
}
}
return { listsConverted };
}
/**
* Delete empty per-swimlane lists
* Only deletes lists that:
* 1. Have a swimlaneId (are per-swimlane, not shared)
* 2. Have no cards
* 3. Have a duplicate list with the same title on the same board that contains cards
*/
async deleteEmptyPerSwimlaneLists(boardId) {
const lists = await ReactiveCache.getLists({ boardId });
const cards = await ReactiveCache.getCards({ boardId });
let listsDeleted = 0;
for (const list of lists) {
// Safety check 1: List must have a swimlaneId (must be per-swimlane, not shared)
if (!list.swimlaneId || list.swimlaneId === '') {
if (process.env.DEBUG === 'true') {
console.log(`Skipping list "${list.title}" - no swimlaneId (shared list)`);
}
continue;
}
// Safety check 2: List must have no cards
const listCards = cards.filter(card => card.listId === list._id);
if (listCards.length > 0) {
if (process.env.DEBUG === 'true') {
console.log(`Skipping list "${list.title}" - has ${listCards.length} cards`);
}
continue;
}
// Safety check 3: There must be another list with the same title on the same board that has cards
const duplicateListsWithSameTitle = lists.filter(l =>
l._id !== list._id &&
l.title === list.title &&
l.boardId === boardId
);
let hasDuplicateWithCards = false;
for (const duplicateList of duplicateListsWithSameTitle) {
const duplicateListCards = cards.filter(card => card.listId === duplicateList._id);
if (duplicateListCards.length > 0) {
hasDuplicateWithCards = true;
break;
}
}
if (!hasDuplicateWithCards) {
if (process.env.DEBUG === 'true') {
console.log(`Skipping list "${list.title}" - no duplicate list with same title that has cards`);
}
continue;
}
// All safety checks passed - delete the empty per-swimlane list
await Lists.removeAsync(list._id);
listsDeleted++;
if (process.env.DEBUG === 'true') {
console.log(`Deleted empty per-swimlane list: "${list.title}" (swimlane: ${list.swimlaneId}) - duplicate with cards exists`);
}
}
return { listsDeleted };
}
/**
* Get detailed status of empty lists
*/
async getStatus(boardId) {
const lists = await ReactiveCache.getLists({ boardId });
const cards = await ReactiveCache.getCards({ boardId });
const sharedLists = [];
const emptyPerSwimlaneLists = [];
const nonEmptyLists = [];
for (const list of lists) {
const listCards = cards.filter(card => card.listId === list._id);
const isShared = !list.swimlaneId || list.swimlaneId === '';
const isEmpty = listCards.length === 0;
if (isShared) {
sharedLists.push({
id: list._id,
title: list.title,
cardCount: listCards.length
});
} else if (isEmpty) {
emptyPerSwimlaneLists.push({
id: list._id,
title: list.title,
swimlaneId: list.swimlaneId
});
} else {
nonEmptyLists.push({
id: list._id,
title: list.title,
swimlaneId: list.swimlaneId,
cardCount: listCards.length
});
}
}
return {
sharedListsCount: sharedLists.length,
emptyPerSwimlaneLists: emptyPerSwimlaneLists.length,
totalLists: lists.length,
details: {
sharedLists,
emptyPerSwimlaneLists,
nonEmptyLists
}
};
}
}
const deleteDuplicateEmptyListsMigration = new DeleteDuplicateEmptyListsMigration();
// Register Meteor methods
Meteor.methods({
async 'deleteDuplicateEmptyLists.needsMigration'(boardId) {
check(boardId, String);
// AttachmentMigrationBleed: a board the caller can see, not any board.
await assertMigrationBoardVisible(this.userId, boardId, 'ddp:deleteDuplicateEmptyLists.needsMigration');
return await deleteDuplicateEmptyListsMigration.needsMigration(boardId);
},
async 'deleteDuplicateEmptyLists.execute'(boardId) {
check(boardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in');
}
// Check if user is board admin
const board = await ReactiveCache.getBoard(boardId);
if (!board) {
throw new Meteor.Error('board-not-found', 'Board not found');
}
const user = await ReactiveCache.getUser(this.userId);
if (!user) {
throw new Meteor.Error('user-not-found', 'User not found');
}
// Only board admins can run migrations
const isBoardAdmin = board.members && board.members.some(
member => member.userId === this.userId && member.isAdmin
);
if (!isBoardAdmin && !user.isAdmin) {
throw new Meteor.Error('not-authorized', 'Only board administrators can run migrations');
}
return await deleteDuplicateEmptyListsMigration.executeMigration(boardId);
},
async 'deleteDuplicateEmptyLists.getStatus'(boardId) {
check(boardId, String);
// AttachmentMigrationBleed: a board the caller can see, not any board.
await assertMigrationBoardVisible(this.userId, boardId, 'ddp:deleteDuplicateEmptyLists.getStatus');
return await deleteDuplicateEmptyListsMigration.getStatus(boardId);
}
});
export default deleteDuplicateEmptyListsMigration;