Skip to content

Conversation

@ChristopherSchultz
Copy link
Contributor

The unit tests describe the problem: if a URL already contains a CSRF token and that URL is passed through HttpServletResponse.encode(Redirect)URL, then the URL will end up with multiple instances of a CSRF token.

This patch removes those extra instances should they exist.

@ChristopherSchultz
Copy link
Contributor Author

There is a bug in this code. For the URL /foo/bar?xcsrf=&xcsrf&xcsrf&xcsrf&xcsrf=abc&xcsrf= it will enter an infinite loop.

@ChristopherSchultz
Copy link
Contributor Author

It also will incorrectly identify parameters which end with the parameter name (e.g. xcsrf).

This fixes incorrect matching of parameters whose names *end with* the CSRF token name
The code is arguably easier to read
@ChristopherSchultz
Copy link
Contributor Author

All fixed with recent commits. Ready for review.

@rmaucher
Copy link
Contributor

Remove the commented out System.outs ;)


}

private static String dumbButAccurateCleanse(String url, String csrfParameterName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't handle /foo/bar?bar=fo?&csrf=abc correctly but the actual CSRF code does so not a big deal.

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 this pull request may close these issues.

3 participants