Skip to content

Commit 5ed0b3e

Browse files
committed
adjust cookie security settings
1 parent 1f7c614 commit 5ed0b3e

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/handlers/enrollment.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use axum::{Json, Router, extract::State, routing::post};
2-
use axum_extra::extract::{PrivateCookieJar, cookie::Cookie};
2+
use axum_extra::extract::{
3+
PrivateCookieJar,
4+
cookie::{Cookie, SameSite},
5+
};
36
use time::OffsetDateTime;
47

58
use super::register_mfa::router as register_mfa_router;
@@ -56,7 +59,14 @@ async fn start_enrollment_process(
5659
);
5760
// set session cookie
5861
let cookie = Cookie::build((ENROLLMENT_COOKIE_NAME, token))
59-
.expires(OffsetDateTime::from_unix_timestamp(response.deadline_timestamp).unwrap());
62+
.expires(
63+
OffsetDateTime::from_unix_timestamp(response.deadline_timestamp).map_err(|_| {
64+
ApiError::Unexpected("Invalid enrollment deadline timestamp".into())
65+
})?,
66+
)
67+
.http_only(true)
68+
.same_site(SameSite::Strict)
69+
.path("/api/v1/enrollment");
6070

6171
Ok((private_cookies.add(cookie), Json(response)))
6272
} else {

src/handlers/password_reset.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use axum::{Json, Router, extract::State, routing::post};
2-
use axum_extra::extract::{PrivateCookieJar, cookie::Cookie};
2+
use axum_extra::extract::{
3+
PrivateCookieJar,
4+
cookie::{Cookie, SameSite},
5+
};
36
use time::OffsetDateTime;
47

58
use crate::{
@@ -65,7 +68,14 @@ async fn start_password_reset(
6568
if let core_response::Payload::PasswordResetStart(response) = payload {
6669
// set session cookie
6770
let cookie = Cookie::build((PASSWORD_RESET_COOKIE_NAME, token))
68-
.expires(OffsetDateTime::from_unix_timestamp(response.deadline_timestamp).unwrap());
71+
.expires(
72+
OffsetDateTime::from_unix_timestamp(response.deadline_timestamp).map_err(|_| {
73+
ApiError::Unexpected("Invalid password reset deadline timestamp".into())
74+
})?,
75+
)
76+
.http_only(true)
77+
.same_site(SameSite::Strict)
78+
.path("/api/v1/password-reset");
6979

7080
info!("Started password reset process");
7181
Ok((private_cookies.add(cookie), Json(response)))

0 commit comments

Comments
 (0)