import { validateImportSourceShape } from './lib/importSourceShape'; import { requireBoardMutation } from '/models/lib/boardMutationGuard'; import { Meteor } from 'meteor/meteor'; import { ReactiveCache } from '/imports/reactiveCache'; import { TrelloCreator } from './trelloCreator'; import { WekanCreator } from './wekanCreator'; import { CsvCreator } from './csvCreator'; import { JiraCreator } from './jiraCreator'; import { KanboardCreator } from './kanboardCreator'; import { EXTERNAL_PARSERS } from './lib/externalParsers'; import { Exporter } from './exporter'; import { getMembersToMap } from './wekanmapper'; import { assertImportEnabled } from './lib/importExportSecurity'; import { withDeadline } from './lib/withDeadline'; import { importDeadlineFor } from './lib/importDeadline'; import { isCsvMappingShape, mappingForSheet } from './lib/csvImportMapping'; const { isAttachmentAuthShape } = require('./lib/importAttachmentAuth'); // Hard deadline for a single board import, so a stalled/hung import can never leave the // client's spinner running forever — the method returns a timeout error instead. // Tunable via WEKAN_IMPORT_TIMEOUT_MS (0/invalid disables the deadline). It is the // BASE: importBoard adds time per record of the file (models/lib/importDeadline.js, // #6792), so a large import is not stopped halfway for being large. function importDeadlineMs() { const ms = parseInt(process.env.WEKAN_IMPORT_TIMEOUT_MS, 10); return Number.isFinite(ms) ? ms : 120000; } function recordAnonymousImportAttempt(method, connection) { if (!Meteor.isServer) return; const { record } = require('/server/lib/securityLog'); record({ key: 'authn.import', action: 'blocked', source: 'ddp:' + method, ip: connection && connection.clientAddress, detail: 'Anonymous board import denied', }); } function sanitizeImported(value, source, invocation) { if (!Meteor.isServer) return value; try { return require('/server/lib/secureTransfer').secureTransfer(value, { direction: 'import', source: `import:${source}`, userId: invocation && invocation.userId, ip: invocation && invocation.connection && invocation.connection.clientAddress, }); } catch (error) { // #6792: a plain Error reached the import page as "Internal server // error", so a file over a size limit looked like a broken WeKan. The // page translates the error key; the reason names the limit. const message = String((error && error.message) || error); throw new Meteor.Error(/limit exceeded/.test(message) ? 'import-too-large' : 'invalid-import-format', message); } } // On Sandstorm an import replaces the board it was started from: the creators // archive `currentBoard`. That id comes from the client, and nothing checked // it, so anyone could archive any board by naming it. Only a board admin may // have their board replaced; for anyone else the import still runs and simply // leaves that board alone. No Problems record: a member who is not an admin // reaches this by importing from a board page, which is ordinary use. // CreateBleed (GHSA-qcfm-2g4w-wqcc): this file is shared with the client, and // the guard reads server-only settings, so it is required on the server only. async function assertMayCreateBoardOnServer(userId, source) { if (!Meteor.isServer) return; const { assertMayCreateBoard } = require('/server/lib/boardCreationGuard'); await assertMayCreateBoard(userId, { source, type: 'board' }); } async function replaceableBoardId(userId, boardId) { if (!boardId || !userId) return undefined; const board = await ReactiveCache.getBoard(boardId); return board && board.hasAdmin(userId) ? boardId : undefined; } Meteor.methods({ async importBoard(board, data, importSource, currentBoard) { // All check() calls must run BEFORE the first `await`: Meteor's // audit-argument-checks tracks checked arguments on the current async context, // and an early throw before checking them replaces the intended error with // "Did not check() all arguments". These checks validate types only; no parser, // feature lookup, creator or write is reached before authentication. // String is accepted alongside Object/Array for markdown-kanban text // imports (models/lib/externalParsers.js parseMarkdownKanban); the // 'markdown', 'todotxt', 'taskwarrior', 'focalboard', 'todoist', 'orgmode', 'leo' and 'opml' cases below are the only // ones that let a string through their own per-source check(). check(board, Match.OneOf(Object, Array, String)); check(data, Object); check(importSource, String); check(currentBoard, Match.Maybe(String)); // The CSV/TSV and Excel imports' column mapping (models/lib/csvImportMapping.js): // its shape here, its column numbers against the file's header in the creator. check(data.csvMapping, Match.Maybe(Match.Where(isCsvMappingShape))); // The sign-in for the attachment files of a Jira, Deck, OpenProject, Asana // or GitLab import (models/lib/importAttachmentAuth.js): used for this // import's downloads only, never stored or logged. check(data.attachmentAuth, Match.Maybe(Match.Where(isAttachmentAuthShape))); // An upload streamed to the local disk (server/routes/importUpload.js): // the file is read from there instead of `board`. check(data.uploadId, Match.Maybe(Match.Where(id => typeof id === 'string' && /^[0-9a-f]{32}$/.test(id)))); // Jira's estimate mapping, sent with the call when the file was uploaded. check(data.wekanScrumMapping, Match.Maybe(Match.ObjectIncluding({ estimateFieldId: String }))); // ImportBleed (GHSA-qp32-wqxw-wq3h): this method reaches direct collection // writes, so authentication is rejected immediately after Meteor's mandatory // argument audit and before feature checks, parsing or creator construction. if (!this.userId) { recordAnonymousImportAttempt('importBoard', this.connection); throw new Meteor.Error('error-notAuthorized'); } // Admin Panel / Features / Security: master switch to disable all import. await assertImportEnabled(); // CreateBleed: every import makes a new board - the UI's, and POST // /api/boards/import and /api/boards/import/:source, which call this. await assertMayCreateBoardOnServer(this.userId, 'method:importBoard'); let uploadId = null; if (data.uploadId) { if (!Meteor.isServer) return undefined; uploadId = data.uploadId; try { const Settings = require('/models/settings').default; board = await require('/server/lib/importUploadSource').uploadedImportValue(uploadId, this.userId, importSource, { setting: (await Settings.findOneAsync({}, { fields: { importMaxMegabytes: 1 } })) || {}, spec: require('/models/lib/importSources').importSource(importSource), }); } catch (error) { throw new Meteor.Error(error.code || 'invalid-import-format', error.message); } if (importSource === 'jira' && data.wekanScrumMapping && board && typeof board === 'object' && !Array.isArray(board)) { board.wekanScrumMapping = { estimateFieldId: String(data.wekanScrumMapping.estimateFieldId), ...(typeof data.wekanScrumMapping.estimateUnit === 'string' ? { estimateUnit: data.wekanScrumMapping.estimateUnit } : {}) }; } // The people of an uploaded Jira file, for the page's map-members step. if (data.previewPeople === true && importSource === 'jira') { return require('/models/lib/jiraMembersMapper').jiraGetMembersToMap(board); } } try { validateImportSourceShape(importSource, board); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } let creator; // The boards of an Excel workbook: one per sheet that has a header. let excelBoards = null; // A .leo or OPML outline is XML: sanitizing the raw text would strip its // tags as markup. It is parsed first and the parsed tasks are sanitized // instead. // A Vikunja export is a zip, or the text of its data.json, whose HTML // descriptions sit inside JSON strings: sanitizing that text as markup // would break the JSON. It is parsed first as well. // So is a Notion export: a .zip whose pages are read on the server, or a // database CSV; the parsed board is sanitized. And a Plane export: a zip, a // workbook, or JSON or CSV text whose cells hold JSON. // So are mail (raw MIME, whose "Name
" would read as a tag), an // iCalendar, chat and note text, and the Slack and Google Takeout zips: // each is parsed first, and what was parsed is sanitized. let importedBoard = importSource === 'mail' || importSource === 'ical' || importSource === 'googletakeout' || importSource === 'slack' || importSource === 'mattermost' || importSource === 'whatsapp' || importSource === 'evernote' || importSource === 'leo' || importSource === 'opml' || importSource === 'vikunja' || importSource === 'notion' || importSource === 'plane' ? board : sanitizeImported(board, importSource, this); switch (importSource) { case 'trello': check(board, Object); creator = new TrelloCreator(data); break; case 'wekan': check(board, Object); creator = new WekanCreator(data); break; case 'csv': check(board, Array); creator = new CsvCreator(data); break; case 'jira': check(board, Object); creator = new JiraCreator(data); break; case 'kanboard': check(board, Object); // Resolve Kanboard's ids and nested subtasks/comments into the shared // task shape; the creator used to read only the handful of fields // that shape and Kanboard's API happen to spell the same way. importedBoard = EXTERNAL_PARSERS.kanboard(importedBoard); creator = new KanboardCreator(data, 'kanboard'); break; case 'excel': // board = { excelBase64 }; every sheet with a header is a board // (server/lib/excelBoardWorkbook.js), read through the CSV creator. check(board, Object); if (!Meteor.isServer) return undefined; try { excelBoards = (await require('/server/lib/excelBoardWorkbook').readExcelBoards(importedBoard.excelBase64)).boards; } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } excelBoards = excelBoards.map(part => ({ ...part, rows: sanitizeImported(part.rows, 'excel-cells', this) })); importedBoard = excelBoards[0].rows; creator = new CsvCreator(data, { title: excelBoards[0].title }); break; case 'markdown': // A markdown-kanban task list is plain text, not JSON - see // parseMarkdownKanban in models/lib/externalParsers.js. check(board, String); importedBoard = EXTERNAL_PARSERS.markdown(importedBoard); creator = new KanboardCreator(data, 'markdown'); break; case 'todotxt': // todo.txt, one task per line - see models/lib/todoTxtFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.todotxt(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'todotxt'); break; case 'taskwarrior': // Taskwarrior's `task export` JSON - see models/lib/taskwarriorFormat.js. // Sent as text: older versions write one object per line, not an array. check(board, String); try { importedBoard = EXTERNAL_PARSERS.taskwarrior(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'taskwarrior'); break; case 'focalboard': // A Focalboard board.jsonl - see models/lib/focalboardFormat.js. Sent // as text: one JSON object per line. check(board, String); try { importedBoard = EXTERNAL_PARSERS.focalboard(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'focalboard'); break; case 'todoist': // A Todoist project template (CSV) - see models/lib/todoistCsvFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.todoist(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'todoist'); break; case 'meistertask': // A MeisterTask project CSV - see models/lib/meistertaskCsvFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.meistertask(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'meistertask'); break; case 'obsidian': // An Obsidian Kanban plugin board - see models/lib/obsidianKanbanFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.obsidian(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'obsidian'); break; case 'linear': // Linear's CSV export - see models/lib/linearCsvFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.linear(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'linear'); break; case 'ticktick': // A TickTick backup CSV - see models/lib/ticktickCsvFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.ticktick(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'ticktick'); break; case 'clickup': // A ClickUp task CSV - see models/lib/clickupCsvFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.clickup(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'clickup'); break; case 'nullboard': // A Nullboard .nbx board file (JSON text) - see models/lib/nullboardFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.nullboard(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'nullboard'); break; case 'pivotal': // A Pivotal Tracker stories CSV - see models/lib/pivotalCsvFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.pivotal(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'pivotal'); break; case 'redmine': // Redmine's issues CSV - see models/lib/redmineCsvFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.redmine(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'redmine'); break; case 'tasksorg': // A Tasks.org backup (JSON) - see models/lib/tasksorgFormat.js. check(board, Object); try { importedBoard = EXTERNAL_PARSERS.tasksorg(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'tasksorg'); break; case 'monday': // monday.com's "Export board to Excel" workbook - see // models/lib/mondayFormat.js. Like Planner, { excelBase64 }; the // parsed tasks are sanitized again below. check(board, Object); if (!Meteor.isServer) return undefined; try { importedBoard = await require('/server/lib/mondayWorkbook').readMondayWorkbook(importedBoard.excelBase64); importedBoard = EXTERNAL_PARSERS.monday(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } importedBoard = sanitizeImported(importedBoard, 'monday', this); creator = new KanboardCreator(data, 'monday'); break; case 'teamwork': // Teamwork.com's Excel task import template - see // models/lib/teamworkFormat.js. Like Planner, { excelBase64 }; the // parsed tasks are sanitized again below. check(board, Object); if (!Meteor.isServer) return undefined; try { importedBoard = await require('/server/lib/teamworkWorkbook').readTeamworkWorkbook(importedBoard.excelBase64); importedBoard = EXTERNAL_PARSERS.teamwork(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } importedBoard = sanitizeImported(importedBoard, 'teamwork', this); creator = new KanboardCreator(data, 'teamwork'); break; case 'superproductivity': // A Super Productivity backup (sp-backup_*.json), sent as text - see // models/lib/superProductivityFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.superproductivity(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'superproductivity'); break; case 'taiga': // A Taiga project dump (one JSON object) - see models/lib/taigaFormat.js. // The browser sends it without the attachment bytes it embeds. check(board, Object); try { importedBoard = EXTERNAL_PARSERS.taiga(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'taiga'); break; case 'vikunja': // Vikunja's user data export - see models/lib/vikunjaFormat.js. The // import page sends the .zip as { zipBase64 }, or the text of its // data.json; server/lib/vikunjaArchive.js opens the zip under size // limits, and the parsed tasks are sanitized below. check(board, Match.OneOf(Object, String)); if (!Meteor.isServer) return undefined; try { importedBoard = await require('/server/lib/vikunjaArchive').readVikunjaImport(importedBoard); importedBoard = EXTERNAL_PARSERS.vikunja(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } importedBoard = sanitizeImported(importedBoard, 'vikunja', this); creator = new KanboardCreator(data, 'vikunja'); break; case 'quire': // A Quire project CSV - see models/lib/quireCsvFormat.js. check(board, String); try { importedBoard = EXTERNAL_PARSERS.quire(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } creator = new KanboardCreator(data, 'quire'); break; case 'wrike': // Wrike's Excel import template - see models/lib/wrikeFormat.js. Like // Planner and monday.com, { excelBase64 }; the parsed tasks are // sanitized again below. check(board, Object); if (!Meteor.isServer) return undefined; try { importedBoard = await require('/server/lib/wrikeWorkbook').readWrikeWorkbook(importedBoard.excelBase64); importedBoard = EXTERNAL_PARSERS.wrike(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } importedBoard = sanitizeImported(importedBoard, 'wrike', this); creator = new KanboardCreator(data, 'wrike'); break; case 'businessmap': // A Businessmap (Kanbanize) Excel workbook - see // models/lib/businessmapFormat.js. Like monday.com, { excelBase64 }; // the parsed tasks are sanitized again below. check(board, Object); if (!Meteor.isServer) return undefined; try { importedBoard = await require('/server/lib/businessmapWorkbook').readBusinessmapWorkbook(importedBoard.excelBase64); importedBoard = EXTERNAL_PARSERS.businessmap(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } importedBoard = sanitizeImported(importedBoard, 'businessmap', this); creator = new KanboardCreator(data, 'businessmap'); break; case 'notion': // Notion's Markdown & CSV export - see models/lib/notionFormat.js. The // import page sends the .zip as { zipBase64 }, or the text of one // database CSV; server/lib/notionArchive.js opens the zip under size // limits, and the parsed board is sanitized below. check(board, Match.OneOf(Object, String)); if (!Meteor.isServer) return undefined; try { importedBoard = await require('/server/lib/notionArchive').readNotionImport(importedBoard); importedBoard = EXTERNAL_PARSERS.notion(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } importedBoard = sanitizeImported(importedBoard, 'notion', this); creator = new KanboardCreator(data, 'notion'); break; case 'plane': // Plane's issue export - see models/lib/planeFormat.js. The import // page sends the export .zip as { zipBase64 }, a workbook from it as // { xlsxBase64 }, or the text of its JSON or CSV file; // server/lib/planeArchive.js opens the zip and the workbook under size // limits, and the parsed tasks are sanitized below. check(board, Match.OneOf(Object, String)); if (!Meteor.isServer) return undefined; try { importedBoard = await require('/server/lib/planeArchive').readPlaneImport(importedBoard); importedBoard = EXTERNAL_PARSERS.plane(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } importedBoard = sanitizeImported(importedBoard, 'plane', this); creator = new KanboardCreator(data, 'plane'); break; case 'planner': // Microsoft Planner's "Export plan to Excel" workbook - see // models/lib/plannerFormat.js. It arrives like the Excel import, as // { excelBase64 }; the cells are only text once the workbook is // opened, so the parsed tasks are sanitized again below. check(board, Object); if (!Meteor.isServer) return undefined; try { importedBoard = await require('/server/lib/plannerWorkbook').readPlannerWorkbook(importedBoard.excelBase64); importedBoard = EXTERNAL_PARSERS.planner(importedBoard); } catch (error) { throw new Meteor.Error('invalid-import-format', error.message); } importedBoard = sanitizeImported(importedBoard, 'planner', this); creator = new KanboardCreator(data, 'planner'); break; case 'planka': case 'mstodo': case 'kanbanflow': case 'basecamp': case 'googletasks': case 'googlekeep': // What server/apiImport.js fetched from the service's API (or that JSON // pasted) - see models/lib/