diff --git a/nova/console/websocketproxy.py b/nova/console/websocketproxy.py index b5e66f563f..4f2e264c50 100644 --- a/nova/console/websocketproxy.py +++ b/nova/console/websocketproxy.py @@ -19,7 +19,9 @@ Leverages websockify.py by Joel Martin ''' import copy +from http import HTTPStatus from http import cookies as Cookie +import os import socket import sys from urllib import parse as urlparse @@ -280,6 +282,28 @@ class NovaProxyRequestHandler(websockify.ProxyRequestHandler): def socket(self, *args, **kwargs): return websockifyserver.WebSockifyServer.socket(*args, **kwargs) + def send_head(self): + # This code is copied from this example patch: + # https://bugs.python.org/issue32084#msg306545 + path = self.translate_path(self.path) + f = None + if os.path.isdir(path): + parts = urlparse.urlsplit(self.path) + if not parts.path.endswith('/'): + # redirect browser - doing basically what apache does + new_parts = (parts[0], parts[1], parts[2] + '/', + parts[3], parts[4]) + new_url = urlparse.urlunsplit(new_parts) + + # Browsers interpret "Location: //uri" as an absolute URI + # like "http://URI" + if new_url.startswith('//'): + self.send_error(HTTPStatus.BAD_REQUEST, + "URI must not start with //") + return None + + return websockifyserver.SimpleHTTPRequestHandler.send_head(self) + class NovaWebSocketProxy(websockify.WebSocketProxy): def __init__(self, *args, **kwargs):