Skip to content

Commit 6fbd0b7

Browse files
committed
address open redirect with 3 forward slashes
Ie36401c782f023d1d5f2623732619105dc2cfa24 was intended to address OSSA-2021-002 (CVE-2021-3654) however after its release it was discovered that the fix only worked for urls with 2 leading slashes or more then 4. This change adresses the missing edgecase for 3 leading slashes and also maintian support for rejecting 2+. Change-Id: I95f68be76330ff09e5eabb5ef8dd9a18f5547866 co-authored-by: Matteo Pozza Closes-Bug: #1927677
1 parent 10b1dc8 commit 6fbd0b7

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

nova/console/websocketproxy.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,9 @@ def send_head(self):
280280
if os.path.isdir(path):
281281
parts = urlparse.urlsplit(self.path)
282282
if not parts.path.endswith('/'):
283-
# redirect browser - doing basically what apache does
284-
new_parts = (parts[0], parts[1], parts[2] + '/',
285-
parts[3], parts[4])
286-
new_url = urlparse.urlunsplit(new_parts)
287-
288283
# Browsers interpret "Location: //uri" as an absolute URI
289284
# like "http://URI"
290-
if new_url.startswith('//'):
285+
if self.path.startswith('//'):
291286
self.send_error(HTTPStatus.BAD_REQUEST,
292287
"URI must not start with //")
293288
return None

nova/tests/unit/console/test_websocketproxy.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,40 @@ def fake_sendall(data):
622622
self.assertIn('Error code: 400', self.data)
623623
self.assertIn('Message: URI must not start with //', self.data)
624624

625+
def test_reject_open_redirect_3_slashes(self):
626+
# This will test the behavior when an attempt is made to cause an open
627+
# redirect. It should be rejected.
628+
mock_req = mock.MagicMock()
629+
mock_req.makefile().readline.side_effect = [
630+
b'GET ///example.com/%2F.. HTTP/1.1\r\n',
631+
b''
632+
]
633+
634+
# Collect the response data to verify at the end. The
635+
# SimpleHTTPRequestHandler writes the response data by calling the
636+
# request socket sendall() method.
637+
self.data = b''
638+
639+
def fake_sendall(data):
640+
self.data += data
641+
642+
mock_req.sendall.side_effect = fake_sendall
643+
644+
client_addr = ('8.8.8.8', 54321)
645+
mock_server = mock.MagicMock()
646+
# This specifies that the server will be able to handle requests other
647+
# than only websockets.
648+
mock_server.only_upgrade = False
649+
650+
# Constructing a handler will process the mock_req request passed in.
651+
websocketproxy.NovaProxyRequestHandler(
652+
mock_req, client_addr, mock_server)
653+
654+
# Verify no redirect happens and instead a 400 Bad Request is returned.
655+
self.data = self.data.decode()
656+
self.assertIn('Error code: 400', self.data)
657+
self.assertIn('Message: URI must not start with //', self.data)
658+
625659
@mock.patch('nova.objects.ConsoleAuthToken.validate')
626660
def test_no_compute_rpcapi_with_invalid_token(self, mock_validate):
627661
"""Tests that we don't create a ComputeAPI object until we actually

0 commit comments

Comments
 (0)