Open
Description
Describe the bug
When trace logging is active a simple GET request that does not require CSRF protection logs the following:
Did not protect against CSRF since request did not match CsrfNotRequired [TRACE, HEAD, GET, OPTIONS]
But it is indeed a GET request.
To Reproduce
Enable spring security, use trace level logging, perform GET request.
Expected behavior
Log message should state the correct condition.
Sample
Problem is in
The logic
if (!this.requireCsrfProtectionMatcher.matches(request)) {
if (this.logger.isTraceEnabled()) {
this.logger.trace("Did not protect against CSRF since request did not match "
+ this.requireCsrfProtectionMatcher);
}
filterChain.doFilter(request, response);
return;
}
matches the intended log message, but the log message uses the toString method of DefaultRequiresCsrfMatcher
which references allowed methods and the matcher again negates the condition, leading to a mismatch between output and behaviour.
@Override
public String toString() {
return "CsrfNotRequired " + this.allowedMethods;
}