From 8367a8fae19bb883747a8fecfa3b00d022513104 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Tue, 3 Dec 2013 15:42:38 -0800 Subject: [PATCH] CLOUDSTACK-5355: addImageStore should not log password in clear text in the log. --- .../lifecycle/CloudStackImageStoreLifeCycleImpl.java | 6 ++++-- utils/src/com/cloud/utils/StringUtils.java | 4 ++-- utils/test/com/cloud/utils/StringUtilsTest.java | 12 ++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java index d6448785a93..65a40188e47 100644 --- a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java +++ b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java @@ -26,6 +26,8 @@ import javax.inject.Inject; import org.apache.log4j.Logger; +import com.ibm.wsdl.util.StringUtils; + import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; @@ -84,13 +86,13 @@ public class CloudStackImageStoreLifeCycleImpl implements ImageStoreLifeCycle { DataStoreRole role = (DataStoreRole) dsInfos.get("role"); Map details = (Map) dsInfos.get("details"); - s_logger.info("Trying to add a new data store at " + url + " to data center " + dcId); + s_logger.info("Trying to add a new data store at " + StringUtils.cleanString(url) + " to data center " + dcId); URI uri = null; try { uri = new URI(UriUtils.encodeURIComponent(url)); if (uri.getScheme() == null) { - throw new InvalidParameterValueException("uri.scheme is null " + url + ", add nfs:// (or cifs://) as a prefix"); + throw new InvalidParameterValueException("uri.scheme is null " + StringUtils.cleanString(url) + ", add nfs:// (or cifs://) as a prefix"); } else if (uri.getScheme().equalsIgnoreCase("nfs")) { if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) { diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java index 948c0ac4c37..7aafff1b7a1 100644 --- a/utils/src/com/cloud/utils/StringUtils.java +++ b/utils/src/com/cloud/utils/StringUtils.java @@ -157,8 +157,8 @@ public class StringUtils { return sb.toString(); } - // removes a password request param and it's value - private static final Pattern REGEX_PASSWORD_QUERYSTRING = Pattern.compile("&?(password|accesskey|secretkey)=.*?(?=[&'\"])"); + // removes a password request param and it's value, also considering password is in query parameter value which has been url encoded + private static final Pattern REGEX_PASSWORD_QUERYSTRING = Pattern.compile("(&|%26)?(password|accesskey|secretkey)(=|%3D).*?(?=(%26|[&'\"]))"); // removes a password/accesskey/ property from a response json object private static final Pattern REGEX_PASSWORD_JSON = Pattern.compile("\"(password|accesskey|secretkey)\":\".*?\",?"); diff --git a/utils/test/com/cloud/utils/StringUtilsTest.java b/utils/test/com/cloud/utils/StringUtilsTest.java index ae37c24f991..cc22f9db7a9 100644 --- a/utils/test/com/cloud/utils/StringUtilsTest.java +++ b/utils/test/com/cloud/utils/StringUtilsTest.java @@ -16,9 +16,9 @@ // under the License. package com.cloud.utils; -import org.junit.Test; import static org.junit.Assert.assertEquals; -import com.cloud.utils.StringUtils; + +import org.junit.Test; public class StringUtilsTest { @Test @@ -71,6 +71,14 @@ public class StringUtilsTest { assertEquals(result, expected); } + @Test + public void testCleanPasswordFromEncodedRequestString() { + String input = "name=SS1&provider=SMB&zoneid=5a60af2b-3025-4f2a-9ecc-8e33bf2b94e3&url=cifs%3A%2F%2F10.102.192.150%2FSMB-Share%2Fsowmya%2Fsecondary%3Fuser%3Dsowmya%26password%3DXXXXX%40123%26domain%3DBLR"; + String expected = "name=SS1&provider=SMB&zoneid=5a60af2b-3025-4f2a-9ecc-8e33bf2b94e3&url=cifs%3A%2F%2F10.102.192.150%2FSMB-Share%2Fsowmya%2Fsecondary%3Fuser%3Dsowmya%26domain%3DBLR"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + @Test public void testCleanPasswordFromRequestStringWithMultiplePasswords() { String input = "username=foo&password=bar&url=foobar&password=bar2&test=4";