diff options
| author | metamuffin <metamuffin@disroot.org> | 2023-12-11 01:19:51 +0100 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2023-12-11 01:19:51 +0100 | 
| commit | 36d7fb2790774c53415c96f8c6955be42bad952f (patch) | |
| tree | 4481dac53a6d0896e90ff72b9b68665e59e159db /server/src/routes/ui/account/session | |
| parent | 767d6c4c7b8518198b0343781128027051b94ae5 (diff) | |
| download | jellything-36d7fb2790774c53415c96f8c6955be42bad952f.tar jellything-36d7fb2790774c53415c96f8c6955be42bad952f.tar.bz2 jellything-36d7fb2790774c53415c96f8c6955be42bad952f.tar.zst  | |
(partially) fix security problem with federated session
Diffstat (limited to 'server/src/routes/ui/account/session')
| -rw-r--r-- | server/src/routes/ui/account/session/token.rs | 18 | 
1 files changed, 6 insertions, 12 deletions
diff --git a/server/src/routes/ui/account/session/token.rs b/server/src/routes/ui/account/session/token.rs index b6c22f7..969207d 100644 --- a/server/src/routes/ui/account/session/token.rs +++ b/server/src/routes/ui/account/session/token.rs @@ -12,7 +12,7 @@ use anyhow::anyhow;  use base64::Engine;  use chrono::{Duration, Utc};  use jellybase::CONF; -use jellycommon::user::User; +use jellycommon::user::PermissionSet;  use log::warn;  use std::sync::LazyLock; @@ -29,11 +29,11 @@ static SESSION_KEY: LazyLock<[u8; 32]> = LazyLock::new(|| {      }  }); -pub fn create(user: &User, expire: Duration) -> String { +pub fn create(username: String, permissions: PermissionSet, expire: Duration) -> String {      let session_data = SessionData {          expire: Utc::now() + expire, -        username: user.name.to_owned(), -        permissions: user.permissions.clone(), +        username: username.to_owned(), +        permissions,      };      let mut plaintext =          bincode::serde::encode_to_vec(&session_data, bincode::config::standard()).unwrap(); @@ -73,14 +73,8 @@ pub fn validate(token: &str) -> anyhow::Result<String> {  #[test]  fn test() {      let tok = create( -        &User { -            name: "blub".to_string(), -            display_name: "blub".to_owned(), -            password: vec![], -            admin: false, -            permissions: jellycommon::user::PermissionSet::default(), -            theme: jellycommon::user::Theme::Dark, -        }, +        "blub".to_string(), +        jellycommon::user::PermissionSet::default(),          Duration::days(1),      );      validate(&tok).unwrap();  |