-
Notifications
You must be signed in to change notification settings - Fork 68
Add logging to /login failure
#4688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
39120cf
485a577
048acdb
6f167a8
612a15e
35a8d6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,8 @@ use zeroize::Zeroizing; | |
| use super::{MatrixError, MatrixJsonBody}; | ||
| use crate::{ | ||
| BoundActivityTracker, Limiter, METER, RequesterFingerprint, impl_from_error_for_route, | ||
| passwords::PasswordManager, rate_limit::PasswordCheckLimitedError, | ||
| passwords::{PasswordManager, PasswordVerificationResult}, | ||
| rate_limit::PasswordCheckLimitedError, | ||
| }; | ||
|
|
||
| static LOGIN_COUNTER: LazyLock<Counter<u64>> = LazyLock::new(|| { | ||
|
|
@@ -193,7 +194,7 @@ pub enum RouteError { | |
| NoPassword, | ||
|
|
||
| #[error("password verification failed")] | ||
| PasswordVerificationFailed(#[source] anyhow::Error), | ||
| PasswordVerificationFailed, | ||
|
||
|
|
||
| #[error("request rate limited")] | ||
| RateLimited(#[from] PasswordCheckLimitedError), | ||
|
|
@@ -210,6 +211,12 @@ pub enum RouteError { | |
|
|
||
| impl_from_error_for_route!(mas_storage::RepositoryError); | ||
|
|
||
| impl From<anyhow::Error> for RouteError { | ||
| fn from(err: anyhow::Error) -> Self { | ||
| Self::Internal(err.into()) | ||
| } | ||
| } | ||
|
|
||
| impl IntoResponse for RouteError { | ||
| fn into_response(self) -> axum::response::Response { | ||
| let sentry_event_id = | ||
|
|
@@ -241,7 +248,7 @@ impl IntoResponse for RouteError { | |
| error: "Missing property 'identifier", | ||
| status: StatusCode::BAD_REQUEST, | ||
| }, | ||
| Self::UserNotFound | Self::NoPassword | Self::PasswordVerificationFailed(_) => { | ||
| Self::UserNotFound | Self::NoPassword | Self::PasswordVerificationFailed => { | ||
| MatrixError { | ||
| errcode: "M_FORBIDDEN", | ||
| error: "Invalid username/password", | ||
|
|
@@ -576,28 +583,32 @@ async fn user_password_login( | |
| // Verify the password | ||
| let password = Zeroizing::new(password); | ||
|
|
||
| let new_password_hash = password_manager | ||
| match password_manager | ||
| .verify_and_upgrade( | ||
| &mut rng, | ||
| user_password.version, | ||
| password, | ||
| user_password.hashed_password.clone(), | ||
| ) | ||
| .await | ||
| .map_err(RouteError::PasswordVerificationFailed)?; | ||
|
|
||
| if let Some((version, hashed_password)) = new_password_hash { | ||
| // Save the upgraded password if needed | ||
| repo.user_password() | ||
| .add( | ||
| &mut rng, | ||
| clock, | ||
| &user, | ||
| version, | ||
| hashed_password, | ||
| Some(&user_password), | ||
| ) | ||
| .await?; | ||
| .await? | ||
| { | ||
| PasswordVerificationResult::Success(Some((version, hashed_password))) => { | ||
| // Save the upgraded password if needed | ||
| repo.user_password() | ||
| .add( | ||
| &mut rng, | ||
| clock, | ||
| &user, | ||
| version, | ||
| hashed_password, | ||
| Some(&user_password), | ||
| ) | ||
| .await?; | ||
| } | ||
| PasswordVerificationResult::Success(None) => {} | ||
| PasswordVerificationResult::Failure => { | ||
| return Err(RouteError::PasswordVerificationFailed); | ||
| } | ||
| } | ||
|
|
||
| // We're about to create a device, let's explicitly acquire a lock, so that | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea of adding a display implementation for things in datamodel, unless the whole thing has an obvious string representation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, have removed for now. Although I do suspect we'll run into this later where we want to ergonomically log the user, so not sure what the best plan there is