mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-12-03 05:10:04 +01:00
Block account creation from restricted origins
This commit is contained in:
1 parent
c85359f4a3
commit
e37036a67f
1 file changed
+15
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user