mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
bug 11973: Escape VM name to prevent from XSS attack. Reviewed-by: Alex huang
This commit is contained in:
parent
a7ac3d577a
commit
c3eba2933e
@ -248,7 +248,7 @@ public class ConsoleProxyServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("<html><title>").append(vmName).append("</title><frameset><frame src=\"").append(composeConsoleAccessUrl(rootUrl, vm, host));
|
||||
sb.append("<html><title>").append(escapeHTML(vmName)).append("</title><frameset><frame src=\"").append(composeConsoleAccessUrl(rootUrl, vm, host));
|
||||
sb.append("\"></frame></frameset></html>");
|
||||
sendResponse(resp, sb.toString());
|
||||
}
|
||||
@ -554,4 +554,23 @@ public class ConsoleProxyServlet extends HttpServlet {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final String escapeHTML(String content){
|
||||
if(content == null || content.isEmpty())
|
||||
return content;
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < content.length(); i++) {
|
||||
char c = content.charAt(i);
|
||||
switch (c) {
|
||||
case '<': sb.append("<"); break;
|
||||
case '>': sb.append(">"); break;
|
||||
case '&': sb.append("&"); break;
|
||||
case '"': sb.append("""); break;
|
||||
case ' ': sb.append(" ");break;
|
||||
default: sb.append(c); break;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user