-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix refresh token flow in OIDC accounting for cookie split #1569
Conversation
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Codecov Report
@@ Coverage Diff @@
## main #1569 +/- ##
=======================================
Coverage 66.18% 66.18%
=======================================
Files 93 93
Lines 2339 2339
Branches 312 312
=======================================
Hits 1548 1548
Misses 722 722
Partials 69 69 |
Signed-off-by: Craig Perkins <craig5008@gmail.com>
return ''; | ||
} | ||
|
||
if (cookie.credentials?.expires_at > Date.now()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the check on 243, drop the coalescing operator? I'm not sure what this check would resolve to if it wasn't set (for whatever crazy reason). Could you also add unit tests?
if (cookie.credentials?.expires_at > Date.now()) { | |
if (cookie.credentials.expires_at > Date.now()) { |
@@ -277,6 +286,10 @@ export abstract class AuthenticationType implements IAuthenticationType { | |||
cookie: SecuritySessionCookie, | |||
request: OpenSearchDashboardsRequest | |||
): Promise<boolean>; | |||
public abstract refreshAccessToken( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide a default implementation that returns empty string?
Hi @cwperks! First of all, my apologies for this regression. I'm quite surprised I haven't been bitten by this before - as you describe, when accessing the cookie within the same request, it still holds the previous value. I did come up with an alternative solution that I'd like to run by you. It does unfortunately include accessing the raw Hapi objects, but we already do that within the cookie splitting code, so I guess one more place doesn't hurt. To my understanding, the Hapi request objects holds the cookie values in two different objects:
That said - when you set the cookie via the sessionStorageFactory it seems like the Then, upon the next request, the I haven't gone through all Hapi code yet, and I'm not sure when/how Anyhow, with that in mind, we can change these lines https://github.com/opensearch-project/security-dashboards-plugin/blob/main/server/session/cookie_splitter.ts#L142-L144
The
With this in place, all other changes can be dropped/reverted, which I'd say is the main advantage. I've tested this locally, and I've also tested to make sure it doesn't affect any existing cookies (re: backwards compatibility). I would appreciate your input on this - do you think this approach is worth pursuing? |
@jochen-kressin Thank you very much for the detailed explanation and proposed patch! I would be in favor of referencing the value from @peternied @davidlago @RyanL1997 @scrawfor99 @cliu123 Any thoughts on relying on the raw |
@jochen-kressin thanks for the detailed response, I'm sold
With this 💯 % on board |
@cwperks I'm onboard this too. Should we close this in lieu of @jochen-kressin 's PR? |
Closing in favor of #1580 |
Description
This PR fixes an issue with the refresh token workflow for OIDC after cookie splitting was introduced in 2.7.0. (Link to PR where cookie splitting was introduced: #1352)
The reason the flow was not working was because in the OIDC flow it would refresh the token in the
isValidCookie
call here. The implementation ofisValidCookie
inoidc_auth.ts
calls onsetExtraAuthStorage
to save the new access token and split it into multiple cookies.Later on in
authentication_type.ts
it calls onbuildAuthHeaderFromCookie
which calls on getExtraAuthStorageValue to unsplit the cookies.When operated on the same request object, the getter to get the new access token is not fetching the updated value. This PR makes it so that it does not rely on cookie splitting on the request where the access token is refreshed.
Category
[Enhancement, New feature, Bug fix, Test fix, Refactoring, Maintenance, Documentation]
Bug fix
Issues Resolved
#1522
Testing
[Please provide details of testing done: unit testing, integration testing and manual testing]
Check List
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.