Skip to content

Redact sensitive duplicate query parameter values in ApiServlet logs - #13677

Open
dheeraj12347 wants to merge 2 commits into
apache:4.20from
dheeraj12347:fix-redact-sensitive-duplicate-params-4.20
Open

Redact sensitive duplicate query parameter values in ApiServlet logs#13677
dheeraj12347 wants to merge 2 commits into
apache:4.20from
dheeraj12347:fix-redact-sensitive-duplicate-params-4.20

Conversation

@dheeraj12347

@dheeraj12347 dheeraj12347 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Description

This PR manually backports the fix from #13559 to the 4.20 LTS branch.

Changes

  • Redact duplicate values for sensitive query parameters before logging in ApiServlet.
  • Add helper methods to identify sensitive parameters and format logged values.
  • Backport the corresponding unit tests.

This backport includes the changes applicable to the 4.20 branch.

Fixes #13311

@dheeraj12347

Copy link
Copy Markdown
Contributor Author

@DaanHoogland

As discussed in #13559, this is the manual backport of the fix for the 4.20 LTS branch.

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some linting but clgtm still

Comment on lines +82 to +94
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"
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

indent seems off

Comment on lines +191 to +201
}

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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

indent is off for this bit as well

@DaanHoogland

Copy link
Copy Markdown
Contributor

@dheeraj12347 , you should not have to open a new PR (next time) just rebase your fix with git rebase --onto <new branch> <old base>

I think we can close the one on main now and it looks like it won’t give major conflicts when merging forwards.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.42105% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.35%. Comparing base (e8df87e) to head (e9a1890).
⚠️ Report is 35 commits behind head on 4.20.

Files with missing lines Patch % Lines
server/src/main/java/com/cloud/api/ApiServer.java 0.00% 3 Missing ⚠️
server/src/main/java/com/cloud/api/ApiServlet.java 81.25% 2 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
uitests 4.14% <ø> (-0.01%) ⬇️
unittests 17.21% <68.42%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dheeraj12347

Copy link
Copy Markdown
Contributor Author

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 smoke/test_network_permissions job, which is failing while creating an IPv6 network because the zone has no IPv6 DNS configured. This appears unrelated to the ApiServlet change. Could you please take a look when you get a chance and let me know if anything else is needed from my side?

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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if(parameterMap.putIfAbsent(param.getName(), new String[]{param.getValue()}) != null) {
String message = String.format("Query parameter '%s' has multiple values [%s, %s]. Only the last value will be respected." +
"It is advised to pass only a single parameter", param.getName(), param.getValue(), parameterMap.get(param.getName()));
logger.warn(StringUtils.cleanString(message));
}
}

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 ?

@harikrishna-patnala harikrishna-patnala moved this from Ready to In review in CloudStack Testing Sep 7, 2026
@harikrishna-patnala harikrishna-patnala moved this from In review to conflict/waiting in CloudStack Testing Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: conflict/waiting

Development

Successfully merging this pull request may close these issues.

3 participants