mirror of
https://github.com/dani-garcia/vaultwarden
synced 2024-12-14 17:43:46 +01:00
Include IP in invalid admin token error
This commit is contained in:
parent
4309df8334
commit
a0a08c4c5a
2 changed files with 13 additions and 2 deletions
|
@ -91,8 +91,15 @@ impl<'a, 'r> FromRequest<'a, 'r> for AdminToken {
|
||||||
// Option 2a: Send it to admin email, like upstream
|
// Option 2a: Send it to admin email, like upstream
|
||||||
// Option 2b: Print in console or save to data dir, so admin can check
|
// Option 2b: Print in console or save to data dir, so admin can check
|
||||||
|
|
||||||
|
use crate::auth::ClientIp;
|
||||||
|
|
||||||
|
let ip = match request.guard::<ClientIp>() {
|
||||||
|
Outcome::Success(ip) => ip,
|
||||||
|
_ => err_handler!("Error getting Client IP"),
|
||||||
|
};
|
||||||
|
|
||||||
if access_token != config_token {
|
if access_token != config_token {
|
||||||
err_handler!("Invalid admin token")
|
err_handler!("Invalid admin token", format!("IP: {}.", ip.ip))
|
||||||
}
|
}
|
||||||
|
|
||||||
Outcome::Success(AdminToken {})
|
Outcome::Success(AdminToken {})
|
||||||
|
|
|
@ -163,7 +163,11 @@ macro_rules! err_json {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! err_handler {
|
macro_rules! err_handler {
|
||||||
($expr:expr) => {{
|
($expr:expr) => {{
|
||||||
error!("Unauthorized Error: {:#?}", $expr);
|
error!("Unauthorized Error: {}", $expr);
|
||||||
return rocket::Outcome::Failure((rocket::http::Status::Unauthorized, $expr));
|
return rocket::Outcome::Failure((rocket::http::Status::Unauthorized, $expr));
|
||||||
}};
|
}};
|
||||||
|
($usr_msg:expr, $log_value:expr) => {{
|
||||||
|
error!("Unauthorized Error: {}. {}", $usr_msg, $log_value);
|
||||||
|
return rocket::Outcome::Failure((rocket::http::Status::Unauthorized, $usr_msg));
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue