[pdm-devel] [PATCH yew-comp v3 19/21] LoginPanel/http helpers: add support for handling HttpOnly cookies

Shannon Sterz s.sterz at proxmox.com
Thu Feb 27 15:07:10 CET 2025


this makes sure that we handle tickets that are stored in in HttpOnly
cookies correctly by:

- assuming that the properly sign ticket is in a cookie we can't
  access when refreshing tickets and only an informational ticket is
  available to us.
- handling `TicketResult::HttpOnly` correctly

Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
 src/http_helpers.rs | 30 ++++++++++++++++++++++++++----
 src/login_panel.rs  |  5 ++++-
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/http_helpers.rs b/src/http_helpers.rs
index 9f0403f..e2489cc 100644
--- a/src/http_helpers.rs
+++ b/src/http_helpers.rs
@@ -108,11 +108,25 @@ async fn ticket_refresh_loop() {
                 }
                 Validity::Refresh => {
                     let client = CLIENT.with(|c| Rc::clone(&*c.borrow()));
-                    if let Ok(TicketResult::Full(auth)) =
+
+                    // if the ticket is not signed, there is no point in sending it, assume we
+                    // are using a HttpOnly cookie that is properly handled by the
+                    // browser/cookie anyway
+                    let result = if data.ticket.is_info_only() {
+                        client.refresh(&data.userid).await
+                    } else {
                         client.login(&data.userid, &data.ticket.to_string()).await
-                    {
-                        log::info!("ticket_refresh_loop: Got ticket update.");
-                        client.set_auth(auth.clone());
+                    };
+
+                    match result {
+                        // TODO: eventually deprecate support for `TicketResult::Full` and
+                        // throw an error. this package should only ever be used in a browser
+                        // context where authentication info should be set via HttpOnly cookies.
+                        Ok(TicketResult::Full(auth)) | Ok(TicketResult::HttpOnly(auth)) => {
+                            log::info!("ticket_refresh_loop: Got ticket update.");
+                            client.set_auth(auth.clone());
+                        }
+                        _ => { /* do nothing */ }
                     }
                 }
                 Validity::Valid => { /* do nothing  */ }
@@ -157,11 +171,19 @@ pub async fn http_login(
         .await?;
 
     match ticket_result {
+        // TODO: eventually deprecate support for `TicketResult::Full` and
+        // throw an error. this package should only ever be used in a browser
+        // context where authentication info should be set via HttpOnly cookies.
         TicketResult::Full(auth) => {
             client.set_auth(auth.clone());
             update_global_client(client);
             Ok(TicketResult::Full(auth))
         }
+        TicketResult::HttpOnly(auth) => {
+            client.set_auth(auth.clone());
+            update_global_client(client);
+            Ok(TicketResult::HttpOnly(auth))
+        }
         challenge => Ok(challenge),
     }
 }
diff --git a/src/login_panel.rs b/src/login_panel.rs
index d979bbb..aecbf80 100644
--- a/src/login_panel.rs
+++ b/src/login_panel.rs
@@ -74,7 +74,10 @@ impl ProxmoxLoginPanel {
         let link = ctx.link().clone();
         self.async_pool.spawn(async move {
             match crate::http_login(username, password, realm).await {
-                Ok(TicketResult::Full(info)) => {
+                // TODO: eventually deprecate support for `TicketResult::Full` and
+                // throw an error. this package should only ever be used in a browser
+                // context where authentication info should be set via HttpOnly cookies.
+                Ok(TicketResult::Full(info)) | Ok(TicketResult::HttpOnly(info)) => {
                     link.send_message(Msg::Login(info));
                 }
                 Ok(TicketResult::TfaRequired(challenge)) => {
-- 
2.39.5





More information about the pdm-devel mailing list