Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OIDC refresh token flow when using the cookie splitter #1580

Merged

Conversation

jochen-kressin
Copy link
Contributor

@jochen-kressin jochen-kressin commented Sep 11, 2023

Description

This PR fixes a regression regarding the OIDC refresh token flow, caused by the move to the split cookies here: #1352

It closes #1522 and is based on the research made by @cwperks in #1569.

In short, while the refresh token flow was still working correctly, the cookie splitter would not have access to the new idToken that was written to the cookie in the process of refreshing the token. Even though the new value was written, the cookie splitter could not access that value until the next request lifecycle. This caused a "Token expired" and the user would be unauthenticated.

TODO

End to end testing, but we will most likely do that in a separate PR.

Category

Bug fix

Why these changes are required?

To make sure that the OIDC refresh token flow works as expected.

What is the old behavior before changes and new behavior after changes?

If an idToken expires while the user is idle, the user would be unauthenticated even though the IdP provided a refreshed token.

The new behaviour corrects the refresh token flow, and the user stays authenticated.

Issues Resolved

#1522

Testing

Unit tests were added

Check List

  • New functionality includes testing
  • New functionality has been documented N/A
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…n set within the current request

Signed-off-by: Jochen Kressin <[email protected]>
// We don't want to mix and match between _states and .state.
// If we find the first additional cookie in _states, we
// use _states for all subsequent additional cookies
const requestHasNewerCookieState = rawRequest._states && rawRequest._states[cookiePrefix + 1];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cwperks Here I deviated a bit from the original code that I posted in your PR.

I added a check to make sure that we don't mix and match between whatever is in '_states' and '.state'.
Probably just a theoretical risk, but if the new token would use less cookies than the previous one, the unsplit cookie would contain a mix between the two without this check in place. Hope that's ok.

Copy link
Member

Choose a reason for hiding this comment

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

This makes sense to me. We would not want to end up with a bad cookie caused due to mix-up.

@jochen-kressin jochen-kressin changed the title Draft: Fix OIDC refresh token flow when using the cookie splitter Fix OIDC refresh token flow when using the cookie splitter Sep 13, 2023
@jochen-kressin
Copy link
Contributor Author

I removed the Draft status from this PR. While we still need integration tests for this, it probably makes sense to add those in a separate PR even though they should end up in this repository.

So from my side I'd consider this PR finished unless there are any changes wanted. Feedback is always welcome :)

Copy link
Member

@DarshitChanpura DarshitChanpura left a comment

Choose a reason for hiding this comment

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

LGTM!

// We don't want to mix and match between _states and .state.
// If we find the first additional cookie in _states, we
// use _states for all subsequent additional cookies
const requestHasNewerCookieState = rawRequest._states && rawRequest._states[cookiePrefix + 1];
Copy link
Member

Choose a reason for hiding this comment

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

This makes sense to me. We would not want to end up with a bad cookie caused due to mix-up.

@cwperks cwperks added the backport 2.x backport to 2.x branch label Sep 28, 2023
@DarshitChanpura
Copy link
Member

CI is being fixed by: #1596

@jochen-kressin
Copy link
Contributor Author

@DarshitChanpura Thanks for merging!

As per Peter's comment: #1567 (comment), this should be backported to 1.x together with the "offending" original cookie splitting PR: #1352

What is the process for getting things into the correct branch...?
Should I try to combine the two PRs into one, and then open a PR with 1.x as source and target branch?

@codecov
Copy link

codecov bot commented Oct 3, 2023

Codecov Report

Merging #1580 (08b83b3) into main (1e7b421) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1580   +/-   ##
=======================================
  Coverage   66.18%   66.18%           
=======================================
  Files          93       93           
  Lines        2339     2339           
  Branches      317      317           
=======================================
  Hits         1548     1548           
  Misses        722      722           
  Partials       69       69           

@DarshitChanpura
Copy link
Member

@DarshitChanpura Thanks for merging!

As per Peter's comment: #1567 (comment), this should be backported to 1.x together with the "offending" original cookie splitting PR: #1352

What is the process for getting things into the correct branch...? Should I try to combine the two PRs into one, and then open a PR with 1.x as source and target branch?

IMO they should be combine into one so we have a clean commit history.

@RyanL1997
Copy link
Collaborator

RyanL1997 commented Oct 5, 2023

I have tested @jochen-kressin's security frontend fork with my local set up based on main for these failing cypress tests and everything is all green:

  1. aggregation_view.js:
Screenshot 2023-10-05 at 1 00 51 PM
  1. multi_tenancy.js :
Screenshot 2023-10-05 at 12 39 14 PM
  1. default_tenant.js :
Screenshot 2023-10-05 at 12 39 31 PM

@RyanL1997 RyanL1997 merged commit d575e00 into opensearch-project:main Oct 5, 2023
12 of 14 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 5, 2023
…n set within the current request (#1580)

Signed-off-by: Jochen Kressin <[email protected]>
Co-authored-by: Darshit Chanpura <[email protected]>
(cherry picked from commit d575e00)
@RyanL1997 RyanL1997 added the backport 2.11 Backport to 2.11 branch label Oct 5, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 5, 2023
…n set within the current request (#1580)

Signed-off-by: Jochen Kressin <[email protected]>
Co-authored-by: Darshit Chanpura <[email protected]>
(cherry picked from commit d575e00)
@RyanL1997
Copy link
Collaborator

Merging, for more details about the cypress failure lets followup on #1599

peternied pushed a commit that referenced this pull request Oct 6, 2023
…n set within the current request (#1580) (#1603)

Signed-off-by: Jochen Kressin <[email protected]>
Co-authored-by: Darshit Chanpura <[email protected]>
(cherry picked from commit d575e00)

Co-authored-by: Jochen Kressin <[email protected]>
DarshitChanpura added a commit that referenced this pull request Oct 20, 2023
…n set within the current request (#1580) (#1602)

Signed-off-by: Jochen Kressin <[email protected]>
Co-authored-by: Darshit Chanpura <[email protected]>
(cherry picked from commit d575e00)

Co-authored-by: Jochen Kressin <[email protected]>
Co-authored-by: Darshit Chanpura <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport to 2.x branch backport 2.11 Backport to 2.11 branch v2.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] OpenID Token not refreshed
4 participants