Skip to content

Commit

Permalink
mgr/dashboard: fix cookie injection issue
Browse files Browse the repository at this point in the history
Fixes: CVE-2021-3509
Signed-off-by: Ernesto Puerta <[email protected]>
(cherry picked from commit b39922818bc57cde1b016e9ad41908b18063b93b)

Conflicts:
	src/pybind/mgr/dashboard/controllers/docs.py
        - Remove allow_empty_body and _with_token method
  • Loading branch information
epuertat authored and liewegas committed May 13, 2021
1 parent 9b8513d commit 7a1ca8d
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions src/pybind/mgr/dashboard/controllers/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import logging
import cherrypy

from . import Controller, BaseController, Endpoint, ENDPOINT_MAP, \
allow_empty_body
from . import Controller, BaseController, Endpoint, ENDPOINT_MAP
from .. import mgr

from ..tools import str_to_bool
Expand Down Expand Up @@ -371,31 +370,13 @@ def api_json(self):
def api_all_json(self):
return self._gen_spec(True, "/")

def _swagger_ui_page(self, all_endpoints=False, token=None):
def _swagger_ui_page(self, all_endpoints=False):
base = cherrypy.request.base
if all_endpoints:
spec_url = "{}/docs/api-all.json".format(base)
else:
spec_url = "{}/docs/api.json".format(base)

auth_header = cherrypy.request.headers.get('authorization')
auth_cookie = cherrypy.request.cookie['token']
jwt_token = ""
if auth_cookie is not None:
jwt_token = auth_cookie.value
elif auth_header is not None:
scheme, params = auth_header.split(' ', 1)
if scheme.lower() == 'bearer':
jwt_token = params
else:
if token is not None:
jwt_token = token

api_key_callback = """, onComplete: () => {{
ui.preauthorizeApiKey('jwt', '{}');
}}
""".format(jwt_token)

page = """
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -436,23 +417,16 @@ def _swagger_ui_page(self, all_endpoints=False, token=None):
SwaggerUIBundle.presets.apis
],
layout: "BaseLayout"
{}
}})
window.ui = ui
}}
</script>
</body>
</html>
""".format(spec_url, api_key_callback)
""".format(spec_url)

return page

@Endpoint(json_response=False)
def __call__(self, all_endpoints=False):
return self._swagger_ui_page(all_endpoints)

@Endpoint('POST', path="/", json_response=False,
query_params="{all_endpoints}")
@allow_empty_body
def _with_token(self, token, all_endpoints=False):
return self._swagger_ui_page(all_endpoints, token)

0 comments on commit 7a1ca8d

Please sign in to comment.