Skip to content

Commit 92d228b

Browse files
Don't output whole timers map; hash headers in rust (#1411)
1 parent 3cfac4e commit 92d228b

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

Cargo.lock

Lines changed: 2 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
@@ -34,6 +34,7 @@ serde_yaml = "0.9.34"
3434
toml = "0.8.19"
3535
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
3636
tempfile = "3.14.0"
37+
hex = "0.4.3"
3738

3839
[workspace.dependencies.git2]
3940
default-features = false

josh-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ git-version = "0.3.9"
1717
git2 = { workspace = true }
1818
gix-object = "0.46.0"
1919
glob = "0.3.1"
20-
hex = "0.4.3"
20+
hex = { workspace = true }
2121
indoc = "2.0.5"
2222
itertools = "0.13.0"
2323
lazy_static = { workspace = true }

josh-proxy/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ repository = "https://github.com/josh-project/josh"
1010
version = "22.4.15"
1111

1212
[dependencies]
13+
sha2 = "0.10.8"
14+
hex = { workspace = true }
1315
base64 = { workspace = true }
1416
clap = { workspace = true }
1517
futures = { workspace = true }

josh-proxy/src/auth.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,25 @@ impl Handle {
9898
}
9999
}
100100

101+
fn hash_header(header: &hyper::http::HeaderValue) -> String {
102+
use sha2::{Digest, Sha256};
103+
104+
let mut hasher = Sha256::new();
105+
hasher.update(header.as_bytes());
106+
let result = hasher.finalize();
107+
hex::encode(result)
108+
}
109+
101110
pub fn add_auth(token: &str) -> josh::JoshResult<Handle> {
102111
let header = hyper::header::HeaderValue::from_str(&format!("Basic {}", BASE64.encode(token)))?;
103-
let hp = Handle {
104-
hash: Some(git2::Oid::hash_object(git2::ObjectType::Blob, header.as_bytes())?.to_string()),
112+
let handle = Handle {
113+
hash: Some(hash_header(&header)),
105114
};
106-
let p = Header {
115+
let header_wrapper = Header {
107116
header: Some(header),
108117
};
109-
AUTH.lock()?.insert(hp.clone(), p);
110-
Ok(hp)
118+
AUTH.lock()?.insert(handle.clone(), header_wrapper);
119+
Ok(handle)
111120
}
112121

113122
#[tracing::instrument()]
@@ -180,7 +189,7 @@ pub async fn check_http_auth(url: &str, auth: &Handle, required: bool) -> josh::
180189
}
181190

182191
tracing::info!(
183-
auth_timers = ?auth_timers,
192+
auth_timers_count = auth_timers.len(),
184193
"check_http_auth: no valid cached auth"
185194
);
186195

@@ -237,16 +246,14 @@ pub fn strip_auth(
237246
req.headers_mut().remove(hyper::header::AUTHORIZATION);
238247

239248
if let Some(header) = header {
240-
let hp = Handle {
241-
hash: Some(
242-
git2::Oid::hash_object(git2::ObjectType::Blob, header.as_bytes())?.to_string(),
243-
),
249+
let handle = Handle {
250+
hash: Some(hash_header(&header)),
244251
};
245-
let p = Header {
252+
let header_wrapper = Header {
246253
header: Some(header),
247254
};
248-
AUTH.lock()?.insert(hp.clone(), p);
249-
return Ok((hp, req));
255+
AUTH.lock()?.insert(handle.clone(), header_wrapper);
256+
return Ok((handle, req));
250257
}
251258

252259
Ok((Handle { hash: None }, req))

0 commit comments

Comments
 (0)