api/core: generate JWT rate limiting key in auth handler

This commit is contained in:
dumbmoron 2024-10-04 17:03:57 +00:00
parent 418602ca87
commit dcd33803c1
No known key found for this signature in database

View file

@ -81,12 +81,7 @@ export const runAPI = (express, app, __dirname) => {
max: env.rateLimitMax, max: env.rateLimitMax,
standardHeaders: true, standardHeaders: true,
legacyHeaders: false, legacyHeaders: false,
keyGenerator: req => { keyGenerator: req => req.rateLimitKey || generateHmac(getIP(req), ipSalt),
if (req.authorized) {
return generateHmac(req.header("Authorization"), ipSalt);
}
return generateHmac(getIP(req), ipSalt);
},
handler: handleRateExceeded handler: handleRateExceeded
}) })
@ -147,7 +142,7 @@ export const runAPI = (express, app, __dirname) => {
return fail(res, "error.api.auth.jwt.invalid"); return fail(res, "error.api.auth.jwt.invalid");
} }
req.authorized = true; req.rateLimitKey = generateHmac(req.header("Authorization"), ipSalt);
} catch { } catch {
return fail(res, "error.api.generic"); return fail(res, "error.api.generic");
} }