Skip check for rate limit bypass if no user id is provided
This commit is contained in:
parent
ac2062e49d
commit
9f783ec96e
@ -46,8 +46,10 @@ export default function rateLimit(opts: {
|
|||||||
}): any {
|
}): any {
|
||||||
return async (req: Request, res: Response, next: NextFunction): Promise<any> => {
|
return async (req: Request, res: Response, next: NextFunction): Promise<any> => {
|
||||||
// exempt user? if so, immediately short circuit
|
// exempt user? if so, immediately short circuit
|
||||||
const rights = await getRights(req.user_id);
|
if (req.user_id) {
|
||||||
if (rights.has("BYPASS_RATE_LIMITS")) return;
|
const rights = await getRights(req.user_id);
|
||||||
|
if (rights.has("BYPASS_RATE_LIMITS")) return;
|
||||||
|
}
|
||||||
|
|
||||||
const bucket_id = opts.bucket || req.originalUrl.replace(API_PREFIX_TRAILING_SLASH, "");
|
const bucket_id = opts.bucket || req.originalUrl.replace(API_PREFIX_TRAILING_SLASH, "");
|
||||||
var executor_id = getIpAdress(req);
|
var executor_id = getIpAdress(req);
|
||||||
@ -161,7 +163,7 @@ export async function initRateLimits(app: Router) {
|
|||||||
app.use("/auth/register", rateLimit({ onlyIp: true, success: true, ...routes.auth.register }));
|
app.use("/auth/register", rateLimit({ onlyIp: true, success: true, ...routes.auth.register }));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function hitRoute(opts: { executor_id: string; bucket_id: string; max_hits: number; window: number }) {
|
async function hitRoute(opts: { executor_id: string; bucket_id: string; max_hits: number; window: number; }) {
|
||||||
const id = opts.executor_id + opts.bucket_id;
|
const id = opts.executor_id + opts.bucket_id;
|
||||||
var limit = Cache.get(id);
|
var limit = Cache.get(id);
|
||||||
if (!limit) {
|
if (!limit) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user