Skip to content

Introduce logs in RestCsrfPreventionFilter to improve troubleshooting.#452

Closed
PolinaGeorgieva wants to merge 1 commit intoapache:8.5.xfrom
PolinaGeorgieva:8.5.x
Closed

Introduce logs in RestCsrfPreventionFilter to improve troubleshooting.#452
PolinaGeorgieva wants to merge 1 commit intoapache:8.5.xfrom
PolinaGeorgieva:8.5.x

Conversation

@PolinaGeorgieva
Copy link

Add some logs in RestCsrfPreventionFilter that would improve troubleshooting in case of failed CSRF validation.
Note that the RequestUtil.filter method is used only to apply some basic sensitive characters filtering of the requested path.
But as this method is deprecated in v.8.5.x and removed in v.9.0.x, would you recommend an alternative method I could use in this case?

Copy link
Contributor

@ChristopherSchultz ChristopherSchultz left a comment

Choose a reason for hiding this comment

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

The PR looks good, but I have some suggestions for improvement.

Constants.CSRF_REST_NONCE_HEADER_REQUIRED_VALUE);
response.sendError(getDenyStatus(),
sm.getString("restCsrfPreventionFilter.invalidNonce"));
if (log.isErrorEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this should be logged at ERROR level, because an attacker could fill-up your logs just by repeatedly sending-in garbage. I would recommend using DEBUG log-level for this.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @ChristopherSchultz !

sm.getString("restCsrfPreventionFilter.invalidNonce"));
if (log.isErrorEnabled()) {
log.error("CSRF validation for REST failed! Request with method [" + request.getMethod() + "] and URI ["
+ RequestUtil.filter(request.getRequestURI())
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is a reason to use RequestUtil.filter() for this value; it's not going to be embedded in HTML so it's okay to use the value as-is.

}
storeNonceToResponse(response, Constants.CSRF_REST_NONCE_HEADER_NAME,
nonceFromSessionStr);
if (log.isDebugEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I might use TRACE, here.

String nonce = params[0];
for (String param : params) {
if (!Objects.equals(param, nonce)) {
if (log.isErrorEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same: use DEBUG not ERROR.

storeNonceToResponse(response, Constants.CSRF_REST_NONCE_HEADER_NAME,
nonceFromSessionStr);
if (log.isDebugEnabled()) {
log.debug("CSRF Fetch request is succesfully handled - nonce is added to the response."
Copy link
Member

Choose a reason for hiding this comment

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

successfully

Constants.CSRF_REST_NONCE_HEADER_REQUIRED_VALUE);
response.sendError(getDenyStatus(),
sm.getString("restCsrfPreventionFilter.invalidNonce"));
if (log.isErrorEnabled()) {
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @ChristopherSchultz !

@markt-asf
Copy link
Contributor

It has been 2 months and the requested changes have not been made. I made the changes and a number of other fixes and applied this manually.

@markt-asf markt-asf closed this Nov 25, 2021
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.

4 participants