Block account creation from restricted origins

This commit is contained in:
Terncode committed 2026-11-18 19:44:02 +01:00
1 parent c85359f4a3
commit e37036a67f
1 file changed
+15
+15
View File
@@ -263,6 +263,11 @@ export function authRoutes(
const userId = user && user._id.toString();
const mergeAccount = (userId && isMerge(userId)) ? userId : undefined;
const createAccountOptions = createOptions(req, !!connectOnly, server, settings, checkers);
if (!createAccountOptions.creationLocked && await isOriginRestricted(createAccountOptions.ip)) {
createAccountOptions.creationLocked = true;
}
const auth = await findOrCreateAuth(profile, mergeAccount, createAccountOptions);
const account = await findOrCreateAccount(auth, profile, createAccountOptions);
const { ip, userAgent } = createAccountOptions;
@@ -392,6 +397,16 @@ const createMockLoginGuard = (server: ServerConfig): RequestHandler => (req, res
}
};
// lock account creation from origins that are muted, shadowed or banned (cookie lock can be cleared by the user)
async function isOriginRestricted(ip: string | undefined) {
if (!ip) {
return false;
}
const origin = await Origin.findOne({ ip }, 'mute shadow ban').lean().exec();
return !!origin && (isActive(origin.mute) || isActive(origin.shadow) || isActive(origin.ban));
}
function createOptions(
req: Request, connectOnly: boolean, server: ServerConfig, settings: Settings, checkers: SuspiciousCheckers
): CreateAccountOptions {