From: Nizamudeen A Date: Mon, 28 Aug 2023 05:15:28 +0000 (+0530) Subject: mgr/dashboard: allow CORS for unauthorized access X-Git-Tag: v19.0.0~593^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F53171%2Fhead;p=ceph.git mgr/dashboard: allow CORS for unauthorized access Fixes: https://tracker.ceph.com/issues/62612 Signed-off-by: Nizamudeen A --- diff --git a/src/pybind/mgr/dashboard/services/auth.py b/src/pybind/mgr/dashboard/services/auth.py index 8ae897cebd8d..f13963abffdd 100644 --- a/src/pybind/mgr/dashboard/services/auth.py +++ b/src/pybind/mgr/dashboard/services/auth.py @@ -183,6 +183,16 @@ class AuthManagerTool(cherrypy.Tool): if user: self._check_authorization(user.username) return + + resp_head = cherrypy.response.headers + req_head = cherrypy.request.headers + req_header_cross_origin_url = req_head.get('Access-Control-Allow-Origin') + cross_origin_urls = mgr.get_module_option('cross_origin_url', '') + cross_origin_url_list = [url.strip() for url in cross_origin_urls.split(',')] + + if req_header_cross_origin_url in cross_origin_url_list: + resp_head['Access-Control-Allow-Origin'] = req_header_cross_origin_url + self.logger.debug('Unauthorized access to %s', cherrypy.url(relative='server')) raise cherrypy.HTTPError(401, 'You are not authorized to access '