Skip to content

Minified JavaScript file (csrfguard.min.js) behaves differently than non-minified version (csrfguard.js) #341

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

Open
nwaldispuehl opened this issue Apr 17, 2025 · 0 comments · May be fixed by #342

Comments

@nwaldispuehl
Copy link

nwaldispuehl commented Apr 17, 2025

Describe the bug
After upgrading from version 4.4.0-jakarta to 4.5.0-jakarta of the org.owasp:csrfguard library, we suddenly encountered an error 400 dialog in our web application:

Image

The actual error read:

This endpoint should not be invoked if the Token-Per-Page functionality is disabled!

It is caused by the javascript invoking a xhr POST connection:

Image

Our settings include:

org.owasp.csrfguard.TokenPerPage = false

In the non-minified version of the JS (csrfguard.js), this block (line 730ff) is not executed with our settings:

            if ('%TOKENS_PER_PAGE%') {
                let pageTokenRequestCallback = function (receivedPageTokens) {
                    pageTokenWrapper.pageTokens = receivedPageTokens;

                    pageTokenWrapper.pageTokensLoaded = true;

                    if (isLoadedWrapper.isDomContentLoaded) {
                        injectTokens(tokenName, masterTokenValue, receivedPageTokens);
                    }
                };

                requestPageTokens(tokenName, masterTokenValue, pageTokenRequestCallback);
            } else {

It appears as if in the minified version csrfguard.min.js this somehow gets executed, as the requestPageTokens method (which performs this xhr POST request) is called.

If we switch back to the non-minified version with this setting, it works again as expected (that is, without error dialog):

org.owasp.csrfguard.JavascriptServlet.sourceFile = META-INF/csrfguard.js

It would be cool if we could use the minified version. Would you like to have a look at the minification process/settings?

@nwaldispuehl nwaldispuehl linked a pull request Apr 21, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant