CLOUDSTACK-5355: addImageStore should not log password in clear text in

the log.
This commit is contained in:
Min Chen 2013-12-03 15:42:38 -08:00
parent 1c4f1deaa8
commit f420b74890
3 changed files with 14 additions and 4 deletions

View File

@ -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<String, String> details = (Map<String, String>)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("")) {
throw new InvalidParameterValueException("Your host and/or path is wrong. Make sure it's of the format nfs://hostname/path");

View File

@ -152,8 +152,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)\":\".*?\",?");

View File

@ -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";