-
Notifications
You must be signed in to change notification settings - Fork 48
Improve JavaScriptServlet client side caching strategy #327
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
Improve JavaScriptServlet client side caching strategy #327
Conversation
…the same (using md5) Externalize JavaScript Etag to allow custom client side strategy using the Etag in a query param for that script.
…g management of the script. (OWASP/www-project-csrfguard#327) If the PR is merged on the original project, the client side optimization could be propagated to Jahia usage.
Hi @forgedhallpass, do you think it is possible to have a feedback on that PR ? Is it something that could be merged ? |
Hello @jayblanc, Thank you for your contributions. Sorry for the late response, I've been quite busy lately. I'll try to review everything next week and, if all goes well, create a release with the changes. |
Hello @forgedhallpass , |
csrfguard/src/main/java/org/owasp/csrfguard/servlet/JavaScriptServlet.java
Outdated
Show resolved
Hide resolved
csrfguard/src/main/java/org/owasp/csrfguard/servlet/JavaScriptServlet.java
Outdated
Show resolved
Hide resolved
csrfguard/src/main/java/org/owasp/csrfguard/servlet/JavaScriptServlet.java
Show resolved
Hide resolved
Hello @jayblanc, Apologies again for the delayed response. I've taken some time to consider the different configuration scenarios, including page tokens, token rotation, the fact that the master token is embedded in the script, and both stateful and stateless modes. While the caching approach might not be suitable in every case, I still think it's a valuable improvement that can benefit many setups. I've added a few minor observations for consideration. Once you've had a chance to respond, we can move forward with preparing a new release. Thanks again for your contribution! |
…nt-cache-strategy' into Improve-JavaScriptServlet-client-cache-strategy
Hello @forgedhallpass , |
This PR aims to improve client caching strategy for javascript csrf client.
Context :
In our usage, we inject the script on pages using a ServletFilter that build the <script> and add it in the outgoing html. At that time, we have session information about user which query the page and we can decide a particular client side caching strategy for the csrf javascript client code using a watermark (tag) in the URL. That tag is based on the MD5 of the JS generated for that particular client and can then be cached during the session.
If anything changes in the JS (including CSRF master token) the link won't be the same and not retrieved from browser cache.
The JavaScript servlet has been modified to take into consideration that query param (tag) and include a specific client cache header for that purpose.
When param is not used, the servlet now include a ETag with a must revalidate strategy that will compare existing client side ETag avoiding, in case of same hash, to send again the content but a 304 response status code.
Modifications are mainly :