-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Redact sensitive duplicate query parameter values in ApiServlet logs #13677
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
Open
dheeraj12347
wants to merge
1
commit into
apache:4.20
Choose a base branch
from
dheeraj12347:fix-redact-sensitive-duplicate-params-4.20
base: 4.20
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+60
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.servlet.ServletConfig; | ||
|
|
@@ -78,7 +79,19 @@ public class ApiServlet extends HttpServlet { | |
| protected static Logger LOGGER = LogManager.getLogger(ApiServlet.class); | ||
| private static final Logger ACCESSLOGGER = LogManager.getLogger("apiserver." + ApiServlet.class.getName()); | ||
| private static final String REPLACEMENT = "_"; | ||
| private static final String LOGGER_REPLACEMENTS = "[\n\r\t]"; | ||
| private static final String REDACTED = "REDACTED"; | ||
| private static final String LOGGER_REPLACEMENTS = "[\n\r\t]"; | ||
|
|
||
| private static final Set<String> SENSITIVE_PARAMETER_KEYWORDS = Set.of( | ||
| "password", | ||
| "privatekey", | ||
| "accesskey", | ||
| "secretkey", | ||
| "apikey", | ||
| "signature", | ||
| "sessionkey", | ||
| "token" | ||
| ); | ||
|
|
||
| @Inject | ||
| ApiServerService apiServer; | ||
|
|
@@ -161,12 +174,32 @@ private void checkSingleQueryParameterValue(Map<String, String[]> params) { | |
| params.forEach((k, v) -> { | ||
| if (v.length > 1) { | ||
| String message = String.format("Query parameter '%s' has multiple values %s. Only the last value will be respected." + | ||
| "It is advised to pass only a single parameter", k, Arrays.toString(v)); | ||
| "It is advised to pass only a single parameter", k, formatValuesForLog(k, v)); | ||
| LOGGER.warn(message); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| static boolean isSensitiveParameter(String parameterName) { | ||
| if (parameterName == null) { | ||
| return false; | ||
| } | ||
|
|
||
| String lowerCaseParameter = parameterName.toLowerCase(); | ||
| return SENSITIVE_PARAMETER_KEYWORDS.stream() | ||
| .anyMatch(lowerCaseParameter::contains); | ||
| } | ||
|
|
||
| static String formatValuesForLog(String parameterName, String[] values) { | ||
| if (!isSensitiveParameter(parameterName)) { | ||
| return Arrays.toString(values); | ||
| } | ||
|
|
||
| String[] masked = new String[values.length]; | ||
| Arrays.fill(masked, REDACTED); | ||
| return Arrays.toString(masked); | ||
| } | ||
|
Comment on lines
+191
to
+201
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent is off for this bit as well |
||
|
|
||
| void processRequestInContext(final HttpServletRequest req, final HttpServletResponse resp) { | ||
| InetAddress remoteAddress = null; | ||
| try { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
indent seems off