|
39 | 39 | import java.util.HashSet; |
40 | 40 | import java.util.Iterator; |
41 | 41 | import java.util.List; |
| 42 | +import java.util.Arrays; |
42 | 43 | import java.util.Map; |
43 | 44 | import java.util.Set; |
44 | 45 | import java.util.TimeZone; |
@@ -244,6 +245,12 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer |
244 | 245 | @Inject |
245 | 246 | private MessageBus messageBus; |
246 | 247 |
|
| 248 | + private static final Set<String> sensitiveFields = new HashSet<>(Arrays.asList( |
| 249 | + "password", "secretkey", "apikey", "token", |
| 250 | + "sessionkey", "accesskey", "signature", |
| 251 | + "authorization", "credential", "secret" |
| 252 | + )); |
| 253 | + |
247 | 254 | private static final ConfigKey<Integer> IntegrationAPIPort = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED |
248 | 255 | , Integer.class |
249 | 256 | , "integration.api.port" |
@@ -610,10 +617,23 @@ public String handleRequest(final Map params, final String responseType, final S |
610 | 617 | logger.error("invalid request, no command sent"); |
611 | 618 | if (logger.isTraceEnabled()) { |
612 | 619 | logger.trace("dumping request parameters"); |
613 | | - for (final Object key : params.keySet()) { |
614 | | - final String keyStr = (String)key; |
615 | | - final String[] value = (String[])params.get(key); |
616 | | - logger.trace(" key: " + keyStr + ", value: " + ((value == null) ? "'null'" : value[0])); |
| 620 | + |
| 621 | + for (final Object key : params.keySet()) { |
| 622 | + final String keyStr = (String) key; |
| 623 | + final String[] value = (String[]) params.get(key); |
| 624 | + |
| 625 | + String lowerKeyStr = keyStr.toLowerCase(); |
| 626 | + boolean isSensitive = sensitiveFields.stream() |
| 627 | + .anyMatch(lowerKeyStr::contains); |
| 628 | + |
| 629 | + String logValue; |
| 630 | + if (isSensitive) { |
| 631 | + logValue = "******"; // mask sensitive values |
| 632 | + } else { |
| 633 | + logValue = (value == null) ? "'null'" : value[0]; |
| 634 | + } |
| 635 | + |
| 636 | + logger.trace(" key: " + keyStr + ", value: " + logValue); |
617 | 637 | } |
618 | 638 | } |
619 | 639 | throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "Invalid request, no command sent"); |
|
0 commit comments