Files
wekan/packages/ddp-server/writefence.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

112 lines
2.6 KiB
JavaScript

DDPServer._WriteFence = class {
constructor() {
this.armed = false;
this.fired = false;
this.retired = false;
this.outstanding_writes = 0;
this.before_fire_callbacks = [];
this.completion_callbacks = [];
}
beginWrite() {
if (this.retired) {
return { committed: () => {} };
}
if (this.fired) {
throw new Error("fence has already activated -- too late to add writes");
}
this.outstanding_writes++;
let committed = false;
return {
committed: async () => {
if (committed) {
throw new Error("committed called twice on the same write");
}
committed = true;
this.outstanding_writes--;
await this._maybeFire();
}
};
}
arm() {
if (this === DDPServer._getCurrentFence()) {
throw Error("Can't arm the current fence");
}
this.armed = true;
return this._maybeFire();
}
onBeforeFire(func) {
if (this.fired) {
throw new Error("fence has already activated -- too late to add a callback");
}
this.before_fire_callbacks.push(func);
}
onAllCommitted(func) {
if (this.fired) {
throw new Error("fence has already activated -- too late to add a callback");
}
this.completion_callbacks.push(func);
}
async _armAndWait() {
let resolver;
const returnValue = new Promise(r => resolver = r);
this.onAllCommitted(resolver);
await this.arm();
return returnValue;
}
armAndWait() {
return this._armAndWait();
}
async _maybeFire() {
if (this.fired) {
throw new Error("write fence already activated?");
}
if (!this.armed || this.outstanding_writes > 0) {
return;
}
const invokeCallback = async (func) => {
try {
await func(this);
} catch (err) {
Meteor._debug("exception in write fence callback:", err);
}
};
this.outstanding_writes++;
// Process all before_fire callbacks in parallel
const beforeCallbacks = [...this.before_fire_callbacks];
this.before_fire_callbacks = [];
await Promise.all(beforeCallbacks.map(cb => invokeCallback(cb)));
this.outstanding_writes--;
if (this.outstanding_writes === 0) {
this.fired = true;
// Process all completion callbacks in parallel
const callbacks = [...this.completion_callbacks];
this.completion_callbacks = [];
await Promise.all(callbacks.map(cb => invokeCallback(cb)));
}
}
retire() {
if (!this.fired) {
throw new Error("Can't retire a fence that hasn't fired.");
}
this.retired = true;
}
};
DDPServer._CurrentWriteFence = new Meteor.EnvironmentVariable;