Skip to content

Ensure SAML POST requests preserve an existing session#5624

Merged
orenyk merged 1 commit intomainfrom
oyk-saml-cookies-posthaste
Nov 23, 2021
Merged

Ensure SAML POST requests preserve an existing session#5624
orenyk merged 1 commit intomainfrom
oyk-saml-cookies-posthaste

Conversation

@orenyk
Copy link
Contributor

@orenyk orenyk commented Nov 21, 2021

Currently, an external POST request to the IdP will not have access to
an existing session since the cookie is blocked due to SameSite=Lax.
This results in users with an active session having to sign in again if
sent back to the IdP with a POST SAML request.

However, if the POST request comes from the IdP the session will be
available in that request. Therefore, this commit inserts a new action
within our SAML POST handling that captures the SAML parameters of the
original POST request, populates a form with them (with appropriate CSRF
handling), and then submits that form with JS to create an "internal"
POST request with access to the session. This new action skips session
handling so it does not override an existing IdP session cookie.

@orenyk orenyk requested a review from jmhooper November 21, 2021 01:52
@orenyk orenyk force-pushed the oyk-saml-cookies-posthaste branch 2 times, most recently from eafc61e to e153724 Compare November 21, 2021 02:24
@orenyk orenyk force-pushed the oyk-saml-cookies-posthaste branch from e153724 to 987fb15 Compare November 21, 2021 03:19
@orenyk orenyk force-pushed the oyk-saml-cookies-posthaste branch 2 times, most recently from 4cc7f75 to 176bad6 Compare November 23, 2021 03:13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmhooper @zachmargolis so this test works (e.g. fails when we don't update the path in the concern) but only when the routes are reordered a little so that the get comes after the post. I think this has to do with the fact that RSpec looks for a match in the routes file but doesn't check the HTTP verb, so if the get comes first it actually sets the request path to /api/saml/auth2021, even though this controller action is handled by /api/saml/authpost2021 when post is used.

@orenyk orenyk force-pushed the oyk-saml-cookies-posthaste branch from 176bad6 to e4d28a6 Compare November 23, 2021 03:18
@orenyk orenyk force-pushed the oyk-saml-cookies-posthaste branch from e4d28a6 to a596eee Compare November 23, 2021 03:18
Copy link
Contributor

@jmhooper jmhooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a comment about a test, but think this should work otherwise

@orenyk orenyk force-pushed the oyk-saml-cookies-posthaste branch from a596eee to a3e4ff9 Compare November 23, 2021 17:02
Currently, an external POST request to the IdP will not have access to
an existing session since the cookie is blocked due to `SameSite=Lax`.
This results in users with an active session having to sign in again if
sent back to the IdP with a POST SAML request.

However, if the POST request comes _from_ the IdP the session will be
available in that request. Therefore, this commit inserts a new action
within our SAML POST handling that captures the SAML parameters of the
original POST request, populates a form with them (with appropriate CSRF
handling), and then submits that form with JS to create an "internal"
POST request with access to the session. This new action skips session
handling so it does not override an existing IdP session cookie.
@orenyk orenyk force-pushed the oyk-saml-cookies-posthaste branch from a3e4ff9 to 69b7362 Compare November 23, 2021 17:17
@orenyk orenyk merged commit 6b2a96e into main Nov 23, 2021
@orenyk orenyk deleted the oyk-saml-cookies-posthaste branch November 23, 2021 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants