Skip to content

Commit

Permalink
Constant time equal for auth
Browse files Browse the repository at this point in the history
  • Loading branch information
xarantolus committed Dec 31, 2023
1 parent effbd3c commit e284680
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ futures-util = "0.3.29"
log = "0.4.20"
macaddr = { version = "1.0.1", features = ["serde"] }
serde = { version = "1.0.193", features = ["derive"] }
subtle = "2.5.0"
tokio = { version = "1.34.0", features = ["full"] }
tokio-tungstenite = "0.21.0"
toml = "0.8.8"
Expand Down
3 changes: 2 additions & 1 deletion server/src/web_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use log::info;
use std::net::SocketAddr;
use warp::reject::Rejection;
use warp::reply::Reply;
use subtle::ConstantTimeEq;

use std::{convert::Infallible, sync::Arc};

Expand Down Expand Up @@ -109,7 +110,7 @@ struct AuthQuery {
fn with_auth(token: String) -> impl Filter<Extract = (bool,), Error = Rejection> + Clone {
warp::any()
.and(warp::filters::query::query::<AuthQuery>())
.map(move |query: AuthQuery| query.token == token)
.map(move |query: AuthQuery| query.token.as_bytes().ct_eq(token.as_bytes()).into())
}

pub async fn start_web_server(config: &Config, connection_manager: Arc<Manager>) {
Expand Down

0 comments on commit e284680

Please sign in to comment.