mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
api/core: generate JWT rate limiting key in auth handler
This commit is contained in:
parent
418602ca87
commit
dcd33803c1
1 changed files with 2 additions and 7 deletions
|
@ -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");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue