Skip to content

Commit

Permalink
make cookies samesite lax
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-dev committed Jul 19, 2024
1 parent 9c88038 commit 961c939
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/controllers/oauth_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl AuthState {
}

pub fn into_cookie(self) -> Result<Cookie<'static>> {
Ok(Cookie::new(OAUTH_COOKIE, self.encode_b64()?))
Ok(Cookie::build((OAUTH_COOKIE, self.encode_b64()?)).same_site(rocket::http::SameSite::Lax).build())
}

pub fn from_req(
Expand Down
6 changes: 3 additions & 3 deletions src/ephemeral/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn ensure_logged_in_and_redirect(
cookies: &CookieJar,
uri: Origin,
) -> Redirect {
cookies.add_private(Cookie::new(REDIRECT_COOKIE, uri.to_string()));
cookies.add_private(Cookie::build((REDIRECT_COOKIE, uri.to_string())).same_site(rocket::http::SameSite::Lax));
Redirect::to(uri!(new_session))
}

Expand All @@ -45,11 +45,11 @@ impl SessionCookie {
SessionCookie {
session_id: session.id,
}
}
}

pub fn login(self, cookies: &CookieJar) {
let session_str = serde_urlencoded::to_string(self).unwrap();
let session_cookie = Cookie::new(SESSION_COOKIE, session_str);
let session_cookie = Cookie::build((SESSION_COOKIE, session_str)).same_site(rocket::http::SameSite::Lax);
cookies.add_private(session_cookie);
}

Expand Down

0 comments on commit 961c939

Please sign in to comment.