Skip to content

Sidechannel timing attack vulnerability #81

@jakubmanczak

Description

@jakubmanczak

The auth_via_credentials function only performs the expensive-in-terms-of-time hash if a password hash is found for a given user. This means that response times of any endpoint that requires authentication will be significantly and observably (!!) shorter for users with invalid handles, giving potential attackers unauthorized information - if a response is longer than usual, then this user is a valid target.

pub async fn auth_via_credentials(
        login: &str,
        password: &str,
        pool: &Pool<Postgres>,
    ) -> Result<User, OmniError> {
        let hash = match sqlx::query!(
            "SELECT password_hash FROM users WHERE handle = $1",
            login
        )
        .fetch_one(pool)
        .await
        {
            Ok(hash) => hash.password_hash,
            Err(e) => match e {
                sqlx::Error::RowNotFound => return Err(AuthError::InvalidCredentials)?,
                _ => return Err(OmniError::SqlxError(e))?,
            },
        };
        let argon = Argon2::default();
        let hash = match PasswordHash::new(&hash) {
            Ok(hash) => hash,
            Err(e) => return Err(e)?,
        };

        match argon.verify_password(password.as_bytes(), &hash).is_ok() {
            true => User::get_by_handle(login, pool).await,
            false => Err(AuthError::InvalidCredentials)?,
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions