mirror of
https://github.com/aljazceru/pubky-core.git
synced 2025-12-31 12:54:35 +01:00
feat(homeserver): use full public key as cookie name
This commit is contained in:
@@ -146,13 +146,9 @@ fn authorize(
|
||||
Err(Error::with_status(StatusCode::FORBIDDEN))
|
||||
}
|
||||
|
||||
fn cookie_name(public_key: &PublicKey) -> String {
|
||||
public_key.to_string().chars().take(8).collect::<String>()
|
||||
}
|
||||
|
||||
pub fn session_secret_from_cookies(cookies: Cookies, public_key: &PublicKey) -> Option<String> {
|
||||
cookies
|
||||
.get(&cookie_name(public_key))
|
||||
.get(&public_key.to_string())
|
||||
.map(|c| c.value().to_string())
|
||||
}
|
||||
|
||||
@@ -162,7 +158,7 @@ fn session_secret_from_headers(headers: &HeaderMap, public_key: &PublicKey) -> O
|
||||
.get_all(header::COOKIE)
|
||||
.iter()
|
||||
.filter_map(|h| h.to_str().ok())
|
||||
.find(|h| h.starts_with(&cookie_name(public_key)))
|
||||
.find(|h| h.starts_with(&public_key.to_string()))
|
||||
.and_then(|h| {
|
||||
h.split(';')
|
||||
.next()
|
||||
|
||||
@@ -103,10 +103,7 @@ pub async fn signin(
|
||||
|
||||
wtxn.commit()?;
|
||||
|
||||
let mut cookie = Cookie::new(
|
||||
public_key.to_string().chars().take(8).collect::<String>(),
|
||||
session_secret,
|
||||
);
|
||||
let mut cookie = Cookie::new(public_key.to_string(), session_secret);
|
||||
|
||||
cookie.set_path("/");
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct CookieJar {
|
||||
impl CookieJar {
|
||||
pub(crate) fn store_session_after_signup(&self, response: &Response, pubky: &PublicKey) {
|
||||
for (header_name, header_value) in response.headers() {
|
||||
let cookie_name = &pubky.to_string().chars().take(8).collect::<String>();
|
||||
let cookie_name = &pubky.to_string();
|
||||
|
||||
if header_name == "set-cookie"
|
||||
&& header_value.as_ref().starts_with(cookie_name.as_bytes())
|
||||
@@ -70,7 +70,7 @@ impl CookieStore for CookieJar {
|
||||
let host = url.host_str().unwrap_or("");
|
||||
|
||||
if let Ok(public_key) = PublicKey::try_from(host) {
|
||||
let cookie_name = public_key.to_string().chars().take(8).collect::<String>();
|
||||
let cookie_name = public_key.to_string();
|
||||
|
||||
return self.pubky_sessions.read().unwrap().get(host).map(|secret| {
|
||||
HeaderValue::try_from(format!("{cookie_name}={secret}")).unwrap()
|
||||
|
||||
Reference in New Issue
Block a user