-
Notifications
You must be signed in to change notification settings - Fork 306
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
CUSTCOM-168 OpenID Connect: Fixed simultaneous redirects and invalidation of session #4419
Conversation
...security-openid/src/main/java/fish/payara/security/openid/OpenIdAuthenticationMechanism.java
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
Hi @parysto , Thanks for the PR . A import is missing in
And can you also share the sample application with multiple protected resources on a page? |
Hi @jGauravGupta , have pushed the sample application to: https://github.com/parysto/OpenIDJsfDemo To trigger the race condition, set the validity time of the access token to a small value (like 1 min). Open the sample app, log in and wait until the token expired. Press F5 repeatedly, so that multiple requests are sent to Payara at the same time. Due to the race condition, you will be logged out and redirected to callback.xhtml. If you enabled logging for OpenIdAuthenticationMechanism, you will see log messages like:
Will fix the missing imports ;-) |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
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.
Hi @parysto,
Instead of locking the complete OpenIdAuthenticationMechanism#validateRequest
call per request, I recommend synchronizing in specific snippets e.g If access token expired in OpenIdAuthenticationMechanism#reAuthenticate
.
Hi @jGauravGupta , I will check if synchronizing |
Hi @jGauravGupta, hadn't any issues synchronizing on |
Hi @parysto, Thanks for updating the PR, Can you perform the locking operation only in case of token expired as mentioned above.
|
That's a good point (to improve performance). Will update the PR. |
This comment has been minimized.
This comment has been minimized.
Hi @parysto, Please fix the following syntax error:
|
jenkins test please |
Hi @jGauravGupta, is there something more I can do to complete this merge request? |
@@ -364,4 +368,20 @@ private void updateContext(JsonObject tokensObject) { | |||
} | |||
} | |||
|
|||
private Object getSessionLock(HttpServletRequest request) { |
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.
Is really the plan to put the lock to the session object and leave it there forever? What if the token expires for second time? The lock will be still in session attributes from previous iteration.
Also replication in cluster will have some latency, is it or isn't it a problem? (probably it isn't)
I don't say it is incorrect, I am only asking ;-)
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.
Interesting...
I know raw Object is not Serializable. I do not remember perfectly, but I do wonder what happens at HttpSession passivation... Or if session migrates to other VM...
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.
Is really the plan to put the lock to the session object and leave it there forever? What if the token expires for second time? The lock will be still in session attributes from previous iteration.
You mean the lock-object? Yes, when the token expires again, the same instance of the lock will be reused. So, we do not need to set the "lock-attribute" again as long as the user's session is not invalidated. When the user's session is invalidated, the lock will be removed. Or am I wrong?
Also replication in cluster will have some latency, is it or isn't it a problem? (probably it isn't)
Object itself does not have any fields that need to be transferred. So there shouldn't be a huge impact on latency. Although I haven't measured that ;-)
I know raw Object is not Serializable. I do not remember perfectly, but I do wonder what happens at HttpSession passivation... Or if session migrates to other VM...
Good point, haven't thought about that. Yes, Object is not Serializable, so passivation or replication will fail. Will change the lock to an "empty" implementation of Serializable.
I don't say it is incorrect, I am only asking ;-)
I appreciate your feedback :-)
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.
@pzygielo I think I investigated in years ago when I was fixing SSO session replication and I found that nonserializable objects are simply ignored if there is no special implementation for them.
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.
@dmatej thanks for checking
I think I investigated in years ago when I was fixing SSO session replication and I found that nonserializable objects are simply ignored if there is no special implementation for them.
However it's not so clear for me, given section 7.7.2 of Servlet 4.0 spec, and:
The distributed servlet container must throw an IllegalArgumentException for
objects where the container cannot support the mechanism necessary for migration
of the session storing them.
thus I'm not so sure about simply ignoring such session attributes. So it seems I have to investigate myself 😉
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.
Here is one implementation piece I found, that confirms your statement, about "how it is":
Payara/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java
Lines 2172 to 2178 in bdb468a
} else if (isSerializable(value)) { | |
saveNames.add(keys[i]); | |
saveValues.add(value); | |
//end HERCULES:mod | |
} else { | |
removeAttribute(keys[i], true, true); | |
} |
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.
"the container cannot support the mechanism necessary" ... such mechanism might be even ignoring objects which are managed by some mechanism on the other side.
But ... yes, I think there are some "blank spaces" in impl ... the problem is that implementing it would crash nearly all older+larger applications I have seen :D
Jenkins test please |
Jenkins test please |
1 similar comment
Jenkins test please |
Description
This is a bug fix / feature.
Testing
Testing Performed
Deployed developed app on instance with fix installed and compared/validated behavior while using the app (especially when refresh of token happened).
Testing Environment
OpenJDK 11 on Ubuntu 19.10