@@ -43,6 +43,11 @@ use crate::{impl_from_error_for_route, upstream_oauth2::cache::MetadataCache, Pr
4343pub struct Params {
4444 state : String ,
4545
46+ /// An extra parameter to track whether the POST request was re-made by us
47+ /// to the same URL to escape Same-Site cookies restrictions
48+ #[ serde( default ) ]
49+ did_mas_repost_to_itself : bool ,
50+
4651 #[ serde( flatten) ]
4752 code_or_error : CodeOrError ,
4853}
@@ -175,10 +180,14 @@ pub(crate) async fn handler(
175180 // response_mode the provider uses
176181 let params = match ( provider. response_mode , query_params, form_params) {
177182 ( UpstreamOAuthProviderResponseMode :: Query , Some ( Query ( query_params) ) , None ) => query_params,
178- ( UpstreamOAuthProviderResponseMode :: FormPost , None , Some ( Form ( form_params) ) ) => {
179- // We got there from a cross-site form POST, so we need to render a form with
180- // the same values, which posts back to the same URL
181- if sessions_cookie. is_empty ( ) {
183+ ( UpstreamOAuthProviderResponseMode :: FormPost , None , Some ( Form ( mut form_params) ) ) => {
184+ // We set the cookies with a `Same-Site` policy set to `Lax`, so because this is
185+ // usually a cross-site form POST, we need to render a form with the
186+ // same values, which posts back to the same URL. However, there are
187+ // other valid reasons for the cookie to be missing, so to track whether we did
188+ // this POST ourselves, we set a flag.
189+ if sessions_cookie. is_empty ( ) && !form_params. did_mas_repost_to_itself {
190+ form_params. did_mas_repost_to_itself = true ;
182191 let context =
183192 FormPostContext :: new_for_current_url ( form_params) . with_language ( & locale) ;
184193 let html = templates. render_form_post ( & context) ?;
0 commit comments