MCPcopy Create free account
hub / github.com/evilsocket/cake / check_ui_auth

Function check_ui_auth

cake-core/src/cake/sharding/api/ui.rs:338–365  ·  view source on GitHub ↗

Check basic auth if `--ui-auth` is configured. Returns true if OK.

(
    state: &web::Data<Arc<RwLock<Master<M>>>>,
    req: &HttpRequest,
)

Source from the content-addressed store, hash-verified

336
337/// Check basic auth if `--ui-auth` is configured. Returns true if OK.
338async fn check_ui_auth<M: Model>(
339 state: &web::Data<Arc<RwLock<Master<M>>>>,
340 req: &HttpRequest,
341) -> bool {
342 let master = state.read().await;
343 let expected = match &master.ctx.args.ui_auth {
344 Some(cred) => cred.clone(),
345 None => return true, // no auth configured
346 };
347
348 let header = match req.headers().get("Authorization") {
349 Some(h) => h.to_str().unwrap_or(""),
350 None => return false,
351 };
352
353 if let Some(encoded) = header.strip_prefix("Basic ") {
354 if let Ok(decoded) = base64::Engine::decode(
355 &base64::engine::general_purpose::STANDARD,
356 encoded.trim(),
357 ) {
358 if let Ok(cred_str) = String::from_utf8(decoded) {
359 return cred_str == expected;
360 }
361 }
362 }
363
364 false
365}

Callers 2

indexFunction · 0.85
topologyFunction · 0.85

Calls 2

cloneMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected