Redact sensitive duplicate query parameter values in ApiServlet logs - #13677
Redact sensitive duplicate query parameter values in ApiServlet logs#13677dheeraj12347 wants to merge 2 commits into
Conversation
|
As discussed in #13559, this is the manual backport of the fix for the 4.20 LTS branch. |
DaanHoogland
left a comment
There was a problem hiding this comment.
some linting but clgtm still
| 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" | ||
| ); |
| } | ||
|
|
||
| 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); | ||
| } |
There was a problem hiding this comment.
indent is off for this bit as well
|
@dheeraj12347 , you should not have to open a new PR (next time) just rebase your fix with I think we can close the one on main now and it looks like it won’t give major conflicts when merging forwards. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.20 #13677 +/- ##
============================================
+ Coverage 16.26% 16.35% +0.08%
- Complexity 13435 13578 +143
============================================
Files 5667 5669 +2
Lines 500731 501421 +690
Branches 60803 60907 +104
============================================
+ Hits 81430 81992 +562
- Misses 410197 410243 +46
- Partials 9104 9186 +82
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hi @DaanHoogland , I’ve closed #13559 as discussed and checked the CI run for the 4.20 backport #13677. The build, coverage, lint, Codecov and other checks are passing. The only remaining failure is the Simulator |
| 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( |
There was a problem hiding this comment.
cloudstack/server/src/main/java/com/cloud/api/ApiServer.java
Lines 554 to 559 in 02182a1
@dheeraj12347 there is another place with the same content exists and there it has already addressed with "cleanString()" method, which doesnot cover all the sensitive parameters you have listed. Can you please check if this can be fixed somehow.
There was a problem hiding this comment.
@harikrishna-patnala Addressed this by using ApiServlet.formatValuesForLog() in the ApiServer duplicate-parameter warning, so the same sensitive-parameter redaction is applied there as well. The existing cleanString() sanitization is still retained.
There was a problem hiding this comment.
thanks for the changes @dheeraj12347. I've tested it looks good from logic and logs point of view.
2026-09-08 06:25:35,022 WARN [c.c.a.ApiServlet] (qtp1404565079-346:[ctx-92464837]) (logid:4df39a1d) Query parameter 'password' has multiple values [REDACTED, REDACTED]. Only the last value will be respected.It is advised to pass only a single parameter
Can you please move these helper methods to StringUtils class ?
Description
This PR manually backports the fix from #13559 to the 4.20 LTS branch.
Changes
ApiServlet.This backport includes the changes applicable to the 4.20 branch.
Fixes #13311