gwtupload icon indicating copy to clipboard operation
gwtupload copied to clipboard

XML escaping and unescaping not properly handled

Open cinlloc opened this issue 8 years ago • 1 comments

Problem discovered by attempting XSS injection on UploadAction:

  • [SERVER SIDE, UploadAction.java] When creating XML error message, XML entities are not escaped:
postResponse = "<" + TAG_ERROR + ">" + error + "</" + TAG_ERROR + ">";
  • [CLIENT SIDE, Uploader.java] When receiving XML error message from server, strange and uncomplete unescaping is done:
serverRawResponse = serverRawResponse.replace(TAG_MSG_LT, "<").replace(TAG_MSG_GT, ">").replace("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&nbsp;", " ");

Suggestions:

  • There should be a proper StringEscapeUtils.escapeXml in the first place.
  • serverRawResponse shouldn't be unescaped, because serverRawResponse will be parsed as XML.
  • Text extracted from parsed serverRawResponse should be unescape only if needed (i.e. if used in a javascript popup). For example, should unescape msg here (BaseUploadStatus.java):
/* (non-Javadoc)
   * @see gwtupload.client.IUploadStatus#setError(java.lang.String)
   */
  public void setError(String msg) {
    setStatus(Status.ERROR);
    Window.alert(msg.replaceAll("\\\\n", "\\n"));
  }

cinlloc avatar May 09 '16 13:05 cinlloc

Can be closed

csware avatar Feb 14 '21 16:02 csware