-
Notifications
You must be signed in to change notification settings - Fork 47
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
pageTokenSynchronizationTolerance check looks wrong #49
Comments
Hello @bpapez, Indeed, thank you for pointing it out. You can provide a PR if you want to, otherwise will make the change myself. |
Thanks for the quick response. I created the PR. |
Fix time comparison when checking pageToken time tolerance (fix #49)
We don't have any plans yet. When would you like to do your release? I'd say give it some testing, make sure that the solution works fine with your set of configurations/requirements (there can be a lot of combinations and potential corner-cases) and then if all goes well, we can create a new patch version for you. |
Thank you, sounds like a good plan. We still need to do some enhancement work, because our app can work on a Tomcat cluster and in that case we don't use the standard Tomcat sessions, but Spring sessions and we need to be able to continue working when a server goes down, so the load balancer then directs those sessions to other running servers. So we probable need to replace the SessionTokenKeyExtractor and InMemoryTokenHolder. Anyway, I still have a problem with the three AJAX requests sent on page initialization. Now with the fix in place it works fine on the first access to the page. However when clicking the reload button on the browser, we run into issues, because now pageTokens would exist, but the request header still sends the masterToken. I see in the debugger that when handleDynamicallyCreatedNodes handles the url of that AJAX request, the /CsrfServlet has returned the current pageTokens in the response, but it has not yet been parsed, so pageTokenWrapper.pageTokens is still empty and thus these three AJAX urls triggered in the init all are sent with the master token and fail. How is this supposed to work correctly? Is there anything I need to adapt? Should we move this comment to a new discussion or issue? |
You could try making sure that the |
Currently the request/response flow when loading the page looks like this:
On page reload (or navigating to other page and coming back)
So the problem is that the POST request to /CsrfServlet receiving the pageTokens does not yet have xhr.readyState == 4 (DONE) to get the result parsed, when already the POST request to settingsAction.do is sent. |
Hello @bpapez, It is a bit hard to suggest a solution for a scenario I don't fully see/understand. There are multiple ways in which this could potentially be solved, but you'd might need to analyze a couple of things like:
These are the high level ideas I can think of right now, but ofc there might be other, even more suitable solutions depending on your use case. Last but not least, this is an open-source project, hence you can tailor it to your needs. We are accepting suggestions and PRs. |
Hello, thank you very much for listing these options. It will come handy as I need to write a documentation how our customers will be able to solve problems on their pages. To fix the failures we had I was renaming the endpoints getting the information on page load, so that they could get unprotected, while the endpoint on the submit action remained CSRF protected. Due to that, we may not have a pressure to get a new csrfguard patch version. We are currently working on a custom implementation of the LogicalSessionExtractor and TokenHolder, as we use Spring Session with failover support in cluster, where a server can take over the sessions of another failing or shutdown server. |
@bpapez you are welcome. I'm glad you've managed to sort it out! |
I wanted to upgrade csrfguard from 3.1.0 to 4.1.1 in order to activate TokenPerPage in our application. We have a page, where on initialization three AJAX POST requests are sent to the same URL (with different Payload). Our automated test was failing after activating TokenPerPage. On debugging I found that the following method does not match the description:
www-project-csrfguard/csrfguard/src/main/java/org/owasp/csrfguard/token/service/TokenService.java
Lines 282 to 288 in fca27e9
I think that isBefore should be replaced with isAfter. To return true the current time should be before the sum of token creation time and tolerance, but currently its exactly the opposite.
The text was updated successfully, but these errors were encountered: