From a786afdff950586700ebd2f280f3f51c09b2f042 Mon Sep 17 00:00:00 2001 From: Walter Pearce Date: Fri, 31 Oct 2025 12:07:25 -0700 Subject: [PATCH] Add logging of hashed authorization information ... for cross-checking usage of compromised keys. Specifically, adds a `custom_metadata.auth_type` value, specifying the authentication type used for actions. Additionally, adds `http.request.headers.hashed_authorization` and `http.request.headers.hashed_cookie` for logging SHA256 hashed copies of the authorization and/or cookie headers used in the request. --- src/auth.rs | 10 ++++++++-- src/controllers/krate/publish.rs | 2 ++ src/middleware/log_request.rs | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 8a39d18ce4a..e4d2d1a370d 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -288,13 +288,19 @@ async fn authenticate(parts: &Parts, conn: &mut AsyncPgConnection) -> AppResult< match authenticate_via_cookie(parts, conn).await { Ok(None) => {} - Ok(Some(auth)) => return Ok(Authentication::Cookie(auth)), + Ok(Some(auth)) => { + parts.request_log().add("auth_type", "cookie"); + return Ok(Authentication::Cookie(auth)); + } Err(err) => return Err(err), } match authenticate_via_token(parts, conn).await { Ok(None) => {} - Ok(Some(auth)) => return Ok(Authentication::Token(auth)), + Ok(Some(auth)) => { + parts.request_log().add("auth_type", "token"); + return Ok(Authentication::Token(auth)); + } Err(err) => return Err(err), } diff --git a/src/controllers/krate/publish.rs b/src/controllers/krate/publish.rs index a927357c815..56737663671 100644 --- a/src/controllers/krate/publish.rs +++ b/src/controllers/krate/publish.rs @@ -172,6 +172,8 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult().map(|e| e.0.as_str()).unwrap_or_default(), error.message = response.extensions().get::().map(|e| e.0.as_str()).unwrap_or_default(),