-
Notifications
You must be signed in to change notification settings - Fork 6k
NPE in HttpSessionSecurityContextRepository.isTransientAuthentication #8947
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
Comments
@stovocor, I agree that a Since |
@stovocor, thank you for pointing this out. I was looking into the code and the if (authentication == null || trustResolver.isAnonymous(authentication)) { // authentication is being checked for null
if (logger.isDebugEnabled()) {
logger.debug("SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.");
}
if (httpSession != null && authBeforeExecution != null) {
// SEC-1587 A non-anonymous context may still be in the session
// SEC-1735 remove if the contextBeforeExecution was not anonymous
httpSession.removeAttribute(springSecurityContextKey);
}
return;
}
if (httpSession == null) {
httpSession = createNewSessionIfAllowed(context); // the method that is throwing NPE call
} So in the scenario where the It seems to be a concurrency issue where the To narrow the problem down, could you provide a sample that replicates the behavior? |
I am very sorry, but as I mentioned in the original bugreport, I am not able to reproduce this problem and it occurs rarely. |
@stovocor I see, thanks for the feedback. We are planning to work on a more general solution that would address more scenarios. @jzheaux do we have already an issue open for that? |
Yes, #9634 |
Hi @stovocor, we have now a proposed PR #9813 to address this problem. |
Ensure that isTransientAuthentication reuses the same authentication object from saveContext Closes spring-projectsgh-8947
Ensure that isTransientAuthentication reuses the same authentication object from saveContext Closes gh-8947
Ensure that isTransientAuthentication reuses the same authentication object from saveContext Closes gh-8947
Ensure that isTransientAuthentication reuses the same authentication object from saveContext Closes gh-8947
Ensure that isTransientAuthentication reuses the same authentication object from saveContext Closes gh-8947
Hello @stovocor, the PR is now merged and is aimed at the milestone 5.6.0-M1. Thanks for the report and feel free to discuss here if you want anything else. |
Ensure that isTransientAuthentication reuses the same authentication object from saveContext Closes spring-projectsgh-8947
Describe the bug
On our systems we see a
NullPointerException
for cached static resources with spring-security-web-5.3.3:This seems to happen because the authentication returned by
SecurityContextHolder.getContext()
is null.To Reproduce
Unknown, because the error does not happen often.
Expected behavior
I am not sure if the authentication may be null at all, but instead of a
NullPointerException
resulting in an "Internal Server Error" I would expect a plain "Unauthorized".The text was updated successfully, but these errors were encountered: