You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When xsrf token is invalid, delegate.resolveCsrfTokenValue returns null, but the return type of SpaCsrfTokenRequestHandler.resolveCsrfTokenValue is not nullable, which causes NullPointerException
To Reproduce
Use the setup in csrf-integration-javascript-spa, and send a post request with invalid xsrf token, the server will throw NullPointerException.
Expected behavior
the server should throw InvalidCsrfTokenException
Possible solution
-overridefunresolveCsrfTokenValue(request:HttpServletRequest, csrfToken:CsrfToken): String {
+overridefunresolveCsrfTokenValue(request:HttpServletRequest, csrfToken:CsrfToken): String? {
/* * If the request contains a request header, use CsrfTokenRequestAttributeHandler * to resolve the CsrfToken. This applies when a single-page application includes * the header value automatically, which was obtained via a cookie containing the * raw CsrfToken.*/returnif (StringUtils.hasText(request.getHeader(csrfToken.headerName))) {
super.resolveCsrfTokenValue(request, csrfToken)
} else {
/* * In all other cases (e.g. if the request contains a request parameter), use * XorCsrfTokenRequestAttributeHandler to resolve the CsrfToken. This applies * when a server-side rendered form includes the _csrf request parameter as a * hidden input.*/
delegate.resolveCsrfTokenValue(request, csrfToken)
}
}
The text was updated successfully, but these errors were encountered:
Hi, @meouwu-dev! I've tried applying the code from the reference and sent an invalid CSRF token; however, I get a 403 instead of a NullPointerException.
Can you please provide a reproducing GitHub sample? That will help get to the bottom of the issue faster.
Thanks for reporting this @meouwu-dev! I was able to reproduce using a missing token scenario (but not an invalid token) and see the issue exists in the Kotlin example. I've fixed this and additionally added some tests to the testing example in the docs as well.
springboot:3.2.1
springsecurity:6.2.1
When xsrf token is invalid, delegate.resolveCsrfTokenValue returns null, but the return type of SpaCsrfTokenRequestHandler.resolveCsrfTokenValue is not nullable, which causes NullPointerException
To Reproduce
Use the setup in csrf-integration-javascript-spa, and send a post request with invalid xsrf token, the server will throw NullPointerException.
Expected behavior
the server should throw InvalidCsrfTokenException
Possible solution
The text was updated successfully, but these errors were encountered: