makes max IP limit configurable per-user
This commit is contained in:
@@ -50,6 +50,8 @@ export const UserSchema = z
|
||||
disabledReason: z.string().optional(),
|
||||
/** Time at which the user will expire and be disabled (for temp users). */
|
||||
expiresAt: z.number().optional(),
|
||||
/** The user's maximum number of IP addresses; supercedes global max. */
|
||||
maxIps: z.coerce.number().int().min(0).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@ import { User, UserUpdate } from "./schema";
|
||||
|
||||
const log = logger.child({ module: "users" });
|
||||
|
||||
const MAX_IPS_PER_USER = config.maxIpsPerUser;
|
||||
|
||||
const users: Map<string, User> = new Map();
|
||||
const usersToFlush = new Set<string>();
|
||||
let quotaRefreshJob: schedule.Job | null = null;
|
||||
@@ -173,10 +171,10 @@ export function authenticate(token: string, ip: string) {
|
||||
const user = users.get(token);
|
||||
if (!user || user.disabledAt) return;
|
||||
if (!user.ip.includes(ip)) user.ip.push(ip);
|
||||
|
||||
// If too many IPs are associated with the user, disable the account.
|
||||
|
||||
const configIpLimit = user.maxIps ?? config.maxIpsPerUser;
|
||||
const ipLimit =
|
||||
user.type === "special" || !MAX_IPS_PER_USER ? Infinity : MAX_IPS_PER_USER;
|
||||
user.type === "special" || !configIpLimit ? Infinity : configIpLimit;
|
||||
if (user.ip.length > ipLimit) {
|
||||
disableUser(token, "IP address limit exceeded.");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user