Files
wekan/models/lib/clientAccountCreation.js
T
Lauri Ojansivu dd36db3641 Close the SignupBleed DDP sibling: a client sign-up cannot claim admin or LDAP creation.
Accounts.onCreateUser trusts from: 'admin' (admin or REST creation, which
skips the registration checks) and ldap: true (directory account, allowed while
registration is disabled) as server-only signals, and Meteor's createUser DDP
method passes the client's options through unchanged. With "Disable
registration" on, anyone could still create an account by adding either.

The createUser method is wrapped so a client's options lose the server-only
keys; the server's own callers - the admin method, POST /api/users, the LDAP
package - call Accounts.createUserAsync directly and keep them. An attempt is
recorded as SignupBleed. The negative test fails if onCreateUser trusts another
option as an early-return signal without it being stripped from clients; a
browser test signs up both ways with registration disabled.

Thanks to xet7 !
2026-10-02 10:39:40 +03:00

26 lines
1.3 KiB
JavaScript

'use strict';
// SignupBleed, DDP sibling (2026-10-02). Accounts.onCreateUser trusts two
// options as server-only signals: `from: 'admin'` (an admin or the REST API
// creating the account - it skips the registration checks) and `ldap: true`
// (the LDAP package creating an account for a directory user - allowed while
// registration is disabled). Meteor's `createUser` DDP method passes the
// CLIENT's options object to that hook unchanged, so with "Disable
// registration" on, anyone could still sign up by adding either option.
//
// The server's own callers (the admin method, POST /api/users, the LDAP
// package) call Accounts.createUserAsync directly and keep them. A client's
// createUser call never may. Pure: tests/signupBleedDdp.test.cjs.
const SERVER_ONLY_CREATION_OPTIONS = ['from', 'ldap'];
// The options a client may pass, and which server-only ones it tried to.
function clientCreationOptions(options) {
if (!options || typeof options !== 'object') return { options, refused: [] };
const refused = SERVER_ONLY_CREATION_OPTIONS.filter(key => Object.prototype.hasOwnProperty.call(options, key));
if (!refused.length) return { options, refused };
const clean = { ...options };
for (const key of refused) delete clean[key];
return { options: clean, refused };
}
module.exports = { SERVER_ONLY_CREATION_OPTIONS, clientCreationOptions };