fix(server): don't log invalid token in release builds (#112)

* fix(server): don't log invalid token in release builds

* refactor(auth): use inline formatting for auth logs

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
This commit is contained in:
Helmut K. C. Tessarek 2023-08-14 08:05:34 -04:00 committed by GitHub
parent 0b8f63de19
commit 9145c46e18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -11,11 +11,13 @@ pub fn check(host: &str, headers: &HeaderMap, tokens: Option<Vec<String>>) -> Re
.map(|v| v.to_str().unwrap_or_default())
.map(|v| v.split_whitespace().last().unwrap_or_default());
if !tokens.iter().any(|v| v == auth_header.unwrap_or_default()) {
#[cfg(debug_assertions)]
log::warn!(
"authorization failure for {} (header: {})",
host,
"authorization failure for {host} (token: {})",
auth_header.unwrap_or("none"),
);
#[cfg(not(debug_assertions))]
log::warn!("authorization failure for {host}");
return Err(error::ErrorUnauthorized("unauthorized\n"));
}
}