1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-31 09:24:31 +03:00

Fix request handling when the cookie header is not there

This commit is contained in:
Quentin Gliech
2021-09-25 18:09:37 +02:00
parent 28efac242e
commit bb8fe28f4f
2 changed files with 10 additions and 2 deletions

View File

@ -26,7 +26,7 @@ use headers::{Header, HeaderValue, SetCookie};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use thiserror::Error;
use warp::{
reject::{MissingCookie, Reject},
reject::{InvalidHeader, MissingCookie, Reject},
Filter, Rejection, Reply,
};
@ -120,6 +120,8 @@ where
{
encrypted(options)
.map(Some)
.recover(none_on_error::<T, InvalidHeader>)
.unify()
.recover(none_on_error::<T, MissingCookie>)
.unify()
.recover(none_on_error::<T, CookieDecryptionError<T>>)

View File

@ -19,7 +19,7 @@ use sqlx::{pool::PoolConnection, Executor, PgPool, Postgres};
use thiserror::Error;
use tracing::warn;
use warp::{
reject::{MissingCookie, Reject},
reject::{InvalidHeader, MissingCookie, Reject},
Filter, Rejection,
};
@ -134,6 +134,12 @@ async fn recover<T>(rejection: Rejection) -> Result<T, Rejection> {
// propagated
}
if let Some(e) = rejection.find::<InvalidHeader>() {
if e.name() == "cookie" {
return Err(warp::reject::custom(SessionLoadError::MissingCookie));
}
}
if let Some(_e) = rejection.find::<MissingCookie>() {
return Err(warp::reject::custom(SessionLoadError::MissingCookie));
}