Skip to content

Commit

Permalink
Merge pull request #36 from quasiuslikecautious/resist-sid-fingerprin…
Browse files Browse the repository at this point in the history
…ting

[#24] Change default cookie name to avoid fingerprinting
  • Loading branch information
maxcountryman authored Mar 14, 2023
2 parents 0546463 + b01b050 commit a131376
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
//! .unwrap()
//! .split("=")
//! .collect::<Vec<_>>()[0],
//! "axum.sid"
//! "sid"
//! );
//!
//! # Ok(())
Expand Down
10 changes: 5 additions & 5 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<Store: SessionStore> SessionLayer<Store> {
store,
persistence_policy: PersistencePolicy::Always,
cookie_path: "/".into(),
cookie_name: "axum.sid".into(),
cookie_name: "sid".into(),
cookie_domain: None,
same_site_policy: SameSite::Strict,
session_ttl: Some(Duration::from_secs(24 * 60 * 60)),
Expand All @@ -135,7 +135,7 @@ impl<Store: SessionStore> SessionLayer<Store> {
self
}

/// Sets a cookie name for the session. Defaults to `"axum.sid"`.
/// Sets a cookie name for the session. Defaults to `"sid"`.
pub fn with_cookie_name(mut self, cookie_name: impl AsRef<str>) -> Self {
self.cookie_name = cookie_name.as_ref().to_owned();
self
Expand Down Expand Up @@ -435,7 +435,7 @@ mod tests {
.unwrap()
.to_str()
.unwrap()
.starts_with("axum.sid="))
.starts_with("sid="))
}

#[tokio::test]
Expand Down Expand Up @@ -597,7 +597,7 @@ mod tests {
let mut request = Request::get("/").body(Body::empty()).unwrap();
request
.headers_mut()
.insert(COOKIE, "axum.sid=aW52YWxpZC1zZXNzaW9uLWlk".parse().unwrap());
.insert(COOKIE, "sid=aW52YWxpZC1zZXNzaW9uLWlk".parse().unwrap());
let res = service.ready().await.unwrap().call(request).await.unwrap();
match expect_cookie_header_second {
ExpectedResult::Some => assert!(
Expand Down Expand Up @@ -684,7 +684,7 @@ mod tests {
.to_str()
.unwrap()
.len(),
121
116
);
}

Expand Down

0 comments on commit a131376

Please sign in to comment.