mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-07-27 22:29:10 +00:00
Basic ratelimit for user login (including 2FA) and admin login
This commit is contained in:
parent
0a5df06e77
commit
5529264c3f
7 changed files with 134 additions and 2 deletions
|
@ -166,6 +166,10 @@ fn post_admin_login(
|
|||
) -> Result<Redirect, Flash<Redirect>> {
|
||||
let data = data.into_inner();
|
||||
|
||||
if crate::ratelimit::check_limit_admin(&ip.ip).is_err() {
|
||||
return Err(Flash::error(Redirect::to(admin_url(referer)), "Too many requests, try again later."));
|
||||
}
|
||||
|
||||
// If the token is invalid, redirect to login page
|
||||
if !_validate_token(&data.token) {
|
||||
error!("Invalid admin token. IP: {}", ip.ip);
|
||||
|
|
|
@ -84,6 +84,9 @@ fn _password_login(data: ConnectData, conn: DbConn, ip: &ClientIp) -> JsonResult
|
|||
err!("Scope not supported")
|
||||
}
|
||||
|
||||
// Ratelimit the login
|
||||
crate::ratelimit::check_limit_login(&ip.ip)?;
|
||||
|
||||
// Get the user
|
||||
let username = data.username.as_ref().unwrap();
|
||||
let user = match User::find_by_mail(username, &conn) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue