[PATCH] mgr/dashboard: fix improper URL checking
authorErnesto Puerta <epuertat@redhat.com>
Wed, 15 Jan 2020 12:54:26 +0000 (13:54 +0100)
committerBernd Zeimetz <bzed@debian.org>
Sat, 18 Jan 2020 18:58:32 +0000 (18:58 +0000)
This change disables up-level references beyond the HTTP base directory.
[CVE-2020-1699]

Fixes: https://tracker.ceph.com/issues/43607
Signed-off-by: Ernesto Puerta <epuertat@redhat.com>
Gbp-Pq: Name 0443e40c11280ba3b7efcba61522afa70c4f8158.patch

src/pybind/mgr/dashboard/controllers/home.py
src/pybind/mgr/dashboard/tests/test_home.py

index df11340934c003f77edbc057e7411fedfc4d5092..82ad945d0b00c9e682cedfc3084d33e0d823f728 100644 (file)
@@ -100,6 +100,11 @@ class HomeController(BaseController):
 
         base_dir = self._language_dir(langs)
         full_path = os.path.join(base_dir, path)
+
+        # Block uplevel attacks
+        if not os.path.normpath(full_path).startswith(os.path.normpath(base_dir)):
+            raise cherrypy.HTTPError(403)  # Forbidden
+
         logger.debug("serving static content: %s", full_path)
         if 'Vary' in cherrypy.response.headers:
             cherrypy.response.headers['Vary'] = "{}, Accept-Language"
index 341762572aaa0f4f1f844d9a0c2a1ff6fb9d557b..14f6c90ebfdbbfea007f40def555429b5627d59b 100644 (file)
@@ -31,3 +31,8 @@ class HomeTest(ControllerTestCase):
         self.assertStatus(200)
         logger.info(self.body)
         self.assertIn('<html lang="en">', self.body.decode('utf-8'))
+
+    def test_home_uplevel_check(self):
+        self._get('/../../../../../../etc/shadow')
+        self.assertStatus(403)
+