Files
wekan/server/lib/clientAccountCreationGuard.js
T
Lauri Ojansivu 433ff5506c SignupBleed: guard the sign-up form's own method, and keep ordinary sign-up working.
The browser test found two faults in dd36db3641. The real door is
useraccounts' ATCreateUserServer - the method the sign-up form calls, which
picks the profile fields and passes the rest of the client's options to
Accounts.createUser - not Meteor's createUser, which useraccounts already
refuses to clients. Verified against the code before this change: with
registration disabled, ATCreateUserServer with from: 'admin' created the
account. Both methods are wrapped now. And the wrapper handed the original
method a copy, so audit-argument-checks refused every ordinary sign-up ("Did
not check() all arguments"); the client's own arguments are check()ed first.

The browser test now signs up ordinarily first, then makes both attempts the
way the form does (hashed password) on fresh connections, and resets the
shared unknown-user lockout of 127.0.0.1 before and after. The LinkedWriteBleed,
RepointBleed and BackgroundBleed browser tests use a fresh account per refused
attempt and check it is disabled - a refused attempt costs the account.

Thanks to xet7 !
2026-10-02 11:02:21 +03:00

45 lines
2.2 KiB
JavaScript

// SignupBleed, DDP sibling: see models/lib/clientAccountCreation.js. A client
// creates an account through one of two DDP methods: useraccounts'
// ATCreateUserServer (the sign-up form), which picks the profile fields and
// hands the REST of the client's options to Accounts.createUser, and Meteor's
// own createUser (refused while useraccounts forbids client creation, wrapped
// anyway so it cannot become a door). Both are wrapped here so a client cannot
// pass the server-only creation options. Loaded from server/imports.js, after
// the accounts packages registered the methods.
import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
const { clientCreationOptions } = require('/models/lib/clientAccountCreation');
export const CLIENT_ACCOUNT_CREATION_METHODS = ['ATCreateUserServer', 'createUser'];
function guard(methodName, original) {
const guarded = async function guardedAccountCreation(options, ...rest) {
// audit-argument-checks requires every argument the CLIENT sent to be
// check()ed. The original method checks the copy it is handed, so the
// client's own object is checked here - or every sign-up fails with
// "Did not check() all arguments".
check(options, Match.Any);
rest.forEach(arg => check(arg, Match.Any));
const { options: clean, refused } = clientCreationOptions(options);
if (refused.length) {
// Nobody signs up with these through the UI: an attempt to bypass
// "Disable registration". Not logged in yet, so no account to block.
try {
require('/server/lib/securityLog').record({
key: 'authz.register', action: 'blocked', source: `ddp:${methodName}`,
detail: `client sign-up passed server-only option(s): ${refused.join(', ')}`,
});
} catch (e) { /* logging must never break the guard */ }
}
return original.call(this, clean, ...rest);
};
guarded.__wekanClientOptionsGuard = true;
return guarded;
}
const handlers = Meteor.server && Meteor.server.method_handlers;
for (const name of CLIENT_ACCOUNT_CREATION_METHODS) {
const original = handlers && handlers[name];
if (typeof original === 'function' && !original.__wekanClientOptionsGuard) handlers[name] = guard(name, original);
}