Files
wekan/packages/dynamic-import/cache.js
T
Lauri Ojansivu e0189bc53b Meteor 3.5.3's six security fixes on Meteor 3.6-rc.0.
Meteor published the same six fixes as 3.3.3, 3.4.2 and 3.5.3 on
2026-10-16. 3.6-rc.0, which WeKan runs, does not have them: its tag is
behind 3.5.3 by exactly the 15 security commits, and neither it nor
Meteor's devel branch has the fixed code. Going back to 3.5.3 would also
mean Node.js 24 and Rspack 1, so WeKan carries the fixes in packages/,
where a package overrides the release's own: 3.6-rc.0's allow-deny,
ddp-server, dynamic-import, facebook-oauth, google-oauth and shell-server
with Meteor's 3.5.3 patch applied unchanged, each marked with a _1 wrap
number. ddp-server leaves out uWebSockets.js, as Meteor's published
package does; it is only for the opt-in uws transport and came from a git
URL.

- DDP: a message named __proto__, toString or not a string, and an async
  handler that rejected, crashed the server.
- allow/deny: a top-level __proto__ in an update was missing from the field
  list the validators saw.
- dynamic import(): requests are bounded in size (413) and complexity
  (400).
- Google and Facebook direct-token login: a token issued to another
  application was accepted; identity now comes from the provider, and a
  Facebook verification error no longer carries the app secret.
- meteor shell: its history and compile cache are private.
- Deploy discovery is in meteor-tool, which an app cannot replace; WeKan is
  never deployed with meteor deploy, and a test keeps it so.

Refused attempts are in Admin Panel / Problems as Meteor DDP, Meteor
allow-deny, Meteor dynamic-import and Meteor OAuth, through a hook the
packages call (server/lib/meteorSecurityHook.js); none blocks an account.
An oversized import() body, an unknown ordinary DDP name and a network
failure are refused without a row, because ordinary use can reach them.

tests/meteor353SecurityFixes.test.cjs runs each fix's code cut out of the
fork and searches the tree for the shape of each fault; all of them fail on
the unfixed 3.6-rc.0 packages. It also fails when .meteor/release moves
on, because a fork would silently keep 3.6-rc.0's code.
tests/playwright/specs/meteor-353-security.e2e.js sends each attack to a
running WeKan built with the forks. The forked files are recorded in the
source audit baseline, and the suites that check WeKan's own methods and
subscriptions skip Meteor's package tests.

Thanks to Meteor developers, Vext Labs and xet7 !
2026-10-22 04:12:13 +03:00

224 lines
6.5 KiB
JavaScript

var dbPromise;
var dbConnection;
var canUseCache =
// The server doesn't benefit from dynamic module fetching, and almost
// certainly doesn't support IndexedDB.
Meteor.isClient &&
// Cordova bundles all modules into the monolithic initial bundle, so
// the dynamic module cache won't be necessary.
! Meteor.isCordova &&
// Caching can be confusing in development, and is designed to be a
// transparent optimization for production performance.
Meteor.isProduction;
function getIDB() {
if (typeof indexedDB !== "undefined") return indexedDB;
if (typeof webkitIndexedDB !== "undefined") return webkitIndexedDB;
if (typeof mozIndexedDB !== "undefined") return mozIndexedDB;
if (typeof OIndexedDB !== "undefined") return OIndexedDB;
if (typeof msIndexedDB !== "undefined") return msIndexedDB;
}
function withDB(callback) {
dbPromise = dbPromise || new Promise(function (resolve, reject) {
var idb = getIDB();
if (! idb) {
throw new Error("IndexedDB not available");
}
// Incrementing the version number causes all existing object stores
// to be deleted and recreates those specified by objectStoreMap.
var request = idb.open("MeteorDynamicImportCache", 2);
request.onupgradeneeded = function (event) {
var db = event.target.result;
// It's fine to delete existing object stores since onupgradeneeded
// is only called when we change the DB version number, and the data
// we're storing is disposable/reconstructible.
Array.from(db.objectStoreNames).forEach(db.deleteObjectStore, db);
Object.keys(objectStoreMap).forEach(function (name) {
db.createObjectStore(name, objectStoreMap[name]);
});
};
request.onerror = makeOnError(reject, "indexedDB.open");
request.onsuccess = function (event) {
var db = dbConnection = event.target.result;
db.onclose = function () {
forgetDB(db);
};
db.onversionchange = function () {
db.close();
forgetDB(db);
};
resolve(db);
};
});
return dbPromise.then(callback, function (error) {
return callback(null);
});
}
function forgetDB(db) {
// A late close event from an old connection must not discard a newer one.
if (dbConnection === db) {
dbConnection = null;
dbPromise = null;
}
}
function safeTransaction(db, mode) {
try {
return db.transaction(["sourcesByVersion"], mode);
} catch (error) {
// Browsers can close IndexedDB connections while a page is suspended.
// Treat this as a cache miss and let the next operation reopen the DB.
forgetDB(db);
db.close();
return null;
}
}
var objectStoreMap = {
sourcesByVersion: { keyPath: "version" }
};
function makeOnError(reject, source) {
return function (event) {
var error = event.target.error;
reject(new Error(
"IndexedDB failure in " + source + " " +
(error ? error.name + ": " + error.message : "Unknown error")
));
// Returning true from an onerror callback function prevents an
// InvalidStateError in Firefox during Private Browsing. Silencing
// that error is safe because we handle the error more gracefully by
// passing it to the Promise reject function above.
// https://github.com/meteor/meteor/issues/8697
return true;
};
}
var checkCount = 0;
exports.checkMany = function (versions) {
var ids = Object.keys(versions);
var sourcesById = Object.create(null);
// Initialize sourcesById with null values to indicate all sources are
// missing (unless replaced with actual sources below).
ids.forEach(function (id) {
sourcesById[id] = null;
});
if (! canUseCache) {
return Promise.resolve(sourcesById);
}
return withDB(function (db) {
if (! db) {
// We thought we could used IndexedDB, but something went wrong
// while opening the database, so err on the side of safety.
return sourcesById;
}
var txn = safeTransaction(db, "readonly");
if (! txn) {
return sourcesById;
}
var sourcesByVersion = txn.objectStore("sourcesByVersion");
++checkCount;
function finish() {
--checkCount;
return sourcesById;
}
return Promise.all(ids.map(function (id) {
return new Promise(function (resolve, reject) {
var version = versions[id];
if (version) {
var sourceRequest = sourcesByVersion.get(version);
sourceRequest.onerror = makeOnError(reject, "sourcesByVersion.get");
sourceRequest.onsuccess = function (event) {
var result = event.target.result;
if (result) {
sourcesById[id] = result.source;
}
resolve();
};
} else resolve();
});
})).then(finish, finish);
});
};
var pendingVersionsAndSourcesById = Object.create(null);
exports.setMany = function (versionsAndSourcesById) {
if (canUseCache) {
Object.assign(
pendingVersionsAndSourcesById,
versionsAndSourcesById
);
// Delay the call to flushSetMany so that it doesn't contribute to the
// amount of time it takes to call module.dynamicImport.
if (! flushSetMany.timer) {
flushSetMany.timer = setTimeout(flushSetMany, 100);
}
}
};
function flushSetMany() {
if (checkCount > 0) {
// If checkMany is currently underway, postpone the flush until later,
// since updating the cache is less important than reading from it.
return flushSetMany.timer = setTimeout(flushSetMany, 100);
}
flushSetMany.timer = null;
var versionsAndSourcesById = pendingVersionsAndSourcesById;
pendingVersionsAndSourcesById = Object.create(null);
return withDB(function (db) {
if (! db) {
// We thought we could used IndexedDB, but something went wrong
// while opening the database, so err on the side of safety.
return;
}
var setTxn = safeTransaction(db, "readwrite");
if (! setTxn) {
return;
}
var sourcesByVersion = setTxn.objectStore("sourcesByVersion");
return Promise.all(
Object.keys(versionsAndSourcesById).map(function (id) {
var info = versionsAndSourcesById[id];
return new Promise(function (resolve, reject) {
var request = sourcesByVersion.put({
version: info.version,
source: info.source
});
request.onerror = makeOnError(reject, "sourcesByVersion.put");
request.onsuccess = resolve;
});
})
);
}).catch(function () {
// This promise is discarded by setTimeout. Cache write failures must not
// surface as unhandled rejections or interfere with dynamic imports.
});
}