Skip to content

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

@nwaldispuehl

Description

@nwaldispuehl

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions