Skip to content

Commit 9588cdb

Browse files
SeanMooneyElod Illes
authored andcommitted
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+. Conflicts: nova/tests/unit/console/test_websocketproxy.py NOTE: conflict is due to I58b0382c86d4ef798572edb63d311e0e3e6937bb is missing in Victoria and Ie36401c782f023d1d5f2623732619105dc2cfa24 backport contained conflicts and methods order was swapped. Change-Id: I95f68be76330ff09e5eabb5ef8dd9a18f5547866 co-authored-by: Matteo Pozza Closes-Bug: #1927677 (cherry picked from commit 6fbd0b7) (cherry picked from commit 47dad48)
1 parent 1eceeeb commit 9588cdb

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
@@ -290,14 +290,9 @@ def send_head(self):
290290
if os.path.isdir(path):
291291
parts = urlparse.urlsplit(self.path)
292292
if not parts.path.endswith('/'):
293-
# redirect browser - doing basically what apache does
294-
new_parts = (parts[0], parts[1], parts[2] + '/',
295-
parts[3], parts[4])
296-
new_url = urlparse.urlunsplit(new_parts)
297-
298293
# Browsers interpret "Location: //uri" as an absolute URI
299294
# like "http://URI"
300-
if new_url.startswith('//'):
295+
if self.path.startswith('//'):
301296
self.send_error(HTTPStatus.BAD_REQUEST,
302297
"URI must not start with //")
303298
return None

nova/tests/unit/console/test_websocketproxy.py

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

663+
def test_reject_open_redirect_3_slashes(self):
664+
# This will test the behavior when an attempt is made to cause an open
665+
# redirect. It should be rejected.
666+
mock_req = mock.MagicMock()
667+
mock_req.makefile().readline.side_effect = [
668+
b'GET ///example.com/%2F.. HTTP/1.1\r\n',
669+
b''
670+
]
671+
672+
# Collect the response data to verify at the end. The
673+
# SimpleHTTPRequestHandler writes the response data by calling the
674+
# request socket sendall() method.
675+
self.data = b''
676+
677+
def fake_sendall(data):
678+
self.data += data
679+
680+
mock_req.sendall.side_effect = fake_sendall
681+
682+
client_addr = ('8.8.8.8', 54321)
683+
mock_server = mock.MagicMock()
684+
# This specifies that the server will be able to handle requests other
685+
# than only websockets.
686+
mock_server.only_upgrade = False
687+
688+
# Constructing a handler will process the mock_req request passed in.
689+
websocketproxy.NovaProxyRequestHandler(
690+
mock_req, client_addr, mock_server)
691+
692+
# Verify no redirect happens and instead a 400 Bad Request is returned.
693+
self.data = self.data.decode()
694+
self.assertIn('Error code: 400', self.data)
695+
self.assertIn('Message: URI must not start with //', self.data)
696+
663697
@mock.patch('websockify.websocketproxy.select_ssl_version')
664698
def test_ssl_min_version_is_not_set(self, mock_select_ssl):
665699
websocketproxy.NovaWebSocketProxy()

0 commit comments

Comments
 (0)