Files
wekan/server/apiImport.js
T
Lauri Ojansivu 46e30f01e4 Import: Planka, Microsoft To Do, KanbanFlow, Basecamp, Google Tasks and Google Keep from their APIs.
Decided on 2026-10-14. On the import page each of the six asks for what
its service needs - a self-hosted Planka its address, username and
password; the others an access token (Basecamp also its account id) -
lists what that account can import, and fetches the chosen board, list
or project. The credentials go with each call and are used for that
call's requests only; they are never stored or logged, and the page
clears secret fields once a fetch has used them. The fetched JSON fills
the import text box and the import goes on as for a pasted export: the
service's parser (models/lib/<key>ApiFormat.js) into the generalized
importer, with the members step and the loss report. The same JSON can
be pasted, or posted to POST /api/boards/import/<key>.

- server/apiImport.js: apiImportList and apiImportFetch, signed in only,
  off with the Admin Panel's import switch, not in Sandstorm, rate
  limited; credentials checked against the service's own fields
  (models/lib/apiImportServices.js).
- server/lib/apiImportRequest.js: every request through the SSRF guard -
  pinned address, no redirects, bounded in time and size - so a Planka
  address cannot point the server at its own network; an administrator
  can allow such a host with API_IMPORT_ALLOWED_PRIVATE_HOSTS. An error
  names only the origin and the status.
- models/lib/apiImport/<key>.js: each service's client, plain Node with
  the request injected, paging bounded and the token only in a header.
- Each has a docs page under docs/Features/ImportExport/, listed in the
  coverage index and External-Tools.md.

Tests: tests/<key>ApiImport.test.cjs (client with a fake request, every
parsed field, wrong shapes), tests/apiImport.test.cjs (credentials, the
gate, the wiring, the shapes refused), api-import.e2e.js (the form for
every service, fetched JSON imported through the page, refusals incl. a
private address). Live tests, read only, run from build.sh / build.bat ->
Tests -> Live tests with your own accounts (releases/live-tests/README.md);
they were not run here. New strings translated in all locales.

Also: the release risk baseline allows the services' API addresses, and
the guards that count import creators, list the import sources and pin
the platform fetch() calls know the new ones.

Thanks to xet7 !
2026-10-14 22:57:15 +03:00

63 lines
3.1 KiB
JavaScript

// Import from a service's API (models/lib/apiImportServices.js): the import
// page asks what can be imported, then fetches the chosen one; the JSON it
// gets back is imported like a pasted export, through importBoard. The
// credentials come with each call, are used for that call's requests only,
// and are never stored or logged.
import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import { assertImportEnabled } from '/models/lib/importExportSecurity';
import { apiImportRequest } from '/server/lib/apiImportRequest';
import * as planka from '/models/lib/apiImport/planka';
import * as mstodo from '/models/lib/apiImport/mstodo';
import * as kanbanflow from '/models/lib/apiImport/kanbanflow';
import * as basecamp from '/models/lib/apiImport/basecamp';
import * as googletasks from '/models/lib/apiImport/googletasks';
import * as googlekeep from '/models/lib/apiImport/googlekeep';
const { apiImportService, cleanApiImportCredentials } = require('/models/lib/apiImportServices');
const CLIENTS = { planka, mstodo, kanbanflow, basecamp, googletasks, googlekeep };
const MAX_ID_LENGTH = 200;
async function prepare(userId, service, credentials) {
if (!userId) throw new Meteor.Error('error-notAuthorized');
// Sandstorm reaches other sites only through Powerbox grants.
if (Meteor.settings?.public?.sandstorm) throw new Meteor.Error('api-import-unavailable', 'Not available in Sandstorm.');
await assertImportEnabled();
if (!apiImportService(service) || !CLIENTS[service]) throw new Meteor.Error('api-import-unknown-service');
try { return cleanApiImportCredentials(service, credentials); }
catch (error) { throw new Meteor.Error('api-import-credentials', error.message); }
}
// Only the message - origin and status - reaches the page.
const failure = error => new Meteor.Error('api-import-failed', String((error && error.message) || error).slice(0, 300));
Meteor.methods({
async apiImportList(service, credentials) {
check(service, String);
check(credentials, Match.Any);
const clean = await prepare(this.userId, service, credentials);
try {
const items = await CLIENTS[service].list(clean, apiImportRequest);
return (Array.isArray(items) ? items : []).slice(0, 1000)
.map(item => ({ id: String(item.id).slice(0, MAX_ID_LENGTH), name: String(item.name || item.id).slice(0, 300) }));
} catch (error) { throw failure(error); }
},
async apiImportFetch(service, credentials, id) {
check(service, String);
check(credentials, Match.Any);
check(id, String);
const clean = await prepare(this.userId, service, credentials);
if (!id || id.length > MAX_ID_LENGTH) throw new Meteor.Error('api-import-failed', 'Choose what to import.');
try {
return await CLIENTS[service].fetch(clean, id, apiImportRequest);
} catch (error) { throw failure(error); }
},
});
// Each call makes requests to another site with the member's credentials.
DDPRateLimiter.addRule({ type: 'method', name: name => ['apiImportList', 'apiImportFetch'].includes(name),
connectionId: () => true }, 10, 60000);