Use X-Forwarded-Proto as origin protocol if present

Closes-Bug: #1970083
Change-Id: I88c90bbf03b2b7c5f816926c124ec049d9d82b4f
This commit is contained in:
caowei 2022-04-24 15:36:25 +08:00
parent 2e8825a05f
commit 40491ef82f
1 changed files with 7 additions and 0 deletions

View File

@ -283,6 +283,13 @@ class ZunProxyRequestHandlerBase(object):
origin = urlparse.urlparse(origin_url)
origin_hostname = origin.hostname
origin_scheme = origin.scheme
# If the console connection was forwarded by a proxy (example:
# haproxy), the original protocol could be contained in the
# X-Forwarded-Proto header instead of the Origin header. Prefer the
# forwarded protocol if it is present.
forwarded_proto = self.headers.get('X-Forwarded-Proto')
if forwarded_proto is not None:
origin_scheme = forwarded_proto
if origin_hostname == '' or origin_scheme == '':
detail = _("Origin header not valid.")
raise exception.ValidationError(detail)