-
Notifications
You must be signed in to change notification settings - Fork 265
KNOX-3039 Add error message sanitization to GatewayServlet #914
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
Conversation
gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java
Outdated
Show resolved
Hide resolved
gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java
Outdated
Show resolved
Hide resolved
gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java
Outdated
Show resolved
Hide resolved
gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java
Outdated
Show resolved
Hide resolved
gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
Outdated
Show resolved
Hide resolved
gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java
Outdated
Show resolved
Hide resolved
moresandeep
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
|
It would be nice to have a 4xx and 5xx page for errors. So instead of showing the ugly page with an exception we can show a custom page with a UUID corresponding the the error. This UUID would be the request-id for which the error is thrown so we can cross reference it in the logs. Just a though :) can be a new feature. |
|
@moresandeep I think that is a great idea! I will start a discussion on the Apache mailing list to explore implementing custom 4xx and 5xx error pages. |
|
@pzampino @moresandeep I implemented the But maybe I am overthinking things and overengineering. What do y'all think? Is it fine? |
gateway-server/src/main/java/org/apache/knox/gateway/SanitizedException.java
Show resolved
Hide resolved
| private <T extends Exception> T logAndSanitizeException(Exception e) throws T { | ||
| LOG.failedToExecuteFilter(e); | ||
| throw (T) sanitizeException(e); | ||
| return new SanitizedException(sanitizedMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not perform the message sanitization in the SanitizationException class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pzampino There are some downsides in moving the logic over to the SanitizationException class. It makes the code less flexible and potentially harder to maintain (e.g. what if other classes want to throw a SanitizedException but with different logic?). It's also a bit of an effort to refactor the tests. We haven't decided yet that this pattern is better than keeping the original Exception type (see my previous comment). Finally, but less important IMO, moving the logic over to SanitizedException can be seen as a violation of the Single Responsibility Principle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I agree about the Single Responsibility Principle. What is the responsibility of the SanitizationException if not to provide a sanitized the message? Otherwise, the burden of message sanitization is on all entities that throw it, AND there is no guarantee that a thrower will have sanitized the message.
If there is a need to customize the sanitization, IMO that is what extensions are for. Nothing would prevent the subsequent creation of classes that extends SanitizationException to override the sanitizing logic.
Personally, I don't think level of effort for refactoring counts for much in these types of decisions, especially refactoring of test code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pzampino Yeah, I am bummed that I didn't receive any feedback on the tests. This class had none until I wrote some. Refactoring could mean I need tests on both classes, and since we didn't discuss whether this new pattern is actually better than the old one, it seems like wasted work. Feel free to commit a patch if you can. I am going to be a bit busy with some other work over the next couple of weeks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pzampino The Single Responsibility Principle would be violated because it would make the SanitizedException class responsible for both defining an exception and performing sanitization logic, thus giving it more than one reason to change.
Unless the servlet engine treats them differently in some meaningful way, I think it's ok, so long as the exception does not get lost entirely, which in this case, it does not. |
|
Cloned and updated in #1062 . |
What changes were proposed in this pull request?
This pull request introduces a mechanism to sanitize error messages in the
GatewayServletto improve security by hiding IP addresses from exception messages. The following changes were made:isErrorMessageSanitizationEnabledflag to theGatewayServletto control whether error messages should be sanitized.sanitizeExceptionandsanitizeAndRethrowmethods inGatewayServletto handle exception sanitization.GatewayConfiginterface and its implementationGatewayConfigImplto include a new methodisErrorMessageSanitizationEnabled.GatewayServletTestclass to parameterize tests for scenarios where sanitization is enabled and disabled.How was this patch tested?
This patch was tested using the following methods:
GatewayServletTestto cover both scenarios where error message sanitization is enabled and disabled.Test steps:
GatewayServletTestto check for sanitized and non-sanitized error messages.