From efe1046e847c913f93f470c7d10bea065897a2b2 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sun, 10 May 2026 11:03:43 +0800 Subject: [PATCH] chore: log redacted SAML auth metadata --- crates/gpapi/src/auth.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/gpapi/src/auth.rs b/crates/gpapi/src/auth.rs index 1db8357..3f8b1f2 100644 --- a/crates/gpapi/src/auth.rs +++ b/crates/gpapi/src/auth.rs @@ -72,7 +72,11 @@ impl SamlAuthData { let prelogin_cookie = parse_xml_tag(html, "prelogin-cookie"); let portal_userauthcookie = parse_xml_tag(html, "portal-userauthcookie"); - SamlAuthData::new(username, prelogin_cookie, portal_userauthcookie).map_err(AuthDataParseError::Invalid) + let auth_data = + SamlAuthData::new(username, prelogin_cookie, portal_userauthcookie).map_err(AuthDataParseError::Invalid)?; + auth_data.log_summary("html"); + + Ok(auth_data) } Some(status) => Err(AuthDataParseError::Invalid(anyhow::anyhow!( "SAML auth status: {}", @@ -102,6 +106,7 @@ impl SamlAuthData { AuthDataParseError::Invalid(anyhow::anyhow!(e)) })?; + auth_data.log_summary("gpcallback-cas"); return Ok(auth_data); } @@ -129,6 +134,21 @@ impl SamlAuthData { pub fn token(&self) -> Option<&str> { self.token.as_deref() } + + fn log_summary(&self, source: &str) { + info!( + "Parsed SAML auth data: source={}, username_present={}, prelogin_cookie_len={}, portal_userauthcookie_len={}, token_len={}", + source, + !self.username.is_empty(), + optional_len(self.prelogin_cookie.as_deref()), + optional_len(self.portal_userauthcookie.as_deref()), + optional_len(self.token.as_deref()) + ); + } +} + +fn optional_len(value: Option<&str>) -> usize { + value.unwrap_or_default().len() } fn parse_xml_tag(html: &str, tag: &str) -> Option {