Skip to content

Commit fa81f70

Browse files
pflanzesyphar
authored andcommitted
Cargo,web/builds: use constant_time_eq for security
1 parent 811fb95 commit fa81f70

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ chrono = { version = "0.4.11", default-features = false, features = ["clock", "s
109109
# Transitive dependencies we don't use directly but need to have specific versions of
110110
thread_local = "1.1.3"
111111
humantime = "2.1.0"
112+
constant_time_eq = "0.3.0"
112113

113114
[dependencies.postgres]
114115
version = "0.19"

src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub struct Config {
4141
// Gitlab authentication
4242
pub(crate) gitlab_accesstoken: Option<String>,
4343

44-
// Access token for APIs for crates.io
44+
// Access token for APIs for crates.io (careful: use
45+
// constant_time_eq for comparisons!)
4546
pub(crate) cratesio_token: Option<String>,
4647

4748
// amount of retries for external API calls, mostly crates.io

src/web/builds.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use axum_extra::{
2424
TypedHeader,
2525
};
2626
use chrono::{DateTime, Utc};
27+
use constant_time_eq::constant_time_eq;
2728
use http::StatusCode;
2829
use semver::Version;
2930
use serde::Serialize;
@@ -192,7 +193,7 @@ pub(crate) async fn build_trigger_rebuild_handler(
192193
let TypedHeader(auth_header) = opt_auth_header.ok_or(JsonAxumNope(AxumNope::Unauthorized(
193194
"Missing authentication token",
194195
)))?;
195-
if auth_header.token() != expected_token {
196+
if !constant_time_eq(auth_header.token().as_bytes(), expected_token.as_bytes()) {
196197
return Err(JsonAxumNope(AxumNope::Unauthorized(
197198
"The token used for authentication is not valid",
198199
)));

0 commit comments

Comments
 (0)