risdenk commented on a change in pull request #70: KNOX-1817 - Fix XSS issues 
with Alias API
URL: https://github.com/apache/knox/pull/70#discussion_r264872448
 
 

 ##########
 File path: 
gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/AliasResource.java
 ##########
 @@ -100,15 +105,20 @@ public Response postAlias(@PathParam("topology") final 
String topology,
     final AliasService as = getAliasService();
 
     try {
+      /* check if the string is properly encoded and expect encoded values */
+      topology = URLDecoder.decode(topology, StandardCharsets.UTF_8.name());
+      alias = URLDecoder.decode(alias, StandardCharsets.UTF_8.name());
+      value = URLDecoder.decode(value, StandardCharsets.UTF_8.name());
+
       as.addAliasForCluster(topology, alias, value);
       return status(Response.Status.CREATED).
-          entity("{ \"created\" : { \"topology\": \"" + topology
-              + "\", \"alias\": \"" + alias + "\" } }").
+          entity("{ \"created\" : { \"topology\": \"" + 
Encode.forHtml(topology)
+              + "\", \"alias\": \"" + Encode.forHtml(alias) + "\" } }").
           type(MediaType.APPLICATION_JSON_TYPE).
           build();
-    } catch (AliasServiceException e) {
+    } catch (AliasServiceException | UnsupportedEncodingException e) {
       return status(INTERNAL_SERVER_ERROR).
-          entity("Error adding alias " + alias + " for cluster " + topology
+          entity("Error adding alias " + Encode.forHtml(alias) + " for cluster 
" + Encode.forHtml(topology)
               + ", reason: " + e.toString()).
 
 Review comment:
   Will the e.toString() potentially print the value of the alias from line 111 
on a decoding error?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to