Skip to content

Commit

Permalink
mgr/dashboard: allow Origin for CORS if present in config `cross_orig…
Browse files Browse the repository at this point in the history
…in_url`

Signed-off-by: Avan Thakkar <[email protected]>
  • Loading branch information
avanthakkar committed Dec 8, 2022
1 parent 70a1011 commit 04cfd23
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pybind/mgr/dashboard/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,19 @@ def cors_tool(self):
resp_head = cherrypy.response.headers

# Always set response headers necessary for 'simple' CORS.
req_header_origin_url = req_head.get('Access-Control-Allow-Origin')
req_header_cross_origin_url = req_head.get('Access-Control-Allow-Origin')
cross_origin_urls = mgr.get_localized_module_option('cross_origin_url', '')
cross_origin_url_list = [url.strip() for url in cross_origin_urls.split(',')]
if req_header_origin_url in cross_origin_url_list:
resp_head['Access-Control-Allow-Origin'] = req_header_origin_url
if req_header_cross_origin_url in cross_origin_url_list:
resp_head['Access-Control-Allow-Origin'] = req_header_cross_origin_url
resp_head['Access-Control-Expose-Headers'] = 'GET, POST'
resp_head['Access-Control-Allow-Credentials'] = 'true'

# Non-simple CORS preflight request; short-circuit the normal handler.
if cherrypy.request.method == 'OPTIONS':
req_header_origin_url = req_head.get('Origin')
if req_header_origin_url in cross_origin_url_list:
resp_head['Access-Control-Allow-Origin'] = req_header_origin_url
ac_method = req_head.get('Access-Control-Request-Method', None)

allowed_methods = ['GET', 'POST']
Expand Down

0 comments on commit 04cfd23

Please sign in to comment.