Skip to content

Commit b0b2fd4

Browse files
Likitha ShettyPrachi Damle
authored andcommitted
CLOUDSTACK-1125: [EC2 Query API] Permission denied exception when a parameter value contains space
Convert space characters in the parameters to %20 while forming a query string after url-encode because java.net.URLEncoder performs application/x-www-form-urlencoded-type encoding and not percent-encoding. According to RFC 3986 as required by Amazon, we need to percent-encode.
1 parent c26b02a commit b0b2fd4

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

awsapi/src/com/cloud/bridge/service/EC2RestServlet.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,10 +1899,14 @@ private boolean authenticateRequest( HttpServletRequest request, HttpServletResp
18991899
String paramName = (String) params.nextElement();
19001900
// exclude the signature string obviously. ;)
19011901
if (paramName.equalsIgnoreCase("Signature")) continue;
1902+
// URLEncoder performs application/x-www-form-urlencoded-type encoding and not Percent encoding
1903+
// according to RFC 3986 as required by Amazon, we need to Percent-encode (URL Encode)
1904+
String encodedValue = URLEncoder.encode(request.getParameter(paramName), "UTF-8")
1905+
.replace("+", "%20").replace("*", "%2A");
19021906
if (queryString == null)
1903-
queryString = paramName + "=" + URLEncoder.encode(request.getParameter(paramName), "UTF-8");
1907+
queryString = paramName + "=" + encodedValue;
19041908
else
1905-
queryString = queryString + "&" + paramName + "=" + URLEncoder.encode(request.getParameter(paramName), "UTF-8");
1909+
queryString = queryString + "&" + paramName + "=" + encodedValue;
19061910
}
19071911
}
19081912
}

0 commit comments

Comments
 (0)